Initialize SSL_METHOD structures at compile time. This removes the need
authorDr. Stephen Henson <steve@openssl.org>
Fri, 5 Aug 2005 23:56:11 +0000 (23:56 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 5 Aug 2005 23:56:11 +0000 (23:56 +0000)
for locking code. The CRYPTO_LOCK_SSL_METHOD lock is now no longer used.

22 files changed:
CHANGES
ssl/d1_clnt.c
ssl/d1_lib.c
ssl/d1_meth.c
ssl/d1_srvr.c
ssl/s23_clnt.c
ssl/s23_lib.c
ssl/s23_meth.c
ssl/s23_srvr.c
ssl/s2_clnt.c
ssl/s2_lib.c
ssl/s2_meth.c
ssl/s2_srvr.c
ssl/s3_clnt.c
ssl/s3_lib.c
ssl/s3_meth.c
ssl/s3_srvr.c
ssl/ssl_locl.h
ssl/t1_clnt.c
ssl/t1_lib.c
ssl/t1_meth.c
ssl/t1_srvr.c

diff --git a/CHANGES b/CHANGES
index 614348b8c4d532d7cb1f281d98570519ad194fd4..d025d780a3783731dfb0afd87365c648a895435f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 
  Changes between 0.9.8 and 0.9.8a  [XX xxx XXXX]
 
+  *) Initialize SSL_METHOD structures at compile time instead of during
+     runtime, thus removing the need for a lock.
+     [Steve Henson]
+
   *) Make PKCS7_decrypt() work even if no certificate is supplied by
      attempting to decrypt each encrypted key in turn. Add support to
      smime utility.
