~apreiml/bigc

dd847ab00bc7870dd12e6fc58f9cd5a0c56ddf19 — Armin Preiml 1 year, 11 months ago c7e1db2
fromhexmod
3 files changed, 9 insertions(+), 10 deletions(-)

M crypto/bigint/+test/arithm.ha
M crypto/bigint/+test/monty.ha
M crypto/bigint/+test/utils.ha
M crypto/bigint/+test/arithm.ha => crypto/bigint/+test/arithm.ha +1 -5
@@ 90,10 90,7 @@ use fmt;

@test fn modpow() void = {
	let m = fromhex("87654321");
	let x1 = fromhex("00f03202");
	let x = fromhex("00000000");

	reduce(x, x1, m); // to set the same announced bit length
	let x = fromhexmod("00f03202", m);

	let e: [_]u8 = [0x00, 0x00, 0xc1, 0xf4];
	const m0i = ninv31(m[1]);


@@ 106,7 103,6 @@ use fmt;
	assert(equalshex(x, "3de073fc"));

	free(m);
	free(x1);
	free(x);
	free(t1);
	free(t2);

M crypto/bigint/+test/monty.ha => crypto/bigint/+test/monty.ha +1 -5
@@ 1,16 1,12 @@
use fmt;

@test fn montyencode() void = {
	let x1 = fromhex("0000010064");
	let x = fromhex("0000010064");
	let m = fromhex("0010000061");
	let x = fromhexmod("0000010064", m);

	defer free(x1);
	defer free(x);
	defer free(m);

	reduce(x, x1, m);

	const m0i = ninv31(m[1]);

	to_monty(x, m);

M crypto/bigint/+test/utils.ha => crypto/bigint/+test/utils.ha +7 -0
@@ 11,6 11,13 @@ fn fromhex(h: str) []word = {
	return i;
};

// 'h' must be lower than 'm'
fn fromhexmod(h: str, m: []word) []word = {
	let r = fromhex(h);
	r[0] = m[0];
	return r;
};

// The caller must free the result.
fn tohex(x: []word) str = {
	let buf: []u8 = alloc([0...], (len(x) - 1) * size(word));