commit db5c7fb4b62369747a677cf00b4aa0b50161e6e3
parent fb661e20b1fa3cb8d5a6d7d5e8fd39d2d7cfd588
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Thu, 22 Sep 2022 13:00:10 +0200
crypto::bigint: improve some function names
to fit the hare style better.
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
7 files changed, 22 insertions(+), 22 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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) {