Skip to main content

lib_q_ring/
lib.rs

1//! Shared ring arithmetic for ML-DSA / module-lattice constructions over
2//! \(R_q = \mathbb{Z}_q\[X\]/(X^{256}+1)\), \(q = 8\,380\,417\).
3//!
4//! Portable NTT (Cooley–Tukey forward, Gentleman–Sande inverse with Montgomery
5//! scaling) is bit-compatible with the non-`hardened` path in `lib-q-ml-dsa`.
6#![no_std]
7#![forbid(unsafe_code)]
8#![allow(missing_docs)]
9
10#[cfg(feature = "alloc")]
11extern crate alloc;
12
13pub mod challenge;
14pub mod coeff;
15pub mod constants;
16pub mod encoding;
17pub mod field;
18
19mod generated_invntt;
20mod generated_ntt;
21
22pub mod ntt;
23pub mod params;
24pub mod poly;
25pub mod uniform;
26
27#[cfg(feature = "alloc")]
28pub mod expand;
29#[cfg(feature = "alloc")]
30pub mod module;
31
32pub use challenge::sample_in_ball;
33#[cfg(feature = "alloc")]
34pub use expand::expand_a_from_seed;
35pub use field::{
36    FieldElementTimesMontgomeryR,
37    add_coeffs,
38    montgomery_multiply_by_constant,
39    montgomery_multiply_coeffs,
40    montgomery_multiply_fe_by_fer,
41    montgomery_reduce_element,
42    reduce_element,
43    reduce_poly_simd,
44    subtract_coeffs,
45};
46#[cfg(feature = "alloc")]
47pub use module::{
48    ModuleMatrix,
49    ModuleVec,
50};
51pub use ntt::{
52    intt_montgomery,
53    ntt_forward_simd,
54    ntt_multiply_montgomery,
55};
56pub use poly::{
57    NttPoly,
58    Poly,
59};
60pub use uniform::{
61    sample_uniform_coeff_mod_q,
62    sample_uniform_field_coefficient,
63    try_uniform_coeff_mod_q_from_u32,
64    uniform_mod_u32_rejection_threshold,
65};