~sircmpwn/hare-dev

hare: crypto::bigint: improve some function names v1 PROPOSED

Armin Preiml: 1
 crypto::bigint: improve some function names

 7 files changed, 22 insertions(+), 22 deletions(-)
#849055 alpine.yml success
#849056 freebsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/35503/mbox | git am -3
Learn more about email & git

[PATCH hare] crypto::bigint: improve some function names Export this patch

to fit the hare style better.

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
---
 crypto/bigint/+test/encoding.ha | 10 +++++-----
 crypto/bigint/+test/monty.ha    | 16 ++++++++--------
 crypto/bigint/+test/utils.ha    |  2 +-
 crypto/bigint/README            |  2 +-
 crypto/bigint/arithm.ha         |  4 ++--
 crypto/bigint/encoding.ha       |  6 +++---
 crypto/bigint/monty.ha          |  4 ++--
 7 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/crypto/bigint/+test/encoding.ha b/crypto/bigint/+test/encoding.ha
index f2e50eb9..6c7c013a 100644
--- a/crypto/bigint/+test/encoding.ha
+++ b/crypto/bigint/+test/encoding.ha
@@ -20,7 +20,7 @@ use bytes;
	];
	let result: [25]u8 = [0...];

	let buf: []word = alloc([0...], wordsize(decoded));
	let buf: []word = alloc([0...], encodelen(decoded));
	defer free(buf);

	encode(buf, decoded);
@@ -34,7 +34,7 @@ use bytes;
	const input: [4]u8 = [0, 0, 0, 10];

	let mod = fromhex("00190000");
	let resultbuf: []word = alloc([0...], wordsize(input));
	let resultbuf: []word = alloc([0...], encodelen(input));
	let result: [4]u8 = [0...];

	let ret = encodemod(resultbuf[..], input, mod);
@@ -60,7 +60,7 @@ use bytes;

	let mod = fromhex("190000");
	defer free(mod);
	let resultbuf: []word = alloc([0...], wordsize(input));
	let resultbuf: []word = alloc([0...], encodelen(input));
	let result: [4]u8 = [0...];

	encodereduce(resultbuf, input, mod);
@@ -68,13 +68,13 @@ use bytes;
	assert(bytes::equal(result, input));

	const input: [4]u8 = [0, 0x19, 0, 0];
	let resultbuf: []word = alloc([0...], wordsize(input));
	let resultbuf: []word = alloc([0...], encodelen(input));
	encodereduce(resultbuf, input, mod);
	decode(result, resultbuf);
	assert(iszero(resultbuf) == 1);

	const input: [4]u8 = [0x24, 0x17, 0x01, 0x05];
	let resultbuf: []word = alloc([0...], wordsize(input));
	let resultbuf: []word = alloc([0...], encodelen(input));
	encodereduce(resultbuf, input, mod);
	decode(result, resultbuf);
	assert(bytes::equal(result, [0x00, 0x0e, 0x01, 0x05]));
diff --git a/crypto/bigint/+test/monty.ha b/crypto/bigint/+test/monty.ha
index b62d23f6..bc7e9157 100644
--- a/crypto/bigint/+test/monty.ha
+++ b/crypto/bigint/+test/monty.ha
@@ -8,8 +8,8 @@

	const m0i = ninv31(m[1]);

	to_monty(x, m);
	from_monty(x, m, m0i);
	tomonty(x, m);
	frommonty(x, m, m0i);

	assert(equalshex(x, "010064"));
};
@@ -22,10 +22,10 @@

	const m0i = ninv31(m[1]);

	to_monty(x, m);
	to_monty(y, m);
	tomonty(x, m);
	tomonty(y, m);
	montymul(d, x, y, m, m0i);
	from_monty(d, m, m0i);
	frommonty(d, m, m0i);

	assert(equalshex(d, "04544d"));

@@ -37,10 +37,10 @@
	x = fromhexmod("0f98b7cf", m);
	y = fromhexmod("04216b9c", m);

	to_monty(x, m);
	to_monty(y, m);
	tomonty(x, m);
	tomonty(y, m);
	montymul(d, x, y, m, m0i);
	from_monty(d, m, m0i);
	frommonty(d, m, m0i);

	assert(equalshex(d, "0d031f49"));

