# plat-core
Lattice cryptography primitives for Fully Homomorphic Encryption in pure Rust.
Part of the [hyde](https://gitlab.com/Ryujiyasu/hyde) ecosystem.
## What's inside
| `poly` | Polynomial ring Z_q[X]/(X^N + 1) — add, sub, negacyclic multiply |
| `ntt` | Number Theoretic Transform — O(N log N) polynomial multiplication |
| `modular` | Modular arithmetic — add, sub, mul, pow, inv over Z_q |
| `sampling` | Discrete Gaussian, uniform, ternary, binary sampling |
| `params` | Parameter sets (test, research-grade N=2048) |
| `rlwe` | Ring-LWE encryption — keygen, encrypt, decrypt, homomorphic add, scalar multiply |
## Usage
```rust
use plat_core::params::Params;
use plat_core::ntt::NttTables;
use plat_core::rlwe;
use rand::SeedableRng;
use rand::rngs::StdRng;
let params = Params::test_small();
let ntt = NttTables::new(¶ms);
let mut rng = StdRng::seed_from_u64(42);
// Key generation
let (sk, pk) = rlwe::keygen(¶ms, &ntt, &mut rng);
// Encrypt two values
let ct_a = rlwe::encrypt_u64(¶ms, &ntt, &pk, 5, &mut rng);
let ct_b = rlwe::encrypt_u64(¶ms, &ntt, &pk, 7, &mut rng);
// Homomorphic addition (no decryption!)
let ct_sum = rlwe::add(¶ms, &ct_a, &ct_b);
// Decrypt the result
let result = rlwe::decrypt_u64(¶ms, &ntt, &sk, &ct_sum);
assert_eq!(result, 12);
```
## Design
- **Pure Rust** — no C/C++ bindings, no FFI
- **MIT license** — no copyleft restrictions
- NTT uses the negacyclic twist for correct multiplication in Z_q[X]/(X^N + 1)
- Gaussian sampling via Box-Muller (rand_distr)
- All arithmetic uses u128 intermediates to avoid overflow
## Parameters
| `test_tiny` | 64 | 769 | 1.0 | — | Unit tests |
| `test_small` | 256 | 12289 | 1.0 | — | Fast integration tests |
| `research_2048` | 2048 | 132120577 | 3.2 | ~100-bit | Research prototype |
## Ecosystem
| **plat-core** | Lattice primitives (this crate) |
| [plat-mkfhe](https://crates.io/crates/plat-mkfhe) | Multi-Key FHE — compute across independent keys |
| [hyde-plat](https://crates.io/crates/hyde-plat) | Unified re-export of the full stack |
## License
MIT