TRNG Introduction
The hw_random framework is software that makes use of a special hardware feature on your CPU or motherboard, a Random Number Generator (RNG). The software has two parts: a core providing the /dev/hwrng
character device and its sysfs support, plus a hardware-specific driver that plugs into that core.
Architecture
The HW-RNG driver follows Linux RNG framework, it can generate full-entropy 32-bit random data to the kernel entropy pool, and application can get random data from kernel. The HW-RNG architecture is illustrated in figure below.
Implementation
The HW-RNG driver is implemented as following files:
Driver location |
Introduction |
---|---|
|
RNG driver Kconfig |
|
RNG driver Makefile |
|
RNG driver source code. |
Configuration
Build Configuration
Select
.
APIs
APIs for User Space
Linux RNG framework provides /dev/hwrng
for user space to get random data from kernel.
Test
Download or install rng-tools
, the tools use /dev/hwrng
to fill the kernel entropy pool, which is used internally and exported by the /dev/urandom
and /dev/random
special files.
The rngd
daemon reads random numbers from /dev/hwrng
and feeds them into the kernel’s entropy pool.
rngd --rng-device=/dev/hwrng
Use rngtest
to check the data obtained from /dev/hwrng
:
cat /dev/hwrng | rngtest -c 1000