index deeb50da3d23d058f6253b91d2e37a5e5f155595..15ccf435fc65865796b8507456214cfaf3747182 100644 (file)
@@ -136,28 +136,10 @@ static SSL_METHOD *dtls1_get_client_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *DTLSv1_client_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD DTLSv1_client_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&DTLSv1_client_data,(char *)dtlsv1_base_method(),
-                               sizeof(SSL_METHOD));
-                       DTLSv1_client_data.ssl_connect=dtls1_connect;
-                       DTLSv1_client_data.get_ssl_method=dtls1_get_client_method;
-                       init=0;
-                       }
-               
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&DTLSv1_client_data);
-       }
+IMPLEMENT_dtls1_meth_func(DTLSv1_client_method,
+                       ssl_undefined_function,
+                       dtls1_connect,
+                       dtls1_get_client_method)
 
 int dtls1_connect(SSL *s)
        {
index ea0dbf4831c32fa97ee21a107b7932ecd9586b60..070bb1ec184bc31a678e52a240fbc184de332d6b 100644 (file)
@@ -63,9 +63,7 @@
 
 const char *dtls1_version_str="DTLSv1" OPENSSL_VERSION_PTEXT;
 
-static long dtls1_default_timeout(void);
-
-static SSL3_ENC_METHOD DTLSv1_enc_data={
+SSL3_ENC_METHOD DTLSv1_enc_data={
     dtls1_enc,
        tls1_mac,
        tls1_setup_key_block,
@@ -79,49 +77,17 @@ static SSL3_ENC_METHOD DTLSv1_enc_data={
        tls1_alert_code,
        };
 
-static SSL_METHOD DTLSv1_data= {
-       DTLS1_VERSION,
-       dtls1_new,
-       dtls1_clear,
-       dtls1_free,
-       ssl_undefined_function,
-       ssl_undefined_function,
-       ssl3_read,
-       ssl3_peek,
-       ssl3_write,
-       ssl3_shutdown,
-       ssl3_renegotiate,
-       ssl3_renegotiate_check,
-       dtls1_get_message,
-       dtls1_read_bytes,
-       dtls1_write_app_data_bytes,
-       dtls1_dispatch_alert,
-       ssl3_ctrl,
-       ssl3_ctx_ctrl,
-       ssl3_get_cipher_by_char,
-       ssl3_put_cipher_by_char,
-       ssl3_pending,
-       ssl3_num_ciphers,
-       ssl3_get_cipher,
-       ssl_bad_method,
-       dtls1_default_timeout,
-       &DTLSv1_enc_data,
-       ssl_undefined_void_function,
-       ssl3_callback_ctrl,
-       ssl3_ctx_callback_ctrl,
-       };
-
-static long dtls1_default_timeout(void)
+long dtls1_default_timeout(void)
        {
        /* 2 hours, the 24 hours mentioned in the DTLSv1 spec
         * is way too long for http, the cache would over fill */
        return(60*60*2);
        }
 
-SSL_METHOD *dtlsv1_base_method(void)
-       {
-       return(&DTLSv1_data);
-       }
+IMPLEMENT_dtls1_meth_func(dtls1_base_method,
+                       ssl_undefined_function,
+                       ssl_undefined_function,
+                       ssl_bad_method)
 
 int dtls1_new(SSL *s)
        {
index dc4c8ede8667b17d243ceae9d7600f164b53415b..8a6cf31947aba86e65e2f58e0db93cb91804a188 100644 (file)
@@ -70,27 +70,8 @@ static SSL_METHOD *dtls1_get_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *DTLSv1_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD DTLSv1_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-               
-               if (init)
-                       {
-                       memcpy((char *)&DTLSv1_data,(char *)dtlsv1_base_method(),
-                               sizeof(SSL_METHOD));
-                       DTLSv1_data.ssl_connect=dtls1_connect;
-                       DTLSv1_data.ssl_accept=dtls1_accept;
-                       DTLSv1_data.get_ssl_method=dtls1_get_method;
-                       init=0;
-                       }
+IMPLEMENT_dtls1_meth_func(DTLSv1_method,
+                       dtls1_accept,
+                       dtls1_connect,
+                       dtls1_get_method)
 
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       
-       return(&DTLSv1_data);
-       }
index 8865dd2a4e0e580b9e03f9273b1263f4801a8202..6057c1088de9c91f26bcbe3d211f0ff065c03c30 100644 (file)
@@ -137,28 +137,10 @@ static SSL_METHOD *dtls1_get_server_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *DTLSv1_server_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD DTLSv1_server_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&DTLSv1_server_data,(char *)dtlsv1_base_method(),
-                               sizeof(SSL_METHOD));
-                       DTLSv1_server_data.ssl_accept=dtls1_accept;
-                       DTLSv1_server_data.get_ssl_method=dtls1_get_server_method;
-                       init=0;
-                       }
-                       
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&DTLSv1_server_data);
-       }
+IMPLEMENT_dtls1_meth_func(DTLSv1_server_method,
+                       dtls1_accept,
+                       ssl_undefined_function,
+                       dtls1_get_server_method)
 
 int dtls1_accept(SSL *s)
        {
index b21308b6f24268252f5cd4fb46a0eab31ce3ffa7..8bac26c5ac10dc33f9bc6d8ca0a9f2345d895dfb 100644 (file)
@@ -80,28 +80,10 @@ static SSL_METHOD *ssl23_get_client_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv23_client_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv23_client_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&SSLv23_client_data,
-                               (char *)sslv23_base_method(),sizeof(SSL_METHOD));
-                       SSLv23_client_data.ssl_connect=ssl23_connect;
-                       SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
-                       init=0;
-                       }
-
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv23_client_data);
-       }
+IMPLEMENT_ssl23_meth_func(SSLv23_client_method,
+                       ssl_undefined_function,
+                       ssl23_connect,
+                       ssl23_get_client_method)
 
 int ssl23_connect(SSL *s)
        {
index 2c5129831a3516b906e4ae748f5f52de62584ba9..fc2981308d55e3d4b16e5f6fb59482ea5226cd4b 100644 (file)
 #include <openssl/objects.h>
 #include "ssl_locl.h"
 
-static int ssl23_num_ciphers(void );
-static SSL_CIPHER *ssl23_get_cipher(unsigned int u);
-static int ssl23_read(SSL *s, void *buf, int len);
-static int ssl23_peek(SSL *s, void *buf, int len);
-static int ssl23_write(SSL *s, const void *buf, int len);
-static long ssl23_default_timeout(void );
-static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
-static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
-const char *SSL23_version_str="SSLv2/3 compatibility" OPENSSL_VERSION_PTEXT;
-
-static SSL_METHOD SSLv23_data= {
-       TLS1_VERSION,
-       tls1_new,
-       tls1_clear,
-       tls1_free,
-       ssl_undefined_function,
-       ssl_undefined_function,
-       ssl23_read,
-       ssl23_peek,
-       ssl23_write,
-       ssl_undefined_function,
-       ssl_undefined_function,
-       ssl_ok,
-       ssl3_get_message,
-       ssl3_read_bytes,
-       ssl3_write_bytes,
-       ssl3_dispatch_alert,
-       ssl3_ctrl,
-       ssl3_ctx_ctrl,
-       ssl23_get_cipher_by_char,
-       ssl23_put_cipher_by_char,
-       ssl_undefined_const_function,
-       ssl23_num_ciphers,
-       ssl23_get_cipher,
-       ssl_bad_method,
-       ssl23_default_timeout,
-       &ssl3_undef_enc_method,
-       ssl_undefined_void_function,
-       ssl3_callback_ctrl,
-       ssl3_ctx_callback_ctrl,
-       };
-
-static long ssl23_default_timeout(void)
+long ssl23_default_timeout(void)
        {
        return(300);
        }
 
-SSL_METHOD *sslv23_base_method(void)
-       {
-       return(&SSLv23_data);
-       }
+IMPLEMENT_ssl23_meth_func(sslv23_base_method,
+                       ssl_undefined_function,
+                       ssl_undefined_function,
+                       ssl_bad_method)
 
-static int ssl23_num_ciphers(void)
+int ssl23_num_ciphers(void)
        {
        return(ssl3_num_ciphers()
 #ifndef OPENSSL_NO_SSL2
@@ -121,7 +79,7 @@ static int ssl23_num_ciphers(void)
            );
        }
 
-static SSL_CIPHER *ssl23_get_cipher(unsigned int u)
+SSL_CIPHER *ssl23_get_cipher(unsigned int u)
        {
        unsigned int uu=ssl3_num_ciphers();
 
@@ -137,7 +95,7 @@ static SSL_CIPHER *ssl23_get_cipher(unsigned int u)
 
 /* This function needs to check if the ciphers required are actually
  * available */
-static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
+SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
        {
        SSL_CIPHER c,*cp;
        unsigned long id;
@@ -155,7 +113,7 @@ static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
        return(cp);
        }
 
-static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
+int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
        {
        long l;
 
@@ -170,7 +128,7 @@ static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
        return(3);
        }
 
-static int ssl23_read(SSL *s, void *buf, int len)
+int ssl23_read(SSL *s, void *buf, int len)
        {
        int n;
 
@@ -193,7 +151,7 @@ static int ssl23_read(SSL *s, void *buf, int len)
                }
        }
 
-static int ssl23_peek(SSL *s, void *buf, int len)
+int ssl23_peek(SSL *s, void *buf, int len)
        {
        int n;
 
@@ -216,7 +174,7 @@ static int ssl23_peek(SSL *s, void *buf, int len)
                }
        }
 
