summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES12
-rw-r--r--crypto/evp/e_cbc_3d.c25
-rw-r--r--crypto/evp/e_cbc_bf.c6
-rw-r--r--crypto/evp/e_cbc_c.c6
-rw-r--r--crypto/evp/e_cbc_d.c6
-rw-r--r--crypto/evp/e_cbc_i.c19
-rw-r--r--crypto/evp/e_cbc_r2.c6
-rw-r--r--crypto/evp/e_cbc_r5.c6
-rw-r--r--crypto/evp/e_cfb_3d.c28
-rw-r--r--crypto/evp/e_cfb_bf.c8
-rw-r--r--crypto/evp/e_cfb_c.c8
-rw-r--r--crypto/evp/e_cfb_d.c8
-rw-r--r--crypto/evp/e_cfb_i.c8
-rw-r--r--crypto/evp/e_cfb_r2.c8
-rw-r--r--crypto/evp/e_cfb_r5.c8
-rw-r--r--crypto/evp/e_ecb_3d.c18
-rw-r--r--crypto/evp/e_ecb_bf.c3
-rw-r--r--crypto/evp/e_ecb_c.c3
-rw-r--r--crypto/evp/e_ecb_d.c3
-rw-r--r--crypto/evp/e_ecb_i.c17
-rw-r--r--crypto/evp/e_ecb_r2.c5
-rw-r--r--crypto/evp/e_ecb_r5.c3
-rw-r--r--crypto/evp/e_ofb_3d.c28
-rw-r--r--crypto/evp/e_ofb_bf.c8
-rw-r--r--crypto/evp/e_ofb_c.c8
-rw-r--r--crypto/evp/e_ofb_d.c9
-rw-r--r--crypto/evp/e_ofb_i.c8
-rw-r--r--crypto/evp/e_ofb_r2.c8
-rw-r--r--crypto/evp/e_ofb_r5.c8
-rw-r--r--crypto/evp/e_rc4.c3
-rw-r--r--crypto/evp/e_xcbc_d.c13
-rw-r--r--crypto/evp/evp.h16
-rw-r--r--crypto/evp/evp_enc.c62
-rw-r--r--crypto/evp/evp_err.c2
34 files changed, 134 insertions, 253 deletions
diff --git a/CHANGES b/CHANGES
index e57e0f4fc6..c002077345 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,17 @@
Changes between 0.9.5a and 0.9.6 [xx XXX 2000]
+ *) Remove lots of duplicated code from the EVP library. For example *every*
+ cipher init() function handles the 'iv' in the same way according to the
+ cipher mode. They also all do nothing if the 'key' parameter is NULL and
+ for CFB and OFB modes they zero ctx->num.
+
+ By shifting this to the top level EVP_CipherInit() it can be removed from
+ all individual ciphers. If the cipher wants to handle IVs or keys
+ differently it can set the EVP_CIPH_CUSTOM_IV or EVP_CIPH_ALWAYS_CALL_INIT
+ flags.
+ [Steve Henson]
+
*) In ssl/s2_clnt.c and ssl/s3_clnt.c, call ERR_clear_error() when
the handshake is continued after ssl_verify_cert_chain();
otherwise, if SSL_VERIFY_NONE is set, remaining error codes
@@ -23,7 +34,6 @@
Change lots of functions like EVP_EncryptUpdate() to now return a
value: although software versions of the algorithms cannot fail
any installed hardware versions can.
-
[Steve Henson]
*) Implement SSL_OP_TLS_ROLLBACK_BUG: In ssl3_get_client_key_exchange, if
diff --git a/crypto/evp/e_cbc_3d.c b/crypto/evp/e_cbc_3d.c
index 7ee7851c55..bf58d4920d 100644
--- a/crypto/evp/e_cbc_3d.c
+++ b/crypto/evp/e_cbc_3d.c
@@ -113,18 +113,11 @@ static int des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
-
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- memcpy( (char *)ctx->c.des_ede.ks3,
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1));
- }
return 1;
}
@@ -133,16 +126,10 @@ static int des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
- }
return 1;
}
diff --git a/crypto/evp/e_cbc_bf.c b/crypto/evp/e_cbc_bf.c
index feda9e7e02..a2e1413266 100644
--- a/crypto/evp/e_cbc_bf.c
+++ b/crypto/evp/e_cbc_bf.c
@@ -89,11 +89,7 @@ EVP_CIPHER *EVP_bf_cbc(void)
static int bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_cbc_c.c b/crypto/evp/e_cbc_c.c
index d910f67cc5..8164f2b1cd 100644
--- a/crypto/evp/e_cbc_c.c
+++ b/crypto/evp/e_cbc_c.c
@@ -90,11 +90,7 @@ EVP_CIPHER *EVP_cast5_cbc(void)
static int cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_cbc_d.c b/crypto/evp/e_cbc_d.c
index 817d354358..2c9287b583 100644
--- a/crypto/evp/e_cbc_d.c
+++ b/crypto/evp/e_cbc_d.c
@@ -91,11 +91,7 @@ static int des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- des_set_key_unchecked(deskey,ctx->c.des_ks);
+ des_set_key_unchecked(deskey,ctx->c.des_ks);
return 1;
}
diff --git a/crypto/evp/e_cbc_i.c b/crypto/evp/e_cbc_i.c
index 56869b577b..c2c023a1b8 100644
--- a/crypto/evp/e_cbc_i.c
+++ b/crypto/evp/e_cbc_i.c
@@ -90,22 +90,15 @@ EVP_CIPHER *EVP_idea_cbc(void)
static int idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
+ if (enc) idea_set_encrypt_key(key,&(ctx->c.idea_ks));
+ else
{
- if (enc)
- idea_set_encrypt_key(key,&(ctx->c.idea_ks));
- else
- {
- IDEA_KEY_SCHEDULE tmp;
+ IDEA_KEY_SCHEDULE tmp;
- idea_set_encrypt_key(key,&tmp);
- idea_set_decrypt_key(&tmp,&(ctx->c.idea_ks));
- memset((unsigned char *)&tmp,0,
+ idea_set_encrypt_key(key,&tmp);
+ idea_set_decrypt_key(&tmp,&(ctx->c.idea_ks));
+ memset((unsigned char *)&tmp,0,
sizeof(IDEA_KEY_SCHEDULE));
- }
}
return 1;
}
diff --git a/crypto/evp/e_cbc_r2.c b/crypto/evp/e_cbc_r2.c
index 5e91c9d21e..3552b67417 100644
--- a/crypto/evp/e_cbc_r2.c
+++ b/crypto/evp/e_cbc_r2.c
@@ -139,11 +139,7 @@ EVP_CIPHER *EVP_rc2_40_cbc(void)
static int rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
+ RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
key,EVP_CIPHER_key_length(ctx->cipher)*8);
return 1;
}
diff --git a/crypto/evp/e_cbc_r5.c b/crypto/evp/e_cbc_r5.c
index 1639a08cdd..616644df27 100644
--- a/crypto/evp/e_cbc_r5.c
+++ b/crypto/evp/e_cbc_r5.c
@@ -90,11 +90,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_cbc(void)
static int r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,
+ RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,
key,RC5_12_ROUNDS);
return 1;
}
diff --git a/crypto/evp/e_cfb_3d.c b/crypto/evp/e_cfb_3d.c
index b07d90a036..140832703a 100644
--- a/crypto/evp/e_cfb_3d.c
+++ b/crypto/evp/e_cfb_3d.c
@@ -113,19 +113,11 @@ static int des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- memcpy( (char *)ctx->c.des_ede.ks3,
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1));
- }
return 1;
}
@@ -134,17 +126,9 @@ static int des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
- }
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
return 1;
}
diff --git a/crypto/evp/e_cfb_bf.c b/crypto/evp/e_cfb_bf.c
index c1e7a7c935..b82139ac40 100644
--- a/crypto/evp/e_cfb_bf.c
+++ b/crypto/evp/e_cfb_bf.c
@@ -89,13 +89,7 @@ EVP_CIPHER *EVP_bf_cfb(void)
static int bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_cfb_c.c b/crypto/evp/e_cfb_c.c
index d29e5948a4..bbdeac24f4 100644
--- a/crypto/evp/e_cfb_c.c
+++ b/crypto/evp/e_cfb_c.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_cast5_cfb(void)
static int cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_cfb_d.c b/crypto/evp/e_cfb_d.c
index 63d4dff681..72a26e32cf 100644
--- a/crypto/evp/e_cfb_d.c
+++ b/crypto/evp/e_cfb_d.c
@@ -91,13 +91,7 @@ static int des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- des_set_key_unchecked(deskey,ctx->c.des_ks);
+ des_set_key_unchecked(deskey,ctx->c.des_ks);
return 1;
}
diff --git a/crypto/evp/e_cfb_i.c b/crypto/evp/e_cfb_i.c
index d0da6e0382..eb5b8f400d 100644
--- a/crypto/evp/e_cfb_i.c
+++ b/crypto/evp/e_cfb_i.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_idea_cfb(void)
static int idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- idea_set_encrypt_key(key,&(ctx->c.idea_ks));
+ idea_set_encrypt_key(key,&(ctx->c.idea_ks));
return 1;
}
diff --git a/crypto/evp/e_cfb_r2.c b/crypto/evp/e_cfb_r2.c
index 2e0fd53763..661bfad8b4 100644
--- a/crypto/evp/e_cfb_r2.c
+++ b/crypto/evp/e_cfb_r2.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_rc2_cfb(void)
static int rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
+ RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
key,EVP_CIPHER_key_length(ctx->cipher)*8);
return 1;
}
diff --git a/crypto/evp/e_cfb_r5.c b/crypto/evp/e_cfb_r5.c
index bd092b4cd5..730fcc4fac 100644
--- a/crypto/evp/e_cfb_r5.c
+++ b/crypto/evp/e_cfb_r5.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_cfb(void)
static int rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key,
+ RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key,
RC5_12_ROUNDS);
return 1;
}
diff --git a/crypto/evp/e_ecb_3d.c b/crypto/evp/e_ecb_3d.c
index 157fb9e6a8..f024b0068f 100644
--- a/crypto/evp/e_ecb_3d.c
+++ b/crypto/evp/e_ecb_3d.c
@@ -113,14 +113,11 @@ static int des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- memcpy( (char *)ctx->c.des_ede.ks3,
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1));
- }
return 1;
}
@@ -129,12 +126,9 @@ static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
- }
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
return 1;
}
diff --git a/crypto/evp/e_ecb_bf.c b/crypto/evp/e_ecb_bf.c
index c38e56d491..b63577900d 100644
--- a/crypto/evp/e_ecb_bf.c
+++ b/crypto/evp/e_ecb_bf.c
@@ -89,8 +89,7 @@ EVP_CIPHER *EVP_bf_ecb(void)
static int bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (key != NULL)
- BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_ecb_c.c b/crypto/evp/e_ecb_c.c
index 4b18dcc1b7..3d59b89eeb 100644
--- a/crypto/evp/e_ecb_c.c
+++ b/crypto/evp/e_ecb_c.c
@@ -90,8 +90,7 @@ EVP_CIPHER *EVP_cast5_ecb(void)
static int cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (key != NULL)
- CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_ecb_d.c b/crypto/evp/e_ecb_d.c
index fb15670e7a..deac93b01a 100644
--- a/crypto/evp/e_ecb_d.c
+++ b/crypto/evp/e_ecb_d.c
@@ -91,8 +91,7 @@ static int des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- if (deskey != NULL)
- des_set_key_unchecked(deskey,ctx->c.des_ks);
+ des_set_key_unchecked(deskey,ctx->c.des_ks);
return 1;
}
diff --git a/crypto/evp/e_ecb_i.c b/crypto/evp/e_ecb_i.c
index a9bc977a5e..ab8b64e723 100644
--- a/crypto/evp/e_ecb_i.c
+++ b/crypto/evp/e_ecb_i.c
@@ -90,19 +90,16 @@ EVP_CIPHER *EVP_idea_ecb(void)
static int idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (key != NULL)
- {
- if (enc)
+ if (enc)
idea_set_encrypt_key(key,&(ctx->c.idea_ks));
- else
- {
- IDEA_KEY_SCHEDULE tmp;
+ else
+ {
+ IDEA_KEY_SCHEDULE tmp;
- idea_set_encrypt_key(key,&tmp);
- idea_set_decrypt_key(&tmp, &(ctx->c.idea_ks));
- memset((unsigned char *)&tmp,0,
+ idea_set_encrypt_key(key,&tmp);
+ idea_set_decrypt_key(&tmp, &(ctx->c.idea_ks));
+ memset((unsigned char *)&tmp,0,
sizeof(IDEA_KEY_SCHEDULE));
- }
}
return 1;
}
diff --git a/crypto/evp/e_ecb_r2.c b/crypto/evp/e_ecb_r2.c
index b6ff7b77a5..596b78ba72 100644
--- a/crypto/evp/e_ecb_r2.c
+++ b/crypto/evp/e_ecb_r2.c
@@ -90,9 +90,8 @@ EVP_CIPHER *EVP_rc2_ecb(void)
static int rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (key != NULL)
- RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
- key,EVP_CIPHER_key_length(ctx->cipher)*8);
+ RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
+ key,EVP_CIPHER_key_length(ctx->cipher)*8);
return 1;
}
diff --git a/crypto/evp/e_ecb_r5.c b/crypto/evp/e_ecb_r5.c
index ba55e41a6c..1baadb7be5 100644
--- a/crypto/evp/e_ecb_r5.c
+++ b/crypto/evp/e_ecb_r5.c
@@ -90,8 +90,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_ecb(void)
static int rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (key != NULL)
- RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key,
+ RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key,
RC5_12_ROUNDS);
return 1;
}
diff --git a/crypto/evp/e_ofb_3d.c b/crypto/evp/e_ofb_3d.c
index f8b3141935..14ac11c31e 100644
--- a/crypto/evp/e_ofb_3d.c
+++ b/crypto/evp/e_ofb_3d.c
@@ -113,19 +113,12 @@ static int des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- memcpy( (char *)ctx->c.des_ede.ks3,
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1));
- }
+
return 1;
}
@@ -134,17 +127,10 @@ static int des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- ctx->num=0;
+ des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+ des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+ des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- {
- des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
- des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
- des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
- }
return 1;
}
diff --git a/crypto/evp/e_ofb_bf.c b/crypto/evp/e_ofb_bf.c
index f5507a22f7..6d4b62a391 100644
--- a/crypto/evp/e_ofb_bf.c
+++ b/crypto/evp/e_ofb_bf.c
@@ -89,13 +89,7 @@ EVP_CIPHER *EVP_bf_ofb(void)
static int bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_ofb_c.c b/crypto/evp/e_ofb_c.c
index b84a42d7f5..20c843c22f 100644
--- a/crypto/evp/e_ofb_c.c
+++ b/crypto/evp/e_ofb_c.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_cast5_ofb(void)
static int cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
+ CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key);
return 1;
}
diff --git a/crypto/evp/e_ofb_d.c b/crypto/evp/e_ofb_d.c
index b52ebdc016..0926e9cb7b 100644
--- a/crypto/evp/e_ofb_d.c
+++ b/crypto/evp/e_ofb_d.c
@@ -90,14 +90,7 @@ static int des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
des_cblock *deskey = (des_cblock *)key;
-
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- des_set_key_unchecked(deskey,ctx->c.des_ks);
+ des_set_key_unchecked(deskey,ctx->c.des_ks);
return 1;
}
diff --git a/crypto/evp/e_ofb_i.c b/crypto/evp/e_ofb_i.c
index 36c14b492e..b6f6aa2f53 100644
--- a/crypto/evp/e_ofb_i.c
+++ b/crypto/evp/e_ofb_i.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_idea_ofb(void)
static int idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- idea_set_encrypt_key(key,&(ctx->c.idea_ks));
+ idea_set_encrypt_key(key,&(ctx->c.idea_ks));
return 1;
}
diff --git a/crypto/evp/e_ofb_r2.c b/crypto/evp/e_ofb_r2.c
index bfbd602616..b71cc78bcb 100644
--- a/crypto/evp/e_ofb_r2.c
+++ b/crypto/evp/e_ofb_r2.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_rc2_ofb(void)
static int rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
+ RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
key,EVP_CIPHER_key_length(ctx->cipher)*8);
return 1;
}
diff --git a/crypto/evp/e_ofb_r5.c b/crypto/evp/e_ofb_r5.c
index d97d8843a4..3eba2790c1 100644
--- a/crypto/evp/e_ofb_r5.c
+++ b/crypto/evp/e_ofb_r5.c
@@ -90,13 +90,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_ofb(void)
static int rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- ctx->num=0;
-
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (key != NULL)
- RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key,
+ RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key,
RC5_12_ROUNDS);
return 1;
}
diff --git a/crypto/evp/e_rc4.c b/crypto/evp/e_rc4.c
index bc108f4356..42839aef6b 100644
--- a/crypto/evp/e_rc4.c
+++ b/crypto/evp/e_rc4.c
@@ -110,8 +110,7 @@ EVP_CIPHER *EVP_rc4_40(void)
static int rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
unsigned char *iv, int enc)
{
- if (key != NULL)
- memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx));
+ memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx));
RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx),
ctx->c.rc4.key);
return 1;
diff --git a/crypto/evp/e_xcbc_d.c b/crypto/evp/e_xcbc_d.c
index 067b721a0f..e5dcdebe16 100644
--- a/crypto/evp/e_xcbc_d.c
+++ b/crypto/evp/e_xcbc_d.c
@@ -91,15 +91,10 @@ static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
{
des_cblock *deskey = (des_cblock *)key;
- if (iv != NULL)
- memcpy(&(ctx->oiv[0]),iv,8);
- memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
- if (deskey != NULL)
- {
- des_