hare

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

commit 6c27da4aeec62b58aa0e10f6982c23841507c489
parent 1468d7c87c495048a32cc9a70040e2e86370100e
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Thu, 12 Jan 2023 12:10:26 +0100

crypto::salsa: slice instead of array ptr

See similar commit in crypto::chacha

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

Diffstat:
Mcrypto/salsa/+test.ha | 6+++---
Mcrypto/salsa/salsa20.ha | 20+++++++++++++-------
2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/crypto/salsa/+test.ha b/crypto/salsa/+test.ha @@ -62,7 +62,7 @@ use io; let c = salsa20(); defer io::close(&c)!; - xsalsa20_init(&c, &cipherbuf, &key, &nonce); + xsalsa20_init(&c, &cipherbuf, key, nonce); io::writeall(&c, msg)!; assert(bytes::equal(cipher, result)); @@ -115,7 +115,7 @@ use io; let c = salsa20(); defer io::close(&c)!; - xsalsa20_init(&c, &cipherbuf, &key, &nonce); + xsalsa20_init(&c, &cipherbuf, key, nonce); setctr(&c, types::U32_MAX); io::writeall(&c, msg)!; @@ -170,7 +170,7 @@ use io; let c = salsa20(); defer io::close(&c)!; - xsalsa20_init(&c, &cipherbuf, &key, &nonce); + xsalsa20_init(&c, &cipherbuf, key, nonce); setctr(&c, types::U64_MAX); io::writeall(&c, msg)!; diff --git a/crypto/salsa/salsa20.ha b/crypto/salsa/salsa20.ha @@ -46,9 +46,9 @@ export fn salsa20() stream = { fn init( state: *[16]u32, - key: *[KEYSIZE]u8, - nonce: *[8]u8, - ctr: *[8]u8 + key: []u8, + nonce: []u8, + ctr: []u8 ) void = { state[0] = magic[0]; state[1] = endian::legetu32(key[0..4]); @@ -72,9 +72,12 @@ fn init( export fn salsa20_init( s: *stream, h: io::handle, - key: *[KEYSIZE]u8, - nonce: *[NONCESIZE]u8, + key: []u8, + nonce: []u8, ) void = { + assert(len(key) == KEYSIZE); + assert(len(nonce) == NONCESIZE); + let counter: [8]u8 = [0...]; init(&s.state, key, nonce, &counter); s.xorused = BLOCKSIZE; @@ -87,9 +90,12 @@ export fn salsa20_init( export fn xsalsa20_init( s: *stream, h: io::handle, - key: *[KEYSIZE]u8, - nonce: *[XNONCESIZE]u8 + key: []u8, + nonce: []u8 ) void = { + assert(len(key) == KEYSIZE); + assert(len(nonce) == XNONCESIZE); + let state: [16]u32 = [0...]; init(&state, key, nonce[0..8]: *[8]u8, nonce[8..16]: *[8]u8); hblock(state[..], &state, 20);