-static int ssl23_write(SSL *s, const void *buf, int len)
+int ssl23_write(SSL *s, const void *buf, int len)
        {
        int n;
 
index f207140835f8680741db3e4ad3de83f69b1b0712..c88569d32ceb9fa16912c8f28ac18c6a314afd25 100644 (file)
@@ -73,27 +73,8 @@ static SSL_METHOD *ssl23_get_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv23_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv23_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-               
-               if (init)
-                       {
-                       memcpy((char *)&SSLv23_data,(char *)sslv23_base_method(),
-                               sizeof(SSL_METHOD));
-                       SSLv23_data.ssl_connect=ssl23_connect;
-                       SSLv23_data.ssl_accept=ssl23_accept;
-                       SSLv23_data.get_ssl_method=ssl23_get_method;
-                       init=0;
-                       }
-               
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv23_data);
-       }
+IMPLEMENT_ssl23_meth_func(SSLv23_method,
+                       ssl23_accept,
+                       ssl23_connect,
+                       ssl23_get_method)
 
index c5404ca0bcd4c015f0273f38e22ef07bffb92585..945a2c987255958880dee30849f374c17c071227 100644 (file)
@@ -132,28 +132,10 @@ static SSL_METHOD *ssl23_get_server_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv23_server_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv23_server_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&SSLv23_server_data,
-                               (char *)sslv23_base_method(),sizeof(SSL_METHOD));
-                       SSLv23_server_data.ssl_accept=ssl23_accept;
-                       SSLv23_server_data.get_ssl_method=ssl23_get_server_method;
-                       init=0;
-                       }
-
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv23_server_data);
-       }
+IMPLEMENT_ssl23_meth_func(SSLv23_server_method,
+                       ssl23_accept,
+                       ssl_undefined_function,
+                       ssl23_get_server_method)
 
 int ssl23_accept(SSL *s)
        {
index 33ea7592c489b72847a91241550c69fdb11f70e3..0c9e24d5c47f3f17ac4c7cf0779e393d935e5d0c 100644 (file)
@@ -137,28 +137,10 @@ static SSL_METHOD *ssl2_get_client_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv2_client_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv2_client_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&SSLv2_client_data,(char *)sslv2_base_method(),
-                               sizeof(SSL_METHOD));
-                       SSLv2_client_data.ssl_connect=ssl2_connect;
-                       SSLv2_client_data.get_ssl_method=ssl2_get_client_method;
-                       init=0;
-                       }
-
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv2_client_data);
-       }
+IMPLEMENT_ssl2_meth_func(SSLv2_client_method,
+                       ssl_undefined_function,
+                       ssl2_connect,
+                       ssl2_get_client_method)
 
 int ssl2_connect(SSL *s)
        {
index a454d73dc54ea3cd69b231456ea172ead2665205..cec19673f59f24a170b8fba7c141c52c36acbda9 100644 (file)
@@ -63,7 +63,6 @@
 #include <openssl/evp.h>
 #include <openssl/md5.h>
 
-static long ssl2_default_timeout(void );
 const char *ssl2_version_str="SSLv2" OPENSSL_VERSION_PTEXT;
 
 #define SSL2_NUM_CIPHERS (sizeof(ssl2_ciphers)/sizeof(SSL_CIPHER))
@@ -211,47 +210,15 @@ OPENSSL_GLOBAL SSL_CIPHER ssl2_ciphers[]={
 /* end of list :-) */
        };
 
-static SSL_METHOD SSLv2_data= {
-       SSL2_VERSION,
-       ssl2_new,       /* local */
-       ssl2_clear,     /* local */
-       ssl2_free,      /* local */
-       ssl_undefined_function,
-       ssl_undefined_function,
-       ssl2_read,
-       ssl2_peek,
-       ssl2_write,
-       ssl2_shutdown,
-       ssl_ok, /* NULL - renegotiate */
-       ssl_ok, /* NULL - check renegotiate */
-       NULL, /* NULL - ssl_get_message */
-       NULL, /* NULL - ssl_get_record */
-       NULL, /* NULL - ssl_write_bytes */
-       NULL, /* NULL - dispatch_alert */
-       ssl2_ctrl,      /* local */
-       ssl2_ctx_ctrl,  /* local */
-       ssl2_get_cipher_by_char,
-       ssl2_put_cipher_by_char,
-       ssl2_pending,
-       ssl2_num_ciphers,
-       ssl2_get_cipher,
-       ssl_bad_method,
-       ssl2_default_timeout,
-       &ssl3_undef_enc_method,
-       ssl_undefined_void_function,
-       ssl2_callback_ctrl,     /* local */
-       ssl2_ctx_callback_ctrl, /* local */
-       };
-
-static long ssl2_default_timeout(void)
+long ssl2_default_timeout(void)
        {
        return(300);
        }
 
-SSL_METHOD *sslv2_base_method(void)
-       {
-       return(&SSLv2_data);
-       }
+IMPLEMENT_ssl2_meth_func(sslv2_base_method,
+                       ssl_undefined_function,
+                       ssl_undefined_function,
+                       ssl_bad_method)
 
 int ssl2_num_ciphers(void)
        {
index 8b6cbd086e2ab7ba84886ee52a49fe0758022870..a35e435b71379c3d61b89deccf12232df862e1e4 100644 (file)
@@ -70,29 +70,11 @@ static SSL_METHOD *ssl2_get_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv2_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv2_data;
+IMPLEMENT_ssl2_meth_func(SSLv2_method,
+                       ssl2_accept,
+                       ssl2_connect,
+                       ssl2_get_method)
 
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-               
-               if (init)
-                       {
-                       memcpy((char *)&SSLv2_data,(char *)sslv2_base_method(),
-                               sizeof(SSL_METHOD));
-                       SSLv2_data.ssl_connect=ssl2_connect;
-                       SSLv2_data.ssl_accept=ssl2_accept;
-                       SSLv2_data.get_ssl_method=ssl2_get_method;
-                       init=0;
-                       }
-               
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv2_data);
-       }
 #else /* !OPENSSL_NO_SSL2 */
 
 # if PEDANTIC
