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.

../../rst_secure/3_trng_linux/figures/trng_software_arch.svg

Implementation

The HW-RNG driver is implemented as following files:

Driver location

Introduction

<linux>/drivers/rtkdrivers/hw_random/Kconfig

RNG driver Kconfig

<linux>/drivers/rtkdrivers/hw_random/Makefile

RNG driver Makefile

<linux>/drivers/rtkdrivers/hw_random/rtk-rng.c

RNG driver source code.

Configuration

Build Configuration

Select Device Drivers > Drivers for Realtek > HW Random driver.

../../rst_secure/3_trng_linux/figures/trng_driver.png

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