Sample¶
Sample module¶
- class fips.FIPS204.sample.SAMPLE(parameter)[source]¶
Bases:
objectAlgorithms for generating algebraic objects pseudorandomly from a seed rho, rho is a byte string whose length varies depending on the algorithm.
- Parameters:
parameter (dict[str, int])
- SampleInBall(rho)[source]¶
Algorithm 29
Samples a polynomial
cbelonging toRwith coefficients from{-1, 0, 1}and Hamming weighttau <= 64.- Parameters:
rho (
bytes) – a bytestring of lengthlambda / 4bits.- Returns:
a list of integers representing the polynomial.
- Return type:
list[int]- Raises:
ValueError – if length of
rhois notlambda / 4bits.TypeError – if
rhois not a bytestring.
- RejNTTPoly(rho)[source]¶
Algorithm 30
Samples a polynomial belonging to Tq.
- Parameters:
rho (
bytes) – a bytestring of length 34.- Returns:
a list of integers representing the polynomial.
- Return type:
list[int]- Raises:
TypeError – if
rhois not abytestring.ValueError – if length of
rhois not34bytes.
- RejBoundedPoly(rho)[source]¶
Algorithm 31
Samples an element a belonging to R with coefficients in [-eta, eta] computed via rejection sampling from rho.
- Parameters:
rho (
bytes) – a bytestring of length66.- Returns:
a list of integers representing the polynomial.
- Return type:
list[int]- Raises:
TypeError – if
rhois not abytestring.
- ExpandA(rho)[source]¶
Algorithm 32
samples a
k x lmatrix of elements ofTq.- Parameters:
rho (
bytes) – a bytestring of length32.- Returns:
a
k x lmatrix of polynomials.- Return type:
list[list[list[int]]]- Raises:
ValueError – if length of
rhois not32bytes.
- ExpandS(rho)[source]¶
Algorithm 33
Samples vector s1 belonging to R^l and s2 belonging to R^k, each with polynomial coordinates whose coefficients are in the interval [-eta, eta].
- Parameters:
rho (
bytes) – a bytestring of length64.- Returns:
a
listoflpolynomials representing the vectors1. s2 (list): alistofkpolynomials representing the vectors2.- Return type:
tuple[list[list[int]],list[list[int]]]- Raises:
ValueError – if length of
rhois not64bytes.
- ExpandMask(rho, mew)[source]¶
Algorithm 34
Samples a vector
y ∈ R^lsuch that each polynomialy[r]has coefficients between-gamma1 + 1andgamma1.- Parameters:
rho (
bytes) – abytestringof length64.mew (
int) – anintegerused in the sampling process.
- Returns:
a
listof polynomials representing the vectory.- Return type:
list[list[int]]- Raises:
ValueError – if length of
rhois not64bytes.TypeError – if
mewis not an integer.ValueError – if
mewis a negative integer.