index 546feb5174d56e238b68de9b206b75b254bdfe41..247cc89155d4b92e893b33d0403a8b607d35268e 100644 (file)
@@ -137,28 +137,10 @@ static SSL_METHOD *ssl2_get_server_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv2_server_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv2_server_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&SSLv2_server_data,(char *)sslv2_base_method(),
-                               sizeof(SSL_METHOD));
-                       SSLv2_server_data.ssl_accept=ssl2_accept;
-                       SSLv2_server_data.get_ssl_method=ssl2_get_server_method;
-                       init=0;
-                       }
-
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv2_server_data);
-       }
+IMPLEMENT_ssl2_meth_func(SSLv2_server_method,
+                       ssl2_accept,
+                       ssl_undefined_function,
+                       ssl2_get_server_method)
 
 int ssl2_accept(SSL *s)
        {
index 4f67cda042b2b7dff034e5d673a73bc881b91d38..51d4c487247bf04c79ac66549bdb70f7a482d4a4 100644 (file)
@@ -151,28 +151,10 @@ static SSL_METHOD *ssl3_get_client_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv3_client_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv3_client_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(),
-                               sizeof(SSL_METHOD));
-                       SSLv3_client_data.ssl_connect=ssl3_connect;
-                       SSLv3_client_data.get_ssl_method=ssl3_get_client_method;
-                       init=0;
-                       }
-
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv3_client_data);
-       }
+IMPLEMENT_ssl3_meth_func(SSLv3_client_method,
+                       ssl_undefined_function,
+                       ssl3_connect,
+                       ssl3_get_client_method)
 
 int ssl3_connect(SSL *s)
        {
index d9d6ddbbe3bfde6454bd448fa1ec78c345a2210d..e42967b7e3fc69a92e46acfde5d27b488d838b32 100644 (file)
@@ -135,8 +135,6 @@ const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
 
 #define SSL3_NUM_CIPHERS       (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
 
-static long ssl3_default_timeout(void );
-
 OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
 /* The RSA ciphers */
 /* Cipher 01 */
@@ -1356,7 +1354,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
 /* end of list */
        };
 
