# Camera TRNG A minimal cross-platform true random number generator that extracts entropy from camera sensor noise. ## How It Works Camera sensors exhibit thermal noise and shot noise at the pixel level. This noise is most concentrated in the least significant bits (LSBs) of each pixel value. This service: 1. Captures frames from the default camera at the lowest resolution 2. Extracts the 2 LSBs from each pixel (where thermal/shot noise dominates) 3. Hashes the LSBs with SHA-256 to whiten the data and remove any bias 4. Mixes in timing entropy for additional randomness ## Build ```bash cargo build --release ``` ## Run ```bash ./target/release/camera-trng # Or set a custom port PORT=9000 ./target/release/camera-trng ``` ## API ### GET /random Returns random bytes from camera noise. **Query Parameters:** - `bytes` - Number of bytes to return (default: 32, max: 1024) - `hex` - Return as hex string instead of raw bytes (default: false) **Examples:** ```bash # Get 32 random bytes as hex curl "http://localhost:8787/random?hex=true" # Get 64 raw random bytes curl "http://localhost:8787/random?bytes=64" -o random.bin # Get 256 bytes as hex curl "http://localhost:8787/random?bytes=256&hex=true" ``` ### GET /health Returns `ok` if the server is running. ## Rate Limiting - Maximum 4 concurrent requests - Maximum 1024 bytes per request - Returns 429 Too Many Requests when overloaded ## Cross-Platform Support Uses `nokhwa` for camera access, supporting: - macOS (AVFoundation) - Windows (Media Foundation) - Linux (V4L2) ## Security Notes This is intended for hobby/experimental use. For cryptographic applications: - Consider mixing with system entropy (`/dev/urandom`) - The quality of randomness depends on camera sensor characteristics - Environmental factors (lighting, temperature) affect noise levels