hare

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

commit b6177c86d9fb69f58a7c953ba8bbc1c150fc45e4
parent 02e09a92ac424ae9d16bab0a5248372cc66f856b
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Sat, 30 Nov 2024 13:17:56 +0100

ecdh::newkey: fix size interpeted as underread

If ec::newkey returns size it was interpreted as io::underread in
ecdh::newkey.

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

Diffstat:
Mcrypto/ecdh/basic+test.ha | 12++++++++++++
Mcrypto/ecdh/ecdh.ha | 3++-
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/crypto/ecdh/basic+test.ha b/crypto/ecdh/basic+test.ha @@ -3,7 +3,19 @@ use crypto::ec; use bytes; +use memio; + +@test fn p256_newkey() void = { + let priv: [_]u8 = [ + 0xde, 0x5c, 0x88, 0x05, 0x42, 0xa0, 0x71, 0xe2, 0xf6, 0xfe, + 0xd0, 0xdc, 0x80, 0x07, 0x37, 0xc4, 0x35, 0xa6, 0x29, 0x48, + 0x85, 0x70, 0x4f, 0x54, 0x1c, 0x41, 0x89, 0xaf, 0xf6, 0xbc, + 0xb5, 0x19, + ]; + let key = p256(); + newkey(&key, &memio::fixed(priv))!; +}; @test fn p256_invalidpoint() void = { let priv = p256(); diff --git a/crypto/ecdh/ecdh.ha b/crypto/ecdh/ecdh.ha @@ -75,8 +75,9 @@ export fn p521() p521key = p521key { // Generates a key seeding from the 'rand' stream and stores it in 'priv'. // 'rand' must be a cryptographic random generator like // [[crypto::random::stream]]. -export fn newkey(priv: *privkey, rand: io::handle) (void | io::error) = +export fn newkey(priv: *privkey, rand: io::handle) (void | io::error) = { ec::keygen(priv.curve, priv.get_x(priv), rand)?; +}; // Derives the public key from given 'priv' and stores it into 'pub'. Returns // the number of key bytes written to 'pub'.