The swrng utility can be used to verify the SwiftRNG installation status and download true random bytes from a SwiftRNG device. The swrng-cl utility does the same for a cluster of two or more devices.

Linux, macOS, and FreeBSD

The software kit contains the swrngapi.c and swrngapi.h source files, which can be included in other projects to communicate with a SwiftRNG device directly. The swrng-cl-api.c and swrng-cl-api.h source files are used to communicate with a cluster of multiple SwiftRNG devices, which boosts the generation speed and provides fail-over capability.

Note: swrng-cl is the clustered version of the swrng utility and works with a cluster of two or more SwiftRNG devices concurrently. Both utilities require sudo permissions on Linux or FreeBSD. For best results, all devices in a cluster should have the same generation speed, and the system should have one CPU core (or hyper-thread) available per device.

SwiftRNG devices manufactured after March 2020 appear on Linux as ttyACM devices, on macOS as cu.usbmodem devices, and on Windows as COM ports.

Instructions for building the swrng and swrng-cl utilities are available.

Verifying the installation

After the SwiftRNG device is plugged into an available USB port, verify that the device was configured successfully by running the following command:

swrng -ld

When the SwiftRNG device is installed and ready, the output should look like this:

{DevNum=0 DevModel=SwiftRNG DevVer=V1.2 DevS/N=HJA5A6D44A5BD43}

Where:

  • DevNum: logical device number starting with 0 (you can use multiple SwiftRNG devices)
  • DevModel: RNG device model
  • DevVer: SwiftRNG device version
  • DevS/N: unique serial number assigned to the SwiftRNG device when manufactured

Downloading random bytes

To download 12,000,000 bytes of true random numbers from the SwiftRNG device and store them in a file named rnd.bin:

swrng -dd -fn rnd.bin -nb 12000000
...
Completed in 1 seconds, post-processing method used: none, device built-in correction method used: none, 
speed: 11718 KBytes/sec, blocks re-sent: 0

To download 12,000,000 bytes of true random numbers from a cluster of two SwiftRNG devices and store them in a file named rnd.bin:

swrng-cl -dd -fn rnd.bin -nb 12000000 -cs 2
...
Completed,  size: 2, fail-over events: 0,  resize attempts: 0

To download 12,000,000 bytes of true random numbers from the SwiftRNG device and send them to standard output:

swrng -dd -fn STDOUT -nb 12000000

To download an unlimited amount of true random numbers from the SwiftRNG device and store them in a file named rnd.bin:

swrng -dd -fn rnd.bin

Feeding the Linux entropy pool

To continuously feed the Linux /dev/random entropy pool, run the following command (it requires sudo permissions):

swrng -fep
...
Feeding the kernel /dev/random entropy pool. Initial amount of entropy bits in the pool: 652 ...

To start feeding the Linux /dev/random entropy pool automatically at boot time, add the following line to the crontab (open the crontab editor with the sudo crontab -e command):

@reboot /usr/local/bin/swrng -fep >> /var/log/swrng-fep.log 2>&1

Setting the power profile

By default, the swrng utility uses SwiftRNG power profile 9 (the fastest speed and highest power consumption). The following command lowers the power consumption of the SwiftRNG by setting the power profile number to 4 (the number must be between 0 and 9) while downloading random bytes:

swrng -dd -fn rnd.bin -nb 12000000 -ppn 4
...
Completed in 1 seconds, post-processing method used: none, device built-in correction method used: none, 
speed: 11718 KBytes/sec, blocks re-sent: 0

Windows

This section applies to Windows 10/11 (64-bit) and Windows Server 2016/2019 (64-bit).

Connect the SwiftRNG device to the PC using an available USB 2.0 or 3.0 port. When the device is connected for the first time, Windows automatically installs the appropriate certified USB driver.

SwiftRNG devices manufactured after March 2020 appear in Windows as a USB COM port. SwiftRNG devices manufactured before March 2020 appear as a Universal Serial Bus device.

The SwiftRNG software kit contains pre-built utilities and components for Windows. Download the latest windows-binaries.zip from the latest release. The swrng.exe utility, built with Visual Studio 2019, is located in the windows-binaries\windows-x64-vs-2019\ folder.

Verifying the installation

To verify the SwiftRNG device installation status, run the following command:

swrng.exe -ld

When the SwiftRNG device is installed and ready, the output should look like this:

{DevNum=0 DevModel=SwiftRNG DevVer=V1.0 DevS/N=HJA5A6D44A5BD43}

Where:

  • DevNum: logical device number starting with 0
  • DevModel: RNG device model
  • DevVer: SwiftRNG device version
  • DevS/N: unique serial number assigned to the SwiftRNG device when manufactured

Downloading random bytes

To download 12,000,000 bytes of true random numbers from the SwiftRNG device and store them in a file named rnd.bin:

swrng.exe -dd -fn rnd.bin -nb 12000000

To download an unlimited amount of true random numbers from the SwiftRNG device and store them in a file named rnd.bin:

swrng.exe -dd -fn rnd.bin

Setting the power profile

By default, the swrng utility uses SwiftRNG power profile 9 (the fastest speed and highest power consumption). The following command lowers the power consumption of the SwiftRNG by setting the power profile number to 4 (the number must be between 0 and 9) while downloading random bytes:

swrng.exe -dd -fn rnd.bin -nb 12000000 -ppn 4

Other commands and options

The complete list of commands and options available with swrng can be displayed by running the utility without arguments:

swrng

Non-root access on Linux

To enable a non-root user to access the SwiftRNG device, copy the supplied 80-swiftrng-usb-access.rules file to /etc/udev/rules.d/. You may need to reboot the system for the change to take effect. Non-root access can be verified using the following command:

swrng -ld