aboutsummaryrefslogtreecommitdiff
path: root/core/crypto/sha2/sha2.odin
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/sha2/sha2.odin
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/sha2/sha2.odin')
-rw-r--r--core/crypto/sha2/sha2.odin12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/crypto/sha2/sha2.odin b/core/crypto/sha2/sha2.odin
index dd133fa5f..e44c31541 100644
--- a/core/crypto/sha2/sha2.odin
+++ b/core/crypto/sha2/sha2.odin
@@ -387,9 +387,13 @@ init :: proc(ctx: ^$T) {
ctx.tot_len = 0
ctx.length = 0
+
+ ctx.is_initialized = true
}
update :: proc(ctx: ^$T, data: []byte) {
+ assert(ctx.is_initialized)
+
length := uint(len(data))
block_nb: uint
new_len, rem_len, tmp_len: uint
@@ -427,6 +431,8 @@ update :: proc(ctx: ^$T, data: []byte) {
}
final :: proc(ctx: ^$T, hash: []byte) {
+ assert(ctx.is_initialized)
+
block_nb, pm_len: uint
len_b: u64
@@ -457,6 +463,8 @@ final :: proc(ctx: ^$T, hash: []byte) {
endian.unchecked_put_u64be(hash[i * 8:], ctx.h[i])
}
}
+
+ ctx.is_initialized = false
}
/*
@@ -472,6 +480,8 @@ Sha256_Context :: struct {
block: [128]byte,
h: [8]u32,
md_bits: int,
+
+ is_initialized: bool,
}
Sha512_Context :: struct {
@@ -480,6 +490,8 @@ Sha512_Context :: struct {
block: [256]byte,
h: [8]u64,
md_bits: int,
+
+ is_initialized: bool,
}
@(private)