summaryrefslogtreecommitdiff
path: root/keyDerivation.cpp
diff options
context:
space:
mode:
authorErwin Nindl <nine@wirdorange.org>2007-11-21 11:23:34 +0000
committerErwin Nindl <nine@wirdorange.org>2007-11-21 11:23:34 +0000
commitc0790f91d038f136dfd73ffb5458e9906c7a6a08 (patch)
tree8eb0945e9ce3a9f1a329d810a210940fbc44111c /keyDerivation.cpp
parent * TunDevice: changed 'char* getTypeString()' to 'const char* getTypeString()' (diff)
* fixed initialisation of libgcrypt
* reoved libstrp from deps
Diffstat (limited to 'keyDerivation.cpp')
-rw-r--r--keyDerivation.cpp43
1 files changed, 24 insertions, 19 deletions
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 );