From: Richard Henderson Date: Tue, 11 Jul 2023 08:54:06 +0000 (+0100) Subject: crypto: Add generic 32-bit carry-less multiply routines X-Git-Tag: v8.2.0-rc0~125^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a65a570fab1bf2e907d593631a6b588a821d365;p=thirdparty%2Fqemu.git crypto: Add generic 32-bit carry-less multiply routines Reviewed-by: Ard Biesheuvel Signed-off-by: Richard Henderson --- diff --git a/crypto/clmul.c b/crypto/clmul.c index 2c87cfbf8ab..36ada1be9d1 100644 --- a/crypto/clmul.c +++ b/crypto/clmul.c @@ -79,3 +79,16 @@ uint64_t clmul_16x2_odd(uint64_t n, uint64_t m) { return clmul_16x2_even(n >> 16, m >> 16); } + +uint64_t clmul_32(uint32_t n, uint32_t m32) +{ + uint64_t r = 0; + uint64_t m = m32; + + for (int i = 0; i < 32; ++i) { + r ^= n & 1 ? m : 0; + n >>= 1; + m <<= 1; + } + return r; +} diff --git a/include/crypto/clmul.h b/include/crypto/clmul.h index 72672b237c3..80de516464f 100644 --- a/include/crypto/clmul.h +++ b/include/crypto/clmul.h @@ -54,4 +54,11 @@ uint64_t clmul_16x2_even(uint64_t, uint64_t); */ uint64_t clmul_16x2_odd(uint64_t, uint64_t); +/** + * clmul_32: + * + * Perform a 32x32->64 carry-less multiply. + */ +uint64_t clmul_32(uint32_t, uint32_t); + #endif /* CRYPTO_CLMUL_H */