| 1 |
60 |
zero_gravi |
<<<
|
| 2 |
|
|
:sectnums:
|
| 3 |
|
|
==== True Random-Number Generator (TRNG)
|
| 4 |
|
|
|
| 5 |
|
|
[cols="<3,<3,<4"]
|
| 6 |
|
|
[frame="topbot",grid="none"]
|
| 7 |
|
|
|=======================
|
| 8 |
|
|
| Hardware source file(s): | neorv32_trng.vhd |
|
| 9 |
|
|
| Software driver file(s): | neorv32_trng.c |
|
| 10 |
|
|
| | neorv32_trng.h |
|
| 11 |
|
|
| Top entity port: | none |
|
| 12 |
|
|
| Configuration generics: | _IO_TRNG_EN_ | implement TRNG when _true_
|
| 13 |
|
|
| CPU interrupts: | none |
|
| 14 |
|
|
|=======================
|
| 15 |
|
|
|
| 16 |
68 |
zero_gravi |
|
| 17 |
60 |
zero_gravi |
**Theory of Operation**
|
| 18 |
|
|
|
| 19 |
68 |
zero_gravi |
The NEORV32 true random number generator provides _physical_ true random numbers.
|
| 20 |
|
|
Instead of using a pseudo RNG like a LFSR, the TRNG uses a simple, straight-forward ring
|
| 21 |
|
|
oscillator concept as physical entropy source. Hence, voltage, thermal and also semiconductor manufacturing
|
| 22 |
|
|
fluctuations are used to provide a true physical entropy source.
|
| 23 |
60 |
zero_gravi |
|
| 24 |
73 |
zero_gravi |
The TRNG is based on the _neoTRNG_, which is a "spin-off project" of the
|
| 25 |
68 |
zero_gravi |
NEORV32 processor. The TRNG uses the default neoTRNG configuration, which showed very good results in the
|
| 26 |
|
|
`dieharder` battery of random number tests. More detailed information about the neoTRNG, it's architecture and a
|
| 27 |
|
|
detailed evaluation of the random number quality can be found it it's repository: https://github.com/stnolting/neoTRNG
|
| 28 |
|
|
|
| 29 |
74 |
zero_gravi |
.Platform Independent Architecture
|
| 30 |
60 |
zero_gravi |
[NOTE]
|
| 31 |
|
|
The TRNG features a platform independent architecture without FPGA-specific primitives, macros or
|
| 32 |
68 |
zero_gravi |
attributes so it can be synthesized for _any_ FPGA.
|
| 33 |
60 |
zero_gravi |
|
| 34 |
74 |
zero_gravi |
.Inferring Latches
|
| 35 |
|
|
[NOTE]
|
| 36 |
|
|
The synthesis tool might emit a warning like _"inferring latches for ... neorv32_trng ..."_. This is no problem
|
| 37 |
|
|
as this is what we actually want (the TRNG is based on latches).
|
| 38 |
60 |
zero_gravi |
|
| 39 |
74 |
zero_gravi |
|
| 40 |
60 |
zero_gravi |
**Using the TRNG**
|
| 41 |
|
|
|
| 42 |
64 |
zero_gravi |
The TRNG features a single register for status and data access. When the _TRNG_CTRL_EN_ control register (`CTRL`)
|
| 43 |
|
|
bit is set, the TRNG is enabled and starts operation. As soon as the _TRNG_CTRL_VALID_ bit is set, the currently
|
| 44 |
|
|
sampled 8-bit random data byte can be obtained from the lowest 8 bits of the `CTRL` register
|
| 45 |
68 |
zero_gravi |
(_TRNG_CTRL_DATA_MSB_ : _TRNG_CTRL_DATA_LSB_). These bits always keep the latest valid data obtained from the TRNG
|
| 46 |
|
|
entropy source. The _TRNG_CTRL_VALID_ bit is automatically cleared when reading the control register.
|
| 47 |
60 |
zero_gravi |
|
| 48 |
74 |
zero_gravi |
.TRNG Reset
|
| 49 |
68 |
zero_gravi |
[NOTE]
|
| 50 |
|
|
The TRNG core does not provide a dedicated reset. In order to ensure correct operations, the TRNG should be
|
| 51 |
|
|
disabled (=reset) by clearing the _TRNG_CTRL_EN_ and waiting some milliseconds before re-enabling it.
|
| 52 |
60 |
zero_gravi |
|
| 53 |
|
|
|
| 54 |
64 |
zero_gravi |
.TRNG register map (`struct NEORV32_TRNG`)
|
| 55 |
60 |
zero_gravi |
[cols="<2,<2,<4,^1,<7"]
|
| 56 |
|
|
[options="header",grid="all"]
|
| 57 |
|
|
|=======================
|
| 58 |
|
|
| Address | Name [C] | Bit(s), Name [C] | R/W | Function
|
| 59 |
68 |
zero_gravi |
.3+<| `0xffffffb8` .3+<| `NEORV32_TRNG.CTRL` <|`7:0` _TRNG_CTRL_DATA_MSB_ : _TRNG_CTRL_DATA_MSB_ ^| r/- <| 8-bit random data
|
| 60 |
|
|
<|`30` _TRNG_CTRL_EN_ ^| r/w <| TRNG enable
|
| 61 |
|
|
<|`31` _TRNG_CTRL_VALID_ ^| r/- <| random data is valid when set
|
| 62 |
60 |
zero_gravi |
|=======================
|