hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit ea42230b00e471500a2bb9731bc32e137a0eee98
parent 6a8fe0a32464e8f34c8d03d4df1d81e5089fb334
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Wed, 17 Nov 2021 12:30:38 +0100

add block size bsz to hash

HMAC needs to know the block size of given hash.

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>

Diffstat:
Mcrypto/md5/md5.ha | 1+
Mcrypto/sha1/sha1.ha | 1+
Mcrypto/sha256/sha256.ha | 1+
Mcrypto/sha512/sha512.ha | 1+
Mhash/hash.ha | 9+++++++++
5 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/crypto/md5/md5.ha b/crypto/md5/md5.ha @@ -33,6 +33,7 @@ export fn md5() digest = { sum = &sum, reset = &reset, sz = SIZE, + bsz = chunk, ... }; hash::reset(&md5); diff --git a/crypto/sha1/sha1.ha b/crypto/sha1/sha1.ha @@ -32,6 +32,7 @@ export fn sha1() digest = { sum = &sum, reset = &reset, sz = SIZE, + bsz = BLOCKSIZE, ... }; hash::reset(&sha); diff --git a/crypto/sha256/sha256.ha b/crypto/sha256/sha256.ha @@ -46,6 +46,7 @@ export fn sha256() state = { sum = &sum, reset = &reset, sz = SIZE, + bsz = chunk, ... }; hash::reset(&sha); diff --git a/crypto/sha512/sha512.ha b/crypto/sha512/sha512.ha @@ -84,6 +84,7 @@ fn init(var: variant, sz: size) digest = { sum = &sum, reset = &reset, sz = sz, + bsz = chunk, var = var, ... }; diff --git a/hash/hash.ha b/hash/hash.ha @@ -14,6 +14,12 @@ export type hash = struct { // Size of the hash in bytes. sz: size, + + // Internal block size of the hash. Writing data to the hash + // function in chunks of this size will not require padding to + // obtain the final hash, such that [[hash::sum]] shall return + // the same checksum as [[hash::finish]]. + bsz: size, }; // Writes an input to the hash function. @@ -43,3 +49,6 @@ export fn reset(h: *hash) void = h.reset(h); // Returns the size of the hash in bytes. This is consistent regardless // of the hash state. export fn sz(h: *hash) size = h.sz; + +// Returns the block size of the hash. +export fn bsz(h: *hash) size = h.bsz;