DH prime generation taking a long time

Simon Josefsson simon at josefsson.org
Thu Oct 14 22:34:00 CEST 2010


Nikos Mavrogiannopoulos <nmav at gnutls.org> writes:

> On 10/14/2010 09:29 PM, Simon Josefsson wrote:
>> Ludo,
>> This may suggest a real problem in the randomness code -- I thought it
>> should be quicker now than with libgcrypt -- but I think it would be
>> good to fix the self tests to not cause prime generations except when it
>> is those particular functions that are tested.
>
> The nettle code shouldn't have caused multiple reads to /dev/*random. It
> reads 32 bytes on initialization from /dev/urandom and will read some
> more after few hours. Which test causes this delay?

Newly committed self-test tests/gendh.c triggers it too.  Running strace
on it reveals it is calling time() a lot, which suggests it is spending
time in nettle/rnd.c.  This is with GnuTLS built with Nettle as backend.

open("/dev/urandom", O_RDONLY)          = 3
fcntl64(3, F_GETFD)                     = 0
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
read(3, "...", 32) = 32
gettimeofday({1287088271, 237216}, NULL) = 0
open("/etc/gnutls/pkcs11.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
gettimeofday({1287088271, 243685}, NULL) = 0
time(NULL)                              = 1287088271
gettimeofday({1287088271, 243786}, NULL) = 0
time(NULL)                              = 1287088271
gettimeofday({1287088271, 243857}, NULL) = 0
time(NULL)                              = 1287088271
...
gettimeofday({1287088331, 926694}, NULL) = 0
time(NULL)                              = 1287088331
gettimeofday({1287088332, 156845}, NULL) = 0
time(NULL)                              = 1287088332
fstat64(1, {st_mode=S_IFREG|0644, st_size=4779192, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76a9000
write(1, "generated DH params OKSelf test "..., 65generated DH params OKSelf test `./gendh' finished with 0 errors
) = 65
exit_group(0)                           = ?

/Simon




More information about the Gnutls-devel mailing list