md5lib is a set of routines that let you generate md5 digital signatures for various things. It's set up somewhat like stdio -- you open a md5 connection, write data to it, then close it and are handed back a signature.
To generate a digital signature for whatever's on stdin:
/*
* compile with cc -o md5 md5.c -lbasis
*/
#include <stdio.h>
#include <md5lib.h>
main()
{
JH handle;
char bfr[512];
unsigned char *sig;
int siz, ix;
if ((handle = md5_init()) == 0) {
perror("md5_init");
exit(1);
}
while ((siz = read(fileno(0), bfr, sizeof bfr)) > 0)
md5_put(bfr, siz, handle);
sig = md5_finish(handle, 0);
for (ix = 0; ix < 16; ix++)
printf("%02x", sig[ix]);
putchar('\n');
}
There is a woeful lack of error checking. If you pass a bogus JH into md5_put or md5_finish, the function will most crash your program.
md5lib will silently return incorrect signatures for objects larger than 2^29 bytes (approximately 550 megabytes.)
None. This code is in the public domain, and you may do with it as you wish.
This code is written from the specification in RFC1321; it does not include code from the sample implementation there, or from any other source.
JH stands for John Hancock
orc@pell.chi.il.us (David Parsons).