kyber_py.polynomials package

Submodules

kyber_py.polynomials.polynomials module

class kyber_py.polynomials.polynomials.Polynomial(parent, coefficients)

Bases: GenericPolynomial

compress(d)

Compress the polynomial by compressing each coefficient

NOTE: This is lossy compression

decompress(d)

Decompress the polynomial by decompressing each coefficient

NOTE: This as compression is lossy, we have x’ = decompress(compress(x)), which x’ != x, but is close in magnitude.

encode(d)

Encode (Inverse of Algorithm 3)

from_ntt()

Not supported, raises a TypeError

is_constant()

Return if polynomial is constant: f = c

is_zero()

Return if polynomial is zero: f = 0

reduce_coefficients()

Reduce all coefficients modulo q

to_ntt()

Convert a polynomial to number-theoretic transform (NTT) form. The input is in standard order, the output is in bit-reversed order.

class kyber_py.polynomials.polynomials.PolynomialNTT(parent, coefficients)

Bases: Polynomial

compress(d)

Compress the polynomial by compressing each coefficient

NOTE: This is lossy compression

decompress(d)

Decompress the polynomial by decompressing each coefficient

NOTE: This as compression is lossy, we have x’ = decompress(compress(x)), which x’ != x, but is close in magnitude.

encode(d)

Encode (Inverse of Algorithm 3)

from_ntt()

Convert a polynomial from number-theoretic transform (NTT) form in place The input is in bit-reversed order, the output is in standard order.

is_constant()

Return if polynomial is constant: f = c

is_zero()

Return if polynomial is zero: f = 0

reduce_coefficients()

Reduce all coefficients modulo q

to_ntt()

Not supported, raises a TypeError

class kyber_py.polynomials.polynomials.PolynomialRing

Bases: GenericPolynomialRing

Initialise the polynomial ring:

R = GF(3329) / (X^256 + 1)

cbd(input_bytes, eta, is_ntt=False)

Algorithm 2 (Centered Binomial Distribution) https://pq-crystals.org/kyber/data/kyber-specification-round3-20210804.pdf

Algorithm 6 (Sample Poly CBD)

Expects a byte array of length (eta * deg / 4) For Kyber, this is 64 eta.

decode(input_bytes, d, is_ntt=False)

Decode (Algorithm 3)

decode: B^32l -> R_q

gen()

Return the generator x of the polynomial ring

ntt_sample(input_bytes)

Algorithm 1 (Parse) https://pq-crystals.org/kyber/data/kyber-specification-round3-20210804.pdf

Algorithm 6 (Sample NTT)

Parse: B^* -> R

random_element()

Compute a random element of the polynomial ring with coefficients in the canonical range: [0, q-1]

zero()

Return the zero element of the polynomial ring

kyber_py.polynomials.polynomials_generic module

class kyber_py.polynomials.polynomials_generic.GenericPolynomial(parent, coefficients)

Bases: object

is_constant()

Return if polynomial is constant: f = c

is_zero()

Return if polynomial is zero: f = 0

reduce_coefficients()

Reduce all coefficients modulo q

class kyber_py.polynomials.polynomials_generic.GenericPolynomialRing(q, n)

Bases: object

Initialise the polynomial ring:

R = GF(q) / (X^n + 1)

gen()

Return the generator x of the polynomial ring

random_element()

Compute a random element of the polynomial ring with coefficients in the canonical range: [0, q-1]

zero()

Return the zero element of the polynomial ring

Module contents