Raspberry Pi hardware random number generator

Source: Internet
Author: User

Most computers cannot generate real random numbers. They use the formula to generate a very long pseudo-random number stream, but the real random noise comes from the thermal noise of the simulation element. Raspberry Pi has an electronic component that provides seed data for secure transmission ). It was not until recently that the drive was provided for the electronic component. To activate it (on Raspbian ):

  1. Make sure your system is up to date
    Sudo apt-get update
    Sudo apt-get-y dist-upgrade
    Sudo rpi-update
    And, if necessary, reboot.
  2. Installation module:
    Sudo modprobe bcm2708-rng
  3. To ensure that it is always loaded, add the following lines to/etc/modules (edit as root ):
    Bcm2708-rng
  4. For RNG-related work, install rng-tools:
    Sudo apt-get install rng-tools

Now the/dev/hwrng device is available, but it can only be read by the root user.

What does random look like?

The random number looks pretty boring. This is a random RGB value:

sudo cat /dev/hwrng  | rawtoppm -rgb 256 256 | pnmtopng > random$(date +%Y%m%d%H%M%S).png

(You need to install the netpbm toolkit to execute the above command)

What does random sound like?

Two brief WAV noise samples:

  • Random20130603234239
  • Random20130603234250

Yes, it sounds like static interference. This is done using the rndsound. sh script. You need to install sox to execute it.

This is not random

If it sounds like electrostatic interference, even if it is sometimes like electrostatic interference, it may not be a real random noise. RANDU is a notorious case where pseudo-random numbers are not random. A very random result is generated, but the result is predictable after careful research.

I wrote (I think) A RANDU: randu. c implemented in c language. Although you can generate an approximate random audio data (randu17.wav), if you output the data in the form of an image:

These stripes leak the real image; they should not have been regular. It is difficult to test random data, but -- You do need a lot of tests, even if some of them may fail for real random output. Thank God, when you install rngtools, it contains rngtest, a simple random data detector:

Sudo cat/dev/hwrng | rngtest-c 1000
Rngtest 2-unofficial-mt.14
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 particle PURPOSE.

Rngtest: starting FIPS tests...
Rngtest: bits encoded ed 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 = 67.969; avg = 921.967; max = 1953125.000) Kibits/s
Rngtest: FIPS tests speed: (min = 842.881; avg = 3208.336; max = 6407.890) Kibits/s
Rngtest: Program run time: 27658884 microseconds

Fortunately, there is no test failure for this operation; sometimes there are some failures. But for RANDU, the situation is terrible:

./Randu 17 | rngtest-c 1000
Rngtest 2-unofficial-mt.14
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 particle PURPOSE.

Rngtest: starting FIPS tests...
Rngtest: bits encoded ed from input: 20000032
Rngtest: FIPS 140-2 successes: 0
Rngtest: FIPS 140-2 failures: 1000
Rngtest: FIPS 140-2 (2001-10-10) Monobit: 730
Rngtest: FIPS 140-2 (2001-10-10) Poker: 1000
Rngtest: FIPS 140-2 (2001-10-10) Runs: 289
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 = 45.630; avg = 14255.221; max = 19073.486) Mibits/s
Rngtest: FIPS tests speed: (min = 23.694; avg = 154.238; max = 176.606) Mibits/s
Rngtest: Program run time: 141071 microseconds

Have you seen it? Many failures. It is not random at all. If you really want to test randomness, you can use dieharder for testing. Although it takes a long time to execute.

Recommended reading:

Raspberry Pi build LAMP Server

Install Weston on Raspberry Pi

Install a game simulator on Raspberry Pi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.