Welcome to little lamb

Code » limb » commit 4dfc535

blake3: Update interface

author Olivier Brunel
2023-02-20 09:29:44 UTC
committer Olivier Brunel
2023-02-20 09:29:44 UTC
parent 1aeb2c24114b4993d7373746da95ef2b0615166b

blake3: Update interface

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

doc/blake3.3.md +5 -5
include/limb/blake3.h +3 -3
src/blake3/blake3.c +3 -3
src/blake3/blake3_impl.c +2 -2

diff --git a/doc/blake3.3.md b/doc/blake3.3.md
index cb794d7..ef1e155 100644
--- a/doc/blake3.3.md
+++ b/doc/blake3.3.md
@@ -5,8 +5,8 @@
 
 # NAME
 
-blake3_init, blake3_update, blake3_final, blake3 - compute the BLAKE3 of a given block of
-data
+blake3\_init, blake3\_update, blake3\_final, blake3 - compute the BLAKE3 of a
+given block of data
 
 # SYNOPSIS
 
@@ -14,10 +14,10 @@ data
 
 ```pre hl
 void blake3_init(blake3_ctx *<em>ctx</em>);
-void blake3_update(blake3_ctx *<em>ctx</em>, const void *<em>msg</em>, size_t <em>size</em>);
-void blake3_final(blake3_ctx *<em>ctx</em>, unsigned char * restrict <em>md</em>);
+void blake3_update(const void *<em>msg</em>, size_t <em>size</em>, blake3_ctx *<em>ctx</em>);
+void blake3_final(unsigned char * restrict <em>md</em>, blake3_ctx *<em>ctx</em>);
 
-void blake3(const void *<em>msg</em>, size_t <em>size</em>, unsigned char * restrict <em>md</em>);
+void blake3(unsigned char * restrict <em>md</em>, const void *<em>msg</em>, size_t <em>size</em>);
 ```
 
 # DESCRIPTION
diff --git a/include/limb/blake3.h b/include/limb/blake3.h
index ce5aef7..36691ff 100644
--- a/include/limb/blake3.h
+++ b/include/limb/blake3.h
@@ -35,9 +35,9 @@ typedef struct {
 } blake3_ctx;
 
 extern void blake3_init(blake3_ctx *ctx);
-extern void blake3_update(blake3_ctx *ctx, const void *msg, size_t len);
-extern void blake3_final(blake3_ctx *ctx, unsigned char * restrict md);
+extern void blake3_update(const void *msg, size_t len, blake3_ctx *ctx);
+extern void blake3_final(unsigned char * restrict md, blake3_ctx *ctx);
 
-extern void blake3(const void *msg, size_t size, unsigned char * restrict md);
+extern void blake3(unsigned char * restrict md, const void *msg, size_t size);
 
 #endif /* LIMB_BLAKE3_H */
diff --git a/src/blake3/blake3.c b/src/blake3/blake3.c
index f74933a..6bf297c 100644
--- a/src/blake3/blake3.c
+++ b/src/blake3/blake3.c
@@ -1,11 +1,11 @@
 #include "blake3.h"
 
 void
-blake3(const void *msg, size_t size, unsigned char * restrict md)
+blake3(unsigned char * restrict md, const void *msg, size_t size)
 {
     blake3_ctx ctx;
 
     blake3_init(&ctx);
-    blake3_update(&ctx, msg, size);
-    blake3_final(&ctx, md);
+    blake3_update(msg, size, &ctx);
+    blake3_final(md, &ctx);
 }
diff --git a/src/blake3/blake3_impl.c b/src/blake3/blake3_impl.c
index 4af38de..7424ee1 100644
--- a/src/blake3/blake3_impl.c
+++ b/src/blake3/blake3_impl.c
@@ -442,7 +442,7 @@ hasher_push_cv(blake3_ctx *ctx, u8 new_cv[BLAKE3_OUT_LEN], u64 chunk_counter)
 }
 
 void
-blake3_update(blake3_ctx *ctx, const void *input, size_t input_len)
+blake3_update(const void *input, size_t input_len, blake3_ctx *ctx)
 {
     /* Explicitly checking for zero avoids causing UB by passing a null pointer
      * to memcpy. This comes up in practice with things like:
@@ -555,7 +555,7 @@ blake3_update(blake3_ctx *ctx, const void *input, size_t input_len)
 }
 
 void
-blake3_final(blake3_ctx *ctx, unsigned char * restrict out)
+blake3_final(unsigned char * restrict out, blake3_ctx *ctx)
 {
     /* If the subtree stack is empty, then the current chunk is the root. */
     if (ctx->cv_stack_len == 0) {