From 784352e6e52ad04957cebc00b8b8556353cbab3c Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Thu, 25 Jul 2024 12:46:40 +0200 Subject: [PATCH] polynomials: create coefficients in cbd from an iterator Signed-off-by: Hubert Kario --- src/kyber_py/polynomials/polynomials.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/kyber_py/polynomials/polynomials.py b/src/kyber_py/polynomials/polynomials.py index 6876078..0b2ccc5 100644 --- a/src/kyber_py/polynomials/polynomials.py +++ b/src/kyber_py/polynomials/polynomials.py @@ -68,16 +68,14 @@ def cbd(self, input_bytes, eta, is_ntt=False): For Kyber, this is 64 eta. """ assert 64 * eta == len(input_bytes) - coefficients = [0 for _ in range(256)] b_int = int.from_bytes(input_bytes, "little") mask = (1 << eta) - 1 mask2 = (1 << 2 * eta) - 1 - for i in range(256): - x = b_int & mask2 - a = bit_count(x & mask) - b = bit_count((x >> eta) & mask) - b_int >>= 2 * eta - coefficients[i] = (a - b) % 3329 + coefficients = [ + (bit_count(x & mask) - bit_count((x >> eta) & mask)) % 3329 + for x in + ((b_int >> 2 * eta * i) & mask2 for i in range(256)) + ] return self(coefficients, is_ntt=is_ntt) def decode(self, input_bytes, d, is_ntt=False):