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:
Yawning Angel
2023-11-17 19:31:51 +09:00
parent e3a836f93c
commit e86bb3a795
12 changed files with 44 additions and 85 deletions
-8
View File
@@ -53,10 +53,6 @@ hash_string_to_buffer_128 :: proc(data: string, hash: []byte) {
// computed hash into the second parameter.
// It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_128 :: proc(data, hash: []byte) {
assert(
len(hash) >= DIGEST_SIZE_128,
"Size of destination buffer is smaller than the digest size",
)
ctx: _sha3.Sha3_Context
ctx.mdlen = DIGEST_SIZE_128
_sha3.init(&ctx)
@@ -138,10 +134,6 @@ hash_string_to_buffer_256 :: proc(data: string, hash: []byte) {
// computed hash into the second parameter.
// It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_256 :: proc(data, hash: []byte) {
assert(
len(hash) >= DIGEST_SIZE_256,
"Size of destination buffer is smaller than the digest size",
)
ctx: _sha3.Sha3_Context
ctx.mdlen = DIGEST_SIZE_256
_sha3.init(&ctx)