1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Reference NTT120 CPU backend for the Poulpy lattice cryptography library.
//!
//! This crate provides [`NTT120Ref`], a backend implementation for [`poulpy_hal`] that uses
//! scalar Q120 NTT arithmetic (Chinese Remainder Theorem over four ~30-bit primes). It is the
//! reference NTT120 implementation: portable across all CPU architectures, prioritising
//! correctness and debuggability over throughput.
//!
//! # Architecture
//!
//! `poulpy-hal` defines a hardware abstraction layer (HAL) via the [`Backend`](poulpy_hal::layouts::Backend)
//! trait and a family of _open extension point_ (OEP) traits in [`poulpy_hal::oep`]. This crate
//! implements every OEP trait for the [`NTT120Ref`] backend by delegating to the reference
//! functions provided by `crate::reference::ntt120`.
//!
//! The internal modules are organised by operation domain:
//!
//! | Module | Domain |
//! |-----------------|----------------------------------------------------------------|
//! | `module` | Backend handle lifecycle, NTT table management |
//! | `scratch` | Temporary memory allocation and arena-style sub-allocation, now provided by shared `poulpy-hal` portable defaults |
//! | `znx` | Single ring element (`Z[X]/(X^n+1)`) arithmetic |
//! | `vec_znx` | Vectors of ring elements (limb decomposition), now provided by shared `poulpy-hal` portable defaults |
//! | `vec_znx_big` | Large-coefficient (i128) ring element vectors, now provided by shared `poulpy-hal` NTT120 defaults |
//! | `vec_znx_dft` | NTT-domain ring element vectors, now provided by shared `poulpy-hal` NTT120 defaults |
//! | `svp` | Scalar-vector product in NTT domain, now provided by shared `poulpy-hal` NTT120 defaults |
//!
//! # Scalar types
//!
//! For the `NTT120Ref` backend:
//!
//! - `ScalarPrep = Q120bScalar`: coefficients in the NTT / frequency domain (32 bytes = 4 × u64).
//! - `ScalarBig = i128`: coefficients in the large-integer (CRT-reconstructed) domain.
//!
//! # Usage
//!
//! This crate exports a single public type, [`NTT120Ref`], which is used as a type parameter
//! to the HAL generic types. All functionality is accessed through the trait methods defined
//! in `poulpy_hal::api`.
//!
//! # Platform support
//!
//! Compiles and runs on any target supported by the Rust standard library.
//! No platform-specific intrinsics or assembly are used.
pub use NTT120RefHandle;
/// Reference (portable) CPU backend using Q120 NTT arithmetic.
///
/// `NTT120Ref` is a zero-sized marker type that selects the reference NTT120 CPU backend
/// when used as the type parameter `B` in [`poulpy_hal::layouts::Module<B>`](poulpy_hal::layouts::Module)
/// and related HAL types. It implements all open extension point (OEP) traits from
/// `poulpy_hal::oep` by delegating to the portable reference functions in
/// `crate::reference::ntt120`.
///
/// # Backend characteristics
///
/// - **ScalarPrep**: `Q120bScalar` — NTT-domain coefficients stored as 4 × u64 CRT residues.
/// - **ScalarBig**: `i128` — large-coefficient ring elements use 128-bit signed integers.
/// - **Prime set**: `Primes30` (four ~30-bit primes, Q ≈ 2^120).
/// - **NTT tables**: precomputed twiddle factors stored in the module handle
/// (`NTT120RefHandle`), shared across all operations on the same module.
///
/// # Thread safety
///
/// `NTT120Ref` is `Send + Sync` (derived from being a zero-sized, field-less struct).
/// The `Module<NTT120Ref>` that holds the NTT tables is also `Send + Sync`, so modules can
/// be shared across threads.
;