#include "md2.h"
void MD2_Init(c)
MD2_CTX *c;
void MD2_Update(c)
MD2_CTX *c;
unsigned char *data;
unsigned long len);
void MD2_Final(c)
unsigned char *md;
MD2_CTX *c;
unsigned char *MD2(d, n, md)
unsigned long n;
unsigned char *d, *md;
char *MD2_options();
typedef struct MD2state_st { int num; unsigned char data[MD2_BLOCK]; MD2_INT cksm[MD2_BLOCK]; MD2_INT state[MD2_BLOCK]; } MD2_CTX;
Since MD2 processes data in 16-byte blocks, the data subfield is used to keep 'leftover' data from one MD2_Update to the next, buffering it until the last of it is used with padding as needed during the MD2_Final call. The num subfield contains the length of data.
The other subfields keep information on the running hash.
MD2_Init() expects the caller to pass a pointer to a previously allocated MD2_CTX structure. It then initializes all subfields to 0.
MD2_Update() expects len bytes of data to be hashed; the results are stored in the MD2_CTX c.
MD2_Final() provides a message digest of the data digested with MD2_Update(). The message digest is put in the md array and is MD2_DIGEST_LENGTH (16) bytes long. All subfields of the MD2_CTX c are set to zero before the routine returns.
MD2() is a convenience routine that calls MD2_Init(), MD2_Update() and then MD2_Final(). d should be a pointer to the data to be hashed and n should be the length in bytes of that data. If md is NULL, a static buffer will be used and a pointer to it returned to the caller. Otherwise the function returns a pointer to md which will contain the message digest.
If you prefer not to use the convenience routine, the functions may be called separately:
MD2_Init(...); MD2_Update(...); ... MD2_Update(...); MD2_Final(...);
MD2_options can be called to find out what sort of argument MD2 takes. Depending on the size MD2_INT (unsigned int), one of the two strings "md2(char)" or "md2(int)" is returned. This is used only in the timing tests, and in apps/version.c for informational purposes.