本文整理汇总了C++中CRYPTO_set_locking_callback函数的典型用法代码示例。如果您正苦于以下问题:C++ CRYPTO_set_locking_callback函数的具体用法?C++ CRYPTO_set_locking_callback怎么用?C++ CRYPTO_set_locking_callback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CRYPTO_set_locking_callback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: THREAD_cleanup
int THREAD_cleanup(void)
{
int i;
if (!mutex_buf)
return 0;
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks(); i++) {
MUTEX_CLEANUP(mutex_buf[i]);
}
free(mutex_buf);
mutex_buf = NULL;
return 1;
}
示例2: curl_global_init
void LLCurl::initClass()
{
// Do not change this "unless you are familiar with and mean to control
// internal operations of libcurl"
// - http://curl.haxx.se/libcurl/c/curl_global_init.html
curl_global_init(CURL_GLOBAL_ALL);
#if SAFE_SSL
S32 mutex_count = CRYPTO_num_locks();
for (S32 i=0; i<mutex_count; i++)
{
sSSLMutex.push_back(new LLMutex(gAPRPoolp));
}
CRYPTO_set_id_callback(&LLCurl::ssl_thread_id);
CRYPTO_set_locking_callback(&LLCurl::ssl_locking_callback);
#endif
}
示例3: start
void start() {
Platform::ThirdParty::start();
if (!RAND_status()) { // should be always inited in all modern OS
char buf[16];
memcpy(buf, &_msStart, 8);
memcpy(buf + 8, &_msFreq, 8);
uchar sha256Buffer[32];
RAND_seed(hashSha256(buf, 16, sha256Buffer), 32);
if (!RAND_status()) {
LOG(("MTP Error: Could not init OpenSSL rand, RAND_status() is 0..."));
}
}
// Force OpenSSL loading if it is linked in Qt,
// so that we won't mess with our OpenSSL locking with Qt OpenSSL locking.
auto sslSupported = QSslSocket::supportsSsl();
if (!sslSupported) {
LOG(("Error: current Qt build doesn't support SSL requests."));
}
if (!CRYPTO_get_locking_callback()) {
// Qt didn't initialize OpenSSL, so we will.
auto numLocks = CRYPTO_num_locks();
if (numLocks) {
_sslLocks = new QMutex[numLocks];
CRYPTO_set_locking_callback(_sslLockingCallback);
} else {
LOG(("MTP Error: Could not init OpenSSL threads, CRYPTO_num_locks() returned zero!"));
}
CRYPTO_THREADID_set_callback(_sslThreadId);
}
if (!CRYPTO_get_dynlock_create_callback()) {
CRYPTO_set_dynlock_create_callback(_sslCreateFunction);
CRYPTO_set_dynlock_lock_callback(_sslLockFunction);
CRYPTO_set_dynlock_destroy_callback(_sslDestroyFunction);
} else if (!CRYPTO_get_dynlock_lock_callback()) {
LOG(("MTP Error: dynlock_create callback is set without dynlock_lock callback!"));
}
av_register_all();
avcodec_register_all();
av_lockmgr_register(_ffmpegLockManager);
_sslInited = true;
}
示例4: tls_init_locks
/* returns -1 on error, 0 on success */
int tls_init_locks()
{
/* init "static" tls locks */
n_static_locks=CRYPTO_num_locks();
if (n_static_locks<0){
LOG(L_CRIT, "BUG: tls: tls_init_locking: bad CRYPTO_num_locks %d\n",
n_static_locks);
n_static_locks=0;
}
if (n_static_locks){
static_locks=lock_set_alloc(n_static_locks);
if (static_locks==0){
LOG(L_CRIT, "ERROR: tls_init_locking: could not allocate lockset"
" with %d locks\n", n_static_locks);
goto error;
}
if (lock_set_init(static_locks)==0){
LOG(L_CRIT, "ERROR: tls_init_locking: lock_set_init failed "
"(%d locks)\n", n_static_locks);
lock_set_dealloc(static_locks);
static_locks=0;
n_static_locks=0;
goto error;
}
CRYPTO_set_locking_callback(locking_f);
}
/* set "dynamic" locks callbacks */
CRYPTO_set_dynlock_create_callback(dyn_create_f);
CRYPTO_set_dynlock_lock_callback(dyn_lock_f);
CRYPTO_set_dynlock_destroy_callback(dyn_destroy_f);
/* thread id callback: not needed because ser doesn't use thread and
* openssl already uses getpid() (by default)
* CRYPTO_set_id_callback(id_f);
*/
/* atomic add -- since for now we don't have atomic_add
* (only atomic_inc), fallback to the default use-locks mode
* CRYPTO_set_add_lock_callback(atomic_add_f);
*/
return 0;
error:
tls_destroy_locks();
return -1;
}
示例5: SetupOpenSSLThreadLocks
static void SetupOpenSSLThreadLocks(void)
{
#if defined(HAVE_PTHREAD)
const int numLocks = CRYPTO_num_locks();
cf_openssl_locks = OPENSSL_malloc(numLocks * sizeof(pthread_mutex_t));
for (int i = 0; i < numLocks; i++)
{
pthread_mutex_init(&(cf_openssl_locks[i]),NULL);
}
#ifndef __MINGW32__
CRYPTO_set_id_callback((unsigned long (*)())ThreadId_callback);
#endif
CRYPTO_set_locking_callback((void (*)())OpenSSLLock_callback);
#endif
}
示例6: torque_stop_ssl
int torque_stop_ssl(void){
int ret = 0;
unsigned z;
RAND_cleanup();
CRYPTO_set_locking_callback(NULL);
CRYPTO_set_id_callback(NULL);
for(z = 0 ; z < numlocks ; ++z){
if(pthread_mutex_destroy(&openssl_locks[z])){
ret = -1;
}
}
numlocks = 0;
free(openssl_locks);
openssl_locks = NULL;
return ret;
}
示例7: CRYPTO_thread_setup
void CRYPTO_thread_setup(void)
{
int i;
syslog(LOG_DEBUG, "Setting up pthreads TLS.");
lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
for (i = 0; i < CRYPTO_num_locks(); i++) {
lock_count[i]=0;
pthread_mutex_init(&(lock_cs[i]),NULL);
}
CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
}
示例8: sthreads_init
void sthreads_init(void) {
int i;
/* Initialize stunnel critical sections */
for(i=0; i<CRIT_SECTIONS; i++)
pthread_mutex_init(stunnel_cs+i, NULL);
/* Initialize OpenSSL locking callback */
for(i=0; i<CRYPTO_NUM_LOCKS; i++)
pthread_mutex_init(lock_cs+i, NULL);
CRYPTO_set_id_callback(stunnel_thread_id);
CRYPTO_set_locking_callback(locking_callback);
pthread_attr_init(&pth_attr);
pthread_attr_setdetachstate(&pth_attr, PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize(&pth_attr, STACK_SIZE);
}
示例9: sdns_openssl_lock_init
int sdns_openssl_lock_init(void)
{
int i;
sdns_openssl_locks = (lock_basic_t*)malloc(
sizeof(lock_basic_t)*CRYPTO_num_locks());
if(!sdns_openssl_locks)
return 0;
for(i=0; i<CRYPTO_num_locks(); i++) {
lock_basic_init(&sdns_openssl_locks[i]);
}
//openssl 1.0.0 CRYPTO_set_id_callback was replaced by CRYPTO_THREADID_set_callback
openssl_set_id_callback(sdns_openssl_id_cb);
CRYPTO_set_locking_callback(&sdns_openssl_lock_cb);
return 1;
}
示例10: THREAD_setup
int THREAD_setup(void) {
int i;
mutex_buf = (MUTEX_TYPE *) malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE));
if(!mutex_buf) {
return 0;
}
for(i = 0; i < CRYPTO_num_locks(); i++) {
MUTEX_SETUP(mutex_buf[i]);
}
CRYPTO_set_id_callback(id_function);
CRYPTO_set_locking_callback(locking_function);
return 1;
}
示例11: ff_openssl_deinit
void ff_openssl_deinit(void)
{
avpriv_lock_avformat();
openssl_init--;
if (!openssl_init) {
#if HAVE_THREADS
if (CRYPTO_get_locking_callback() == openssl_lock) {
int i;
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < CRYPTO_num_locks(); i++)
pthread_mutex_destroy(&openssl_mutexes[i]);
av_free(openssl_mutexes);
}
#endif
}
avpriv_unlock_avformat();
}
示例12: SSLSocket_initialize
int SSLSocket_initialize()
{
int rc = 0;
/*int prc;*/
int i;
int lockMemSize;
FUNC_ENTRY;
if ((rc = SSL_library_init()) != 1)
rc = -1;
ERR_load_crypto_strings();
SSL_load_error_strings();
/* OpenSSL 0.9.8o and 1.0.0a and later added SHA2 algorithms to SSL_library_init().
Applications which need to use SHA2 in earlier versions of OpenSSL should call
OpenSSL_add_all_algorithms() as well. */
OpenSSL_add_all_algorithms();
lockMemSize = CRYPTO_num_locks() * sizeof(ssl_mutex_type);
sslLocks = malloc(lockMemSize);
if (!sslLocks)
{
rc = -1;
goto exit;
}
else
memset(sslLocks, 0, lockMemSize);
for (i = 0; i < CRYPTO_num_locks(); i++)
{
/* prc = */SSL_create_mutex(&sslLocks[i]);
}
CRYPTO_THREADID_set_callback(SSLThread_id);
CRYPTO_set_locking_callback(SSLLocks_callback);
SSL_create_mutex(&sslCoreMutex);
exit:
FUNC_EXIT_RC(rc);
return rc;
}
示例13: debug
void TlsSocket::Init()
{
debug("Initializing TLS library");
#ifdef HAVE_LIBGNUTLS
int error_code;
#ifdef NEED_GCRYPT_LOCKING
error_code = gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_Mutex);
if (error_code != 0)
{
error("Could not initialize libcrypt");
return;
}
#endif /* NEED_GCRYPT_LOCKING */
error_code = gnutls_global_init();
if (error_code != 0)
{
error("Could not initialize libgnutls");
return;
}
#endif /* HAVE_LIBGNUTLS */
#ifdef HAVE_OPENSSL
for (int i = 0, num = CRYPTO_num_locks(); i < num; i++)
{
g_OpenSSLMutexes.emplace_back(std::make_unique<Mutex>());
}
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
CRYPTO_set_locking_callback(openssl_locking);
//CRYPTO_set_id_callback(openssl_thread_id);
CRYPTO_set_dynlock_create_callback(openssl_dynlock_create);
CRYPTO_set_dynlock_destroy_callback(openssl_dynlock_destroy);
CRYPTO_set_dynlock_lock_callback(openssl_dynlock_lock);
#endif /* HAVE_OPENSSL */
m_tlsSocketFinalizer = std::make_unique<TlsSocketFinalizer>();
}
示例14: neo4j_openssl_init
int neo4j_openssl_init(void)
{
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
int num_locks = CRYPTO_num_locks();
thread_locks = calloc(num_locks, sizeof(neo4j_mutex_t));
if (thread_locks == NULL)
{
return -1;
}
for (int i = 0; i < num_locks; i++)
{
int err = neo4j_mutex_init(&(thread_locks[i]));
if (err)
{
for (; i > 0; --i)
{
neo4j_mutex_destroy(&(thread_locks[i-1]));
}
free(thread_locks);
errno = err;
return -1;
}
}
if (CRYPTO_get_locking_callback() == NULL)
{
CRYPTO_set_locking_callback(locking_callback);
CRYPTO_set_id_callback(neo4j_current_thread_id);
}
SSL_CTX *ctx = SSL_CTX_new(TLSv1_method());
if (ctx == NULL)
{
errno = openssl_error(NULL, NEO4J_LOG_ERROR, __FILE__, __LINE__);
return -1;
}
SSL_CTX_free(ctx);
return 0;
}
示例15: _winpr_openssl_cleanup_locking
static BOOL _winpr_openssl_cleanup_locking(void)
{
/* undo our static locking modifications */
if (CRYPTO_get_locking_callback() == _winpr_openssl_locking)
{
int i;
CRYPTO_set_locking_callback(NULL);
for (i = 0; i < g_winpr_openssl_num_locks; i++)
{
CloseHandle(g_winpr_openssl_locks[i]);
}
g_winpr_openssl_num_locks = 0;
free(g_winpr_openssl_locks);
g_winpr_openssl_locks = NULL;
}
/* unset our dynamic locking callbacks */
if (CRYPTO_get_dynlock_create_callback() == _winpr_openssl_dynlock_create)
{
CRYPTO_set_dynlock_create_callback(NULL);
}
if (CRYPTO_get_dynlock_lock_callback() == _winpr_openssl_dynlock_lock)
{
CRYPTO_set_dynlock_lock_callback(NULL);
}
if (CRYPTO_get_dynlock_destroy_callback() == _winpr_openssl_dynlock_destroy)
{
CRYPTO_set_dynlock_destroy_callback(NULL);
}
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
if (CRYPTO_get_id_callback() == _winpr_openssl_id)
{
CRYPTO_set_id_callback(NULL);
}
#endif
return TRUE;
}