mirror of
https://github.com/mii443/qemu.git
synced 2025-08-22 23:25:48 +00:00
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>
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user