Skip to content

paim-creater/prng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bolt & Tempest: Algebraic Degree-Driven PRNG Design

License: MIT Language: C99 Benchmark Awesome

Two high-performance pseudorandom number generators designed through an algebraic degree-driven methodology — target the algebraic degree (deg) over GF(2) first, then reverse-engineer the optimal primitive combination.

Platform Status
x86-64 (GCC/Clang/MSVC) ✅ Full support
ARM64 (Apple M / Cortex-A) ✅ Full support
RISC-V 64 ✅ Full support
MSVC ✅ Supported via src/platform.h

At a Glance

Algorithm Type Throughput Security Test Status
ADC-Bolt Non-crypto PRNG 70.3 Gbit/s (12.1× ChaCha20) deg=2 (non-crypto) NIST ✅ TestU01 ✅ PractRand ✅
Tempest v3 CSPRNG 17.7 Gbit/s (3.0× ChaCha20) deg≥256 + DP≤2⁻²⁷⁶ NIST ✅ TestU01 ✅ PractRand 1 TiB ✅
Tempest v3 AVX-512 CSPRNG (SIMD) 65.4 Gbit/s (11.3× ChaCha20) deg≥256 NIST ✅ TestU01 ✅ PractRand ✅

⚡ Benchmarked on AMD Ryzen 9 8940HX (Zen 4), MinGW-w64 GCC 16.1.0, -O3 -march=native. Single-core scalar: 17.7 Gbit/s (dual-output), AVX-512 8-way parallel: 65.4 Gbit/s (3.69× speedup, 11.3× ChaCha20).


Quick Start

git clone https://github.com/paim-creater/prng.git && cd prng
make && make bench

Expected output:

============================================
  Bolt & Tempest — Throughput Benchmark
============================================
  ADC-Bolt:            62753 Mbit/s  (62.8 Gbit/s)
  Tempest v3:          17700 Mbit/s  (17.7 Gbit/s)  [ZFC-provable security]
============================================

Drop-In Usage (Single Header)

Copy one file — no build system needed:

#include "prng_single_header.h"

// Non-crypto: games, Monte Carlo, ML
adcbolt_state rng;
adcbolt_seed(&rng, 42);
double x = adcbolt_double(&rng);
int dice = adcbolt_range(&rng, 1, 6);

// Cryptographic: keys, tokens, authentication
tempest_state csprng;
tempest_init(&csprng, key, nonce);
uint64_t token = tempest_u64(&csprng);

Python

import prng

rng = prng.ADC_Bolt(seed=42)
print(rng.randint(1, 6))

csprng = prng.Tempest(key=bytes(32), nonce=bytes(16))
print(csprng.hex(16))

Design Methodology

Traditional PRNG design follows: choose structure → test → add rounds. We reverse this:

First determine the target algebraic degree (deg), then reverse-engineer the primitives.

The key metric is deg-per-op — algebraic degree yield per nonlinear operation (AND-gate, ADD-carry, or MULX). ADC-Bolt uses ADD+ADD (deg-per-op = 1.0, 2c latency). Tempest v3 uses AND-mix cascade (deg ×16 per 4-stage chain, 4c latency).

ADC-Bolt (70.3 Gbit/s)

Replace MULX multiplication (3-cycle latency) with carry-chain dual-addition (ADD+ADD, 2-cycle latency). Same algebraic degree (deg=2), shorter critical path, 52% throughput gain over the MULX baseline.

// Core nonlinearity: carry-chain provides deg=2 at 2c latency
z = (z + u) + v;   // majority carry = quadratic over GF(2)

Tempest v3 (Pure GF(2), ZFC-Provable Degree)

ZFC-Provable: After 2 rounds, output deg ≥ 256, XL complexity ≥ 2⁵⁹⁷. All nonlinearity via AND (GF(2) multiplication) — integer ADD/CMUL removed.

  1. Pure GF(2) round function — only XOR, ROTL, AND operations (all ZFC-analyzable)
  2. 4-stage AND-mix cascade — each stage doubles algebraic degree (proven in ZFC)
  3. Cross-word XOR-ROT diffusion — all 4 ops parallel, preserves GF(2) linearity
  4. Dual-output — 2×64-bit per round via state permutation

Statistical Testing

Both algorithms have passed all statistical tests applied:

