Radek 1b99573b65 Add FastAPI entropy service with simple API-key auth and Dockerfile
api.py runs the camera producer in a background thread and serves the
latest entropy blob over HTTP. Endpoints: GET / (info), GET /healthz
(liveness, unauthenticated), GET /entropy (returns {hex, bits, ts}).
Auth is a single shared secret via X-API-Key header, controlled by the
ENTROPY_API_KEY env var; empty means no auth, so it is easy to start
open and lock down later. All config is via env vars for containers.

Dockerfile uses python:3.12-slim, installs OpenCV runtime libs, pins
deps from requirements.txt, exposes 8000, and has a healthcheck against
/healthz. Run with: docker build -t entropy-rng . && docker run -p 8000:8000 \
-e ENTROPY_CAMERA_URL=http://192.168.0.200/mjpg/video.mjpg entropy-rng

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-09-02 11:51:19 +01:00
2026-03-11 15:41:06 +00:00
2026-04-20 09:08:16 +01:00
2026-03-11 15:45:22 +00:00

Entropy-RNG: Camera-Based Random Number Generator

This project uses a live video feed from an Axis M1013 network camera to generate cryptographically secure random numbers. The camera is pointed at a high-contrast scene (e.g., ceiling and lamps) to ensure ever-changing pixel data, which is used as a source of entropy.


How It Works

  1. Capture Image Frames The script fetches a single frame from the camera's MJPEG stream using OpenCV or manual HTTP requests.

  2. Extract Entropy The pixel data from the frame is hashed using SHA-256 to generate a high-quality entropy pool.

  3. Generate Random Numbers The entropy is used to seed Python's secrets module, which generates cryptographically secure random numbers of specified bit lengths (e.g., 128-bit, 256-bit).


Requirements

  • Python 3.x
  • OpenCV (opencv-python)
  • Pillow (Pillow)
  • requests library

Install dependencies:

pip install opencv-python Pillow requests

Usage

Run the OpenCV script to fetch a frame and generate random numbers:

python3 entropy-rng-opencv.py

Example Output:

128-bit random number: 0x67dbaf3c5eba5a0d41429d2173a21f2f
256-bit random number: 0xe3a707c10f70f975e074633ad22ea0eaaa8b482e87c6418e3ae2380b2e647a4

2. Manual HTTP Method

Run the manual script (alternative to OpenCV):

python3 entropy-rng-cam.py

Example Output:

128-bit random number: 0x494d97b11a4b6008e4597cfc29108354
256-bit random number: 0xd59f7f4d22ebf7507b702fb60e0f2a6ccbf2ad4b5e3ab969f9152222da8e9443

Output Format

The generated random numbers are in hexadecimal format (e.g., 0x67dbaf3c5eba5a0d41429d2173a21f2f).

  • 128-bit numbers: 32 hex digits
  • 256-bit numbers: 64 hex digits

Why This Approach?

  • True Entropy Source: The camera feed provides a dynamic, unpredictable source of entropy.
  • Cryptographically Secure: Uses SHA-256 hashing and Python's secrets module.
  • No Additional Hardware: Leverages existing network cameras.

Notes

  • Ensure the camera feed is dynamic (e.g., pointing at changing light patterns).
  • For production use, consider adding error handling and logging.
S
Description
Generate entropy from a MJPEG stream
Readme
51 KiB
Languages
Python 95.3%
Dockerfile 4.7%