commit 0aa7dfdc9d77fab0ba0735a82730e2b5eb9c1d43
parent 181b5c0bd8827845c35801304f6431c80ed51a81
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Tue, 29 Nov 2022 13:24:00 +0100
crypto::bigint: add decrodd and isodd
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/crypto/bigint/arithm.ha b/crypto/bigint/arithm.ha
@@ -55,6 +55,12 @@ export fn sub(a: []word, b: const []word, do: u32) u32 = {
return carry;
};
+// Decrements 1 from an odd integer 'x'.
+export fn decrodd(x: []word) void = {
+ assert(isodd(x));
+ x[1] ^= 1;
+};
+
// Right-shift an integer 'x' by 'count'. The shift amount must be less than
// [[WORD_BITSIZE]].
export fn rshift(x: []word, count: word) void = {
diff --git a/crypto/bigint/util.ha b/crypto/bigint/util.ha
@@ -64,4 +64,6 @@ fn iszero(x: []word) u32 = {
free(y);
};
-
+fn isodd(x: []word) bool = {
+ return x[1] & 1 == 1;
+};