TRNG Driver

The TRNG (True Random Number Generator) module generates hardware-level random numbers. It can be used for encrypted communication and authentication in embedded devices. It can generate initial keys or sessions keys for cryptographic algorithms such as AES and RSA.

The TRNG module has three working modes:
  • Interrupted mode: Triggers an interrupt once random number generation is complete, enbling efficient response.

  • Polling mode: Actively queries the status register to retrieve data, with low resource consumption.

  • Nonce mode: Supports 32-bit batch output of random numbers.

The RTOS includes a TRNG driver and a test program that is located at rtthread/bsp/starfive/libraries/driver/drv_trng.c.

Figure 1. TRNG Test Case

Test description: The test program calls the TRNG module to generate random numbers in poll mode, interrupt mode, and nonce mode.