X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/cc55d2b5489082d0801147c69b105005f74e0fd8..refs/heads/mdw/xdh:/sha512.c diff --git a/sha512.c b/sha512.c index 16129c3..5fa40d2 100644 --- a/sha512.c +++ b/sha512.c @@ -22,6 +22,8 @@ #include +#include "secnet.h" + #include "sha512.h" #include @@ -439,3 +441,34 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) h = ctx->state[7] = u64plus (ctx->state[7], h); } } + +struct sha512 { + closure_t cl; + struct hash_if ops; +}; + +static void *sha512_init(void) + { struct sha512_ctx *ctx; NEW(ctx); sha512_init_ctx(ctx); return ctx; } + +static void sha512_update(void *st, const void *buf, int32_t len) + { struct sha512_ctx *ctx = st; sha512_process_bytes(buf, len, ctx); } + +static void sha512_final(void *st, uint8_t *digest) + { struct sha512_ctx *ctx = st; sha512_finish_ctx(ctx, digest); free(ctx); } + +void sha512_module(dict_t *dict) +{ + struct sha512 *st; + + NEW(st); + st->cl.description="sha512"; + st->cl.type=CL_HASH; + st->cl.apply=NULL; + st->cl.interface=&st->ops; + st->ops.len=64; + st->ops.init=sha512_init; + st->ops.update=sha512_update; + st->ops.final=sha512_final; + + dict_add(dict,"sha512",new_closure(&st->cl)); +}