pub struct Ntt64Context {
pub n: usize,
pub log_n: u32,
pub arith: Ntt64Arith,
pub root_powers: Vec<u64>,
pub inv_root_powers: Vec<u64>,
pub n_inv: u64,
}Expand description
Precomputed NTT context for a given (N, modulus) pair.
Contains twiddle-factor tables for both forward and inverse NTT, organized in Longa-Naehrig ordering for negacyclic convolution.
Fields§
§n: usizePolynomial size (power of 2).
log_n: u32log₂(n).
arith: Ntt64ArithModular arithmetic context (Barrett/Montgomery constants).
root_powers: Vec<u64>Twiddle factors for forward NTT.
Organized for sequential access in the Cooley-Tukey butterfly:
root_powers[m + j] for layer with half-size m and group index j.
inv_root_powers: Vec<u64>Inverse twiddle factors for inverse NTT.
Organized for sequential access in the Gentleman-Sande butterfly.
n_inv: u64N⁻¹ mod q — normalization factor for the INTT.
Implementations§
Source§impl Ntt64Context
impl Ntt64Context
Sourcepub fn try_new(n: usize, arith: Ntt64Arith) -> Result<Self, NttError>
pub fn try_new(n: usize, arith: Ntt64Arith) -> Result<Self, NttError>
Fallible constructor for an NTT context.
Validates all preconditions and returns an error instead of panicking.
§Arguments
n— polynomial size, must be a power of 2 (≥ 2)arith— precomputed modular arithmetic context; the modulus must be prime and satisfy q ≡ 1 (mod 2N)
§Errors
crate::NttError::InvalidSizeifnis not a power of 2 ≥ 2crate::NttError::NotPrimeif the modulus is not primecrate::NttError::NotNttFriendlyifq − 1is not divisible by2N
Sourcepub fn new(n: usize, arith: Ntt64Arith) -> Self
pub fn new(n: usize, arith: Ntt64Arith) -> Self
Creates a new NTT context for polynomial size n and the given arithmetic context.
§Arguments
n— polynomial size, must be a power of 2 (≥ 2)arith— precomputed modular arithmetic context; the modulus must satisfy q ≡ 1 (mod 2N)
§Panics
- If
nis not a power of 2 - If the modulus is not prime
- If q − 1 is not divisible by 2N
Sourcepub fn forward_tiled(&self, data: &mut [u64])
pub fn forward_tiled(&self, data: &mut [u64])
Applies the tiled forward NTT in-place.
Currently delegates to the standard forward NTT. A cache-optimized four-step variant is planned for v0.2.
Sourcepub fn pointwise_mul(&self, a: &[u64], b: &[u64], result: &mut [u64])
pub fn pointwise_mul(&self, a: &[u64], b: &[u64], result: &mut [u64])
Pointwise multiplication of two NTT-domain vectors.
result[i] = a[i] * b[i] mod q
This is the core operation: in NTT domain, polynomial convolution becomes element-wise multiplication.
Trait Implementations§
Source§impl Clone for Ntt64Context
impl Clone for Ntt64Context
Source§fn clone(&self) -> Ntt64Context
fn clone(&self) -> Ntt64Context
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more