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:
1 parent
e3a836f93c
commit
e86bb3a795
12 files changed
+44
-85
No files matched your search
@@ -54,10 +54,6 @@ hash_string_to_buffer_224 :: 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_224 :: proc(data, hash: []byte) {
|
||||
assert(
|
||||
len(hash) >= DIGEST_SIZE_224,
|
||||
"Size of destination buffer is smaller than the digest size",
|
||||
)
|
||||
ctx: _sha3.Sha3_Context
|
||||
ctx.mdlen = DIGEST_SIZE_224
|
||||
_sha3.init(&ctx)
|
||||
@@ -136,10 +132,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)
|
||||
@@ -218,10 +210,6 @@ hash_string_to_buffer_384 :: 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_384 :: proc(data, hash: []byte) {
|
||||
assert(
|
||||
len(hash) >= DIGEST_SIZE_384,
|
||||
"Size of destination buffer is smaller than the digest size",
|
||||
)
|
||||
ctx: _sha3.Sha3_Context
|
||||
ctx.mdlen = DIGEST_SIZE_384
|
||||
_sha3.init(&ctx)
|
||||
@@ -300,10 +288,6 @@ hash_string_to_buffer_512 :: 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_512 :: proc(data, hash: []byte) {
|
||||
assert(
|
||||
len(hash) >= DIGEST_SIZE_512,
|
||||
"Size of destination buffer is smaller than the digest size",
|
||||
)
|
||||
ctx: _sha3.Sha3_Context
|
||||
ctx.mdlen = DIGEST_SIZE_512
|
||||
_sha3.init(&ctx)
|
||||
@@ -367,6 +351,6 @@ update :: proc "contextless" (ctx: ^_sha3.Sha3_Context, data: []byte) {
|
||||
_sha3.update(ctx, data)
|
||||
}
|
||||
|
||||
final :: proc "contextless" (ctx: ^_sha3.Sha3_Context, hash: []byte) {
|
||||
final :: proc(ctx: ^_sha3.Sha3_Context, hash: []byte) {
|
||||
_sha3.final(ctx, hash)
|
||||
}
|
||||
Reference in new issue
Block a user