Skip to content

Commit

Permalink
polynomials: create coefficients in cbd from an iterator
Browse files Browse the repository at this point in the history
Signed-off-by: Hubert Kario <hkario@redhat.com>
  • Loading branch information
tomato42 committed Jul 25, 2024
1 parent 4b4e6bb commit 784352e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/kyber_py/polynomials/polynomials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 784352e

Please sign in to comment.