mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
core/crypto: Switch to using ensure
This commit is contained in:
@@ -53,7 +53,7 @@ init :: proc(ctx: ^Context) {
|
||||
|
||||
// update adds more data to the Context.
|
||||
update :: proc(ctx: ^Context, data: []byte) {
|
||||
assert(ctx.is_initialized)
|
||||
ensure(ctx.is_initialized)
|
||||
|
||||
data := data
|
||||
ctx.length += u64(len(data))
|
||||
@@ -83,11 +83,8 @@ update :: proc(ctx: ^Context, 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: ^Context, hash: []byte, finalize_clone: bool = false) {
|
||||
assert(ctx.is_initialized)
|
||||
|
||||
if len(hash) < DIGEST_SIZE {
|
||||
panic("crypto/sm3: invalid destination digest size")
|
||||
}
|
||||
ensure(ctx.is_initialized)
|
||||
ensure(len(hash) >= DIGEST_SIZE, "crypto/sm3: invalid destination digest size")
|
||||
|
||||
ctx := ctx
|
||||
if finalize_clone {
|
||||
@@ -110,7 +107,7 @@ final :: proc(ctx: ^Context, hash: []byte, finalize_clone: bool = false) {
|
||||
length <<= 3
|
||||
endian.unchecked_put_u64be(pad[:], length)
|
||||
update(ctx, pad[0:8])
|
||||
assert(ctx.bitlength == 0)
|
||||
assert(ctx.bitlength == 0) // Check for bugs
|
||||
|
||||
for i := 0; i < DIGEST_SIZE / 4; i += 1 {
|
||||
endian.unchecked_put_u32be(hash[i * 4:], ctx.state[i])
|
||||
|
||||
Reference in New Issue
Block a user