Linux: TRNGs
ChaosKey TRNG
Der ChaosKey ist ein TRNG in einem USB-Stick (Platinen-Schema), der von Keith Packard und Bdale Garbee entwickelt wurde. Zur Geschichte und dem Design des ChaosKeys sind die Präsentationen ChaosKey To Production, Chaoskey A Hardware Random Number Generator for Everyone und Security not by chance: the AltusMetrum hardware true random number generator bei YouTube abrufbar, auf der Homepage sind die verwendeten Hardware-Komponenten aufgelistet. Den ChaosKey kann man für 45 € (Okt. 2018) im Vikings Store bestellen (Ich hatte noch über 90 € via US-Import bezahlt ;)).
Einsatz
Der Code für den ChaosKey-Treiber wurde dem Linux Kernel ab Version 4.1 hinzugefügt. Wenn die enstprechende Option im Kernel aktiviert sind, kann der USB-Stick einfach eingesteckt werden und ist dann einsatzbereit.
Infinite Noise TRNG
Der Infinite Noise ist ebenfalls ein TRNG in einem USB-Stick (Platinen-Schema), der per Crowdfunding finanziert und von Bill Cox entwickelt wurde. Manuel Domke stellt den Infinite Noise mit USB-Konnektor und die Linux-Software her. Zur Geschichte und dem Design des Infinite Noise kann man sich über die vorher genannten Links informieren, auf der Crowdfunding-Seite sind die verwendeten Hardware-Komponenten aufgelistet.
Einsatz
Auf der GNU/Linux Pakete für den Infinite Noise TRNG Seite sind die Informationen zur Einrichtung und Installation von Paketen und Paketquellen für Ubuntu/Debian, CentOS 7 und Raspbian (ARMv7) verfügbar. Die Readme-Datei zur Software enthält weitere Informationen zu ihrem Einsatz.
Unter Debian installiert man das infnoise
Paket, das den Infnoise-Treiber, eine UDEV-Regel, systemd Unit-Datei und die /etc/infnoise.conf Konfigurationsdatei installiert. Über den systemd Dienst oder /usr/sbin/infnoise tritt dann der Ininite Noise in Aktion.
Für den Initinite Noise und OpenSSL kann auch eine Infnoise OpenSSL Engine installiert werden, um den OpenSSL PRNG mit Zufallszahlendaten vom Infinite Noise zu füttern.
Andere TRNGs
Neben den beiden oben vorgestellten TRNGs gibt es noch weitere TRNGs:
Vielleicht folgen zukünftig weitere Vorstellungen anderer TRNGs.
Tests
Vorbereitung
sudo echo "3072" > /proc/sys/kernel/random/write_wakeup_threshold sudo aptitude install rng-tools5 ent dieharder sudo systemctl disable rngd.service
sudo dd if=/dev/random of=chaoskey.bin iflag=fullblock count=83886080 bs=256 83886080+0 Datensätze ein 83886080+0 Datensätze aus 21474836480 Bytes (21 GB, 20 GiB) kopiert, 25973,3 s, 827 kB/s sudo infnoise --multiplier 34 | dd of=infnoise.bin iflag=fullblock count=83886080 bs=256 83886080+0 Datensätze ein 83886080+0 Datensätze aus 21474836480 Bytes (21 GB, 20 GiB) kopiert, 25343 s, 847 kB/s
wget https://downloads.sourceforge.net/project/pracrand/PractRand_0.94.zip unzip PractRand_0.94.zip -d PractRand cd PractRand g++ -c src/*.cpp src/RNGs/*.cpp src/RNGs/other/*.cpp -O3 -Iinclude -pthread -std=gnu++11 ar rcs libPractRand.a *.o g++ -o RNG_test tools/RNG_test.cpp libPractRand.a -O3 -Iinclude -pthread -std=gnu++11 g++ -o RNG_benchmark tools/RNG_benchmark.cpp libPractRand.a -O3 -Iinclude -pthread -std=gnu++11 g++ -o RNG_output tools/RNG_output.cpp libPractRand.a -O3 -Iinclude -pthread -std=gnu++11
entropy_avail
- entropy_avail
#!/bin/sh cat /proc/sys/kernel/random/entropy_avail; \ dd if=/dev/random of=/dev/null iflag=fullblock bs=384 count=1; \ for n in $(seq 1 5); do \ cat /proc/sys/kernel/random/entropy_avail; \ sleep 1; \ done exit 0
ChaosKey
3154 1+0 Datensätze ein 1+0 Datensätze aus 384 Bytes kopiert, 0,11943 s, 3,2 kB/s 2853 3146 3146 3147 3147
Infinite Noise
INFNOISE_MULTIPLIER=33
3416 1+0 Datensätze ein 1+0 Datensätze aus 384 Bytes kopiert, 0,00500748 s, 76,7 kB/s 400 3153 3153 3154 3154
INFNOISE_MULTIPLIER=1
3099 1+0 Datensätze ein 1+0 Datensätze aus 384 Bytes kopiert, 0,010085 s, 38,1 kB/s 484 3092 3093 3093 3093
rngtest
ChaosKey
cat chaoskey.bin | rngtest rngtest 5 Copyright (c) 2004 by Henrique de Moraes Holschuh rngtest: bits received from input: 171798691840 rngtest: FIPS 140-2 successes: 8583084 rngtest: FIPS 140-2 failures: 6850 rngtest: FIPS 140-2(2001-10-10) Monobit: 901 rngtest: FIPS 140-2(2001-10-10) Poker: 827 rngtest: FIPS 140-2(2001-10-10) Runs: 2585 rngtest: FIPS 140-2(2001-10-10) Long run: 2585 rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
Infinite Noise
cat infnoise.bin | rngtest rngtest 5 Copyright (c) 2004 by Henrique de Moraes Holschuh rngtest: bits received from input: 171798691840 rngtest: FIPS 140-2 successes: 8583153 rngtest: FIPS 140-2 failures: 6781 rngtest: FIPS 140-2(2001-10-10) Monobit: 879 rngtest: FIPS 140-2(2001-10-10) Poker: 812 rngtest: FIPS 140-2(2001-10-10) Runs: 2615 rngtest: FIPS 140-2(2001-10-10) Long run: 2521 rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
ent
ChaosKey
ent ./chaoskey.bin Entropy = 8.000000 bits per byte. Optimum compression would reduce the size of this 21474836480 byte file by 0 percent. Chi square distribution for 21474836480 samples is 254.67, and randomly would exceed this value 49.40 percent of the times. Arithmetic mean value of data bytes is 127.5008 (127.5 = random). Monte Carlo value for Pi is 3.141580080 (error 0.00 percent). Serial correlation coefficient is -0.000012 (totally uncorrelated = 0.0).
Infinite Noise
ent ./infnoise.bin Entropy = 8.000000 bits per byte. Optimum compression would reduce the size of this 21474836480 byte file by 0 percent. Chi square distribution for 21474836480 samples is 272.38, and randomly would exceed this value 21.71 percent of the times. Arithmetic mean value of data bytes is 127.5003 (127.5 = random). Monte Carlo value for Pi is 3.141558348 (error 0.00 percent). Serial correlation coefficient is 0.000005 (totally uncorrelated = 0.0).
dieharder
- dieharder_test
#!/bin/bash store=/opt/git ck=$store/chaoskey.bin in=$store/infnoise.bin tests1=(1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 100 101 102) tests2=(201 202 203 204 205 206 207 208 209) # chaoskey dieharder -d 0 -g 201 -f $ck -D 1 -D 2 -D 4 -D 8 -D 16 -D 32 -D 64 -D 128 -D 256 > $store/chaoskey_dieharder.txt for i in "${tests1[@]}"; do dieharder -d $i -g 201 -f $ck | tail -n 1 >> $store/chaoskey_dieharder.txt ; done dieharder -d 200 -n 12 -g 201 -f $ck | tail -n 1 >> $store/chaoskey_dieharder.txt for i in "${tests2[@]}"; do dieharder -d $i -g 201 -f $ck | tail -n 1 >> $store/chaoskey_dieharder.txt ; done # infnoise dieharder -d 0 -g 201 -f $in -D 1 -D 2 -D 4 -D 8 -D 16 -D 32 -D 64 -D 128 -D 256 > $store/infnoise_dieharder.txt for i in "${tests1[@]}"; do dieharder -d $i -g 201 -f $in | tail -n 1 >> $store/infnoise_dieharder.txt ; done dieharder -d 200 -n 12 -g 201 -f $in | tail -n 1 >> $store/infnoise_dieharder.txt for i in "${tests2[@]}"; do dieharder -d $i -g 201 -f $in | tail -n 1 >> $store/infnoise_dieharder.txt ; done exit 0
ChaosKey
#=============================================================================# # dieharder version 3.31.1 Copyright 2003 Robert G. Brown # #=============================================================================# rng_name | filename | file_input_raw| /opt/git/chaoskey.bin| #=============================================================================# test_name |ntup| tsamples |psamples| p-value |Assessment #=============================================================================# diehard_birthdays| 0| 100| 100|0.67590484| PASSED diehard_operm5| 0| 1000000| 100|0.97031407| PASSED diehard_rank_32x32| 0| 40000| 100|0.92160283| PASSED diehard_rank_6x8| 0| 100000| 100|0.11501817| PASSED diehard_bitstream| 0| 2097152| 100|0.74369164| PASSED diehard_opso| 0| 2097152| 100|0.16195465| PASSED diehard_oqso| 0| 2097152| 100|0.92021039| PASSED diehard_dna| 0| 2097152| 100|0.30453762| PASSED diehard_count_1s_str| 0| 256000| 100|0.48852325| PASSED diehard_count_1s_byt| 0| 256000| 100|0.60025966| PASSED diehard_parking_lot| 0| 12000| 100|0.96026595| PASSED diehard_2dsphere| 2| 8000| 100|0.89431759| PASSED diehard_3dsphere| 3| 4000| 100|0.06657006| PASSED diehard_squeeze| 0| 100000| 100|0.82087522| PASSED diehard_runs| 0| 100000| 100|0.00953785| PASSED diehard_craps| 0| 200000| 100|0.18786617| PASSED marsaglia_tsang_gcd| 0| 10000000| 100|0.47207274| PASSED sts_monobit| 1| 100000| 100|0.27899273| PASSED sts_runs| 2| 100000| 100|0.77303709| PASSED sts_serial| 16| 100000| 100|0.55840120| PASSED rgb_bitdist| 12| 100000| 100|0.78924393| PASSED rgb_minimum_distance| 0| 10000| 1000|0.00000000| FAILED rgb_permutations| 5| 100000| 100|0.40660598| PASSED rgb_lagged_sum| 0| 1000000| 100|0.72057497| PASSED rgb_kstest_test| 0| 10000| 1000|0.00492418| WEAK dab_bytedistrib| 0| 51200000| 1|0.57234399| PASSED dab_dct| 256| 50000| 1|0.07966361| PASSED dab_filltree| 32| 15000000| 1|0.48245539| PASSED dab_filltree2| 1| 5000000| 1|0.23836597| PASSED dab_monobit2| 12| 65000000| 1|0.77712454| PASSED
Infinite Noise
#=============================================================================# # dieharder version 3.31.1 Copyright 2003 Robert G. Brown # #=============================================================================# rng_name | filename | file_input_raw| /opt/git/infnoise.bin| #=============================================================================# test_name |ntup| tsamples |psamples| p-value |Assessment #=============================================================================# diehard_birthdays| 0| 100| 100|0.83168194| PASSED diehard_operm5| 0| 1000000| 100|0.78254566| PASSED diehard_rank_32x32| 0| 40000| 100|0.91879960| PASSED diehard_rank_6x8| 0| 100000| 100|0.89465617| PASSED diehard_bitstream| 0| 2097152| 100|0.67096158| PASSED diehard_opso| 0| 2097152| 100|0.66949889| PASSED diehard_oqso| 0| 2097152| 100|0.55234882| PASSED diehard_dna| 0| 2097152| 100|0.92685470| PASSED diehard_count_1s_str| 0| 256000| 100|0.49209592| PASSED diehard_count_1s_byt| 0| 256000| 100|0.83927735| PASSED diehard_parking_lot| 0| 12000| 100|0.31640509| PASSED diehard_2dsphere| 2| 8000| 100|0.95147128| PASSED diehard_3dsphere| 3| 4000| 100|0.83118298| PASSED diehard_squeeze| 0| 100000| 100|0.98180230| PASSED diehard_runs| 0| 100000| 100|0.60801278| PASSED diehard_craps| 0| 200000| 100|0.94182872| PASSED marsaglia_tsang_gcd| 0| 10000000| 100|0.89847330| PASSED sts_monobit| 1| 100000| 100|0.55887749| PASSED sts_runs| 2| 100000| 100|0.94459315| PASSED sts_serial| 16| 100000| 100|0.96412288| PASSED rgb_bitdist| 12| 100000| 100|0.49901769| PASSED rgb_minimum_distance| 0| 10000| 1000|0.00000000| FAILED rgb_permutations| 5| 100000| 100|0.01890818| PASSED rgb_lagged_sum| 0| 1000000| 100|0.75822453| PASSED rgb_kstest_test| 0| 10000| 1000|0.43591405| PASSED dab_bytedistrib| 0| 51200000| 1|0.08815477| PASSED dab_dct| 256| 50000| 1|0.92289596| PASSED dab_filltree| 32| 15000000| 1|0.57338349| PASSED dab_filltree2| 1| 5000000| 1|0.35102214| PASSED dab_monobit2| 12| 65000000| 1|0.07821916| PASSED
PractRand
ChaosKey
cd ./PractRand cat /opt/git/chaoskey.bin | ./RNG_test stdin -e 0.1 -tf 1 -te 0 -tlmax 20GB -tlmaxonly -multithreaded RNG_test using PractRand version 0.94 RNG = RNG_stdin, seed = unknown test set = core, folding = standard(unknown format) rng=RNG_stdin, seed=unknown length= 256 megabytes (2^28 bytes), time= 3.2 seconds no anomalies in 213 test result(s) rng=RNG_stdin, seed=unknown length= 512 megabytes (2^29 bytes), time= 6.7 seconds no anomalies in 229 test result(s) rng=RNG_stdin, seed=unknown length= 1 gigabyte (2^30 bytes), time= 13.2 seconds no anomalies in 248 test result(s) rng=RNG_stdin, seed=unknown length= 2 gigabytes (2^31 bytes), time= 25.0 seconds no anomalies in 266 test result(s) rng=RNG_stdin, seed=unknown length= 4 gigabytes (2^32 bytes), time= 52.4 seconds no anomalies in 282 test result(s) rng=RNG_stdin, seed=unknown length= 8 gigabytes (2^33 bytes), time= 106 seconds no anomalies in 299 test result(s) rng=RNG_stdin, seed=unknown length= 16 gigabytes (2^34 bytes), time= 207 seconds no anomalies in 315 test result(s) rng=RNG_stdin, seed=unknown length= 20.000 gigabytes (2^34.322 bytes), time= 252 seconds no anomalies in 319 test result(s)
Infinite Noise
cd ./PractRand cat /opt/git/infnoise.bin | ./RNG_test stdin -e 0.1 -tf 1 -te 0 -tlmax 20GB -tlmaxonly -multithreaded RNG_test using PractRand version 0.94 RNG = RNG_stdin, seed = unknown test set = core, folding = standard(unknown format) rng=RNG_stdin, seed=unknown length= 256 megabytes (2^28 bytes), time= 3.4 seconds no anomalies in 213 test result(s) rng=RNG_stdin, seed=unknown length= 512 megabytes (2^29 bytes), time= 7.1 seconds no anomalies in 229 test result(s) rng=RNG_stdin, seed=unknown length= 1 gigabyte (2^30 bytes), time= 13.4 seconds no anomalies in 248 test result(s) rng=RNG_stdin, seed=unknown length= 2 gigabytes (2^31 bytes), time= 25.3 seconds no anomalies in 266 test result(s) rng=RNG_stdin, seed=unknown length= 4 gigabytes (2^32 bytes), time= 48.8 seconds no anomalies in 282 test result(s) rng=RNG_stdin, seed=unknown length= 8 gigabytes (2^33 bytes), time= 96.7 seconds no anomalies in 299 test result(s) rng=RNG_stdin, seed=unknown length= 16 gigabytes (2^34 bytes), time= 178 seconds no anomalies in 315 test result(s) rng=RNG_stdin, seed=unknown length= 20.000 gigabytes (2^34.322 bytes), time= 229 seconds Test Name Raw Processed Evaluation [Low4/32]DC6-9x1Bytes-1 R= -4.6 p =1-3.4e-3 unusual ...and 318 test result(s) without anomalies
Visualisierung
sudo aptitude install python-numpy python-matplotlib
#!/bin/bash # Quelle: https://github.com/13-37-org/infnoise/blob/master/tests/runtests.sh GRAPHS=1 function checkCommand { $1 $2 >/dev/null if [ $? -ne 0 ]; then echo "$1 not installed. Exiting.." exit 1 fi } function checkPythonModule { python -c "import $1" >/dev/null if [ $? -ne 0 ]; then echo "python module $1 not installed. Exiting.." exit 1 fi } function makePlots { python plots/colormap.py $1 & python plots/scatterplot.py $1 & sleep 3 mv $1-colormap.png results/plots/ mv $1-scatter.png results/plots/ } if [ $GRAPHS -eq 1 ] ; then checkCommand "python" "-h" checkPythonModule "numpy" checkPythonModule "matplotlib" fi mkdir plots if [ $GRAPHS -eq 1 ] ; then makePlots ./chaoskey.bin makePlots ./infnoise.bin fi