Further BUILDENV refinement, further fool-proofing of Makefiles and
[openssl.git] / ssl / s2_enc.c
index a9458e7..18882bf 100644 (file)
@@ -57,7 +57,7 @@
  */
 
 #include "ssl_locl.h"
-#ifndef NO_SSL2
+#ifndef OPENSSL_NO_SSL2
 #include <stdio.h>
 
 int ssl2_enc_init(SSL *s, int client)
@@ -80,11 +80,11 @@ int ssl2_enc_init(SSL *s, int client)
 
        if ((s->enc_read_ctx == NULL) &&
                ((s->enc_read_ctx=(EVP_CIPHER_CTX *)
-               Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
+               OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
                goto err;
        if ((s->enc_write_ctx == NULL) &&
                ((s->enc_write_ctx=(EVP_CIPHER_CTX *)
-               Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
+               OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
                goto err;
 
        rs= s->enc_read_ctx;
@@ -95,12 +95,15 @@ int ssl2_enc_init(SSL *s, int client)
 
        num=c->key_len;
        s->s2->key_material_length=num*2;
+       OPENSSL_assert(s->s2->key_material_length <= sizeof s->s2->key_material);
 
-       ssl2_generate_key_material(s);
+       if (ssl2_generate_key_material(s) <= 0)
+               return 0;
 
-       EVP_EncryptInit(ws,c,&(s->s2->key_material[(client)?num:0]),
+       OPENSSL_assert(c->iv_len <= (int)sizeof(s->session->key_arg));
+       EVP_EncryptInit_ex(ws,c,NULL,&(s->s2->key_material[(client)?num:0]),
                s->session->key_arg);
-       EVP_DecryptInit(rs,c,&(s->s2->key_material[(client)?0:num]),
+       EVP_DecryptInit_ex(rs,c,NULL,&(s->s2->key_material[(client)?0:num]),
                s->session->key_arg);
        s->s2->read_key=  &(s->s2->key_material[(client)?0:num]);
        s->s2->write_key= &(s->s2->key_material[(client)?num:0]);
@@ -111,8 +114,8 @@ err:
        }
 
 /* read/writes from s->s2->mac_data using length for encrypt and 
- * decrypt.  It sets the s->s2->padding, s->[rw]length and
- * s->s2->pad_data ptr if we are encrypting */
+ * decrypt.  It sets s->s2->padding and s->[rw]length
+ * if we are encrypting */
 void ssl2_enc(SSL *s, int send)
        {
        EVP_CIPHER_CTX *ds;
@@ -169,16 +172,17 @@ void ssl2_mac(SSL *s, unsigned char *md, int send)
        l2n(seq,p);
 
        /* There has to be a MAC algorithm. */
-       EVP_DigestInit(&c,s->read_hash);
+       EVP_MD_CTX_init(&c);
+       EVP_DigestInit_ex(&c, s->read_hash, NULL);
        EVP_DigestUpdate(&c,sec,
                EVP_CIPHER_CTX_key_length(s->enc_read_ctx));
        EVP_DigestUpdate(&c,act,len); 
        /* the above line also does the pad data */
        EVP_DigestUpdate(&c,sequence,4); 
-       EVP_DigestFinal(&c,md,NULL);
-       /* some would say I should zero the md context */
+       EVP_DigestFinal_ex(&c,md,NULL);
+       EVP_MD_CTX_cleanup(&c);
        }
-#else /* !NO_SSL2 */
+#else /* !OPENSSL_NO_SSL2 */
 
 # if PEDANTIC
 static void *dummy=&dummy;