-static SSL3_ENC_METHOD SSLv3_enc_data={
+SSL3_ENC_METHOD SSLv3_enc_data={
        ssl3_enc,
        ssl3_mac,
        ssl3_setup_key_block,
@@ -1370,49 +1368,17 @@ static SSL3_ENC_METHOD SSLv3_enc_data={
        ssl3_alert_code,
        };
 
-static SSL_METHOD SSLv3_data= {
-       SSL3_VERSION,
-       ssl3_new,
-       ssl3_clear,
-       ssl3_free,
-       ssl_undefined_function,
-       ssl_undefined_function,
-       ssl3_read,
-       ssl3_peek,
-       ssl3_write,
-       ssl3_shutdown,
-       ssl3_renegotiate,
-       ssl3_renegotiate_check,
-       ssl3_get_message,
-       ssl3_read_bytes,
-       ssl3_write_bytes,
-       ssl3_dispatch_alert,
-       ssl3_ctrl,
-       ssl3_ctx_ctrl,
-       ssl3_get_cipher_by_char,
-       ssl3_put_cipher_by_char,
-       ssl3_pending,
-       ssl3_num_ciphers,
-       ssl3_get_cipher,
-       ssl_bad_method,
-       ssl3_default_timeout,
-       &SSLv3_enc_data,
-       ssl_undefined_void_function,
-       ssl3_callback_ctrl,
-       ssl3_ctx_callback_ctrl,
-       };
-
-static long ssl3_default_timeout(void)
+long ssl3_default_timeout(void)
        {
        /* 2 hours, the 24 hours mentioned in the SSLv3 spec
         * is way too long for http, the cache would over fill */
        return(60*60*2);
        }
 
-SSL_METHOD *sslv3_base_method(void)
-       {
-       return(&SSLv3_data);
-       }
+IMPLEMENT_ssl3_meth_func(sslv3_base_method,
+                       ssl_undefined_function,
+                       ssl_undefined_function,
+                       ssl_bad_method)
 
 int ssl3_num_ciphers(void)
        {
index 1fd7a96f87ba23ce91c57d14f428c4fb839f7122..6a6eb1c58f80cbb8e1b9fda9ff8ad35c201047ba 100644 (file)
@@ -69,27 +69,9 @@ static SSL_METHOD *ssl3_get_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv3_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv3_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-               
-               if (init)
-                       {
-                       memcpy((char *)&SSLv3_data,(char *)sslv3_base_method(),
-                               sizeof(SSL_METHOD));
-                       SSLv3_data.ssl_connect=ssl3_connect;
-                       SSLv3_data.ssl_accept=ssl3_accept;
-                       SSLv3_data.get_ssl_method=ssl3_get_method;
-                       init=0;
-                       }
+IMPLEMENT_ssl3_meth_func(SSLv3_method,
+                       ssl3_accept,
+                       ssl3_connect,
+                       ssl3_get_method)
 
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv3_data);
-       }
 
index cd10334b90cd3ba3666706696ec2556233fc9111..7cc7634bb362cbf9ef9ace70c0a16efad0f5de31 100644 (file)
@@ -156,28 +156,10 @@ static SSL_METHOD *ssl3_get_server_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *SSLv3_server_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD SSLv3_server_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
-                               sizeof(SSL_METHOD));
-                       SSLv3_server_data.ssl_accept=ssl3_accept;
-                       SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
-                       init=0;
-                       }
-                       
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&SSLv3_server_data);
-       }
+IMPLEMENT_ssl3_meth_func(SSLv3_server_method,
+                       ssl3_accept,
+                       ssl_undefined_function,
+                       ssl3_get_server_method)
 
 int ssl3_accept(SSL *s)
        {
index f61b1cd7e5768900ad146b4e95a705fbbd477d8e..69970a7692efb049cfab11aed06c5abe9c43b4de 100644 (file)
@@ -515,6 +515,195 @@ SSL_METHOD *sslv2_base_method(void);
 SSL_METHOD *sslv23_base_method(void);
 SSL_METHOD *sslv3_base_method(void);
 
+extern SSL3_ENC_METHOD TLSv1_enc_data;
+extern SSL3_ENC_METHOD SSLv3_enc_data;
+extern SSL3_ENC_METHOD DTLSv1_enc_data;
+
+#define IMPLEMENT_tls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               TLS1_VERSION, \
+               tls1_new, \
+               tls1_clear, \
+               tls1_free, \
+               s_accept, \
+               s_connect, \
+               ssl3_read, \
+               ssl3_peek, \
+               ssl3_write, \
+               ssl3_shutdown, \
+               ssl3_renegotiate, \
+               ssl3_renegotiate_check, \
+               ssl3_get_message, \
+               ssl3_read_bytes, \
+               ssl3_write_bytes, \
+               ssl3_dispatch_alert, \
+               ssl3_ctrl, \
+               ssl3_ctx_ctrl, \
+               ssl3_get_cipher_by_char, \
+               ssl3_put_cipher_by_char, \
+               ssl3_pending, \
+               ssl3_num_ciphers, \
+               ssl3_get_cipher, \
+               s_get_meth, \
+               tls1_default_timeout, \
+               &TLSv1_enc_data, \
+               ssl_undefined_void_function, \
+               ssl3_callback_ctrl, \
+               ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_ssl3_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               SSL3_VERSION, \
+               ssl3_new, \
+               ssl3_clear, \
+               ssl3_free, \
+               s_accept, \
+               s_connect, \
+               ssl3_read, \
+               ssl3_peek, \
+               ssl3_write, \
+               ssl3_shutdown, \
+               ssl3_renegotiate, \
+               ssl3_renegotiate_check, \
+               ssl3_get_message, \
+               ssl3_read_bytes, \
+               ssl3_write_bytes, \
+               ssl3_dispatch_alert, \
+               ssl3_ctrl, \
+               ssl3_ctx_ctrl, \
+               ssl3_get_cipher_by_char, \
+               ssl3_put_cipher_by_char, \
+               ssl3_pending, \
+               ssl3_num_ciphers, \
+               ssl3_get_cipher, \
+               s_get_meth, \
+               ssl3_default_timeout, \
+               &SSLv3_enc_data, \
+               ssl_undefined_void_function, \
+               ssl3_callback_ctrl, \
+               ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_ssl23_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+       TLS1_VERSION, \
+       tls1_new, \
+       tls1_clear, \
+       tls1_free, \
+       s_accept, \
+       s_connect, \
+       ssl23_read, \
+       ssl23_peek, \
+       ssl23_write, \
+       ssl_undefined_function, \
+       ssl_undefined_function, \
+       ssl_ok, \
+       ssl3_get_message, \
+       ssl3_read_bytes, \
+       ssl3_write_bytes, \
+       ssl3_dispatch_alert, \
+       ssl3_ctrl, \
+       ssl3_ctx_ctrl, \
+       ssl23_get_cipher_by_char, \
+       ssl23_put_cipher_by_char, \
+       ssl_undefined_const_function, \
+       ssl23_num_ciphers, \
+       ssl23_get_cipher, \
+       s_get_meth, \
+       ssl23_default_timeout, \
+       &ssl3_undef_enc_method, \
+       ssl_undefined_void_function, \
+       ssl3_callback_ctrl, \
+       ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_ssl2_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               SSL2_VERSION, \
+               ssl2_new,       /* local */ \
+               ssl2_clear,     /* local */ \
+               ssl2_free,      /* local */ \
+               s_accept, \
+               s_connect, \
+               ssl2_read, \
+               ssl2_peek, \
+               ssl2_write, \
+               ssl2_shutdown, \
+               ssl_ok, /* NULL - renegotiate */ \
+               ssl_ok, /* NULL - check renegotiate */ \
+               NULL, /* NULL - ssl_get_message */ \
+               NULL, /* NULL - ssl_get_record */ \
+               NULL, /* NULL - ssl_write_bytes */ \
+               NULL, /* NULL - dispatch_alert */ \
+               ssl2_ctrl,      /* local */ \
+               ssl2_ctx_ctrl,  /* local */ \
+               ssl2_get_cipher_by_char, \
+               ssl2_put_cipher_by_char, \
+               ssl2_pending, \
+               ssl2_num_ciphers, \
+               ssl2_get_cipher, \
+               s_get_meth, \
+               ssl2_default_timeout, \
+               &ssl3_undef_enc_method, \
+               ssl_undefined_void_function, \
+               ssl2_callback_ctrl,     /* local */ \
+               ssl2_ctx_callback_ctrl, /* local */ \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_dtls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               DTLS1_VERSION, \
+               dtls1_new, \
+               dtls1_clear, \
+               dtls1_free, \
+               s_accept, \
+               s_connect, \
+               ssl3_read, \
+               ssl3_peek, \
+               ssl3_write, \
+               ssl3_shutdown, \
+               ssl3_renegotiate, \
+               ssl3_renegotiate_check, \
+               dtls1_get_message, \
+               dtls1_read_bytes, \
+               dtls1_write_app_data_bytes, \
+               dtls1_dispatch_alert, \
+               ssl3_ctrl, \
+               ssl3_ctx_ctrl, \
+               ssl3_get_cipher_by_char, \
+               ssl3_put_cipher_by_char, \
+               ssl3_pending, \
+               ssl3_num_ciphers, \
+               ssl3_get_cipher, \
+               s_get_meth, \
+               dtls1_default_timeout, \
+               &DTLSv1_enc_data, \
+               ssl_undefined_void_function, \
+               ssl3_callback_ctrl, \
+               ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
 void ssl_clear_cipher_ctx(SSL *s);
 int ssl_clear_bad_session(SSL *s);
 CERT *ssl_cert_new(void);
@@ -578,6 +767,7 @@ long        ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg);
 long   ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)(void));
 long   ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)(void));
 int    ssl2_pending(const SSL *s);
