chiark / gitweb /
sha1: Provide sha1_hash_if
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 13 Feb 2020 16:55:51 +0000 (16:55 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:55 +0000 (21:56 +0000)
This will be useful in a moment.

As a side effect, the sha1 st is statically allocated now.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
secnet.h
sha1.c

index 5c351afb44a6e04d3e78308a67627e4e383268a0..ffe8360053d20fa9774e11eb03575b4f570ec24a 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -786,6 +786,8 @@ struct hash_if {
     hash_final_fn *final;
 };
 
+extern struct hash_if *const sha1_hash_if; /* for where this is hardcoded */
+
 /* BUFFER interface */
 
 struct buffer_if {
diff --git a/sha1.c b/sha1.c
index f442e08c91033c805e4c2987810021d507c40525..a78345a55f6378dc51d1bb67b3e2dab4eb8d404f 100644 (file)
--- a/sha1.c
+++ b/sha1.c
@@ -314,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]=
@@ -328,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;