X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=sha1.c;h=a78345a55f6378dc51d1bb67b3e2dab4eb8d404f;hb=4d9d6e20e19c1aaa0d138e70897d136b36d673c0;hp=b11c25a6686506e22469b768bb04baa3e51a5246;hpb=7d52d0bd861c3aeaea5214131ef64543d63ea309;p=secnet.git diff --git a/sha1.c b/sha1.c index b11c25a..a78345a 100644 --- a/sha1.c +++ b/sha1.c @@ -78,6 +78,7 @@ A million repetitions of "a" /* #define SHA1HANDSOFF */ #include "secnet.h" +#include "util.h" #include #include @@ -313,9 +314,11 @@ struct sha1 { struct hash_if ops; }; +static struct sha1 st[1]; +struct hash_if *const sha1_hash_if = &st->ops; + void sha1_module(dict_t *dict) { - struct sha1 *st; cstring_t testinput="abcdbcdecdefdefgefghfghigh" "ijhijkijkljklmklmnlmnomnopnopq"; uint8_t expected[20]= @@ -327,7 +330,6 @@ void sha1_module(dict_t *dict) uint8_t digest[20]; int i; - NEW(st); st->cl.description="sha1"; st->cl.type=CL_HASH; st->cl.apply=NULL; @@ -340,10 +342,7 @@ void sha1_module(dict_t *dict) dict_add(dict,"sha1",new_closure(&st->cl)); - uint8_t ctx[st->ops.slen]; - sha1_init(ctx); - sha1_update(ctx,testinput,strlen(testinput)); - sha1_final(ctx,digest); + hash_hash(&st->ops,testinput,strlen(testinput),digest); for (i=0; i<20; i++) { if (digest[i]!=expected[i]) { fatal("sha1 module failed self-test");