Skip to main content

PqNtt

Struct PqNtt 

Source
pub struct PqNtt { /* private fields */ }
Expand description

A ready-to-use NTT engine configured for a specific post-quantum scheme.

Wraps Ntt32Context with scheme metadata for safety and convenience.

§Example

use vaea_ntt::pq::{PqScheme, PqNtt};

let ntt = PqNtt::new(PqScheme::MlDsa65);
assert_eq!(ntt.scheme(), PqScheme::MlDsa65);
assert_eq!(ntt.n(), 256);
assert_eq!(ntt.q(), 8380417);

let mut data = vec![0u32; 256];
data[0] = 1;
ntt.forward(&mut data);
ntt.inverse(&mut data);
assert_eq!(data[0], 1);

Implementations§

Source§

impl PqNtt

Source

pub fn new(scheme: PqScheme) -> Self

Creates a new PQ-NTT engine for the given scheme.

This precomputes all twiddle factors and modular arithmetic constants. The context can be reused for multiple NTT calls.

Source

pub fn scheme(&self) -> PqScheme

Returns the scheme this engine was configured for.

Source

pub fn n(&self) -> usize

Returns the polynomial degree N.

Source

pub fn q(&self) -> u32

Returns the prime modulus q.

Source

pub fn security_level(&self) -> u8

Returns the NIST security level.

Source

pub fn context(&self) -> &Ntt32Context

Returns a reference to the underlying Ntt32Context.

Source

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

Applies forward NTT in-place.

Transforms from coefficient domain to evaluation (NTT) domain. In NTT domain, polynomial multiplication is pointwise O(N).

§Panics

If data.len() != self.n().

Source

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

Applies inverse NTT in-place.

Transforms from evaluation (NTT) domain back to coefficient domain. Includes the N⁻¹ normalization factor.

§Panics

If data.len() != self.n().

Source

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

Computes negacyclic polynomial multiplication: result = a × b mod (X^N + 1, q).

Both inputs must be in coefficient domain (not NTT). Result is in coefficient domain.

§Panics

If a.len() != self.n() or b.len() != self.n().

Source

pub fn multiply_into(&self, a: &mut [u32], b: &mut [u32], result: &mut [u32])

Computes negacyclic polynomial multiplication: result = a × b mod (X^N + 1, q).

Both a and b are consumed (transformed in-place as scratch space). Result is written to result.

§Panics

If any slice length != self.n().

Trait Implementations§

Source§

impl Debug for PqNtt

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for PqNtt

§

impl RefUnwindSafe for PqNtt

§

impl Send for PqNtt

§

impl Sync for PqNtt

§

impl Unpin for PqNtt

§

impl UnsafeUnpin for PqNtt

§

impl UnwindSafe for PqNtt

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> 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, 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.