diff options
Diffstat (limited to 'crypto/openssl/crypto/threads')
-rw-r--r-- | crypto/openssl/crypto/threads/README | 14 | ||||
-rw-r--r-- | crypto/openssl/crypto/threads/mttest.c | 122 | ||||
-rw-r--r-- | crypto/openssl/crypto/threads/profile.sh | 4 | ||||
-rw-r--r-- | crypto/openssl/crypto/threads/pthread.sh | 9 | ||||
-rwxr-xr-x | crypto/openssl/crypto/threads/pthread2.sh | 7 | ||||
-rw-r--r-- | crypto/openssl/crypto/threads/purify.sh | 4 | ||||
-rw-r--r-- | crypto/openssl/crypto/threads/solaris.sh | 4 | ||||
-rw-r--r-- | crypto/openssl/crypto/threads/th-lock.c | 55 |
8 files changed, 159 insertions, 60 deletions
diff --git a/crypto/openssl/crypto/threads/README b/crypto/openssl/crypto/threads/README new file mode 100644 index 0000000..df6b26e --- /dev/null +++ b/crypto/openssl/crypto/threads/README @@ -0,0 +1,14 @@ +Mutithreading testing area. + +Since this stuff is very very platorm specific, this is not part of the +normal build. Have a read of doc/threads.doc. + +mttest will do some testing and will currently build under Windows NT/95, +Solaris and Linux. The IRIX stuff is not finished. + +I have tested this program on a 12 CPU ultra sparc box (solaris 2.5.1) +and things seem to work ok. + +The Linux pthreads package can be retrieved from +http://www.mit.edu:8001/people/proven/pthreads.html + diff --git a/crypto/openssl/crypto/threads/mttest.c b/crypto/openssl/crypto/threads/mttest.c index 142623ed..24713a3 100644 --- a/crypto/openssl/crypto/threads/mttest.c +++ b/crypto/openssl/crypto/threads/mttest.c @@ -74,26 +74,29 @@ #include <ulocks.h> #include <sys/prctl.h> #endif +#ifdef PTHREADS +#include <pthread.h> +#endif #include <openssl/lhash.h> #include <openssl/crypto.h> #include <openssl/buffer.h> -#include "../e_os.h" +#include "../../e_os.h" #include <openssl/x509.h> #include <openssl/ssl.h> #include <openssl/err.h> +#include <openssl/rand.h> #ifdef NO_FP_API #define APPS_WIN16 -#include "../crypto/buffer/bss_file.c" +#include "../buffer/bss_file.c" #endif -#define TEST_SERVER_CERT "../apps/server.pem" -#define TEST_CLIENT_CERT "../apps/client.pem" +#define TEST_SERVER_CERT "../../apps/server.pem" +#define TEST_CLIENT_CERT "../../apps/client.pem" #define MAX_THREAD_NUMBER 100 -int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, - int error,char *arg); +int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs); void thread_setup(void); void thread_cleanup(void); void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); @@ -121,6 +124,8 @@ int number_of_loops=10; int reconnect=0; int cache_stats=0; +static const char rnd_seed[] = "string to make the random number generator think it has entropy"; + int doit(char *ctx[4]); static void print_stats(FILE *fp, SSL_CTX *ctx) { @@ -170,6 +175,8 @@ int main(int argc, char *argv[]) char *ccert=TEST_CLIENT_CERT; SSL_METHOD *ssl_method=SSLv23_method(); + RAND_seed(rnd_seed, sizeof rnd_seed); + if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); if (bio_stdout == NULL) @@ -244,7 +251,7 @@ bad: if (cipher == NULL) cipher=getenv("SSL_CIPHER"); SSL_load_error_strings(); - SSLeay_add_ssl_algorithms(); + OpenSSL_add_ssl_algorithms(); c_ctx=SSL_CTX_new(ssl_method); s_ctx=SSL_CTX_new(ssl_method); @@ -259,8 +266,15 @@ bad: SSL_CTX_set_session_cache_mode(c_ctx, SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); - SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM); - SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM); + if (!SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM)) + { + ERR_print_errors(bio_err); + } + else if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM)) + { + ERR_print_errors(bio_err); + goto end; + } if (client_auth) { @@ -489,6 +503,7 @@ int doit(char *ctx[4]) else { fprintf(stderr,"ERROR in CLIENT\n"); + ERR_print_errors_fp(stderr); return(1); } } @@ -520,6 +535,7 @@ int doit(char *ctx[4]) else { fprintf(stderr,"ERROR in CLIENT\n"); + ERR_print_errors_fp(stderr); return(1); } } @@ -652,18 +668,23 @@ err: return(0); } -int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, - int error, char *arg) +int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx) { - char buf[256]; + char *s, buf[256]; if (verbose) { - X509_NAME_oneline(X509_get_subject_name(xs),buf,256); - if (ok) - fprintf(stderr,"depth=%d %s\n",depth,buf); - else - fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf); + s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert), + buf,256); + if (s != NULL) + { + if (ok) + fprintf(stderr,"depth=%d %s\n", + ctx->error_depth,buf); + else + fprintf(stderr,"depth=%d error=%d %s\n", + ctx->error_depth,ctx->error,buf); + } } return(ok); } @@ -672,13 +693,14 @@ int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, #ifdef WIN32 -static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; +static HANDLE *lock_cs; void thread_setup(void) { int i; - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE)); + for (i=0; i<CRYPTO_num_locks(); i++) { lock_cs[i]=CreateMutex(NULL,FALSE,NULL); } @@ -692,8 +714,9 @@ void thread_cleanup(void) int i; CRYPTO_set_locking_callback(NULL); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + for (i=0; i<CRYPTO_num_locks(); i++) CloseHandle(lock_cs[i]); + Free(lock_cs); } void win32_locking_callback(int mode, int type, char *file, int line) @@ -763,15 +786,17 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) #ifdef SOLARIS -static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; -/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ -static long lock_count[CRYPTO_NUM_LOCKS]; +static mutex_t *lock_cs; +/*static rwlock_t *lock_cs; */ +static long *lock_count; void thread_setup(void) { int i; - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t)); + lock_count=Malloc(CRYPTO_num_locks() * sizeof(long)); + for (i=0; i<CRYPTO_num_locks(); i++) { lock_count[i]=0; /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ @@ -787,31 +812,37 @@ void thread_cleanup(void) int i; CRYPTO_set_locking_callback(NULL); -fprintf(stderr,"cleanup\n"); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + + fprintf(stderr,"cleanup\n"); + + for (i=0; i<CRYPTO_num_locks(); i++) { /* rwlock_destroy(&(lock_cs[i])); */ mutex_destroy(&(lock_cs[i])); fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i)); } -fprintf(stderr,"done cleanup\n"); + Free(lock_cs); + Free(lock_count); + + fprintf(stderr,"done cleanup\n"); + } void solaris_locking_callback(int mode, int type, char *file, int line) { #ifdef undef -fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", - CRYPTO_thread_id(), - (mode&CRYPTO_LOCK)?"l":"u", - (type&CRYPTO_READ)?"r":"w",file,line); + fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", + CRYPTO_thread_id(), + (mode&CRYPTO_LOCK)?"l":"u", + (type&CRYPTO_READ)?"r":"w",file,line); #endif -/* -if (CRYPTO_LOCK_SSL_CERT == type) + /* + if (CRYPTO_LOCK_SSL_CERT == type) fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", CRYPTO_thread_id(), mode,file,line); -*/ + */ if (mode & CRYPTO_LOCK) { /* if (mode & CRYPTO_READ) @@ -871,7 +902,7 @@ unsigned long solaris_thread_id(void) static usptr_t *arena; -static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; +static usema_t **lock_cs; void thread_setup(void) { @@ -888,7 +919,8 @@ void thread_setup(void) arena=usinit(filename); unlink(filename); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *)); + for (i=0; i<CRYPTO_num_locks(); i++) { lock_cs[i]=usnewsema(arena,1); } @@ -902,7 +934,7 @@ void thread_cleanup(void) int i; CRYPTO_set_locking_callback(NULL); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + for (i=0; i<CRYPTO_num_locks(); i++) { char buf[10]; @@ -910,6 +942,7 @@ void thread_cleanup(void) usdumpsema(lock_cs[i],stdout,buf); usfreesema(lock_cs[i],arena); } + Free(lock_cs); } void irix_locking_callback(int mode, int type, char *file, int line) @@ -962,14 +995,16 @@ unsigned long irix_thread_id(void) #ifdef PTHREADS -static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; -static long lock_count[CRYPTO_NUM_LOCKS]; +static pthread_mutex_t *lock_cs; +static long *lock_count; void thread_setup(void) { int i; - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); + lock_count=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); @@ -985,12 +1020,15 @@ void thread_cleanup(void) CRYPTO_set_locking_callback(NULL); fprintf(stderr,"cleanup\n"); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + for (i=0; i<CRYPTO_num_locks(); i++) { pthread_mutex_destroy(&(lock_cs[i])); fprintf(stderr,"%8ld:%s\n",lock_count[i], CRYPTO_get_lock_name(i)); } + Free(lock_cs); + Free(lock_count); + fprintf(stderr,"done cleanup\n"); } @@ -1045,7 +1083,7 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) } printf("pthreads threads done (%d,%d)\n", - s_ctx->references,c_ctx->references); + s_ctx->references,c_ctx->references); } unsigned long pthreads_thread_id(void) diff --git a/crypto/openssl/crypto/threads/profile.sh b/crypto/openssl/crypto/threads/profile.sh new file mode 100644 index 0000000..6e3e342 --- /dev/null +++ b/crypto/openssl/crypto/threads/profile.sh @@ -0,0 +1,4 @@ +#!/bin/sh +/bin/rm -f mttest +cc -p -DSOLARIS -I../../include -g mttest.c -o mttest -L/usr/lib/libc -ldl -L../.. -lthread -lssl -lcrypto -lnsl -lsocket + diff --git a/crypto/openssl/crypto/threads/pthread.sh b/crypto/openssl/crypto/threads/pthread.sh new file mode 100644 index 0000000..f1c4982 --- /dev/null +++ b/crypto/openssl/crypto/threads/pthread.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# +# build using pthreads +# +# http://www.mit.edu:8001/people/proven/pthreads.html +# +/bin/rm -f mttest +pgcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto + diff --git a/crypto/openssl/crypto/threads/pthread2.sh b/crypto/openssl/crypto/threads/pthread2.sh new file mode 100755 index 0000000..41264c6 --- /dev/null +++ b/crypto/openssl/crypto/threads/pthread2.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# +# build using pthreads where it's already built into the system +# +/bin/rm -f mttest +gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread + diff --git a/crypto/openssl/crypto/threads/purify.sh b/crypto/openssl/crypto/threads/purify.sh new file mode 100644 index 0000000..6d44fe2 --- /dev/null +++ b/crypto/openssl/crypto/threads/purify.sh @@ -0,0 +1,4 @@ +#!/bin/sh +/bin/rm -f mttest +purify cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket + diff --git a/crypto/openssl/crypto/threads/solaris.sh b/crypto/openssl/crypto/threads/solaris.sh new file mode 100644 index 0000000..bc93094 --- /dev/null +++ b/crypto/openssl/crypto/threads/solaris.sh @@ -0,0 +1,4 @@ +#!/bin/sh +/bin/rm -f mttest +cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket + diff --git a/crypto/openssl/crypto/threads/th-lock.c b/crypto/openssl/crypto/threads/th-lock.c index afb4f4c..3ee9780 100644 --- a/crypto/openssl/crypto/threads/th-lock.c +++ b/crypto/openssl/crypto/threads/th-lock.c @@ -74,6 +74,9 @@ #include <ulocks.h> #include <sys/prctl.h> #endif +#ifdef PTHREADS +#include <pthread.h> +#endif #include <openssl/lhash.h> #include <openssl/crypto.h> #include <openssl/buffer.h> @@ -82,7 +85,7 @@ #include <openssl/ssl.h> #include <openssl/err.h> -int CRYPTO_thread_setup(void); +void CRYPTO_thread_setup(void); void CRYPTO_thread_cleanup(void); static void irix_locking_callback(int mode,int type,char *file,int line); @@ -96,7 +99,7 @@ static unsigned long pthreads_thread_id(void ); /* usage: * CRYPTO_thread_setup(); - * applicaion code + * application code * CRYPTO_thread_cleanup(); */ @@ -104,13 +107,14 @@ static unsigned long pthreads_thread_id(void ); #ifdef WIN32 -static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; +static HANDLE *lock_cs; -int CRYPTO_thread_setup(void) +void CRYPTO_thread_setup(void) { int i; - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE)); + for (i=0; i<CRYPTO_num_locks(); i++) { lock_cs[i]=CreateMutex(NULL,FALSE,NULL); } @@ -125,8 +129,9 @@ static void CRYPTO_thread_cleanup(void) int i; CRYPTO_set_locking_callback(NULL); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + for (i=0; i<CRYPTO_num_locks(); i++) CloseHandle(lock_cs[i]); + Free(lock_cs); } void win32_locking_callback(int mode, int type, char *file, int line) @@ -147,18 +152,24 @@ void win32_locking_callback(int mode, int type, char *file, int line) #define USE_MUTEX -static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; #ifdef USE_MUTEX -static long lock_count[CRYPTO_NUM_LOCKS]; +static mutex_t *lock_cs; #else -static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; +static rwlock_t *lock_cs; #endif +static long *lock_count; void CRYPTO_thread_setup(void) { int i; - for (i=0; i<CRYPTO_NUM_LOCKS; i++) +#ifdef USE_MUTEX + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t)); +#else + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(rwlock_t)); +#endif + lock_count=Malloc(CRYPTO_num_locks() * sizeof(long)); + for (i=0; i<CRYPTO_num_locks(); i++) { lock_count[i]=0; #ifdef USE_MUTEX @@ -177,7 +188,7 @@ void CRYPTO_thread_cleanup(void) int i; CRYPTO_set_locking_callback(NULL); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + for (i=0; i<CRYPTO_num_locks(); i++) { #ifdef USE_MUTEX mutex_destroy(&(lock_cs[i])); @@ -185,6 +196,8 @@ void CRYPTO_thread_cleanup(void) rwlock_destroy(&(lock_cs[i])); #endif } + Free(lock_cs); + Free(lock_count); } void solaris_locking_callback(int mode, int type, char *file, int line) @@ -237,7 +250,7 @@ unsigned long solaris_thread_id(void) /* I don't think this works..... */ static usptr_t *arena; -static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; +static usema_t **lock_cs; void CRYPTO_thread_setup(void) { @@ -254,7 +267,8 @@ void CRYPTO_thread_setup(void) arena=usinit(filename); unlink(filename); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *)); + for (i=0; i<CRYPTO_num_locks(); i++) { lock_cs[i]=usnewsema(arena,1); } @@ -268,7 +282,7 @@ void CRYPTO_thread_cleanup(void) int i; CRYPTO_set_locking_callback(NULL); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + for (i=0; i<CRYPTO_num_locks(); i++) { char buf[10]; @@ -276,6 +290,7 @@ void CRYPTO_thread_cleanup(void) usdumpsema(lock_cs[i],stdout,buf); usfreesema(lock_cs[i],arena); } + Free(lock_cs); } void irix_locking_callback(int mode, int type, char *file, int line) @@ -302,14 +317,16 @@ unsigned long irix_thread_id(void) /* Linux and a few others */ #ifdef PTHREADS -static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; -static long lock_count[CRYPTO_NUM_LOCKS]; +static pthread_mutex_t *lock_cs; +static long *lock_count; void CRYPTO_thread_setup(void) { int i; - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); + lock_count=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); @@ -324,10 +341,12 @@ void thread_cleanup(void) int i; CRYPTO_set_locking_callback(NULL); - for (i=0; i<CRYPTO_NUM_LOCKS; i++) + for (i=0; i<CRYPTO_num_locks(); i++) { pthread_mutex_destroy(&(lock_cs[i])); } + Free(lock_cs); + Free(lock_count); } void pthreads_locking_callback(int mode, int type, char *file, |