aboutsummaryrefslogtreecommitdiff
path: root/core/crypto/hash/hash.odin
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2024-01-28 01:11:13 +0900
committerYawning Angel <yawning@schwanenlied.me>2024-02-07 00:37:18 +0900
commit7a8b1669b012c6c09bc31639aecae601f6386624 (patch)
treeae4b16ba13b8e2071fa7b09b169a5d6cc14106a5 /core/crypto/hash/hash.odin
parentbc160d2eb75d73f9e46c4aa11a2cb36538ae31f9 (diff)
core/crypto: Expose the block sizes for every hash algorithm
While I just went and made this private, this information is required for keying HMAC.
Diffstat (limited to 'core/crypto/hash/hash.odin')
-rw-r--r--core/crypto/hash/hash.odin12
1 files changed, 7 insertions, 5 deletions
diff --git a/core/crypto/hash/hash.odin b/core/crypto/hash/hash.odin
index 2931cb4a0..e861be72e 100644
--- a/core/crypto/hash/hash.odin
+++ b/core/crypto/hash/hash.odin
@@ -58,10 +58,12 @@ hash_stream :: proc(
init(&ctx, algorithm, context.temp_allocator)
- _BUFFER_SIZE :: 512
- buf := make([]byte, _BUFFER_SIZE, context.temp_allocator)
- defer mem.zero_explicit(raw_data(buf), _BUFFER_SIZE)
- defer delete(buf)
+ buffer_size := block_size(&ctx) * 4
+ buf := make([]byte, buffer_size, context.temp_allocator)
+ defer {
+ mem.zero_explicit(raw_data(buf), buffer_size)
+ delete(buf, context.temp_allocator)
+ }
loop: for {
n, err := io.read(s, buf)
@@ -103,7 +105,7 @@ hash_file :: proc(
if !ok {
return nil, io.Error.Unknown
}
- defer delete(buf)
+ defer delete(buf, allocator)
return hash_bytes(algorithm, buf, allocator), io.Error.None
}