- Vectors, matrices, dot products
- Modular arithmetic: Z_q arithmeticCentral to every PQC algorithm
- Polynomial rings: Z_q[x]/(x^n + 1)The ring used in ML-KEM, ML-DSA, FALCON
- Lattices: basis, shortest vector, duality
- LWE problem: s·A + e ≡ b (mod q)The hard problem ML-KEM relies on
- Modular inverses (extended Euclidean)
- Chinese Remainder Theorem
- Primitive roots and cyclic groups
- NTT primes: q = 3329 (Kyber), q = 8380417 (Dilithium)Must satisfy q ≡ 1 mod 2n for NTT to work
- Hash functions as random oracles
- Dart — your primary scripting, algorithm prototyping, and test harness languagedart:typed_data for byte-level buffer manipulation; dart:ffi for native calls
- Rust — constant-time crypto primitives, firmware, PKCS#11 driverNo secret-dependent branches. Rust borrow checker enforces no aliasing of key material
- SageMath via Dart FFI — polynomial ring arithmetic, lattice toolssage: R.<x> = ZZ['x']; R.quotient(x^256 + 1)
- Bit manipulation: shifts, masks, XOR, rotate — learn in both Dart and Rust
- Constant-time programmingNo secret-dependent branches or memory access — Rust's type system helps enforce this
/// NTT over Z_3329 in Dart — the computational core of ML-KEM and ML-DSA
import 'dart:typed_data';
const int q = 3329 // ML-KEM modulus
const int omega = 17 // primitive 256th root of unity mod 3329
const int n = 256 // polynomial degree
int modpow(int base, int exp, int mod) {
int result = 1;
base %= mod;
while (exp > 0) {
if (exp & 1 == 1) result = result * base % mod;
exp >>= 1;
base = base * base % mod;
}
return result;
}
/// Cooley-Tukey NTT butterfly — O(n log n)
Int32List ntt(Int32List f) {
final res = Int32List.fromList(f);
for (var len = 1; len < n; len <<= 1) {
final w = modpow(omega, n ~/ (2 * len), q);
for (var i = 0; i < n; i += 2 * len) {
int wn = 1;
for (var j = 0; j < len; j++) {
final u = res[i + j];
final v = res[i + j + len] * wn % q;
res[i + j] = (u + v) % q;
res[i + j + len] = (u - v + q) % q;
wn = wn * w % q;
}
}
}
return res;
}
/// Pointwise multiply in NTT domain — O(n)
Int32List polyMulNTT(Int32List a, Int32List b) {
final hatA = ntt(a), hatB = ntt(b);
return Int32List.fromList(
List.generate(n, (i) => hatA[i] * hatB[i] % q)
);
}
This single algorithm is the computational core of 3 of your 4 target algorithms. Implement it in Dart with full test coverage against NIST Known Answer Test vectors.
- Step 1 Find primitive 256th root of unity ω mod 3329 in Dart
- Step 2 Implement bit-reversal permutation
- Step 3 Cooley-Tukey butterfly iteration
- Step 4 Inverse NTT + verify a == intt(ntt(a))
- Step 5 Port to Rust for constant-time version
- Step 6 Verify both against CRYSTALS-Kyber reference KATs
- Boolean algebra, truth tables, K-maps
- Multiplexers, adders, carry-lookahead
- Barrett & Montgomery multipliersYou'll reuse these constantly for modular arithmetic
- Timing analysis: critical path, slack
- D flip-flops, registers, shift registers
- Finite state machines (Mealy/Moore)
- Pipelines: stages, hazards, stall/flush
- Deep pipeline design for throughputGoal: 1 result per clock cycle
- Clock domain crossing (CDC)
- Module hierarchy, ports, wire vs reg
- Always blocks, assign, generate
- Parameterized modulesOne multiplier for any bit width
- Testbench writing, $display, $monitor
- Avoid latches — always synchronous reset
- CLB, LUT, DSP48, BRAM architecture
- Vivado: synthesis, implementation, bitstream
- Constraints: .xdc, I/O, timing
- ILA for hardware debugging
- Resource reportsLUT%, DSP%, BRAM% — critical for dense designs
// Parameterized Montgomery multiplier — workhorse of modular crypto
module montgomery_mult #(
parameter W = 12, // bit width
parameter N = 3329, // modulus (ML-KEM)
parameter R = 4096 // R = 2^12 > N
) (
input clk, rst,
input [W-1:0] a, b,
output reg [W-1:0] result,
output reg valid
);
// Computes a*b*R^-1 mod N in constant time — no data-dependent branching
/// Rust golden-reference for Montgomery multiply verification
const Q: u32 = 3329;
const Q_INV: u32 = 3327; // Q^(-1) mod 2^12
const R: u32 = 4096; // 2^12
#[inline(always)]
pub fn montgomery_reduce(a: i64) -> i16 {
let t = (a as i32).wrapping_mul(Q_INV as i32) as i64;
let u = (a - t * Q as i64) >> 16;
u as i16 // result in (-Q/2, Q/2] — constant time guaranteed
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn verify_against_rtl_output() {
// Load Verilog simulation output, verify every result
let rtl_results = std::fs::read("sim_output.bin").unwrap();
// Compare byte-for-byte — any mismatch = RTL bug
}
}
- Week 1–2 Blinky → 7-seg → UART echo in Verilog
- Week 3–4 Barrett reduction in Verilog with Dart test harness
- Week 5–6 Parameterized Montgomery multiplier + Rust testbench
- Week 7–8 Verify 10k multiply-mod-3329 results match Dart reference 1:1
- NTT forward/inverse — Cooley-Tukey butterfly, twiddle factorsuse subtle crate for constant-time ops
- Polynomial mul — pointwise in NTT domain (O(n log n))
- Compress/Decompress — rounding to fewer bits
- CBD sampler — centered binomial distributiontrivial in Rust: XOR + popcount on random bytes
- Expand (SHAKE-128/256) — deterministic matrix generation
- Power2Round / HighBits / LowBits — Dilithium-specific
- F, H, T_l, PRF — four hash functions (SHA-2/SHAKE via sha2 crate)
- WOTS+ chain — iterated hash chain, length n
- XMSS tree — binary Merkle tree, implement leaf parallel
- FORS — few-times signature for message digest
- HT (hypertree) — d layers of XMSS trees
- Key insight: all parallelizable via Rayon crate
- FFT over Z_p — use fixed-point in Rust; avoid f64 for timing security
- NTRU keygen — LLL/BKZ reduction; computationally heavy
- Gaussian sampler — CDT table lookup, constant-time critical
- Fast Fourier Sampling — tree-based trapdoor
- Use
zeroizecrate on all secret material - Hardware decision: fixed-point FFT preferred for timing security
- KAT Files Download NIST Known Answer Tests for FIPS 203/204/205/206
- ML-KEM Rust impl, add #[inline(never)] on hot loops for profiling
- ML-DSA Profile rejection sampling loop — this determines latency variance
- SLH-DSA Count hash calls per operation — this is your HW budget
- FNDSA Constant-time Gaussian sampler — no timing variance allowed
- Dart driver Call Rust via dart:ffi, run all KATs, report pass/fail
- Butterfly unit: 2 multiplications + 2 additions per butterfly
- Input: 256 × 12-bit coefficients (ML-KEM) or 23-bit (ML-DSA)
- Pipeline: multiply → reduce → add/sub; 3 stages per butterfly
- Target: 1 NTT in 256 clock cycles (one butterfly/cycle)
- Twiddle ROM: 128 entries in Montgomery form, Verilog readmemh
- Montgomery reduction after every multiply — no overflow
- Module: k×k matrix × k vector (k=2,3,4 for -512/-768/-1024)
- Parallelism: k² NTT units running simultaneously
- Pipeline: KeyGen → Encap → Decap
- CBD noise sampler: trivial in HW — 64-byte XOR + popcount
- Integrate SHAKE-128 core for matrix expansion (XOF)
- Target: 12M keygen/sec → 83ns per operation
- Core: parallel SHA-256 engines (~64 cycles/block each)
- WOTS+ chains: 32 independent chains, each 16 hashes deep
- XMSS tree: leaves are independent → massive parallelism
- FORS: 14 trees × 2^9 leaves → all parallel
- Architecture: 128 SHA-256 cores simultaneously
- Target: 5M sign/sec → 200ns per op
- Decision: 64-bit fixed-point FFT (avoid float — timing security)
- FFT butterfly: complex multiply (2 FP mul + 2 FP add)
- Use DSP48E2 blocks for fixed-point complex multiply
- Gaussian sampler: CDT table in BRAM, constant-time lookup
- No data-dependent timing in sampler — verified by Rust side-channel sim
- Target: 8.3M keygen/sec → 120ns per op
| Technique | Description | Gain | Where used |
|---|---|---|---|
| Deep pipeline | Split op into N stages; N results in flight simultaneously | N× | NTT butterfly, SHA-256 core |
| 128-tile tiling | 128 independent accelerator tiles, each one key op | 128× | All algorithms — main PQForge strategy |
| Vectorization | 4–8 NTT coefficients per cycle with wide datapaths | 4–8× | NTT inner loop |
| Task queuing | Rust work-stealing queue fills all tiles continuously | 95%+ util | HSM dispatch layer |
| Memory interleaving | Bank NTT coefficient RAM so parallel access never conflicts | No stalls | All NTT access patterns |
- Step 1 Verilog: 12-bit Montgomery mul, verified vs Rust
- Step 2 NTT core: full 256-point, verified vs NIST KATs
- Step 3 ML-KEM-512 KeyGen: SHAKE-128 → expand → NTT → noise
- Step 4 Encap + Decap pipelines
- Step 5 Rust driver reads results via PCIe/UART, runs KAT check
- Step 6 Profile DSP48 utilization; optimize for max clock frequency
- Ring oscillator entropy source — thermal noise in CMOS inverters
- Multiple oscillators at different frequencies → XOR outputs
- Min-entropy estimation per NIST SP 800-90B
- Health tests: repetition count test, adaptive proportion test
- Conditioning: SHAKE-256, AES-256-CTR_DRBG
- Implement DRBG as Verilog FSM; Rust driver reads entropy pool
- Attack: DPA/CPA — power traces correlate with key hamming weight
- Defense: Boolean masking — split secret s into s = s0 XOR s1
- Every NTT operation runs on both shares independently
- Rust: use
subtle::Choicefor constant-time select - Shuffling: process polynomial coefficients in random order
- FIPS 140-3 L4: 2nd-order masking required
- Active mesh: ~20µm copper traces over all circuitry
- Continuous mesh resistance monitoring
- Environmental sensors: voltage, temp, frequency, light
- Zeroization engine: Verilog FSM clears all key material <100µs
- Battery-backed: sensors active even without external power
- FIPS 140-3 L4: environmental attack protection mandatory
- Key material never leaves secure boundary in plaintext
- Rust: all key structs implement
Dropviazeroize::Zeroize - AES-256-GCM wrapping key in battery-backed SRAM
- KEK derived from: TRNG seed XOR PUF response
- Key hierarchy: Master → Domain → Session
- One zeroization signal clears entire key tree
| Requirement | Level 3 | Level 4 (target) |
|---|---|---|
| Physical security | Tamper-evident + response | Active mesh + ENV attack protection |
| Side-channel | Not specified | Must mitigate (EMA, DPA) — 2nd order masking |
| Operating env | Standard | Voltage/temp/freq protection |
| Key mgmt | Zeroize on tamper | Proactive zeroize, battery-backed |
| Algorithms | NIST approved | NIST + PQC (FIPS 203/204/205/206) |
- Step 1 16-oscillator TRNG on FPGA; Rust SP 800-90B health tests
- Step 2 Capture 1M power traces of unmasked NTT butterfly
- Step 3 Rust CPA attack — confirm key leaks from unmasked version
- Step 4 Implement 1st-order masked butterfly (two shares in Verilog
- Step 5 Re-run Rust CPA — confirm 1st-order attack fails at 1M traces
- Step 6 Measure masking overhead: target <3× performance cost
- HBM3E: up to 1.2 TB/s bandwidth per stack
- 16 pseudo-channels per stack, each independently addressable
- Zero-contention: each tile owns dedicated channels
- Per-tile map: coefficients + key buffer + scratch
- ECC: SECDED on all key material storage lanes
- Rust driver: maps HBM channels as memory-mapped regions via UIO
- All-to-all crossbar for 128 tiles: 128×128 non-blocking switch
- 2 TB/s aggregate: 128 × 16 GB/s bidirectional links
- Credit-based flow control (no head-of-line blocking)
- Network-on-chip (NoC): fat-tree topology in Verilog
- AXI4 / AXI-S protocol between tiles
- Rust async task per tile; Tokio runtime for scheduling
- PCIe Gen5 ×16: 128 GB/s host interface
- CXL 3.0: memory-semantic key access
- 400/800GbE: direct network key-gen without host CPU
- RDMA (RoCEv2): zero-copy key delivery
- Rust: DPDK bindings for kernel-bypass network path
| Algorithm | Cycles/op | 500 MHz tiles | 1-tile ops/s | Tiles → target |
|---|---|---|---|---|
| ML-KEM-768 | 83 | 500 MHz | 6.0M | 2 tiles → 12M/s |
| ML-DSA-65 | 103 | 500 MHz | 4.8M | 2 tiles → 9.7M/s |
| SLH-DSA-128f | 196 | 500 MHz | 2.5M | 2 tiles → 5.1M/s |
| FNDSA-512 | 120 | 500 MHz | 4.1M | 2 tiles → 8.3M/s |
| TOTAL | — | — | — | 8 tiles → 35M/s ✓ |
- L1: Components + Signal (high density, tamper mesh)
- L2: GND — solid copper pour, primary reference plane
- L3: Signal 1 (horizontal routing)
- L4: Power (split planes by voltage domain)
- L5: Signal 2 (vertical routing)
- L6: GND — return path for L5
- L7: Signal 3 + Power
- L8: Bottom + internal tamper mesh
- Via-in-pad with copper fill for BGA fanout (ENIG finish)
- Impedance control: 50Ω single-ended, 100Ω differential
- USB, PCIe, QSPI: route matched within ±0.1mm
- DDR4/HBM: length matching ±25ps (≈5mm on FR4)
- 3W rule: trace spacing ≥ 3× trace width
- Back-drill vias for PCIe Gen4+ (removes stub resonance)
- Simulate: Saturn PCB Toolkit (free) or HyperLynx
- Buck regulators: 12V → 3.3V → 1.8V → 1.0V (core)
- 100nF + 10µF decoupling per power pin (ceramic)
- N+1 hot-swap OR-ing controllers (LTC4370)
- Per-rail monitoring: INA226 read via Rust I2C driver
- Heat pipes: vapor-chamber → fins + fan
- Per-tile thermal monitoring via FPGA thermal diode
Schematic capture in KiCad
MCU + SE + NFC + USB-C. Dart generates test vectors for USB enumeration test.
Component placement + ground plane
Place MCU, SE, crystal, decoupling caps. Flood fill GND L2. Run DRC — zero errors.
Route high-speed signals
USB differential pair, SPI to SE, UART debug. Controlled impedance on USB.
Order from JLCPCB (~$50 for 5 boards)
ENIG finish, PCBA service for SMD components. 8-layer HDI prototype.
Bring-up with Rust firmware
Power sequence check. UART debug first (Rust embassy-rs no_std). Progress to SPI, USB, NFC.
Dart integration test suite
Dart serial/USB test driver exercises every PKCS#11 operation from the host side.
- Stage 0: ROM bootloader in Rust (no_std, no heap)
- Stage 1: ML-DSA signature verify of Stage 2 image
- Stage 2: HSM firmware, measured boot, extend PCR
- Anti-rollback: monotonic counter in fused OTP
- Update path: Dart tooling signs firmware; Rust verifies before flashing
- All Rust boot stages:
#![no_std] #![no_main]
- Rust: implement C_GenerateKeyPair for all 4 PQC algorithms
- Rust: C_Sign, C_Verify, C_Encrypt, C_Decrypt — all constant-time
- Dart:
dart:ffibindings to Rust PKCS#11 shared library - Dart: PQForge client SDK — developer-facing API
- Session management: SO (Security Officer) vs User roles
- Audit log: Rust writes HMAC-chained log; Dart reads and renders
- States: Pre-activation → Active → Suspended → Destroyed
- KMIP 2.1 protocol: Rust server (axum + rustls)
- Key wrapping: AES-256-KWAP or ML-KEM encapsulation
- Rust: all key structs
derive Zeroize + ZeroizeOnDrop - Export policy: never plaintext export — Rust type system enforces
- Dart: fleet management dashboard and key lifecycle UI
- Rust: DPDK bindings via dpdk-sys crate for kernel bypass
- Custom UDP protocol: 64-byte request, 2KB response
- RDMA via RoCEv2: zero-copy key delivery, <5µs latency
- TLS 1.3 with hybrid classical + PQC key exchange (rustls)
- Load balancing: Rust work-stealing queue to tile dispatcher
- Dart: async client SDK wraps the network protocol
#![no_std] // HSM firmware: no standard library
use zeroize::{Zeroize, ZeroizeOnDrop}
use subtle::ConstantTimeEq;
/// ML-KEM decapsulation key — zeroized on drop, always
#[derive(Zeroize, ZeroizeOnDrop)]
pub struct MlKemDk(Box<[u8; 2400]>
/// Generate ML-KEM key pair on hardware accelerator tile
pub fn c_generate_mlkem_keypair(
h_session: CK_SESSION_HANDLE,
tile_id: u8,
) -> Result<(MlKemEk, MlKemDk), CryptokiError> {
let entropy = trng::read_64_bytes(tile_id)?; // ring-osc TRNG
let (ek, dk) = accelerator::mlkem_keygen(tile_id, &entropy)?;
trng::zeroize_entropy_buffer(&entropy); // immediately wipe
Ok((ek, dk))
// dk.zeroize() called automatically on drop — Rust guarantees this
}
import 'dart:ffi';
import 'package:ffi/ffi.dart';
/// PQForge Dart SDK — wraps Rust PKCS#11 shared library
class PQForgeClient {
final DynamicLibrary _lib;
late final _GenerateKeyPairFn _generateKeyPair;
PQForgeClient({String libPath = 'libpqforge.so'})
: _lib = DynamicLibrary.open(libPath) {
_generateKeyPair = _lib
.lookup<NativeFunction<_CGenerateKeyPair>>('C_GenerateKeyPair')
.asFunction();
}
/// Generate ML-KEM-768 key pair — async, hardware-accelerated
Future<MlKemKeyPair> generateMlKemKeyPair({int level = 768 }) async {
return compute(_generateKeyPairIsolate, level); // off main isolate
}
}
- All 4 algorithms: 100% NIST KAT pass via Dart test driver
- Cross-check: Rust firmware sign → Dart verify (and vice versa)
- Compare vs liboqs, pqclean, BoringSSL reference impls
- Edge cases: all-zero seed, max-length messages
- Timing uniformity: 1M ops via Dart, stddev <0.1%
- TVLA: Welch's t-test on 1M power traces (Rust implementation)
- |t| < 4.5 required across all traces for FIPS 140-3 L4
- EMA: near-field probe, Rust analysis pipeline on captured data
- Timing oracle: Dart measures 10M op timings, checks independence
- Equipment: Rigol DHO1074 (~$400) + ChipWhisperer
- Tamper mesh continuity: Rust daemon monitors resistance 24/7
- Zeroization test: trigger tamper; Dart verifies key material cleared <100µs
- Environmental: -40°C to +85°C; Dart runs full KAT suite at each temp
- Battery removal: sensors active for 72h confirmed
- Dart generates final test report: PDF with all pass/fail evidence
- Dart: sustained 1-hour benchmark, all 4 algorithms simultaneously
- Latency: Dart measures p99.9 — must be <1ms per operation
- Memory: Rust HBM utilization monitor; must stay <70%
- Error rate: 0 cryptographic errors in 1 billion operations
- Redundancy: remove PSU at full load; Dart verifies 0 dropped ops
CMVP Pre-submission
Select accredited lab (SGS, Leidos, UL, Acumen). Costs $50k–200k+ for full validation.
Security Policy Document
Documents every security claim, role, service, algorithm. Dart tooling generates initial template from code annotations.
Algorithm Testing (ACVTS)
NIST ACVTS online system. Dart client automates all test vector submissions. All algorithms must pass before lab submission.
Lab Testing
Independent verification of all FIPS 140-3 requirements. Typically 6–18 months.
NIST Review & Certificate
NIST/CCCS review lab report. Certificate issued — check cmvp.nist.gov for current queue times.
Single ML-KEM-768 tile on Alveo U280
NTT + noise sampler + SHAKE-128 + key storage. Rust PCIe driver. Target: 4M keygen/sec at 400MHz. Dart KAT test suite confirms correctness.
Multi-algorithm tile: all 4 in one tile
Shared SHA-3 core, shared memory, Verilog algorithm-dispatch FSM. Rust verifies all pass KATs. Measure resource utilization per tile.
8-tile system with Rust scheduler + PCIe DMA
Rust async work-stealing dispatcher. Benchmark: 8× single-tile throughput. Latency p99 <5ms via Dart load tester.
TRNG, 2nd-order masking, Rust TVLA harness
Ring-oscillator TRNG per tile. 2nd-order masked NTT butterfly in Verilog. Run Rust TVLA — confirm |t| < 4.5.
Rust PKCS#11 + Dart SDK + OpenSSL provider
C_GenerateKeyPair, C_Sign, C_Verify all 4 algorithms. Dart integration tests. OpenSSL 3 provider wrapper in Rust. Benchmark TLS handshake throughput end-to-end.
Custom PCB: PQForge Titan X-class
12-layer HDI. FPGA + LPDDR5 + NVMe + 10GbE + tamper mesh. KiCad → JLCPCB → bring-up with Rust embassy-rs firmware → validate vs Alveo baseline.
Full 2U rack HSM chassis
4–8 custom boards in rack. 400GbE network. Redundant PSU. IPMI management via Rust BMC firmware. Target: 10M+ ops/sec sustained on initial prototype.
Design-to-Build Specification
Compute
- Architecture 128× FPGA/ASIC tiles
- ML-KEM tile NTT-256 pipelined
- SLH-DSA tile 128× SHA-256 parallel
- FNDSA tile Fixed-point FFT-512
- Clock fabric 500 MHz
- TRNG Per-tile ring oscillator
Memory
- Per-tile BRAM 256KB zero-contention
- Shared memory HBM3E 1.2 TB/s
- Key storage AES-256 battery NVRAM
- Vault capacity 1M key objects
- ECC SECDED all paths
Software Stack
- Firmware Rust no_std + embassy
- PKCS#11 Rust implementation
- Host SDK Dart + dart:ffi
- Network driver Rust + DPDK bindings
- Test framework Dart (all KATs)
Security
- Certification FIPS 140-3 Level 4
- Tamper Active mesh + ENV sensors
- Side-channel 2nd-order masking
- Zeroize <100µs on tamper
- Secure boot ML-DSA signed stages
- Redundancy N+1 × 2000W PSU