Skip to content

Instantly share code, notes, and snippets.

@neuronsoverflow
Forked from jesrui/ForwardRasPiHwRng.md
Created March 26, 2020 21:03
Show Gist options
  • Save neuronsoverflow/64bafbcd5a2f1bad37939207669cdca2 to your computer and use it in GitHub Desktop.
Save neuronsoverflow/64bafbcd5a2f1bad37939207669cdca2 to your computer and use it in GitHub Desktop.
How to forward the Raspberry Pi hardware random number generator over ssh

How to forward the Raspberry Pi hardware random number generator over ssh

This is a modification of RandPi. The diffrence is that here the data transport is done via ssh forwarding instead of a custom http service.

See the C't article Mit dem Raspberry Pi Zufallszahlen erzeugen und verteilen for more information (in german).

In a nutshell: The Raspberry Pi can be used as an entropy server. Clients get access to the Pi random number generator by forwarding the server's /dev/hwrng over ssh and making use of rngd locally to add the forwarded random source to /dev/random.

Installation

These instructions are tested in archlinux (both for client and server).

No special configuration is required on the server (your raspi). To configure the client, follow these steps:

  1. Install rng-tools

  2. Create a pipe named /dev/hwrng, which is the name of the device used by default by rngd

     # mkfifo /dev/hwrng
    
  3. Forward read requests to the actual /dev/hwrng on the server

     # ssh root@myraspi 'cat /dev/hwrng' > /dev/hwrng &
    
  4. Start rngd

     # rngd
    

Testing

$ cat /dev/random | rngtest -c 1000
rngtest 5
Copyright (c) 2004 by Henrique de Moraes Holschuh
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rngtest: starting FIPS tests...
rngtest: bits received from input: 20000032
rngtest: FIPS 140-2 successes: 1000
rngtest: FIPS 140-2 failures: 0
rngtest: FIPS 140-2(2001-10-10) Monobit: 0
rngtest: FIPS 140-2(2001-10-10) Poker: 0
rngtest: FIPS 140-2(2001-10-10) Runs: 0
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=17.403; avg=230.809; max=9765625.000)Kibits/s
rngtest: FIPS tests speed: (min=14.004; avg=55.461; max=128.875)Mibits/s
rngtest: Program run time: 84967236 microseconds

As this is a statistical test, one failure or two are probable. If you see an average speed around 230 Kbits/s then rngd is pumping randomness from your raspi correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment