aboutsummaryrefslogtreecommitdiff
path: root/core/crypto/hash/hash.odin
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2024-02-07 02:29:02 +0900
committerYawning Angel <yawning@schwanenlied.me>2024-02-07 02:33:53 +0900
commit44758f2a6035803e504a06ec1d6b47f6336bb8cb (patch)
treee18ff272c65514ce2c106b8babbb9737478628a4 /core/crypto/hash/hash.odin
parent56516ee8b267c1be0ca714db4b6c43bc8be508cb (diff)
core/crypto: Stop using context.temp_allocator
The max digest size for the foreseeable future will be 512 bits, and the max block size is currently 1152 bits (SHA3-224). If people add more exotic hash algorithms without bumping the constants when required, tests will fail. The stream buffer will currently be 576 bytes, which is "fine" to just stick on the stack, and is a sensible multiple of the more common block size of 64 bytes.
Diffstat (limited to 'core/crypto/hash/hash.odin')
-rw-r--r--core/crypto/hash/hash.odin12
1 files changed, 4 insertions, 8 deletions
diff --git a/core/crypto/hash/hash.odin b/core/crypto/hash/hash.odin
index 0840910c1..e4b3d4be1 100644
--- a/core/crypto/hash/hash.odin
+++ b/core/crypto/hash/hash.odin
@@ -56,17 +56,13 @@ hash_stream :: proc(
) {
ctx: Context
- init(&ctx, algorithm)
+ buf: [MAX_BLOCK_SIZE * 4]byte
+ defer mem.zero_explicit(&buf, size_of(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)
- }
+ init(&ctx, algorithm)
loop: for {
- n, err := io.read(s, buf)
+ n, err := io.read(s, buf[:])
if n > 0 {
// XXX/yawning: Can io.read return n > 0 and EOF?
update(&ctx, buf[:n])