Skip to main content

Ntt64Context

Struct Ntt64Context 

Source
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: usize

Polynomial size (power of 2).

§log_n: u32

log₂(n).

§arith: Ntt64Arith

Modular 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: u64

N⁻¹ mod q — normalization factor for the INTT.

Implementations§

Source§

impl Ntt64Context

Source

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
Source

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 n is not a power of 2
  • If the modulus is not prime
  • If q − 1 is not divisible by 2N
Source

pub fn forward(&self, data: &mut [u64])

Applies forward NTT in-place.

Source

pub fn inverse(&self, data: &mut [u64])

Applies inverse NTT in-place.

Source

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.

Source

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.

Source

pub fn negacyclic_mul(&self, a: &[u64], b: &[u64]) -> Vec<u64>

Full negacyclic polynomial multiplication: c = a * b mod (X^N + 1).

Performs forward NTT on both inputs, pointwise multiplication, and inverse NTT on the result.

Trait Implementations§

Source§

impl Clone for Ntt64Context

Source§

fn clone(&self) -> Ntt64Context

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ntt64Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.