Hardware random overview

来自百问网嵌入式Linux wiki
Zhouyuebiao讨论 | 贡献2020年5月8日 (五) 22:24的版本 (创建页面,内容为“==Article Purpose== This article gives information about the hardware random (HWRNG) framework. ==Framework purpose== The Hardware random framework is integrated in…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

Article Purpose

This article gives information about the hardware random (HWRNG) framework.

Framework purpose

The Hardware random framework is integrated in the kernel. It provides access to RNG peripherals and focuses on supporting the hardware number generator.

System overview

The HW random framework allows retrieving random numbers in userland.

Component description

  • HW random core (Kernel space)

Generic interface in kernel space. This layer is in charge of creating the character device (char device) and sysfs to access hw_random.

  • RNG (Kernel space)

Hardware random Linux® drivers handling the HW blocks.

  • RNG (Hardware)

HW blocks handling the RNG peripheral.

API description

The Hardware random framework uses char device API[1] ioctl operations. For additional information, refer to:

  • sysfs interface.
  • Kernel Documentation directory[2]

Configuration

Kernel configuration

The Hardware random support is activated by default in ST deliveries. No specific configuration is required apart from enabling or disabling peripheral support using Linux® Menuconfig tool. Refer to Menuconfig or how to configure kernel and select:

  [*] Device Drivers --->
    [*] Character devices --->
      [*] Hardware Random Number Generator Core support --->
        [*] STMicroelectronics STM32 random number generator

Device tree configuration

DT configuration can be done thanks to the STM32CubeMX.

A detailed device tree configuration is described in RNG device tree configuration.

How to use the framework

The framework provides external interfaces from userland : How to control RNG.

How to use from char device

The community tool for using Hardware random framework is rng_tools[3] which provides a complete set of utilities related to random number generators:

  • rngd: runs a background daemon that opens /dev/hwrng file (default) to connect and retrieve random numbers.
  • rngtest: runs different tests that check the entropy and verify the compliance regarding FIPS 140-2 standard.

How to use from sysfs

Available devices compatible with Hardware framework can be listed using sysfs commands:

 Board $> cat /sys/class/misc/hw_random/rng_available
 stm32-rng

The selected device is shown here:

 Board $> cat /sys/class/misc/hw_random/rng_current
 stm32-rng

To select a different device:

 Board $> echo "stm32-rng"> /sys/class/misc/hw_random/rng_current

How to trace and debug the framework

Light information on the framework can be accessed by using sysfs.

By default, the framework does not provide any specific debug output or dynamic debugging tool.

Source code location

Hardware random drivers and framework are available here[4].

To go further

Code examples are directly available from rng-tools[3] github.

References


<securetransclude src="ProtectedTemplate:ArticleBasedOnModel" params="Framework overview article model"></securetransclude> <securetransclude src="ProtectedTemplate:PublicationRequestId" params="9410 | 2018-10-24 | AnneJ"></securetransclude>