5 // boost thread callbacks for libgcrypt
6 #if defined(BOOST_HAS_PTHREADS)
8 static int boost_mutex_init(void **priv
)
10 boost::mutex
*lock
= new boost::mutex();
17 static int boost_mutex_destroy(void **lock
)
19 delete reinterpret_cast<boost::mutex
*>(*lock
);
23 static int boost_mutex_lock(void **lock
)
25 reinterpret_cast<boost::mutex
*>(*lock
)->lock();
29 static int boost_mutex_unlock(void **lock
)
31 reinterpret_cast<boost::mutex
*>(*lock
)->unlock();
35 static struct gcry_thread_cbs gcry_threads_boost
=
36 { GCRY_THREAD_OPTION_USER
, NULL
,
37 boost_mutex_init
, boost_mutex_destroy
,
38 boost_mutex_lock
, boost_mutex_unlock
};
40 #error this libgcrypt thread callbacks only work with pthreads
44 #define MIN_GCRYPT_VERSION "1.2.0"
48 // make libgcrypt thread safe
49 // this must be called before any other libgcrypt call
50 gcry_control( GCRYCTL_SET_THREAD_CBS
, &gcry_threads_boost
);
52 // this must be called right after the GCRYCTL_SET_THREAD_CBS command
53 // no other function must be called till now
54 if( !gcry_check_version( MIN_GCRYPT_VERSION
) ) {
55 std::cout
<< "initLibGCrypt: Invalid Version of libgcrypt, should be >= " << MIN_GCRYPT_VERSION
<< std::endl
;
59 gcry_error_t err
= gcry_control (GCRYCTL_DISABLE_SECMEM
, 0);
61 char buf
[STERROR_TEXT_MAX
];
63 std::cout
<< "initLibGCrypt: Failed to disable secure memory: " << gpg_strerror_r(err
, buf
, STERROR_TEXT_MAX
) << std::endl
;
67 // Tell Libgcrypt that initialization has completed.
68 err
= gcry_control(GCRYCTL_INITIALIZATION_FINISHED
);
70 char buf
[STERROR_TEXT_MAX
];
72 std::cout
<< "initLibGCrypt: Failed to finish initialization: " << gpg_strerror_r(err
, buf
, STERROR_TEXT_MAX
) << std::endl
;
76 cLog
.msg(Log::PRIO_NOTICE
) << "initLibGCrypt: libgcrypt init finished";