H49339 s 00117/00000/00000 d D 1.1 98/05/25 09:24:57 orc 2 1 c New html manpage for md5lib cC cK24531 cZ-00:00 e s 00000/00000/00000 d D 1.0 70/01/01 03:09:62 BK 1 0 c RCS to BitKeeper cBorc@india.pell.portland.or.us|ChangeSet|20000922002442|17918|777fbc9d629e3be4 cK00042 cPbasis/doc/md5.html cO-rw-rw-r-- cR66a28790706d5485 cT cV4 cX0x23 e u U f e 0 f x 0x23 t T I 2 MD5lib -- MD5 digital signature generation
Description
Functions
Example Code
Bugs
Author
Copyright
Notes

Description

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.

Functions

JH md5_init()
Set up for generating a md5 signature. If md5_init() succeeds, it returns a JH handle which you then use when generating the signature.
void md5_put(bfr, count, handle)
Add the signature for the bfr into the current md5 signature.
char* md5_finish(handle, sig)
Finish building the digital signature for the current handle. If the caller passes in a signature buffer, the signature will be written into that buffer and a pointer to it will be returned, otherwise md5_finish will use a local static array for the signature.

Example

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');
}

Bugs

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.)

Copyright

None. This code is in the public domain, and you may do with it as you wish.

Notes

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

Author

orc@pell.chi.il.us (David Parsons). E 2 I 1 E 1