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