X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=md5.c;h=caaa5a68a2410c32aa939a89b0745bc3d422ef11;hb=7d52d0bd861c3aeaea5214131ef64543d63ea309;hp=343ad8fc893cdd29bbc208c74b7e044f7499d857;hpb=dfa6ab137e7565bd1afc03b045fff4aa737a7c9e;p=secnet.git diff --git a/md5.c b/md5.c index 343ad8f..caaa5a6 100644 --- a/md5.c +++ b/md5.c @@ -3,6 +3,7 @@ * The algorithm is due to Ron Rivest. This code was * written by Colin Plumb in 1993, no copyright is claimed. * This code is in the public domain; do with it what you wish. + * [I interpet this as a blanket permision -iwj.] * * Equivalent code is available from RSA Data Security, Inc. * This code has been tested against that, and is equivalent, @@ -237,14 +238,11 @@ MD5Transform(uint32_t buf[4], uint32_t const in[16]) #endif -static void *md5_init(void) +static void md5_init(void *sst) { - struct MD5Context *ctx; + struct MD5Context *ctx=sst; - ctx=safe_malloc(sizeof(*ctx),"md5_init"); MD5Init(ctx); - - return ctx; } static void md5_update(void *sst, const void *buf, int32_t len) @@ -259,7 +257,6 @@ static void md5_final(void *sst, uint8_t *digest) struct MD5Context *ctx=sst; MD5Final(digest,ctx); - free(ctx); } struct md5 { @@ -270,7 +267,6 @@ struct md5 { void md5_module(dict_t *dict) { struct md5 *st; - void *ctx; cstring_t testinput="12345\n"; uint8_t expected[16]= {0xd5,0x77,0x27,0x3f,0xf8,0x85,0xc3,0xf8, @@ -278,19 +274,21 @@ void md5_module(dict_t *dict) uint8_t digest[16]; int i; - st=safe_malloc(sizeof(*st),"md5_module"); + NEW(st); st->cl.description="md5"; st->cl.type=CL_HASH; st->cl.apply=NULL; st->cl.interface=&st->ops; - st->ops.len=16; + st->ops.hlen=16; + st->ops.slen=sizeof(struct MD5Context); st->ops.init=md5_init; st->ops.update=md5_update; st->ops.final=md5_final; dict_add(dict,"md5",new_closure(&st->cl)); - ctx=md5_init(); + uint8_t ctx[st->ops.slen]; + md5_init(ctx); md5_update(ctx,testinput,strlen(testinput)); md5_final(ctx,digest); for (i=0; i<16; i++) {