Add support for shared libraries with OS/2.
[oweals/openssl.git] / crypto / threads / mttest.c
index 47faef53c4641313efe16038e1f7b3a04ea8a11a..7142e4edc77cf8086195ee49cd5d8853ae4d1576 100644 (file)
@@ -63,7 +63,7 @@
 #ifdef LINUX
 #include <typedefs.h>
 #endif
-#ifdef WIN32
+#ifdef OPENSSL_SYS_WIN32
 #include <windows.h>
 #endif
 #ifdef SOLARIS
@@ -84,8 +84,9 @@
 #include <openssl/x509.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
+#include <openssl/rand.h>
 
-#ifdef NO_FP_API
+#ifdef OPENSSL_NO_FP_API
 #define APPS_WIN16
 #include "../buffer/bss_file.c"
 #endif
@@ -123,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)
 {
@@ -172,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)
@@ -261,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)
                {
@@ -491,6 +503,7 @@ int doit(char *ctx[4])
                                        else
                                                {
                                                fprintf(stderr,"ERROR in CLIENT\n");
+                                               ERR_print_errors_fp(stderr);
                                                return(1);
                                                }
                                        }
@@ -522,6 +535,7 @@ int doit(char *ctx[4])
                                        else
                                                {
                                                fprintf(stderr,"ERROR in CLIENT\n");
+                                               ERR_print_errors_fp(stderr);
                                                return(1);
                                                }
                                        }
@@ -677,7 +691,7 @@ int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
 
 #define THREAD_STACK_SIZE (16*1024)
 
-#ifdef WIN32
+#ifdef OPENSSL_SYS_WIN32
 
 static HANDLE *lock_cs;
 
@@ -685,7 +699,7 @@ void thread_setup(void)
        {
        int i;
 
-       lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE));
+       lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(HANDLE));
        for (i=0; i<CRYPTO_num_locks(); i++)
                {
                lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
@@ -702,7 +716,7 @@ void thread_cleanup(void)
        CRYPTO_set_locking_callback(NULL);
        for (i=0; i<CRYPTO_num_locks(); i++)
                CloseHandle(lock_cs[i]);
-       Free(lock_cs);
+       OPENSSL_free(lock_cs);
        }
 
 void win32_locking_callback(int mode, int type, char *file, int line)
@@ -768,7 +782,7 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
        printf("win32 threads done - %.3f seconds\n",ret);
        }
 
-#endif /* WIN32 */
+#endif /* OPENSSL_SYS_WIN32 */
 
 #ifdef SOLARIS
 
@@ -780,8 +794,8 @@ void thread_setup(void)
        {
        int i;
 
-       lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t));
-       lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
+       lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(mutex_t));
+       lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
        for (i=0; i<CRYPTO_num_locks(); i++)
                {
                lock_count[i]=0;
@@ -807,8 +821,8 @@ void thread_cleanup(void)
                mutex_destroy(&(lock_cs[i]));
                fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i));
                }
-       Free(lock_cs);
-       Free(lock_count);
+       OPENSSL_free(lock_cs);
+       OPENSSL_free(lock_count);
 
        fprintf(stderr,"done cleanup\n");
 
@@ -905,7 +919,7 @@ void thread_setup(void)
        arena=usinit(filename);
        unlink(filename);
 
-       lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *));
+       lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(usema_t *));
        for (i=0; i<CRYPTO_num_locks(); i++)
                {
                lock_cs[i]=usnewsema(arena,1);
@@ -928,7 +942,7 @@ void thread_cleanup(void)
                usdumpsema(lock_cs[i],stdout,buf);
                usfreesema(lock_cs[i],arena);
                }
-       Free(lock_cs);
+       OPENSSL_free(lock_cs);
        }
 
 void irix_locking_callback(int mode, int type, char *file, int line)
@@ -988,8 +1002,8 @@ void thread_setup(void)
        {
        int i;
 
-       lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
-       lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
+       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;
@@ -1012,8 +1026,8 @@ void thread_cleanup(void)
                fprintf(stderr,"%8ld:%s\n",lock_count[i],
                        CRYPTO_get_lock_name(i));
                }
-       Free(lock_cs);
-       Free(lock_count);
+       OPENSSL_free(lock_cs);
+       OPENSSL_free(lock_count);
 
        fprintf(stderr,"done cleanup\n");
        }