Welcome to little lamb

Code » limb » commit 1aeb2c2

sha3: Update interface

author Olivier Brunel
2023-02-20 09:24:17 UTC
committer Olivier Brunel
2023-02-20 09:24:17 UTC
parent 37f2532805dc8eb8f7e301e33ca0054430a43f92

sha3: Update interface

Moving to better consistency (within limb) where (when applicable) we
put destination first and context last.

doc/sha3.3.md +6 -6
include/limb/sha3.h +4 -4
src/sha3/sha3.c +4 -4
src/sha3/sha3_final.c +2 -2
src/sha3/sha3_init.c +2 -2
src/sha3/sha3_update.c +3 -3

diff --git a/doc/sha3.3.md b/doc/sha3.3.md
index d98202a..fd7a06c 100644
--- a/doc/sha3.3.md
+++ b/doc/sha3.3.md
@@ -5,19 +5,19 @@
 
 # NAME
 
-sha3_init, sha3_update, sha3_final, sha3 - compute the SHA3 of a given block of
-data
+sha3\_init, sha3\_update, sha3\_final, sha3 - compute the SHA3 of a given block
+of data
 
 # SYNOPSIS
 
     #include <limb/sha3.h>
 
 ```pre hl
-void sha3_init(sha3_ctx *<em>ctx</em>, unsigned <em>bits</em>);
-void sha3_update(sha3_ctx *<em>ctx</em>, const void *<em>msg</em>, size_t <em>size</em>);
-void sha3_final(sha3_ctx *<em>ctx</em>, unsigned char * restrict <em>md</em>);
+void sha3_init(unsigned <em>bits</em>, sha3_ctx *<em>ctx</em>);
+void sha3_update(const void *<em>msg</em>, size_t <em>size</em>, sha3_ctx *<em>ctx</em>);
+void sha3_final(unsigned char * restrict <em>md</em>, sha3_ctx *<em>ctx</em>);
 
-void sha3(unsigned <em>bits</em>, const void *<em>msg</em>, size_t <em>size</em>, unsigned char * restrict <em>md</em>);
+void sha3(unsigned char * restrict <em>md</em>, unsigned <em>bits</em>, const void *<em>msg</em>, size_t <em>size</em>);
 ```
 
 # DESCRIPTION
diff --git a/include/limb/sha3.h b/include/limb/sha3.h
index 532a5c1..16bc802 100644
--- a/include/limb/sha3.h
+++ b/include/limb/sha3.h
@@ -20,10 +20,10 @@ struct sha3_ctx
 };
 typedef struct sha3_ctx sha3_ctx;
 
-extern void sha3_init(sha3_ctx *ctx, unsigned bits);
-extern void sha3_update(sha3_ctx *ctx, const void *msg, size_t size);
-extern void sha3_final(sha3_ctx *ctx, unsigned char * restrict md);
+extern void sha3_init(unsigned bits, sha3_ctx *ctx);
+extern void sha3_update(const void *msg, size_t size, sha3_ctx *ctx);
+extern void sha3_final(unsigned char * restrict md, sha3_ctx *ctx);
 
-extern void sha3(unsigned bits, const void *msg, size_t size, unsigned char * restrict md);
+extern void sha3(unsigned char * restrict md, unsigned bits, const void *msg, size_t size);
 
 #endif /* LIMB_SHA3_H */
diff --git a/src/sha3/sha3.c b/src/sha3/sha3.c
index 5bd2029..b66e82d 100644
--- a/src/sha3/sha3.c
+++ b/src/sha3/sha3.c
@@ -1,9 +1,9 @@
 #include "sha3/sha3.h"
 
-void sha3(unsigned bits, const void *msg, size_t size, unsigned char * restrict md)
+void sha3(unsigned char * restrict md, unsigned bits, const void *msg, size_t size)
 {
     sha3_ctx ctx;
-    sha3_init(&ctx, bits);
-    sha3_update(&ctx, msg, size);
-    sha3_final(&ctx, md);
+    sha3_init(bits, &ctx);
+    sha3_update(msg, size, &ctx);
+    sha3_final(md, &ctx);
 }
diff --git a/src/sha3/sha3_final.c b/src/sha3/sha3_final.c
index 134315d..b57d91c 100644
--- a/src/sha3/sha3_final.c
+++ b/src/sha3/sha3_final.c
@@ -25,10 +25,10 @@
 /**
  * Store calculated hash into the given array.
  *
+ * @param md  calculated hash in binary form
  * @param ctx the algorithm context containing current hashing state
- * @param md calculated hash in binary form
  */
-void sha3_final(sha3_ctx *ctx, unsigned char * restrict md)
+void sha3_final(unsigned char * restrict md, sha3_ctx *ctx)
 {
     size_t digest_length = 100 - ctx->block_size / 2;
     const size_t block_size = ctx->block_size;
diff --git a/src/sha3/sha3_init.c b/src/sha3/sha3_init.c
index 6fae937..296cba2 100644
--- a/src/sha3/sha3_init.c
+++ b/src/sha3/sha3_init.c
@@ -24,10 +24,10 @@
 /**
  * Initializing a sha3 context for given number of output bits
  *
- * @param ctx  context to initialize
  * @param bits number of output bits
+ * @param ctx  context to initialize
  */
-void sha3_init(sha3_ctx *ctx, unsigned bits)
+void sha3_init(unsigned bits, sha3_ctx *ctx)
 {
     /* NB: The Keccak capacity parameter = bits * 2 */
     unsigned rate = 1600 - bits * 2;
diff --git a/src/sha3/sha3_update.c b/src/sha3/sha3_update.c
index dac47d9..3662a71 100644
--- a/src/sha3/sha3_update.c
+++ b/src/sha3/sha3_update.c
@@ -26,11 +26,11 @@
  * Calculate message hash.
  * Can be called repeatedly with chunks of the message to be hashed.
  *
- * @param ctx the algorithm context containing current hashing state
- * @param msg message chunk
+ * @param msg  message chunk
  * @param size length of the message chunk
+ * @param ctx  the algorithm context containing current hashing state
  */
-void sha3_update(sha3_ctx *ctx, const void *msg_, size_t size)
+void sha3_update(const void *msg_, size_t size, sha3_ctx *ctx)
 {
     const unsigned char *msg = msg_;
     size_t index = (size_t) ctx->rest;