#include "MD5.h"
void MD5_Init(c)
MD5_CTX *c;
void MD5_Update(c)
MD5_CTX *c;
unsigned char *data;
unsigned long len);
void MD5_Final(c)
unsigned char *md;
MD5_CTX *c;
unsigned char *MD5(d, n, md)
unsigned long n;
unsigned char *d, *md;
void MD5_Transform(c, b)
MD5_CTX *c;
unsigned char *b;
typedef struct MD5state_st { unsigned long A,B,C,D; unsigned long Nl,Nh; unsigned long data[MD5_LBLOCK]; int num; } MD5_CTX;
Since MD5 processes data in 16-byte blocks, the data subfield is used to keep 'leftover' data from one MD5_Update to the next, buffering it until the last of it is used with padding as needed during the MD5_Final call. The num subfield contains the length of data.
A, B, C and D are internal buffers used during the computation.
The other subfields keep information on the running hash.
MD5_Init() expects the caller to pass a pointer to a previously allocated MD5_CTX structure. It then initializes all subfields to 0 except for A, B, C, and D which get initialized according to the specs (see the RFC).
MD5_Update() expects len bytes of data to be hashed; the results are stored in the MD5_CTX c.
MD5_Final() provides a message digest of the data digested with MD5_Update(). The message digest is put in the md array and is MD5_DIGEST_LENGTH (16) bytes long. All subfields of the MD5_CTX c are set to zero before the routine returns.
MD5() is a convenience routine that calls MD5_Init(), MD5_Update() and then MD5_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:
MD5_Init(...); MD5_Update(...); ... MD5_Update(...); MD5_Final(...);
MD5_Transform does some endian conversions on b before calling the internal function md5_block. I don't see it used anywhere. Anybody know why it would be useful?