[How-To / DIY] $3 Hardware True Random Number Generator (ESP8266+CP2102)+WidgetHi everyone,
If you are running OPNsense on legacy or de-bloated hardware without dedicated hardware RNG instructions (RDRAND/RDSEED) or a TPM — such as my Sandy Bridge with Intel ME stripped via me_cleaner — FreeBSD's Fortuna CSPRNG relies solely on software-harvested system events and interrupt timings. To add an independent, physical noise source to the entropy pool without buying commercial USB entropy keys, I built a ~$3 DIY
Hardware TRNG using an
ESP8266 and a
CP2102 USB-UART bridge, complete with BearSSL SHA-256 conditioning and a zero-wear RAM dashboard widget for OPNsense.
GitHub Repository: https://github.com/Vladimir7xr/opnsense-esp8266-trng
Key Features & Architecture- Entropy Source: Uses internal silicon thermal noise (ADC_VCC), CPU jitter, and hard-disabled Wi-Fi with pulled-up/down GPIOs to avoid EMI.
- Hardware Data Diode: Uses only 3 wires (3V3, GND, TXD -> RXD). The router is physically isolated and cannot send commands or reflash the chip.
- Live Health Checks & Conditioning: Runs real-time variance and bias checks before feeding a BearSSL SHA-256 sponge directly into FreeBSD's /dev/random.
- OPNsense Integration: Cleanly integrates via devd, configd, and rc.syshook.d, writing live dashboard telemetry strictly to /tmp (RAM) to protect SSDs.
Verification & Diagnostic Tools- Entropy Metrics: Passes FIPS 140-2 and ENT tests with ~7.9943 bits/byte Shannon entropy.
- Pre-Deployment Calibration: Includes raw_entropy_dump.ino and a Python verification script (check_raw_entropy.py) in the repository to test your board's raw noise floor before flashing.
Wiring (3 Wires Only)- DON'T USE 5V(!!) GND(ESP8266)->GND(CP2102), VCC(ESP8266)-VCC3V3(CP2102), TX(ESP8266)->RX(CP2102)
Shared as-is for anyone interested in the concept — it works reliably on my setup, and feel free to fork or adapt it to your own needs.