LoginSignup
2
3

More than 5 years have passed since last update.

gpg --gen-keyが止まる件について

Last updated at Posted at 2019-01-28

gpg --gen-keyが止まっているようにみえるのは、出力にもあるように"gain enough entropy"(entropyを集めている)ためです。そのため、止まっているわけではありません。

これを早めるためには、

dd if=/dev/sda of=/dev/null

などを実行して、システムに処理をさせるといいみたいです。コマンドの実行前にentropy稼ぎをしておくと良いかもしれません。

現在、何bitのentropyがある(bit!?)かは、/proc/sys/kernel/random/entropy_availを見るとわかります。

/proc interfaces
The files in the directory /proc/sys/kernel/random (present since 2.3.16) provide additional information about the /dev/random device:

entropy_avail
This read-only file gives the available entropy, in bits. This will be a number in the range 0 to 4096.
(man urandom(4))

例えば、

watch -n 1 cat /proc/sys/kernel/random/entropy_avail

で監視してみると、数字が少しづつ増えて、64となったあたりで0に戻るという挙動をしていました。これは、gpgがkernel's random number generatorを使っているからでしょう。。

また、

When the entropy pool is empty, reads from /dev/random will block until additional environmental noise is gathered.
(man urandom(4))

とあるので、/proc/sys/kernel/random/entropy_availが0となると、gpg --gen-keyが止まってしまうのでしょう。

余談ですが、gpgにおいて最長の鍵長は4096みたいですが、これは、kernelのentropy poolが4096bitなのと関係しているのでしょうか。

[/proc/sys/kernel/random/]poolsize
This file gives the size of the entropy pool. The semantics of this file vary across kernel versions:

Linux 2.6 and later
This file is read-only, and gives the size of the entropy pool in bits. It contains the value 4096.
(man urandom(4))

さらに、64までインクリメントすると0に戻るという挙動は、
/proc/sys/kernel/random/read_wakeup_thresholdの値が64であることによるのだと思います。

[/proc/sys/kernel/random/]read_wakeup_threshold
This file contains the number of bits of entropy required for waking up processes that sleep waiting for entropy from /dev/random. The
default is 64.

以上、gpg --gen-keyが終わるのを待っている間に書いた記事でした。4096bitにしたから、終わるのがめちゃくちゃ遅い。。。entropyの代わりに擬似乱数を使えたら早いのにな。

2
3
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3