ec-field-test.c: Make the field-element type use internal format.
[secnet] / sha512.c
index 16129c3..5fa40d2 100644 (file)
--- a/sha512.c
+++ b/sha512.c
@@ -22,6 +22,8 @@
 
 #include <config.h>
 
+#include "secnet.h"
+
 #include "sha512.h"
 
 #include <stddef.h>
@@ -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));
+}