Intro

MicroRNG is a hardware (true) random number generator device that can be used in embedded systems as a reliable entropy source. It can interface with microcontrollers or microprocessors (mainboards) with integrated circuits and modules through a mikroBUS™ socket using SPI or 2-wire UART interface. It can generate random numbers at a rate up to 1 Mbps in SPI mode and up to 1.5 Mbps in UART mode.

Hardware requirements

  • Raspberry Pi 3+ or 4
  • An expansion board such as ‘PI2 Click Shield’ or similar with mikroBUS™ socket as shown in the picture below

Connecting MicroRNG in SPI mode

Operation system requirements

  • Ubuntu Server 18.04 32/64 bits for Raspberry Pi
  • or Ubuntu Server 20.04 32/64 bits for Raspberry Pi
  • or Rasbian

Downloading the software kit

MicroRNG software kit doesn’t include binaries for Linux platforms. You will need to download the source code and build utilities and components. The MicroRNG software kit can be downloaded from this location. Alternatively it can be downloaded with git using the following command:

git clone https://github.com/tectrolabs/microrng.git

Locate the source code with the following command:

cd microrng/mcrng

Prerequisites

Make sure packages make and gcc-c++ are installed before running the build.

On Ubuntu, this can be done with the following commands to install the required dependencies:

sudo apt-get update
sudo apt-get install make
sudo apt-get install g++

Building utilities and components

To build and install utilities you will need to run the following from the command line:

make
sudo make install

Verify communication with the MicroRNG

  • Connect MicroRNG device to the target board through the provided SPI interface.
  • Verify device connectivity with the following command (you may need to use a target board specific device path):
    sudo mcdiag /dev/spidev0.0
    
  • You may get an output similar to the following:
~/microrng/mcrng$ sudo mcdiag /dev/spidev0.0 
-------------------------------------------------------------------
--- TectroLabs - mcdiag - MicroRNG diagnostics utility Ver 1.0  ---
--- Use with RPI 3+ or other Linux-based single-board computers ---
-------------------------------------------------------------------
Opening device /dev/spidev0.0 ----------------------------- Success
Identifying device /dev/spidev0.0 --------------  MicroRNG detected
Identifying maximum SPI clock frequency --------------- 31000000 Hz
New SPI clock frequency ------------------------------- 31000000 Hz
Retrieving 32000 random bytes ----------------------------- Success
Retrieving 32000 RAW random bytes ------------------------- Success
Retrieving 32000 random bytes ----------------------------- Success
Shutting down RNG ----------------------------------------- Success
Starting RNG up ------------------------------------------- Success
Computing SPI transfer speed ----------------------------  497 kbps
Validating MicroRNG internal status  ---------------------- Healthy

Downloading random numbers from the MicroRNG

Random numbers can be retrieved with provided mcrng utility. For example, to retrieve 120000 of true random bytes from the MicroRNG device into rnd.bin file with clock frequency 20000 KHz, simply run the following command:

sudo mcrng -dd -fn rnd.bin -nb 120000 -cf 20000