diff --git a/crypto/bigint/+test/utils.ha b/crypto/bigint/+test/utils.ha
index 8ca321fb..0b035579 100644
--- a/crypto/bigint/+test/utils.ha
+++ b/crypto/bigint/+test/utils.ha
@@ -5,7 +5,7 @@ export fn fromhex(h: str) []word = {
	let n: []u8 = hex::decodestr(h)!;
	defer free(n);

	let i: []word = alloc([0...], wordsize(n));
	let i: []word = alloc([0...], encodelen(n));
	encode(i, n);
	return i;
};
diff --git a/crypto/bigint/README b/crypto/bigint/README
index ab0e261f..215c457a 100644
--- a/crypto/bigint/README
+++ b/crypto/bigint/README
@@ -4,7 +4,7 @@ carefully to avoid misuse. Restrictions apply to the compatibility of
differently-sized big integers, and some functions require an uneven modulo.

A big integer is an array of [[word]] and must be encoded using [[encode]],
[[encodemod]] or [[encodereduce]]. See [[wordsize]] on how to calculate the
[[encodemod]] or [[encodereduce]]. See [[encodelen]] on how to calculate the
required size of the array. The big integer will also store its announced bit
length, i.e. the number of bits that are actually used to store its value; and
the effective word length, i.e. the number of words that are actually used to
diff --git a/crypto/bigint/arithm.ha b/crypto/bigint/arithm.ha
index 58c305c1..2819adef 100644
--- a/crypto/bigint/arithm.ha
+++ b/crypto/bigint/arithm.ha
@@ -361,7 +361,7 @@ export fn modpow(
	};

	// Everything is done in Montgomery representation.
	to_monty(x, m);
	tomonty(x, m);

	// Compute window contents. If the window has size one bit only,
	// then t2 is set to x; otherwise, t2[0] is left untouched, and
@@ -441,6 +441,6 @@ export fn modpow(
	};

	// Convert back from Montgomery representation, and exit.
	from_monty(x, m, m0i);
	frommonty(x, m, m0i);
	return 1;
};
diff --git a/crypto/bigint/encoding.ha b/crypto/bigint/encoding.ha
index ea7fe736..4a192e12 100644
--- a/crypto/bigint/encoding.ha
+++ b/crypto/bigint/encoding.ha
@@ -21,17 +21,17 @@
// SOFTWARE.
use crypto::math::*;

// Minimal required words to store x into an []word. To statically allocate
// Minimal required words to encode 'x' into an []word. To statically allocate
// resources, following expression may be used:
//
//     ((number_of_bits + WORD_BITSIZE - 1) / WORD_BITSIZE) + 1
export fn wordsize(x: []u8) size = {
export fn encodelen(x: []u8) size = {
	return (((len(x) * 8) + WORD_BITSIZE - 1) / WORD_BITSIZE) + 1;
};

// Encode 'src' from its big-endian unsigned encoding into the internal
// representation. The caller must make sure that 'dest' has enough space to
// store 'src'. See [[wordsize]] for how to calculate the required size.
// store 'src'. See [[encodelen]] for how to calculate the required size.
//
// This function runs in constant time for given 'src' length.
export fn encode(dest: []word, src: const []u8) void = {
diff --git a/crypto/bigint/monty.ha b/crypto/bigint/monty.ha
index 14dc0481..78fb4451 100644
--- a/crypto/bigint/monty.ha
+++ b/crypto/bigint/monty.ha
@@ -23,7 +23,7 @@ use crypto::math::*;

// Convert a modular integer to Montgomery representation. The integer 'x' must
// be lower than 'm', but with the same announced bit length.
export fn to_monty(x: []word, m: const []word) void = {
export fn tomonty(x: []word, m: const []word) void = {
	assert(equ32(x[0], m[0]) == 1);
	for (let k: u32 = ewordlen(m); k > 0; k -= 1) {
		muladd_small(x, 0, m);
@@ -35,7 +35,7 @@ export fn to_monty(x: []word, m: const []word) void = {
// parameter is equal to -(1/m0) mod 2^32, where m0 is the least significant
// value word of 'm' (this works only if 'm' is an odd integer). See [[ninv]]
// for how to get this value.
export fn from_monty(x: []word, m: const []word, m0i: word) void = {
export fn frommonty(x: []word, m: const []word, m0i: word) void = {
	assert(equ32(x[0], m[0]) == 1);
	const mlen = ewordlen(m);
	for (let u = 0z; u < mlen; u += 1) {
-- 
2.37.3
builds.sr.ht <builds@sr.ht>
hare/patches: SUCCESS in 1m53s

[crypto::bigint: improve some function names][0] from [Armin Preiml][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/35503
[1]: mailto:apreiml@strohwolke.at

✓ #849056 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/849056
✓ #849055 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/849055