nc-polynomial
Polynomial arithmetic over Z_q[x] with validated ring contexts for lattice-style cryptography experiments.
What This Crate Provides
- Dense polynomial type:
Polynomial - Arithmetic in
Z_q[x]:add,sub,neg,scalar_mulmul(schoolbook),mul_ntt,mul_truncated
- Quotient-ring operations modulo a polynomial:
rem_mod_poly,add_mod_poly,sub_mod_poly,mul_mod_poly
- Utilities:
evaluate,derivative,div_rem
- Validated ring configuration:
Params,RingContext,RingElem
Security Scope
This crate includes cryptography-oriented building blocks and runnable examples, but the example encryption code is educational and not production-hardened.
In particular, side-channel protections, serialization hardening, and operational key-management safeguards are not complete.
Installation
Local path dependency:
[]
= { = "/path/to/polynomial" }
Quick Start
1) Basic Polynomial Arithmetic
use Polynomial;
2) Use a Validated Ring Context (R_q = Z_q[x]/(f(x)))
use RingContext;
Project Layout
src/lib.rs: crate exportssrc/polynomial.rs: core polynomial arithmetic and testssrc/params.rs:Params,RingContext,RingElembenches/multiplication_speed.rs: schoolbook vs NTT benchmarkexamples/: runnable Rust examplesexamples/helpers_sampling.rsexamples/helpers_codec.rsexamples/rlwe_pke.rs- shared example code under
examples/common/
Run Examples
Tests and Benchmarks
# library tests
# example tests (unit tests embedded in examples/common modules)
# check example builds
# multiplication benchmark
NTT Notes
mul_ntt requires parameters compatible with NTT length derived from operand degrees.
Practical requirements include:
- transform length must divide
q - 1 - provided primitive root must induce a valid root of unity for that length
If these are not satisfied, NTT-specific errors are returned.
License
MIT, see LICENSE.
Copyright (c) 2026 Raja Lehtihet & Wael El Oraiby.