+long   ssl2_default_timeout(void );
 
 SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
 int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
@@ -629,7 +819,18 @@ int        ssl3_pending(const SSL *s);
 
 void ssl3_record_sequence_update(unsigned char *seq);
 int ssl3_do_change_cipher_spec(SSL *ssl);
-
+long ssl3_default_timeout(void );
+
+int ssl23_num_ciphers(void );
+SSL_CIPHER *ssl23_get_cipher(unsigned int u);
+int ssl23_read(SSL *s, void *buf, int len);
+int ssl23_peek(SSL *s, void *buf, int len);
+int ssl23_write(SSL *s, const void *buf, int len);
+int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
+SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
+long ssl23_default_timeout(void );
+
+long tls1_default_timeout(void);
 int dtls1_do_write(SSL *s,int type);
 int ssl3_read_n(SSL *s, int n, int max, int extend);
 int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
@@ -640,6 +841,7 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
 unsigned char *dtls1_set_message_header(SSL *s, 
        unsigned char *p, unsigned char mt,     unsigned long len, 
        unsigned long frag_off, unsigned long frag_len);
+
 int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len);
 int dtls1_write_bytes(SSL *s, int type, const void *buf, int len);
 
@@ -654,6 +856,7 @@ void dtls1_clear_record_buffer(SSL *s);
 void dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr);
 void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr);
 void dtls1_reset_seq_numbers(SSL *s, int rw);
