|
||
---|---|---|
Makefile | ||
PERFORMANCE_COMPARISON.md | ||
README.md | ||
main.c | ||
main.py | ||
output.txt | ||
random.bin | ||
test_output.hex | ||
test_output.txt | ||
truerng |
README.md
TrueRNG C Implementation
This is a C equivalent of the Python main.py
script for reading data from TrueRNG devices.
Overview
The program reads random data from a TrueRNG device via serial port, counts the number of ones and zeros in the data, and saves the raw data to a binary file called random.bin
.
Supported Devices
- TrueRNG (PID: 04D8, HID: F5FE)
- TrueRNGpro (PID: 16D0, HID: 0AA0)
- TrueRNGproV2 (PID: 04D8, HID: EBB5)
Requirements
- Linux system with termios support
- GCC compiler
- TrueRNG device connected via USB
- Appropriate permissions to access the serial device (may need root or proper udev rules)
Building
make
Or manually:
gcc -Wall -Wextra -std=c99 -O2 -o truerng main.c
Usage
./truerng
The program will:
- Automatically detect connected TrueRNG devices
- Read 1024 blocks of 1024 bytes each (1MB total)
- Count ones and zeros in real-time
- Display read rate in KB/s
- Save raw data to
random.bin
- Display final statistics
Configuration
You can modify the following constants in main.c
:
BLOCKSIZE
: Number of bytes to read per block (default: 1024)NUMLOOPS
: Number of blocks to read (default: 1024)
Permissions
On Linux, you may need to set proper permissions for the serial device:
sudo chmod 666 /dev/ttyUSB0 # Replace with your device
Or add your user to the dialout group:
sudo usermod -a -G dialout $USER
Differences from Python Version
The C implementation:
- Uses native Linux serial port APIs instead of pyserial
- Implements USB device detection via sysfs
- Uses lookup tables for efficient bit counting
- Provides equivalent functionality with better performance
Output
Sample output:
TrueRNG Counting Ones vs Zeros Example
http://ubld.it
==================================================
TrueRNG Found
Using com port: /dev/ttyUSB0
Block Size: 1024 Bytes
Number of loops: 1024
Total size: 1048576 Bytes
Writing to: random.bin
==================================================
1048576 Bytes Read at 45.23 Kbytes/s
Results
=======
Total Ones : 4194234
Total Zeros: 4194314
Total Bits : 8388608
There are 80 more zeros in the Capture!
=======