hare

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

genkeys+test.ha (861B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use bytes;
      5 use io;
      6 use memio;
      7 
      8 
      9 @test fn keygen_p256() void = edgecases(p256);
     10 @test fn keygen_p384() void = edgecases(p384);
     11 @test fn keygen_p521() void = edgecases(p521);
     12 
     13 fn edgecases(c: *curve) void = {
     14 	const scalarsz = len(c.order());
     15 	let priv: [MAX_SCALARSZ]u8 = [0...];
     16 	let priv = priv[..scalarsz];
     17 
     18 	let zero: [MAX_SCALARSZ]u8 = [0...];
     19 	let zero = zero[..scalarsz];
     20 
     21 	let rnd = memio::fixed(zero);
     22 	assert(keygen(c, priv, &rnd) is io::error);
     23 
     24 	let rnd = memio::fixed(c.order());
     25 	assert(keygen(c, priv, &rnd) is io::error);
     26 
     27 	let sub1: [MAX_SCALARSZ]u8 = [0...];
     28 	let sub1 = sub1[..scalarsz];
     29 
     30 	sub1[..] = c.order()[..];
     31 	sub1[len(sub1) - 1] -= 1;
     32 
     33 	let rnd = memio::fixed(sub1);
     34 	assert(keygen(c, priv, &rnd): size == scalarsz);
     35 	assert(bytes::equal(sub1, priv));
     36 };