aboutsummaryrefslogtreecommitdiff
path: root/core/crypto/sha2/sha2.odin
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2025-01-18 13:51:04 +0900
committerYawning Angel <yawning@schwanenlied.me>2025-03-23 19:14:33 +0900
commit2f301e46dc21e6a4660ac669a5ffb20e2f2297dd (patch)
tree49a763346409bf72515b0e1638f66ba3f2e52ac2 /core/crypto/sha2/sha2.odin
parentdc94452fb99c889df78e992b59540032a2be6e15 (diff)
core/crypto: Switch to using `ensure`
Diffstat (limited to 'core/crypto/sha2/sha2.odin')
-rw-r--r--core/crypto/sha2/sha2.odin11
1 files changed, 4 insertions, 7 deletions
diff --git a/core/crypto/sha2/sha2.odin b/core/crypto/sha2/sha2.odin
index 8ab0ce005..bf9b81601 100644
--- a/core/crypto/sha2/sha2.odin
+++ b/core/crypto/sha2/sha2.odin
@@ -158,7 +158,7 @@ _init :: proc(ctx: ^$T) {
// update adds more data to the Context.
update :: proc(ctx: ^$T, data: []byte) {
- assert(ctx.is_initialized)
+ ensure(ctx.is_initialized)
when T == Context_256 {
CURR_BLOCK_SIZE :: BLOCK_SIZE_256
@@ -194,11 +194,8 @@ update :: proc(ctx: ^$T, data: []byte) {
// Iff finalize_clone is set, final will work on a copy of the Context,
// which is useful for for calculating rolling digests.
final :: proc(ctx: ^$T, hash: []byte, finalize_clone: bool = false) {
- assert(ctx.is_initialized)
-
- if len(hash) * 8 < ctx.md_bits {
- panic("crypto/sha2: invalid destination digest size")
- }
+ ensure(ctx.is_initialized)
+ ensure(len(hash) * 8 >= ctx.md_bits, "crypto/sha2: invalid destination digest size")
ctx := ctx
if finalize_clone {
@@ -238,7 +235,7 @@ final :: proc(ctx: ^$T, hash: []byte, finalize_clone: bool = false) {
endian.unchecked_put_u64be(pad[8:], length_lo)
update(ctx, pad[0:16])
}
- assert(ctx.bitlength == 0)
+ assert(ctx.bitlength == 0) // Check for bugs
when T == Context_256 {
for i := 0; i < ctx.md_bits / 32; i += 1 {