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#![forbid(unsafe_code)]
7#![allow(missing_docs)]
8#![cfg_attr(not(feature = "std"), no_std)]
9
10#[cfg(feature = "alloc")]
11extern crate alloc;
12
13#[cfg(all(not(feature = "std"), feature = "no_std_panic_handler"))]
14mod no_std_panic_handler {
15    use core::panic::PanicInfo;
16
17    #[panic_handler]
18    #[allow(clippy::empty_loop)]
19    fn panic(_info: &PanicInfo) -> ! {
20        loop {}
21    }
22}
23
24pub mod challenge;
25pub mod coeff;
26pub mod constants;
27pub mod encoding;
28pub mod field;
29
30mod generated_invntt;
31mod generated_ntt;
32
33pub mod ntt;
34pub mod params;
35pub mod poly;
36pub mod uniform;
37
38#[cfg(feature = "alloc")]
39pub mod expand;
40#[cfg(feature = "alloc")]
41pub mod module;
42
43pub use challenge::sample_in_ball;
44#[cfg(feature = "alloc")]
45pub use expand::expand_a_from_seed;
46pub use field::{
47    FieldElementTimesMontgomeryR,
48    add_coeffs,
49    montgomery_multiply_by_constant,
50    montgomery_multiply_coeffs,
51    montgomery_multiply_fe_by_fer,
52    montgomery_reduce_element,
53    reduce_element,
54    reduce_poly_simd,
55    subtract_coeffs,
56};
57#[cfg(feature = "alloc")]
58pub use module::{
59    ModuleMatrix,
60    ModuleVec,
61};
62pub use ntt::{
63    intt_montgomery,
64    ntt_forward_simd,
65    ntt_multiply_montgomery,
66};
67pub use poly::{
68    NttPoly,
69    Poly,
70};
71pub use uniform::{
72    sample_uniform_coeff_mod_q,
73    sample_uniform_field_coefficient,
74    try_uniform_coeff_mod_q_from_u32,
75    uniform_mod_u32_rejection_threshold,
76};
77
78#[cfg(feature = "wasm")]
79pub mod wasm;