Skip to content

Commit

Permalink
crypto: Add generic 32-bit carry-less multiply routines
Browse files Browse the repository at this point in the history
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Sep 15, 2023
1 parent a2c6734 commit 9a65a57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crypto/clmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions include/crypto/clmul.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 9a65a57

Please sign in to comment.