summaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2023-07-11 10:10:47 +0100
committerRichard Henderson <richard.henderson@linaro.org>2023-09-15 13:57:00 +0000
commit00f463b38aa7cfca0bc65e3af7f2c49e1b9da690 (patch)
tree1a0835b5c4babf3806eb4d3e373691b23efdd254 /crypto
parentf56d3c1a140267ae88874d755fa2f24cb71a1572 (diff)
crypto: Add generic 64-bit carry-less multiply routine
Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/clmul.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/clmul.c b/crypto/clmul.c
index 36ada1be9d..9e3e61a77d 100644
--- a/crypto/clmul.c
+++ b/crypto/clmul.c
@@ -92,3 +92,20 @@ uint64_t clmul_32(uint32_t n, uint32_t m32)
}
return r;
}
+
+Int128 clmul_64_gen(uint64_t n, uint64_t m)
+{
+ uint64_t rl = 0, rh = 0;
+
+ /* Bit 0 can only influence the low 64-bit result. */
+ if (n & 1) {
+ rl = m;
+ }
+
+ for (int i = 1; i < 64; ++i) {
+ uint64_t mask = -((n >> i) & 1);
+ rl ^= (m << i) & mask;
+ rh ^= (m >> (64 - i)) & mask;
+ }
+ return int128_make128(rl, rh);
+}