hare

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

monty_test.ha (978B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 @test fn montyencode() void = {
      5 	let m = fromhex("0010000061");
      6 	let x = fromhexmod("0000010064", m);
      7 
      8 	defer free(x);
      9 	defer free(m);
     10 
     11 	const m0i = ninv31(m[1]);
     12 
     13 	tomonty(x, m);
     14 	frommonty(x, m, m0i);
     15 
     16 	assert(equalshex(x, "010064"));
     17 };
     18 
     19 @test fn montymul() void = {
     20 	let m = fromhex("10000061");
     21 	defer free(m);
     22 	let x = fromhexmod("00000123", m);
     23 	defer free(x);
     24 	let y = fromhexmod("000003cf", m);
     25 	defer free(y);
     26 	let d = fromhexmod("00000000", m);
     27 	defer free(d);
     28 
     29 	const m0i = ninv31(m[1]);
     30 
     31 	tomonty(x, m);
     32 	tomonty(y, m);
     33 	montymul(d, x, y, m, m0i);
     34 	frommonty(d, m, m0i);
     35 
     36 	assert(equalshex(d, "04544d"));
     37 
     38 	let d = fromhexmod("00000000", m);
     39 	defer free(d);
     40 	let x = fromhexmod("0f98b7cf", m);
     41 	defer free(x);
     42 	let y = fromhexmod("04216b9c", m);
     43 	defer free(y);
     44 
     45 	tomonty(x, m);
     46 	tomonty(y, m);
     47 	montymul(d, x, y, m, m0i);
     48 	frommonty(d, m, m0i);
     49 
     50 	assert(equalshex(d, "0d031f49"));
     51 };