hare

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

commit dcd1121a25a585a05b3bd993c84a3ed5e851fc3f
parent 197c92016b890df7b54ebf6a45332f5f2ed77177
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Thu, 21 Apr 2022 10:49:35 +0200

replacing hash::finish with hash::sum

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

Diffstat:
Mcrypto/argon2/argon2.ha | 6+++---
Mcrypto/blake2b/+test.ha | 6++++--
Mcrypto/ed25519/ed25519.ha | 11++++++-----
3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/crypto/argon2/argon2.ha b/crypto/argon2/argon2.ha @@ -309,7 +309,7 @@ fn inithash( hash_leputu32(&h, len(cfg.data): u32); hash::write(&h, cfg.data); - hash::finish(&h, dest[..]); + hash::sum(&h, dest[..]); }; fn hash_leputu32(h: *hash::hash, u: u32) void = { @@ -327,7 +327,7 @@ fn varhash(dest: []u8, block: []u8) void = { defer hash::close(&h); hash_leputu32(&h, len(dest): u32); hash::write(&h, block); - hash::finish(&h, dest); + hash::sum(&h, dest); return; }; @@ -357,7 +357,7 @@ fn varhash(dest: []u8, block: []u8) void = { let hend = blake2b::blake2b([], remainder); defer hash::close(&hend); hash::write(&hend, v[..]); - hash::finish(&hend, v[..remainder]); + hash::sum(&hend, v[..remainder]); io::write(&destbuf, v[..remainder])!; }; diff --git a/crypto/blake2b/+test.ha b/crypto/blake2b/+test.ha @@ -20,13 +20,14 @@ use strio; let in = hex::decode(vectors[i].in)!; defer free(in); let blake = blake2b(key, len(out)); + defer hash::close(&blake); hash::write(&blake, in); let sum: []u8 = alloc([], len(out)); defer free(sum); for (let i = 0z; i < len(out); i += 1) { append(sum, 0); }; - hash::finish(&blake, sum); + hash::sum(&blake, sum); let out = strio::dynamic(); defer io::close(&out); hex::encode(&out, sum)!; @@ -96,9 +97,10 @@ use strio; let result: [32]u8 = [0...]; let h = blake2b([], len(result)); + defer hash::close(&h); hash::write(&h, in[..4]); hash::write(&h, in[4..]); - hash::finish(&h, result[..]); + hash::sum(&h, result[..]); assert(bytes::equal(expected, result)); }; diff --git a/crypto/ed25519/ed25519.ha b/crypto/ed25519/ed25519.ha @@ -32,7 +32,7 @@ export fn private_init(out: *privatekey, seed: *seed) void = { let h: [64]u8 = [0...]; let sha = sha512::sha512(); hash::write(&sha, seed[..]); - hash::finish(&sha, h[..]); + hash::sum(&sha, h[..]); hash::close(&sha); let s: scalar = [0...]; @@ -60,7 +60,7 @@ export fn sign(priv: *privatekey, msg: []u8) [SIGNATURESZ]u8 = { let h: [64]u8 = [0...]; let sha = sha512::sha512(); hash::write(&sha, priv[0..SEEDSZ]); - hash::finish(&sha, h); + hash::sum(&sha, h); let esk: scalar = [0...]; esk[..] = h[0..32]; scalar_clamp(&esk); @@ -69,7 +69,7 @@ export fn sign(priv: *privatekey, msg: []u8) [SIGNATURESZ]u8 = { hash::write(&sha, h[32..64]); hash::write(&sha, msg); let msg_digest: [64]u8 = [0...]; - hash::finish(&sha, msg_digest); + hash::sum(&sha, msg_digest); let msg_reduced: scalar = [0...]; scalar_reduce(&msg_reduced, &msg_digest); @@ -83,7 +83,7 @@ export fn sign(priv: *privatekey, msg: []u8) [SIGNATURESZ]u8 = { hash::write(&sha, priv[32..64]); hash::write(&sha, msg); let hram: [64]u8 = [0...]; - hash::finish(&sha, hram); + hash::sum(&sha, hram); hash::close(&sha); let hram_reduced: scalar = [0...]; scalar_reduce(&hram_reduced, &hram); @@ -111,7 +111,8 @@ export fn verify(pub: *publickey, msg: []u8, sig: *[SIGNATURESZ]u8) bool = { hash::write(&sha, pub[..]); hash::write(&sha, msg); let hram: [64]u8 = [0...]; - hash::finish(&sha, hram); + hash::sum(&sha, hram); + hash::close(&sha); let hram_reduced: scalar = [0...]; scalar_reduce(&hram_reduced, &hram);