[devel] rngd vs haveged vs crng

Konstantin Lepikhov lakostis на altlinux.org
Чт Апр 25 13:29:00 MSK 2019


Привет!

В продолжение обсуждения у кого энтропия длиннее^W лучше я тут провел
несколько тестов. Идея - замерить как быстро будет заканчиваться энтропия
в случае использования haveged/rngd/ничего (ядра).

В качесте теста был выбран rngtest из пакета rng-tools. rngtest позволяет
проверить качество энтропии из /dev/random по стандарту FIPS 140-2 и
замерить скорость чтения данных.

Кол-во запусков rngtest - 5 (выбрано просто так, чтобы быстрее).
Ядро: 5.0.0-lks-wks-alt0.3

1. запускаем rngtest без всего (rngd/haveged сервисы выключены). В этом
случае ядро будет само наполнять /dev/random.

$ rngtest -c 1000 </dev/random
...
rngtest: input channel speed: (min=1.721; avg=2.008; max=2.143)Mibits/s
rngtest: FIPS tests speed: (min=49.413; avg=60.802; max=151.377)Mibits/s
rngtest: Program run time: 9815390 microseconds

2. Запускаем тесты с rngd:

$ ll /dev/hwrng 
crw------- 1 root root 10, 183 23 apr 11:01 /dev/hwrng

$ egrep "^HRNGD" /etc/sysconfig/rngd
HRNGDEVICE=/dev/hwrng

$ cat /proc/cpuinfo
...
model name      : AMD FX(tm)-6300 Six-Core Processor
...
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt
pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid
aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt aes
xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a
misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce nodeid_msr
tbm topoext perfctr_core perfctr_nb cpb hw_pstate ssbd ibpb vmmcall bmi1
arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid
decodeassists pausefilter pfthreshold
bugs            : fxsave_leak sysret_ss_attrs null_seg spectre_v1
spectre_v2 spec_store_bypass

$ rngtest -c 1000 </dev/random
...
rngtest: input channel speed: (min=1.488; avg=5.397; max=18.217)Mibits/s
rngtest: FIPS tests speed: (min=40.324; avg=138.440; max=152.588)Mibits/s
rngtest: Program run time: 3673417 microseconds

run time отличается между тестами +- 0.5s.

3. Запускаем тесты с haveged:

$ service rngd stop && service haveged start
$ rngtest -c 1000 </dev/random
...
rngtest: input channel speed: (min=2.047; avg=17.271; max=21.076)Mibits/s
rngtest: FIPS tests speed: (min=20.465; avg=141.851; max=153.818)Mibits/s
rngtest: Program run time: 1239069 microseconds

run time отличается между тестами +- 0.5s.

Еще более интересные результаты на моем ноуте, который с Intel CPU и TPM:

1. Запускаем без всего, используем только ядро:

for i in $(seq 1 5); do rngtest -c 1000 </dev/random; done
rngtest 6.7
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...
^Crngtest: bits received from input: 3720
rngtest: FIPS 140-2 successes: 0
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=0.000; avg=0.000; max=0.000)bits/s
rngtest: FIPS tests speed: (min=0.000; avg=0.000; max=0.000)bits/s
rngtest: Program run time: 317191113 microseconds
....
(тут я не дождался и прервал тест). Видно, что ядро ничего может
сгенерить за приемлемое время.

2. Запускаем с rngd:

$ ll /dev/hwrng 
crw------- 1 root root 10, 183 23 apr 11:01 /dev/hwrng

$ egrep "^HRNGD" /etc/sysconfig/rngd
HRNGDEVICE=/dev/hwrng

$ cat /proc/cpuinfo
...
model name	: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
...
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx
pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl
xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64
monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1
sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand
lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs
ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase
tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt
intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp
hwp_notify hwp_act_window hwp_epp flush_l1d
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass
l1tf

$ dmesg|fgrep tpm
[    9.695064] tpm_tis MSFT0101:00: 2.0 TPM (device-id 0xFE, rev-id 4)

$ for i in $(seq 1 5); do rngtest -c 1000 </dev/random; done
rngtest 6.7
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...
^Crngtest: bits received from input: 4997088
rngtest: FIPS 140-2 successes: 249
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=24.220; avg=31.911; max=51.710)Kibits/s
rngtest: FIPS tests speed: (min=26.128; avg=54.413; max=181.652)Mibits/s
rngtest: Program run time: 152957345 microseconds
(тут я опять прервал тест). Уже получше, но все равно скорость не очень
приемлема для реальных условий.

3. Запускаем с haveged:

$ for i in $(seq 1 5); do rngtest -c 1000 </dev/random; done
...
rngtest 6.7
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=2.810; avg=20.824; max=23.635)Mibits/s
rngtest: FIPS tests speed: (min=14.983; avg=176.216; max=188.846)Mibits/s
rngtest: Program run time: 1024351 microseconds

среднее отклонение run time +- 10000ms

В общем, выводы можно сделать.

-- 
WBR et al.


Подробная информация о списке рассылки Devel