Test Suite Tests ADC-Bolt Tempest v3
NIST SP 800-22 15 series ✅ 15/15 ✅ 15/15
TestU01 SmallCrush 15 ✅ Pass ✅ Pass
TestU01 Rabbit 40 ✅ Pass ✅ Pass
TestU01 Alphabit 17 ✅ Pass ✅ Pass
TestU01 BigCrush 160 ✅ Pass (1h39m) ✅ Pass (3h20m)
TestU01 Crush 144 ✅ Pass (12h46m) ✅ Pass (23m)
PractRand ✅ 1 TiB, 354 sets ✅ 1 TiB, 354 sets, 0 anomalies

Full test logs: results/


Performance

Reference Platform (AMD Zen 4)

Algorithm Rounds Time Throughput
ADC-Bolt 2×10⁸ 182 ms 70.3 Gbit/s
Tempest v3 5×10⁷ 325 ms 17.7 Gbit/s
ChaCha20 (scalar) 2×10⁸ 5.8 Gbit/s

Predicted Performance by Architecture

CPU ADC-Bolt Tempest v3 Key Factor
Apple M4 Pro/Max 🥇 85–95 Gbit/s 16–18 Gbit/s UMULL=1c (=ADD latency)
AMD Zen 5 75–82 Gbit/s 13–15 Gbit/s IPC +15% over Zen 4
AMD Zen 4 70.3 17.7 Reference platform
Intel Arrow Lake 75–85 Gbit/s 12–14 Gbit/s Higher clock (5.7 GHz)
Intel Raptor Lake 60–70 Gbit/s 10–12 Gbit/s Previous gen
ARM Cortex-X4 55–65 Gbit/s 10–13 Gbit/s Mobile thermal limits

🥇 ARM64 is the ideal platform — multiply latency (UMULL=1c) equals ADD latency (1c), eliminating the MULX bottleneck that limits x86-64.

Reproduce on Your Hardware

git clone https://github.com/paim-creater/prng.git && cd prng
gcc -O3 -march=native -o benchmark benchmark.c src/adcbolt.c src/tempest_v3.c -I.
./benchmark

Then submit your results to the community database!

Contributor CPU ADC-Bolt Tempest v3
Submit yours →
@paim-creater Ryzen 9 8940HX (Zen 4) 70.3 Gbit/s 17.7 Gbit/s
GitHub Actions CI Xeon E5 v4 8.6 Gbit/s 4.6 Gbit/s

Repository Structure

.
├── README.md
├── LICENSE                    ← MIT
├── CONTRIBUTING.md
├── CMakeLists.txt             ← CMake build (MSVC / Xcode / Make / Ninja)
├── Makefile                   ← One-click: make && make bench
├── prng_single_header.h       ← Drop-in: copy one file, #include it
├── prng.py                    ← Python bindings
├── benchmark.c                ← Throughput benchmark
├── test_bolt.c                ← ADC-Bolt self-test
├── test_tempest.c             ← Tempest v3 self-test
├── examples/
│   ├── dice_roll.c            ← Game dice roller
│   ├── generate_token.c       ← Secure API token
│   └── monte_carlo.c          ← π via Monte Carlo
├── src/
│   ├── platform.h             ← Auto-detects x86-64 / ARM64 / RISC-V / MSVC
│   ├── adcbolt.h              ← ADC-Bolt API
│   ├── adcbolt.c              ← ADC-Bolt implementation
│   ├── tempest_v3.h           ← Tempest v3 API
│   ├── tempest_v3.c           ← Tempest v3 implementation
│   ├── tempest_openssl.c      ← OpenSSL 3.x Provider (EVP_RAND)
│   ├── tempest_cuda_kernel.cu ← CUDA GPU RNG kernel
│   ├── bitgen_tempest.c       ← NumPy BitGenerator C extension
│   └── _tempest_numpy.c       ← NumPy bulk fill acceleration
├── tempest_rng.py              ← ⭐ NumPy: random/normal/integers/shuffle (11 Gbit/s)
├── tempest_cuda.py             ← GPU: CUDA-accelerated Monte Carlo
├── setup_bitgen.py             ← Build script for NumPy BitGenerator
├── tempest-rs/                 ← ⭐ Rust crate: RngCore + CryptoRng
│   ├── Cargo.toml
│   ├── src/lib.rs
│   └── examples/pi_estimation.rs
├── results/                   ← Full test logs
│   ├── nist_tempest_v3_report.txt
│   ├── smallcrush_tempest_v3.log
│   ├── rabbit_tempest_v3.log
│   ├── alphabit_tempest_v3.log
│   ├── bigcrush_tempest_v3.log
│   ├── crush_tempest_v3.log
│   ├── practrand_tempest_v3_1tb.log
│   └── (adcbolt counterparts)
└── .github/
    ├── workflows/benchmark.yml  ← CI benchmark
    └── ISSUE_TEMPLATE/

Quick Verification

