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 committed 2023-11-17 19:31:51 +09:00
1 parent e3a836f93c
commit e86bb3a795
12 files changed
+44 -85

No files matched your search

+7 -1
View File
@@ -121,7 +121,13 @@ update :: proc "contextless" (c: ^Sha3_Context, data: []byte) {
c.pt = j
}
final :: proc "contextless" (c: ^Sha3_Context, hash: []byte) {
final :: proc(c: ^Sha3_Context, hash: []byte) {
if len(hash) < c.mdlen {
if c.is_keccak {
panic("crypto/keccac: invalid destination digest size")
}
panic("crypto/sha3: invalid destination digest size")
}
if c.is_keccak {
c.st.b[c.pt] ~= 0x01
} else {