+long dtls1_default_timeout(void);
 
 
 /* some client-only functions */
index 57205fb429ab7bb2361c825e69838fbb5e7a860b..4d1e198cdcde1ec6c04eb47e9a76d9b11d567d93 100644 (file)
@@ -72,26 +72,8 @@ static SSL_METHOD *tls1_get_client_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *TLSv1_client_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD TLSv1_client_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(),
-                               sizeof(SSL_METHOD));
-                       TLSv1_client_data.ssl_connect=ssl3_connect;
-                       TLSv1_client_data.get_ssl_method=tls1_get_client_method;
-                       init=0;
-                       }
-               
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&TLSv1_client_data);
-       }
+IMPLEMENT_tls1_meth_func(TLSv1_client_method,
+                       ssl_undefined_function,
+                       ssl3_connect,
+                       tls1_get_client_method)
 
index 6f95fc1ca8bd8c6f06d8d0ba29db8f8bafef41e8..d4516eba71e077e0ffa09fa3ba53b5170ef93fd8 100644 (file)
@@ -62,9 +62,7 @@
 
 const char *tls1_version_str="TLSv1" OPENSSL_VERSION_PTEXT;
 
-static long tls1_default_timeout(void);
-
-static SSL3_ENC_METHOD TLSv1_enc_data={
+SSL3_ENC_METHOD TLSv1_enc_data={
        tls1_enc,
        tls1_mac,
        tls1_setup_key_block,
@@ -78,49 +76,17 @@ static SSL3_ENC_METHOD TLSv1_enc_data={
        tls1_alert_code,
        };
 
-static SSL_METHOD TLSv1_data= {
-       TLS1_VERSION,
-       tls1_new,
-       tls1_clear,
-       tls1_free,
-       ssl_undefined_function,
-       ssl_undefined_function,
-       ssl3_read,
-       ssl3_peek,
-       ssl3_write,
-       ssl3_shutdown,
-       ssl3_renegotiate,
-       ssl3_renegotiate_check,
-       ssl3_get_message,
-       ssl3_read_bytes,
-       ssl3_write_bytes,
-       ssl3_dispatch_alert,
-       ssl3_ctrl,
-       ssl3_ctx_ctrl,
-       ssl3_get_cipher_by_char,
-       ssl3_put_cipher_by_char,
-       ssl3_pending,
-       ssl3_num_ciphers,
-       ssl3_get_cipher,
-       ssl_bad_method,
-       tls1_default_timeout,
-       &TLSv1_enc_data,
-       ssl_undefined_void_function,
-       ssl3_callback_ctrl,
-       ssl3_ctx_callback_ctrl,
-       };
-
-static long tls1_default_timeout(void)
+long tls1_default_timeout(void)
        {
        /* 2 hours, the 24 hours mentioned in the TLSv1 spec
         * is way too long for http, the cache would over fill */
        return(60*60*2);
        }
 
-SSL_METHOD *tlsv1_base_method(void)
-       {
-       return(&TLSv1_data);
-       }
+IMPLEMENT_tls1_meth_func(tlsv1_base_method,
+                       ssl_undefined_function,
+                       ssl_undefined_function,
+                       ssl_bad_method)
 
 int tls1_new(SSL *s)
        {
index fcc243f782643d5cdb3c015d90390a442562208f..f5d8df634ee1dbfce815a07d3cdee968fb02ee2e 100644 (file)
@@ -69,28 +69,8 @@ static SSL_METHOD *tls1_get_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *TLSv1_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD TLSv1_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-               
-               if (init)
-                       {
-                       memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(),
-                               sizeof(SSL_METHOD));
-                       TLSv1_data.ssl_connect=ssl3_connect;
-                       TLSv1_data.ssl_accept=ssl3_accept;
-                       TLSv1_data.get_ssl_method=tls1_get_method;
-                       init=0;
-                       }
-
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       
-       return(&TLSv1_data);
-       }
+IMPLEMENT_tls1_meth_func(TLSv1_method,
+                       ssl3_accept,
+                       ssl3_connect,
+                       tls1_get_method)
 
index 1c1149e49fe19b6a956200b96474009ca2418c38..b75636abba91718132dfa3b0a176078f5b90d865 100644 (file)
@@ -73,26 +73,8 @@ static SSL_METHOD *tls1_get_server_method(int ver)
                return(NULL);
        }
 
-SSL_METHOD *TLSv1_server_method(void)
-       {
-       static int init=1;
-       static SSL_METHOD TLSv1_server_data;
-
-       if (init)
-               {
-               CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
-
-               if (init)
-                       {
-                       memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(),
-                               sizeof(SSL_METHOD));
-                       TLSv1_server_data.ssl_accept=ssl3_accept;
-                       TLSv1_server_data.get_ssl_method=tls1_get_server_method;
-                       init=0;
-                       }
-                       
-               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
-               }
-       return(&TLSv1_server_data);
-       }
+IMPLEMENT_tls1_meth_func(TLSv1_server_method,
+                       ssl3_accept,
+                       ssl_undefined_function,
+                       tls1_get_server_method)