Anyone can verify the implementation is correct in under a second:

#include "src/kat_tempest.h"

tempest_state s;
if (tempest_kat_verify(&s) == 0) {
    printf("Tempest v3: correct\n");
}

This runs a known-answer test (key={1,2,3,4}, nonce={5,6}) and checks against reference outputs. No external dependencies, no build system required.

Full test suite:

gcc -O3 -o test_self test_tempest.c src/tempest_v3.c -I.  
./test_self

Statistical Test Results

Suite Tests Result
NIST SP 800-22 15/15 ✅ PASS
TestU01 SmallCrush 15 ✅ PASS
TestU01 Rabbit 40 ✅ PASS
TestU01 Alphabit 17 ✅ PASS
TestU01 Crush 144 ✅ PASS
TestU01 BigCrush 160 ✅ PASS
PractRand ≥354 (1 TiB) ✅ PASS

Security

Tempest v3 provides ZFC-provable algebraic degree guarantees and empirically bounded differential resistance:

ZFC-Provable (Mathematically Proven in ZFC Axioms)

  • Algebraic degree: deg ≥ 16^r after r rounds (AND degree-doubling induction). After r = 2 rounds: deg ≥ 256 → XL complexity ≥ 2⁵⁹⁷
  • Per-bit AND DP: = 1/2 (GF(2) algebra — AND is GF(2) multiplication)
  • Integer ADD/CMUL removed: not ZFC-analyzable, replaced by AND gates

Empirical (Standard Crypto Practice — Like AES S-box DP)

  • AND-mix diffusion: 1→3→9→27→64 bit coverage per cascade (measured for rotation constants (31,53),(17,43),(7,23),(5,19))
  • Iterated DP: empirically consistent with 2¹²⁸ margin

Design Rationale

  • Pure GF(2) operations: all nonlinearity via AND (GF(2) multiplication) — ZFC-analyzable
  • Weyl per-round key: slide-attack resistance (engineering, outside ZFC proof scope)
  • Dual-output: 2×64-bit per round via state permutation

See DESIGN.md for the full security analysis.

NIST SP 800-90A/90B: Tempest v3 is packaged as a complete DRBG (Instantiate/Generate/Reseed/Uninstantiate) with an SP 800-90B-compliant entropy source (RCT/APT health tests + Tempest conditioning). 12 engineering validation tests pass.

Ecosystem integrations: NumPy (tempest_rng.py, 11 Gbit/s), OpenSSL 3.x Provider (TEMPEST-DRBG), Rust rand crate (tempest-rs, RngCore + CryptoRng), CUDA GPU kernel (tempest_cuda_kernel.cu, parallel Monte Carlo).


Build Options

Make (Linux / macOS / MSYS2)

make            # compile + run self-tests
make test       # build and run both test programs
make benchmark  # build benchmark binary
make bench      # build and run benchmark
make clean      # remove binaries

CMake (All platforms including MSVC)

mkdir build && cd build
cmake ..
cmake --build .
ctest           # run test_all
./benchmark     # run benchmark

Manual Compilation

# ADC-Bolt
gcc -O3 -march=native -o test_bolt test_bolt.c src/adcbolt.c -I.

# Tempest v3
gcc -O3 -march=native -o test_tempest test_tempest.c src/tempest_v3.c -I.

# Benchmark
gcc -O3 -march=native -o benchmark benchmark.c src/adcbolt.c src/tempest_v3.c -I.

Comparison

Scalar CSPRNG

Algorithm Throughput Security Verification
Tempest v3 17.7 Gbit/s deg≥256 (ZFC-provable deg) TestU01 all 5 levels, PractRand 1 TiB
ChaCha20 5.8 Gbit/s 2²⁵⁶ 15+ years of cryptanalysis
AES-CTR DRBG (AES-NI) 2–6 Gbit/s 2²⁵⁶ NIST standard

Non-Crypto PRNG

Algorithm Throughput State Update TestU01 BigCrush
RomuTrio ~213 Gbit/s Linear ❌ Fails after 2¹⁹ bytes
wyrand ~178 Gbit/s Linear Partial pass
xoroshiro128+ ~90 Gbit/s Linear ❌ Some failures
ADC-Bolt 70.3 Gbit/s Nonlinear (deg=2) ✅ Full pass

Citation

@misc{bolt_tempest_2026,
  title = {Tempest v3 \& ADC-Bolt:
           Algebraic Degree-Driven PRNG Design},
  author = {Tian Yuezhou},
  year = {2026},
  url = {https://github.com/paim-creater/prng},
}

License

MIT — free for academic, commercial, and personal use. See LICENSE.