[SECNET PATCH 3/6] sha1: Provide sha1_hash_if

Ian Jackson ijackson at chiark.greenend.org.uk
Thu Feb 13 17:52:09 GMT 2020


This will be useful in a moment.

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

Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
 secnet.h | 2 ++
 sha1.c   | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/secnet.h b/secnet.h
index 5c351afb4..ffe836005 100644
--- 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 f442e08c9..a78345a55 100644
--- 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;
-- 
2.11.0




More information about the sgo-software-discuss mailing list