crypto: fix initialization of gcrypt threading
commit373166636b9f07c60d7c32610bd346acf7d143e9
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 10 Oct 2016 11:17:50 +0000 (10 12:17 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 20 Oct 2016 11:19:35 +0000 (20 12:19 +0100)
tree3af354e1e5c8959a81d57424f332606569d83cef
parentd26d6b5d34f825c452f9bf3c9d5126181b10f25b
crypto: fix initialization of gcrypt threading

The gcrypt threads implementation must be set before calling
any other gcrypt APIs, especially gcry_check_version(),
since that triggers initialization of the random pool. After
that is initialized, changes to the threads impl won't be
honoured by the random pool code. This means that gcrypt
will think thread locking is needed and so try to acquire
the random pool mutex, but this is NULL as no threads impl
was set originally. This results in a crash in the random
pool code.

For the same reasons, we must set the gcrypt threads impl
before calling gnutls_init, since that will also trigger
gcry_check_version

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
crypto/init.c