Crates.io | concrete-ntt |
lib.rs | concrete-ntt |
version | 0.2.0 |
source | src |
created_at | 2023-05-05 15:00:30.827588 |
updated_at | 2024-08-29 07:27:38.43876 |
description | Concrete-NTT is a pure Rust high performance number theoretic transform library. |
homepage | https://zama.ai/ |
repository | https://github.com/zama-ai/concrete-ntt |
max_upload_size | |
id | 857804 |
size | 631,992 |
Concrete-NTT is a pure Rust high performance Number Theoretic Transform library that processes vectors of sizes that are powers of two.
This library provides three kinds of NTT:
Concrete-ntt requires a Rust version >= 1.67.0.
std
(default): This enables runtime arch detection for accelerated SIMD instructions.nightly
: This enables unstable Rust features to further speed up the NTT, by enabling
AVX512 instructions on CPUs that support them. This feature requires a nightly Rust
toolchain.use concrete_ntt::prime32::Plan;
const N: usize = 32;
let p = 1062862849;
let plan = Plan::try_new(N, p).unwrap();
let data = [
0, 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,
];
let mut transformed_fwd = data;
plan.fwd(&mut transformed_fwd);
let mut transformed_inv = transformed_fwd;
plan.inv(&mut transformed_inv);
for (&actual, expected) in transformed_inv.iter().zip(data.iter().map(|x| x * N as u32)) {
assert_eq!(expected, actual);
}
More examples can be found in the examples
directory.
mul_poly_prime.rs
: Negacyclic polynomial multiplication with a prime modulus.
Run the example with cargo run --example mul_poly_prime
.mul_poly_native.rs
: Negacyclic polynomial multiplication with a native modulus (2^32
, 2^64
, or 2^128
).
Run the example with cargo run --example mul_poly_native
.Benchmarks can be executed with cargo bench
. If a nightly toolchain is
available, then AVX512 acceleration can be enabled by passing the
--features=nightly
flag.