Skip to content

Non-deterministic random number generator for RP2040 microcontroller

License

Notifications You must be signed in to change notification settings

alastairpatrick/rprand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rprand

Non-deterministic random number generator for RP2040 microcontroller

Makes exclusive use of the following hardware resources:

  • 2 (or 1) DMA channels
  • 1 DMA pacing timer
  • the DMA sniffer

It also uses the ROSC but not exclusively.

Random numbers are generated by the DMA controller rather than either of the CPU cores, resulting in low CPU overhead. This is accomplished by sampling the ROSC RANDOMBIT register a fixed number of times and calculating a CRC-32 checksum using the DMA sniffer. There is a delay between samples, chosen so that ROSC is sampled at about 1/16th of its frequency, improving entropy per sample. The resulting checksums are copied into the random number pool, again using only the DMA controller.

When a CPU core requires a random number, it removes one from the random number pool, waiting only if a random number is not yet available in the pool. The default pool size is 8, allowing 256 random bits to be acquired at once without busy waiting.

Because DMA channels are a valuable resource, if the pool size is reconfigured to be one, only one DMA channel is needed.

If ROSC frequency was 16MHz (it varies by how it is configured, particular device and temperature), it would generate about 10,000 32-bit random numbers per second.

About

Non-deterministic random number generator for RP2040 microcontroller

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published