NTT¶
Ntt module¶
- class fips.FIPS204.ntt.NTT(parameter)[source]¶
Bases:
object- Parameters:
parameter (dict[str, int])
- NTT(coefficient_list)[source]¶
Algorithm 41
Computes the NTT.
- Parameters:
coefficient_list (
list[int]) –listof integers representing polynomial coefficients.- Returns:
listof integers representingNTTtransformed polynomial coefficients.- Return type:
list[int]- Raises:
TypeError – If the input is not a list or tuple, or if any coefficient is not an integer.
ValueError – If the input list does not contain exactly 256 elements.
- inv_NTT(coefficient_list)[source]¶
Algorithm 42
Computes the inverse of the NTT.
- Parameters:
coefficient_list (
list[int]) –listof integers representing polynomial coefficients inNTTdomain.- Returns:
listof integers representing polynomial coefficients.- Return type:
list[int]- Raises:
TypeError – If the input is not a list or tuple, or if any coefficient is not an integer.
ValueError – If the input list does not contain exactly 256 elements.
- AddNTT(a_vec, b_vec)[source]¶
Algorithm 44
Computes the sum
a_vec + b_vecof the two elementsa_vec,b_vecbelong toTq- Parameters:
a_vec (
list[int]) – first polynomial inNTTdomain.b_vec (
list[int]) – second polynomial inNTTdomain.
- Returns:
resulting polynomial in
NTTdomain after addition.- Return type:
list[int]- Raises:
TypeError – If the inputs are not
listsortuples.ValueError – If the input lists are
not of equal size.
- SubNTT(a_vec, b_vec)[source]¶
Algorithm 44 modified
Computes the sum
a_vec - b_vecof the two elementsa_vec,b_vecbelong toTq- Parameters:
a_vec (
list[int]) – first polynomial inNTTdomain.b_vec (
list[int]) – second polynomial inNTTdomain.
- Returns:
resulting polynomial in
NTTdomain after subtraction.- Return type:
list[int]
- MultiplyNTT(a_vec, b_vec)[source]¶
Algorithm 45
Computes the product
a_vec * b_vecof two elementsa_vec,b_vecbelong toTq.- Parameters:
a_vec (
list[int]) –listof integers representing polynomial coefficients inNTTdomain.b_vec (
list[int]) –listof integers representing polynomial coefficients inNTTdomain.
- Returns:
list of integers representing
NTTmultiplied polynomial coefficients.- Return type:
list[int]- Raises:
TypeError – If the inputs are
not listsortuples.ValueError – If the input lists are
not of equal size.
- ScalarVectorNTT(vector, polynomial)[source]¶
Algorithm 47
Computes the product polynomial * vector of a scalar polynomial and a vector over Tq.
- Parameters:
polynomial (
list[int]) – A polynomial inNTTdomain.vector (
list[list[int]]) – Avectorof polynomials inNTTdomain.
- Returns:
The resulting vector of polynomials after multiplication in
NTTdomain.- Return type:
list[list[int]]- Raises:
TypeError – If the inputs are
not listsortuples.ValueError – If the
dimensionsof the polynomial and vector are incompatible.
- MatrixVectorNTT(matrix, vector)[source]¶
Algorithm 48
Computes the product matrix * vector of a matrix and a vector v over Tq.
- Parameters:
matrix (
list[list[list[int]]]) – Amatrixof polynomials inNTTdomain.vector (
list[list[int]]) – Avectorof polynomials inNTTdomain.
- Returns:
The resulting vector of polynomials after multiplication in NTT domain.
- Return type:
list[list[int]]- Raises:
TypeError – If the inputs are
not listsortuples.ValueError – If the dimensions of the matrix and vector are incompatible.