mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 22:28:46 +00:00
core/crypto: Change hash asserts to panics
Assertions can be disabled, but at the point where cryptographic anything is involved, a single branch has an infinitesimally small performance impact. The correct thing to do is to punch the caller in the face if they do something that is blatantly incorrect, especially in a security critical setting.
This commit is contained in:
@@ -180,11 +180,17 @@ update :: proc "contextless" (ctx: ^$T, p: []byte) {
|
||||
ctx.nx += copy(ctx.x[ctx.nx:], p)
|
||||
}
|
||||
|
||||
final :: proc "contextless" (ctx: ^$T, hash: []byte) {
|
||||
final :: proc(ctx: ^$T, hash: []byte) {
|
||||
when T == Blake2s_Context {
|
||||
if len(hash) < BLAKE2S_SIZE {
|
||||
panic("crypto/blake2s: invalid destination digest size")
|
||||
}
|
||||
blake2s_final(ctx, hash)
|
||||
}
|
||||
when T == Blake2b_Context {
|
||||
if len(hash) < BLAKE2B_SIZE {
|
||||
panic("crypto/blake2b: invalid destination digest size")
|
||||
}
|
||||
blake2b_final(ctx, hash)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user