Go to file
Leopere 5b49685ae9
Harden resilience: auto-restart harvester, poison-safe mutexes, graceful shutdown
- Replace all Mutex::lock().unwrap() with lock_or_recover() that recovers
  from poisoned mutexes instead of panicking (cascading failure prevention)
- Wrap harvester loop in catch_unwind with a supervisor thread that
  automatically restarts on panic (requires panic=unwind in release profile)
- Add exponential backoff with jitter for camera reconnection (2s base,
  60s cap) instead of fixed 10s intervals
- Enforce frame deadline: frames exceeding FRAME_TIMEOUT are treated as
  errors rather than just logged
- Add graceful shutdown via SIGINT/SIGTERM with axum's
  with_graceful_shutdown
- Track harvester restart count via AtomicU64 for diagnostics
- Extract docs/MCP handlers into src/docs_handlers.rs to keep main.rs
  under 400 lines
- Change release profile from panic=abort to panic=unwind so
  catch_unwind actually works in production
- Add tokio signal feature for shutdown handling

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-09 13:47:23 -05:00
man Camera TRNG: webcam-based true random number generator 2026-02-05 15:46:26 -05:00
scripts Add QTRNG tools: quantum dice, password generator, coin flip; build-test script 2026-02-08 16:24:51 -05:00
src Harden resilience: auto-restart harvester, poison-safe mutexes, graceful shutdown 2026-02-09 13:47:23 -05:00
.cursorignore Camera TRNG: webcam-based true random number generator 2026-02-05 15:46:26 -05:00
.gitignore Add QTRNG tools: quantum dice, password generator, coin flip; build-test script 2026-02-08 16:24:51 -05:00
.woodpecker.yml Harden resilience: auto-restart harvester, poison-safe mutexes, graceful shutdown 2026-02-09 13:47:23 -05:00
Cargo.lock Harden resilience: auto-restart harvester, poison-safe mutexes, graceful shutdown 2026-02-09 13:47:23 -05:00
Cargo.toml Harden resilience: auto-restart harvester, poison-safe mutexes, graceful shutdown 2026-02-09 13:47:23 -05:00
Dockerfile Camera TRNG: webcam-based true random number generator 2026-02-05 15:46:26 -05:00
LICENSE Camera TRNG: webcam-based true random number generator 2026-02-05 15:46:26 -05:00
README.md Add QTRNG tools: quantum dice, password generator, coin flip; build-test script 2026-02-08 16:24:51 -05:00
RESEARCH.md Camera TRNG: webcam-based true random number generator 2026-02-05 15:46:26 -05:00
TECHNICAL.md Add QTRNG tools: quantum dice, password generator, coin flip; build-test script 2026-02-08 16:24:51 -05:00
docker-compose.yml Harden resilience: auto-restart harvester, poison-safe mutexes, graceful shutdown 2026-02-09 13:47:23 -05:00
openssl-camera-qrng.cnf Camera TRNG: webcam-based true random number generator 2026-02-05 15:46:26 -05:00
skill.md Remove /raw endpoint completely - security hardening 2026-02-05 17:05:57 -05:00

README.md

Camera TRNG

TL;DR: Turn any webcam into a true random number generator. Cover the lens, run the server, get random bytes.

What is this?

Your webcam generates electrical noise even when the lens is covered. This noise comes from quantum effects in the sensor. This tool captures that noise and turns it into random numbers - the same approach used by LavaRnd.

Quick Start

1. Install

# Clone and build
git clone https://git.nixc.us/colin/camera-trng.git
cd camera-trng
cargo build --release

Or use Docker (build locally):

docker build -t camera-trng .

2. Cover Your Camera Lens

Use tape, a lens cap, or put the camera in a dark box. The camera should see nothing but blackness.

3. Run

./target/release/camera-qrng

Server starts at http://localhost:8787

4. Get Random Bytes

# Get 32 random bytes (hex)
curl "http://localhost:8787/random?bytes=32&hex=true"

# Get 1KB of raw random data
curl "http://localhost:8787/random?bytes=1024" -o random.bin

# Continuous stream
curl -N "http://localhost:8787/stream"

Is it actually random?

Yes. This tool passes all NIST SP 800-22 statistical tests for randomness:

# Run the built-in test suite
./scripts/test-randomness.py --server http://localhost:8787

The output is cryptographic quality - suitable for generating encryption keys, secure tokens, etc.

API

Endpoint Description
GET /random?bytes=N Get N random bytes (max 1MB)
GET /random?bytes=N&hex=true Get N random bytes as hex string
GET /stream Continuous stream of random bytes
GET /health Health check

Troubleshooting

macOS "Camera in use" error:

./scripts/release-camera.sh
./target/release/camera-qrng

Docker (Linux):

docker run -d --device /dev/video0 -p 8787:8787 camera-trng

More Info

  • TECHNICAL.md - Full API docs, CI/CD, configuration options
  • RESEARCH.md - The science behind camera-based random number generation

License

CC-BY 4.0. See LICENSE.