libgcrypt painfully slow under Windows
tim.kosse at filezilla-project.org
Fri Nov 3 14:36:22 CET 2006
-----BEGIN PGP SIGNED MESSAGE-----
I'm using GnuTLS under Windows and initializing GnuTLS takes over 10
seconds on my system. After some investigation, I found out that calling
libgcrypt's gcry_randomize causes the delay.
My system is an IBM Thinkpad R52, 2GHz Pentium M, 1 GB RAM running a
fully patched Windows XP SP 2.
Further investigation revealed that the delay is caused inside
_gcry_rndw32_gather_random in cipher/rndw32.c
One of the things libgcrypt does, is to query HKEY_PERFORMANCE_DATA.
That alone takes 3-4 seconds, returning around 140KB of performance data.
Furthermore, libgcrypt walks the local heap. With a minimal program,
this already takes over 1 second. In a more complex program, it will
take a lot of time. Currently _gcry_rndw32_gather_random takes a little
over 10 seconds with my program, which is still far from finished.
The amount of time seems to be only bounded by the amount of heap memory
which can be allocated.
The other methods used to gather entropy are almost instant however.
On http://www.securitypunk.com/libgcrypt/ I found a patch from J.
Salvatore Testa which enables libgcrypt to use the Crypto API of
Windows, in particular the CryptGenRandom function.
I've modified the patch to also work if libgcrypt gets linked statically
and allowed a fallback to the previous, slow methods if the Crypto API
cannot be initialized or CryptGenRandom fails. (patch:
Using this patch, there is no longer any noticeable delay.
Would it be possible to officially apply it to libgcrypt in some way? As
in its current state, libgcrypt and the libraries/programs using it are
barely usable due to the delays under Windows.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the Gcrypt-devel