aboutsummaryrefslogtreecommitdiff
path: root/core/crypto/_blake2
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2023-11-16 13:36:52 +0900
committerYawning Angel <yawning@schwanenlied.me>2023-11-17 19:31:51 +0900
commit70ba4b532176703b11d962e7e4f0bf0e85726c70 (patch)
treecc6fb6467253b6468552fb7555fd73d132ee3635 /core/crypto/_blake2
parent71da3ef9255f6f66ff3124355fdf8c9d0b6ff9a7 (diff)
core/crypto: Add more assertions to the low level API
Assertions here are "fine" and it matches what the code that has the checks in init/update/final already does.
Diffstat (limited to 'core/crypto/_blake2')
-rw-r--r--core/crypto/_blake2/blake2.odin14
1 files changed, 13 insertions, 1 deletions
diff --git a/core/crypto/_blake2/blake2.odin b/core/crypto/_blake2/blake2.odin
index a522a390e..ce6f88f20 100644
--- a/core/crypto/_blake2/blake2.odin
+++ b/core/crypto/_blake2/blake2.odin
@@ -29,6 +29,8 @@ Blake2s_Context :: struct {
size: byte,
is_last_node: bool,
cfg: Blake2_Config,
+
+ is_initialized: bool,
}
Blake2b_Context :: struct {
@@ -43,6 +45,8 @@ Blake2b_Context :: struct {
size: byte,
is_last_node: bool,
cfg: Blake2_Config,
+
+ is_initialized: bool,
}
Blake2_Config :: struct {
@@ -152,9 +156,13 @@ init :: proc(ctx: ^$T) {
}
ctx.nx = 0
+
+ ctx.is_initialized = true
}
-update :: proc "contextless" (ctx: ^$T, p: []byte) {
+update :: proc(ctx: ^$T, p: []byte) {
+ assert(ctx.is_initialized)
+
p := p
when T == Blake2s_Context {
block_size :: BLAKE2S_BLOCK_SIZE
@@ -181,6 +189,8 @@ update :: proc "contextless" (ctx: ^$T, p: []byte) {
}
final :: proc(ctx: ^$T, hash: []byte) {
+ assert(ctx.is_initialized)
+
when T == Blake2s_Context {
if len(hash) < BLAKE2S_SIZE {
panic("crypto/blake2s: invalid destination digest size")
@@ -193,6 +203,8 @@ final :: proc(ctx: ^$T, hash: []byte) {
}
blake2b_final(ctx, hash)
}
+
+ ctx.is_initialized = false
}
@(private)