diff options
Diffstat (limited to 'src/threads/libcrypto.c')
-rw-r--r-- | src/threads/libcrypto.c | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/src/threads/libcrypto.c b/src/threads/libcrypto.c index 5786948b..18951b6a 100644 --- a/src/threads/libcrypto.c +++ b/src/threads/libcrypto.c @@ -24,8 +24,6 @@ #include "libssh/threads.h" #include <libssh/callbacks.h> -#if (OPENSSL_VERSION_NUMBER >= 0x10100000) - int crypto_thread_init(struct ssh_threads_callbacks_struct *cb) { (void) cb; @@ -36,98 +34,3 @@ void crypto_thread_finalize(void) { return; } - -#else - -static struct ssh_threads_callbacks_struct *user_callbacks = NULL; - -static void **libcrypto_mutexes; - -void libcrypto_lock_callback(int mode, int i, const char *file, int line); - -void libcrypto_lock_callback(int mode, int i, const char *file, int line) -{ - (void)file; - (void)line; - - if (mode & CRYPTO_LOCK) { - user_callbacks->mutex_lock(&libcrypto_mutexes[i]); - } else { - user_callbacks->mutex_unlock(&libcrypto_mutexes[i]); - } -} - -#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK -static void libcrypto_THREADID_callback(CRYPTO_THREADID *id) -{ - unsigned long thread_id = (*user_callbacks->thread_id)(); - - CRYPTO_THREADID_set_numeric(id, thread_id); -} -#endif /* HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK */ - -int crypto_thread_init(struct ssh_threads_callbacks_struct *cb) -{ - int n = CRYPTO_num_locks(); - int cmp; - int i; - - if (cb == NULL) { - return SSH_OK; - } - - if (user_callbacks != NULL) { - crypto_thread_finalize(); - } - - user_callbacks = cb; - - cmp = strcmp(user_callbacks->type, "threads_noop"); - if (cmp == 0) { - return SSH_OK; - } - - libcrypto_mutexes = calloc(n, sizeof(void *)); - if (libcrypto_mutexes == NULL) { - return SSH_ERROR; - } - - for (i = 0; i < n; ++i){ - user_callbacks->mutex_init(&libcrypto_mutexes[i]); - } - -#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK - CRYPTO_THREADID_set_callback(libcrypto_THREADID_callback); -#else - CRYPTO_set_id_callback(user_callbacks->thread_id); -#endif - - CRYPTO_set_locking_callback(libcrypto_lock_callback); - - return SSH_OK; -} - -void crypto_thread_finalize(void) -{ - int n = CRYPTO_num_locks(); - int i; - - if (libcrypto_mutexes == NULL) { - return; - } - -#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK - CRYPTO_THREADID_set_callback(NULL); -#else - CRYPTO_set_id_callback(NULL); -#endif - - CRYPTO_set_locking_callback(NULL); - - for (i = 0; i < n; ++i) { - user_callbacks->mutex_destroy(&libcrypto_mutexes[i]); - } - SAFE_FREE(libcrypto_mutexes); -} - -#endif |