From c0790f91d038f136dfd73ffb5458e9906c7a6a08 Mon Sep 17 00:00:00 2001 From: Erwin Nindl Date: Wed, 21 Nov 2007 11:23:34 +0000 Subject: * fixed initialisation of libgcrypt * reoved libstrp from deps --- keyDerivation.cpp | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'keyDerivation.cpp') diff --git a/keyDerivation.cpp b/keyDerivation.cpp index f8e3c55..a171244 100644 --- a/keyDerivation.cpp +++ b/keyDerivation.cpp @@ -44,27 +44,32 @@ const char* KeyDerivation::MIN_GCRYPT_VERSION = "1.2.3"; void KeyDerivation::init(Buffer key, Buffer salt) { gcry_error_t err; - if( !gcry_check_version( MIN_GCRYPT_VERSION ) ) - { - std::cerr << "Invalid Version of libgcrypt, should be >= " << MIN_GCRYPT_VERSION << std::endl; - return; - } - - /* Allocate a pool of 16k secure memory. This also drops priviliges - * on some systems. */ - err = gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0); - if( err ) - { - std::cerr << "Failed to allocate 16k secure memory: " << gpg_strerror( err ) << std::endl; - return; - } - /* Tell Libgcrypt that initialization has completed. */ - err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED); - if( err ) + // No other library has already initialized libgcrypt. + if( !gcry_control(GCRYCTL_ANY_INITIALIZATION_P) ) { - std::cerr << "Failed to finish the initialization of libgcrypt" << gpg_strerror( err ) << std::endl; - return; + if( !gcry_check_version( MIN_GCRYPT_VERSION ) ) { + std::cerr << "Invalid Version of libgcrypt, should be >= " << MIN_GCRYPT_VERSION << std::endl; + return; + } + + /* Allocate a pool of 16k secure memory. This also drops priviliges + * on some systems. */ + err = gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0); + if( err ) + { + std::cerr << "Failed to allocate 16k secure memory: " << gpg_strerror( err ) << std::endl; + return; + } + + /* Tell Libgcrypt that initialization has completed. */ + err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED); + if( err ) { + std::cerr << "Failed to finish the initialization of libgcrypt" << gpg_strerror( err ) << std::endl; + return; + } else { + std::cout << "KeyDerivation::init: libgcrypt init finished" << std::endl; + } } err = gcry_cipher_open( &cipher_, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0 ); -- cgit v1.2.3