Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
virtio-rngのちょっとしたメモ
# RNG@乱数ジェネレーターのメモ
Host:
- Hostではhavegedやrng-toolsを使って乱数を生成して、virtio-rng経由でGuestに渡す
- rngd(TPM,DRNG) or haveged(Software) -> /dev/random -> (qemu-kvm) -> Guestへ
Guest:
- Guestではrng-toolsを使って/dev/hwrngから乱数を生成して/dev/randomに書き込む
- rng-tools(/dev/hwrng) -> /dev/random
## Host側作業
```sh
# yum install haveged
# systemctl start haveged
# cat /proc/sys/kernel/random/entropy_available
-> 3000位だった
# virsh stop GUEST_DOMAIN_NAME
# virsh edit GUEST_DOMAIN_NAME
<device> に追記
~ 省略 ~
<rng model='virtio'>
<backend model='random'>/dev/random</backend>
<rate period='2000' bytes='1234'/>
↑ コレを追加すると2000msec毎に1234byteまで乱数の追加が許可される
ベンチマークを走らせるときは無効にするべし
<alias name='rng0'/>
</rng>
</device>
# virsh start GUEST_DOMAIN_NAME
```
## Guest側作業(といってもパッケージでサービス入れるだけ)
```sh
# lspci | grep RNG
00:09.0 Unclassified device [00ff]: Red Hat, Inc Virtio RNG
# lsmod | grep virtio_rng
virtio_rng 13019 0
# yum install rng-tools
# systemctl start rngd
$ cat /dev/random | rngtest -c 1000
rngtest: starting FIPS tests...
rngtest: FIPS 140-2 successes: 1000
rngtest: FIPS 140-2 failures: 0 <- 多少エラー出るときもあるらしい
省略
rngtest: input channel speed: (min=245.930; avg=747.100; max=1011.196)Kibits/s
rngtest: FIPS tests speed: (min=13.932; avg=77.607; max=116.302)Mibits/s
rngtest: Program run time: 26391190 microseconds
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.