Give everything prototypes (well, everything that's actually used).
[openssl.git] / ssl / s2_lib.c
index 0cbbb06..6f7d11f 100644 (file)
 #include "ssl_locl.h"
 #ifndef OPENSSL_NO_SSL2
 #include <stdio.h>
-#include <openssl/rsa.h>
 #include <openssl/objects.h>
 #include <openssl/evp.h>
 #include <openssl/md5.h>
-#include "cryptlib.h"
 
 static long ssl2_default_timeout(void );
 const char *ssl2_version_str="SSLv2" OPENSSL_VERSION_PTEXT;
@@ -139,6 +137,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl2_ciphers[]={
        SSL_ALL_STRENGTHS,
        },
 /* IDEA_128_CBC_WITH_MD5 */
+#ifndef OPENSSL_NO_IDEA
        {
        1,
        SSL2_TXT_IDEA_128_CBC_WITH_MD5,
@@ -151,6 +150,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl2_ciphers[]={
        SSL_ALL_CIPHERS,
        SSL_ALL_STRENGTHS,
        },
+#endif
 /* DES_64_CBC_WITH_MD5 */
        {
        1,
@@ -234,7 +234,7 @@ static SSL_METHOD SSLv2_data= {
        ssl_bad_method,
        ssl2_default_timeout,
        &ssl3_undef_enc_method,
-       ssl_undefined_function,
+       ssl_undefined_void_function,
        ssl2_callback_ctrl,     /* local */
        ssl2_ctx_callback_ctrl, /* local */
        };
@@ -262,7 +262,7 @@ SSL_CIPHER *ssl2_get_cipher(unsigned int u)
                return(NULL);
        }
 
-int ssl2_pending(SSL *s)
+int ssl2_pending(const SSL *s)
        {
        return SSL_in_init(s) ? 0 : s->s2->ract_data_length;
        }
@@ -308,7 +308,7 @@ void ssl2_free(SSL *s)
        s2=s->s2;
        if (s2->rbuf != NULL) OPENSSL_free(s2->rbuf);
        if (s2->wbuf != NULL) OPENSSL_free(s2->wbuf);
-       memset(s2,0,sizeof *s2);
+       OPENSSL_cleanse(s2,sizeof *s2);
        OPENSSL_free(s2);
        s->s2=NULL;
        }
@@ -348,7 +348,7 @@ long ssl2_ctrl(SSL *s, int cmd, long larg, void *parg)
        return(ret);
        }
 
-long ssl2_callback_ctrl(SSL *s, int cmd, void (*fp)())
+long ssl2_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
        {
        return(0);
        }
@@ -358,7 +358,7 @@ long ssl2_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
        return(0);
        }
 
-long ssl2_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
+long ssl2_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
        {
        return(0);
        }
@@ -371,7 +371,7 @@ SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p)
        static SSL_CIPHER *sorted[SSL2_NUM_CIPHERS];
        SSL_CIPHER c,*cp= &c,**cpp;
        unsigned long id;
-       int i;
+       unsigned int i;
 
        if (init)
                {
@@ -437,7 +437,8 @@ int ssl2_generate_key_material(SSL *s)
        EVP_MD_CTX_init(&ctx);
        km=s->s2->key_material;
 
-       if (s->session->master_key_length < 0 || s->session->master_key_length > sizeof s->session->master_key)
+       if (s->session->master_key_length < 0 ||
+                       s->session->master_key_length > (int)sizeof(s->session->master_key))
                {
                SSLerr(SSL_F_SSL2_GENERATE_KEY_MATERIAL, ERR_R_INTERNAL_ERROR);
                return 0;
@@ -445,7 +446,8 @@ int ssl2_generate_key_material(SSL *s)
 
        for (i=0; i<s->s2->key_material_length; i += EVP_MD_size(md5))
                {
-               if (((km - s->s2->key_material) + EVP_MD_size(md5)) > sizeof s->s2->key_material)
+               if (((km - s->s2->key_material) + EVP_MD_size(md5)) >
+                               (int)sizeof(s->s2->key_material))
                        {
                        /* EVP_DigestFinal_ex() below would write beyond buffer */
                        SSLerr(SSL_F_SSL2_GENERATE_KEY_MATERIAL, ERR_R_INTERNAL_ERROR);
@@ -454,6 +456,9 @@ int ssl2_generate_key_material(SSL *s)
 
                EVP_DigestInit_ex(&ctx, md5, NULL);
 
+               OPENSSL_assert(s->session->master_key_length >= 0
+                   && s->session->master_key_length
+                   < (int)sizeof(s->session->master_key));
                EVP_DigestUpdate(&ctx,s->session->master_key,s->session->master_key_length);
                EVP_DigestUpdate(&ctx,&c,1);
                c++;
@@ -492,9 +497,7 @@ void ssl2_write_error(SSL *s)
 
        error=s->error; /* number of bytes left to write */
        s->error=0;
-       if (error < 0 || error > sizeof buf) /* can't happen */
-               return;
-  
+       OPENSSL_assert(error >= 0 && error <= (int)sizeof(buf));
        i=ssl2_write(s,&(buf[3-error]),error);
 
 /*     if (i == error) s->rwstate=state; */