Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Jun 2016 12:49:27 +0800
From:      Jia-Shiun Li <jiashiun@gmail.com>
To:        "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>
Subject:   Random number generator on rpi
Message-ID:  <CAHNYxxP8fqEdXsL2Jwu-=P4g9_w5P2pnJ-yOvtU1ssEP4ZpqCQ@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
--001a113739ecdaeb54053494cdcc
Content-Type: text/plain; charset=UTF-8

Hi all,

I occasionally found that RPi has a mysterious undocumented random number
generator and Linux has a driver for it. [1]

Out of curiosity I wrote a simple driver according to the Linux one. It is
simple enough for me without prior rng knowledge to make it work. Or so it
appears. Patch is attached.

(Note you need to have the updated dtb file by copying
{OBJDIR}/{SRCDIR}/sys/{KERNCONF}/modules/{SRCDIR}/sys/modules/dtb/rpi/rpi{,2}.dtb
to your /boot/msdos)

Once booted the kernel will output the following line indicating it is
working:

bcmrng0: <BCM2708/2835 random number generator> mem 0x104000-0x10400f on
simplebus0

I only tested it on RPi2. Guess it will work fine on RPi too.

I tried to compile rndtest(4) together into the kernel, and it did not
output or complain about anything. According to the man page this should
mean the rng works fine, right? Or is there any other tools to verify the
quality of a rng?


[1]:
http://scruss.com/blog/2013/06/07/well-that-was-unexpected-the-raspberry-pis-hardware-random-number-generator/

-Jia-Shiun.

--001a113739ecdaeb54053494cdcc
Content-Type: application/octet-stream; name="rpirng.patch"
Content-Disposition: attachment; filename="rpirng.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ip3jfer90

SW5kZXg6IHN5cy9hcm0vYnJvYWRjb20vYmNtMjgzNS9iY20yODM1X3JuZy5jCj09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0K
LS0tIHN5cy9hcm0vYnJvYWRjb20vYmNtMjgzNS9iY20yODM1X3JuZy5jCShub25leGlzdGVudCkK
KysrIHN5cy9hcm0vYnJvYWRjb20v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o9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBzeXMvc3lzL3JhbmRvbS5oCShyZXZp
c2lvbiAyOTkwODApCisrKyBzeXMvc3lzL3JhbmRvbS5oCSh3b3JraW5nIGNvcHkpCkBAIC05MCw2
ICs5MCw3IEBACiAJUkFORE9NX1BVUkVfTkVIRU1JQUgsCiAJUkFORE9NX1BVUkVfUk5EVEVTVCwK
IAlSQU5ET01fUFVSRV9WSVJUSU8sCisJUkFORE9NX1BVUkVfQkNNUk5HLAogCUVOVFJPUFlTT1VS
Q0UKIH07CiAK
--001a113739ecdaeb54053494cdcc--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAHNYxxP8fqEdXsL2Jwu-=P4g9_w5P2pnJ-yOvtU1ssEP4ZpqCQ>