00001 #include "headers.h"
00002
00003
00004 static void pthreads_locking_callback(int mode, int type,
00005 char *file, int line);
00006
00007 static unsigned long pthreads_thread_id(void);
00008
00009 static pthread_mutex_t *lock_cs;
00010
00011
00018 void
00019 ssl_thread_init(void)
00020 {
00021 int i;
00022
00023 lock_cs = (pthread_mutex_t*) malloc(CRYPTO_num_locks() *
00024 sizeof(pthread_mutex_t));
00025
00026 for (i=0; i<CRYPTO_num_locks(); i++) {
00027 pthread_mutex_init(&(lock_cs[i]),NULL);
00028 }
00029
00030 CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
00031 CRYPTO_set_locking_callback((void (*)(int,int,const char*, int))
00032 pthreads_locking_callback);
00033 }
00034
00035
00039 void
00040 ssl_thread_cleanup(void)
00041 {
00042 int i;
00043
00044 CRYPTO_set_locking_callback(NULL);
00045 for (i=0; i<CRYPTO_num_locks(); i++) {
00046 pthread_mutex_destroy(&(lock_cs[i]));
00047 }
00048 free(lock_cs);
00049 }
00050
00051
00059 void
00060 pthreads_locking_callback(int mode, int type, char *file, int line)
00061 {
00062 if (mode & CRYPTO_LOCK) {
00063 pthread_mutex_lock(&(lock_cs[type]));
00064 } else {
00065 pthread_mutex_unlock(&(lock_cs[type]));
00066 }
00067 }
00068
00069
00070
00075 unsigned long
00076 pthreads_thread_id(void)
00077 {
00078 unsigned long ret;
00079
00080 ret = (unsigned long)pthread_self();
00081 return ret;
00082 }
00083
00084
00102 void
00103 ssl_init(void)
00104 {
00105 static const char rnd_seed[] =
00106 "string to make the random number generator think it has entropy";
00107
00108 RAND_seed(rnd_seed, sizeof(rnd_seed));
00109 SSL_library_init();
00110 SSL_load_error_strings();
00111 SSLeay_add_all_algorithms();
00112 }
00113
00114
00118 void
00119 ssl_cleanup(void)
00120 {
00121
00122 }
00123