From be06a9348d83187071270a29aabfe10cc3904f85 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 27 May 2000 12:38:43 +0000 Subject: [PATCH 1/1] Second phase of EVP cipher overhaul. Change functions like EVP_EncryptUpdate() so they now return a value. These normally have software only implementations which cannot fail so this was acceptable. However ciphers can be implemented in hardware and these could return errors. --- CHANGES | 12 ++++++-- crypto/evp/e_cbc_3d.c | 15 ++++++---- crypto/evp/e_cbc_bf.c | 10 ++++--- crypto/evp/e_cbc_c.c | 10 ++++--- crypto/evp/e_cbc_d.c | 10 ++++--- crypto/evp/e_cbc_i.c | 10 ++++--- crypto/evp/e_cbc_r2.c | 10 ++++--- crypto/evp/e_cbc_r5.c | 10 ++++--- crypto/evp/e_cfb_3d.c | 15 ++++++---- crypto/evp/e_cfb_bf.c | 10 ++++--- crypto/evp/e_cfb_c.c | 10 ++++--- crypto/evp/e_cfb_d.c | 10 ++++--- crypto/evp/e_cfb_i.c | 10 ++++--- crypto/evp/e_cfb_r2.c | 10 ++++--- crypto/evp/e_cfb_r5.c | 10 ++++--- crypto/evp/e_ecb_3d.c | 17 ++++++----- crypto/evp/e_ecb_bf.c | 12 ++++---- crypto/evp/e_ecb_c.c | 12 ++++---- crypto/evp/e_ecb_d.c | 12 ++++---- crypto/evp/e_ecb_i.c | 12 ++++---- crypto/evp/e_ecb_r2.c | 12 ++++---- crypto/evp/e_ecb_r5.c | 12 ++++---- crypto/evp/e_null.c | 10 ++++--- crypto/evp/e_ofb_3d.c | 15 ++++++---- crypto/evp/e_ofb_bf.c | 10 ++++--- crypto/evp/e_ofb_c.c | 10 ++++--- crypto/evp/e_ofb_d.c | 10 ++++--- crypto/evp/e_ofb_i.c | 10 ++++--- crypto/evp/e_ofb_r2.c | 10 ++++--- crypto/evp/e_ofb_r5.c | 10 ++++--- crypto/evp/e_rc4.c | 10 ++++--- crypto/evp/e_xcbc_d.c | 10 ++++--- crypto/evp/evp.h | 22 +++++++-------- crypto/evp/evp_enc.c | 65 ++++++++++++++++++++++--------------------- 34 files changed, 259 insertions(+), 184 deletions(-) diff --git a/CHANGES b/CHANGES index 94876612c3..ad61f13440 100644 --- a/CHANGES +++ b/CHANGES @@ -9,9 +9,15 @@ support added for variable key length ciphers via the EVP_CIPHER_CTX_set_key_length() function. Other cipher specific parameters will be added later via the new catchall 'ctrl' function. - New functionality allows removal of S/MIME code RC2 hack. Still needs - support in other library functions, also need to add return codes to - some EVP functions. + New functionality allows removal of S/MIME code RC2 hack. + + Still needs support in other library functions, and allow parameter + setting for algorithms like RC2, RC5. + + 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 a458921583..7ee7851c55 100644 --- a/crypto/evp/e_cbc_3d.c +++ b/crypto/evp/e_cbc_3d.c @@ -62,11 +62,11 @@ #include #include -static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_cbc_ede_cipher2= { @@ -108,7 +108,7 @@ EVP_CIPHER *EVP_des_ede3_cbc(void) return(&d_cbc_ede_cipher3); } -static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -125,9 +125,10 @@ static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } + return 1; } -static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -142,14 +143,16 @@ static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3); } + return 1; } -static void des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { des_ede3_cbc_encrypt(in,out,inl, ctx->c.des_ede.ks1, ctx->c.des_ede.ks2,ctx->c.des_ede.ks3, (des_cblock *) &(ctx->iv[0]), ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cbc_bf.c b/crypto/evp/e_cbc_bf.c index 489e63041d..feda9e7e02 100644 --- a/crypto/evp/e_cbc_bf.c +++ b/crypto/evp/e_cbc_bf.c @@ -62,9 +62,9 @@ #include #include -static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER bfish_cbc_cipher= { @@ -86,7 +86,7 @@ EVP_CIPHER *EVP_bf_cbc(void) return(&bfish_cbc_cipher); } -static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { if (iv != NULL) @@ -94,15 +94,17 @@ static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 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); + return 1; } -static void bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { BF_cbc_encrypt( in,out,(long)inl, &(ctx->c.bf_ks),&(ctx->iv[0]), ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cbc_c.c b/crypto/evp/e_cbc_c.c index 4e8fda9e64..d910f67cc5 100644 --- a/crypto/evp/e_cbc_c.c +++ b/crypto/evp/e_cbc_c.c @@ -63,9 +63,9 @@ #include #include -static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER cast5_cbc_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_cast5_cbc(void) return(&cast5_cbc_cipher); } -static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { if (iv != NULL) @@ -95,15 +95,17 @@ static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 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); + return 1; } -static void cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { CAST_cbc_encrypt( in,out,(long)inl, &(ctx->c.cast_ks),&(ctx->iv[0]), ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cbc_d.c b/crypto/evp/e_cbc_d.c index ae9d25aca1..817d354358 100644 --- a/crypto/evp/e_cbc_d.c +++ b/crypto/evp/e_cbc_d.c @@ -62,9 +62,9 @@ #include #include -static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_cbc_cipher= { @@ -86,7 +86,7 @@ EVP_CIPHER *EVP_des_cbc(void) return(&d_cbc_cipher); } -static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -96,13 +96,15 @@ static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (deskey != NULL) des_set_key_unchecked(deskey,ctx->c.des_ks); + return 1; } -static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { des_ncbc_encrypt(in,out,inl,ctx->c.des_ks, (des_cblock *)&(ctx->iv[0]), ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cbc_i.c b/crypto/evp/e_cbc_i.c index b74f280614..56869b577b 100644 --- a/crypto/evp/e_cbc_i.c +++ b/crypto/evp/e_cbc_i.c @@ -63,9 +63,9 @@ #include #include -static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER i_cbc_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_idea_cbc(void) return(&i_cbc_cipher); } -static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { if (iv != NULL) @@ -107,15 +107,17 @@ static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, sizeof(IDEA_KEY_SCHEDULE)); } } + return 1; } -static void idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { idea_cbc_encrypt( in,out,(long)inl, &(ctx->c.idea_ks),&(ctx->iv[0]), ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cbc_r2.c b/crypto/evp/e_cbc_r2.c index dc94b4fe1f..5e91c9d21e 100644 --- a/crypto/evp/e_cbc_r2.c +++ b/crypto/evp/e_cbc_r2.c @@ -63,9 +63,9 @@ #include #include -static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static int rc2_meth_to_magic(const EVP_CIPHER *e); static EVP_CIPHER *rc2_magic_to_meth(int i); @@ -136,7 +136,7 @@ EVP_CIPHER *EVP_rc2_40_cbc(void) return(&r2_40_cbc_cipher); } -static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { if (iv != NULL) @@ -145,15 +145,17 @@ static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, if (key != NULL) RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx), key,EVP_CIPHER_key_length(ctx->cipher)*8); + return 1; } -static void rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { RC2_cbc_encrypt( in,out,(long)inl, &(ctx->c.rc2_ks),&(ctx->iv[0]), ctx->encrypt); + return 1; } static int rc2_meth_to_magic(const EVP_CIPHER *e) diff --git a/crypto/evp/e_cbc_r5.c b/crypto/evp/e_cbc_r5.c index 4e71f46d02..1639a08cdd 100644 --- a/crypto/evp/e_cbc_r5.c +++ b/crypto/evp/e_cbc_r5.c @@ -63,9 +63,9 @@ #include #include -static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER rc5_32_12_16_cbc_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_cbc(void) return(&rc5_32_12_16_cbc_cipher); } -static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { if (iv != NULL) @@ -96,15 +96,17 @@ static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, if (key != NULL) RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE, key,RC5_12_ROUNDS); + return 1; } -static void r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { RC5_32_cbc_encrypt( in,out,(long)inl, &(ctx->c.rc5_ks),&(ctx->iv[0]), ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cfb_3d.c b/crypto/evp/e_cfb_3d.c index 73b989b3b6..b07d90a036 100644 --- a/crypto/evp/e_cfb_3d.c +++ b/crypto/evp/e_cfb_3d.c @@ -62,11 +62,11 @@ #include #include -static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_ede_cfb_cipher2= { @@ -108,7 +108,7 @@ EVP_CIPHER *EVP_des_ede3_cfb(void) return(&d_ede3_cfb_cipher3); } -static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -126,9 +126,10 @@ static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } + return 1; } -static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -144,9 +145,10 @@ static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3); } + return 1; } -static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { des_ede3_cfb64_encrypt(in,out,(long)inl, @@ -155,5 +157,6 @@ static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, ctx->c.des_ede.ks3, (des_cblock*)&(ctx->iv[0]), &ctx->num,ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cfb_bf.c b/crypto/evp/e_cfb_bf.c index b09485531f..c1e7a7c935 100644 --- a/crypto/evp/e_cfb_bf.c +++ b/crypto/evp/e_cfb_bf.c @@ -62,9 +62,9 @@ #include #include -static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER bfish_cfb_cipher= { @@ -86,7 +86,7 @@ EVP_CIPHER *EVP_bf_cfb(void) return(&bfish_cfb_cipher); } -static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -96,9 +96,10 @@ static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 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); + return 1; } -static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { BF_cfb64_encrypt( @@ -106,5 +107,6 @@ static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.bf_ks), &(ctx->iv[0]), &ctx->num,ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cfb_c.c b/crypto/evp/e_cfb_c.c index c4efb64bd2..d29e5948a4 100644 --- a/crypto/evp/e_cfb_c.c +++ b/crypto/evp/e_cfb_c.c @@ -63,9 +63,9 @@ #include #include -static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER cast5_cfb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_cast5_cfb(void) return(&cast5_cfb_cipher); } -static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -97,9 +97,10 @@ static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 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); + return 1; } -static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { CAST_cfb64_encrypt( @@ -107,5 +108,6 @@ static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.cast_ks), &(ctx->iv[0]), &ctx->num,ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cfb_d.c b/crypto/evp/e_cfb_d.c index 6817d78073..63d4dff681 100644 --- a/crypto/evp/e_cfb_d.c +++ b/crypto/evp/e_cfb_d.c @@ -62,9 +62,9 @@ #include #ifndef NO_DES -static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_cfb_cipher= { @@ -86,7 +86,7 @@ EVP_CIPHER *EVP_des_cfb(void) return(&d_cfb_cipher); } -static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -98,9 +98,10 @@ static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (deskey != NULL) des_set_key_unchecked(deskey,ctx->c.des_ks); + return 1; } -static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { des_cfb64_encrypt( @@ -108,5 +109,6 @@ static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, ctx->c.des_ks, (des_cblock *)&(ctx->iv[0]), &ctx->num,ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cfb_i.c b/crypto/evp/e_cfb_i.c index e228057fa1..d0da6e0382 100644 --- a/crypto/evp/e_cfb_i.c +++ b/crypto/evp/e_cfb_i.c @@ -63,9 +63,9 @@ #include #include -static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER i_cfb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_idea_cfb(void) return(&i_cfb_cipher); } -static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -97,15 +97,17 @@ static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (key != NULL) idea_set_encrypt_key(key,&(ctx->c.idea_ks)); + return 1; } -static void idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { idea_cfb64_encrypt( in,out,(long)inl, &(ctx->c.idea_ks),&(ctx->iv[0]), &ctx->num,ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cfb_r2.c b/crypto/evp/e_cfb_r2.c index 6e5ee8dac6..2e0fd53763 100644 --- a/crypto/evp/e_cfb_r2.c +++ b/crypto/evp/e_cfb_r2.c @@ -63,9 +63,9 @@ #include #include -static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER r2_cfb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_rc2_cfb(void) return(&r2_cfb_cipher); } -static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -98,9 +98,10 @@ static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, if (key != NULL) RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx), key,EVP_CIPHER_key_length(ctx->cipher)*8); + return 1; } -static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { RC2_cfb64_encrypt( @@ -108,5 +109,6 @@ static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.rc2_ks), &(ctx->iv[0]), &ctx->num,ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_cfb_r5.c b/crypto/evp/e_cfb_r5.c index 25ec1193ca..bd092b4cd5 100644 --- a/crypto/evp/e_cfb_r5.c +++ b/crypto/evp/e_cfb_r5.c @@ -63,9 +63,9 @@ #include #include -static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER rc5_cfb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_cfb(void) return(&rc5_cfb_cipher); } -static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -98,9 +98,10 @@ static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, if (key != NULL) RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key, RC5_12_ROUNDS); + return 1; } -static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { RC5_32_cfb64_encrypt( @@ -108,5 +109,6 @@ static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.rc5_ks), &(ctx->iv[0]), &ctx->num,ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/e_ecb_3d.c b/crypto/evp/e_ecb_3d.c index 5308557ee4..157fb9e6a8 100644 --- a/crypto/evp/e_ecb_3d.c +++ b/crypto/evp/e_ecb_3d.c @@ -62,11 +62,11 @@ #include #include -static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_ede_cipher2= { @@ -108,7 +108,7 @@ EVP_CIPHER *EVP_des_ede3(void) return(&d_ede3_cipher3); } -static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -121,9 +121,10 @@ static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } + return 1; } -static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -134,16 +135,17 @@ static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3); } + return 1; } -static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { unsigned int i; des_cblock *output /* = (des_cblock *)out */; des_cblock *input /* = (des_cblock *)in */; - if (inl < 8) return; + if (inl < 8) return 1; inl-=8; for (i=0; i<=inl; i+=8) { @@ -159,5 +161,6 @@ static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, /* output++; */ /* input++; */ } + return 1; } #endif diff --git a/crypto/evp/e_ecb_bf.c b/crypto/evp/e_ecb_bf.c index 31aef248bf..c38e56d491 100644 --- a/crypto/evp/e_ecb_bf.c +++ b/crypto/evp/e_ecb_bf.c @@ -62,9 +62,9 @@ #include #include -static void bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER bfish_ecb_cipher= { @@ -86,19 +86,20 @@ EVP_CIPHER *EVP_bf_ecb(void) return(&bfish_ecb_cipher); } -static void bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +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); + return 1; } -static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { unsigned int i; - if (inl < 8) return; + if (inl < 8) return 1; inl-=8; for (i=0; i<=inl; i+=8) { @@ -106,6 +107,7 @@ static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, &(in[i]),&(out[i]), &(ctx->c.bf_ks),ctx->encrypt); } + return 1; } #endif diff --git a/crypto/evp/e_ecb_c.c b/crypto/evp/e_ecb_c.c index 7eafb8d9b2..4b18dcc1b7 100644 --- a/crypto/evp/e_ecb_c.c +++ b/crypto/evp/e_ecb_c.c @@ -63,9 +63,9 @@ #include #include -static void cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER cast5_ecb_cipher= { @@ -87,19 +87,20 @@ EVP_CIPHER *EVP_cast5_ecb(void) return(&cast5_ecb_cipher); } -static void cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +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); + return 1; } -static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { unsigned int i; - if (inl < 8) return; + if (inl < 8) return 1; inl-=8; for (i=0; i<=inl; i+=8) { @@ -107,6 +108,7 @@ static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, &(in[i]),&(out[i]), &(ctx->c.cast_ks),ctx->encrypt); } + return 1; } #endif diff --git a/crypto/evp/e_ecb_d.c b/crypto/evp/e_ecb_d.c index b55d5b0ee4..fb15670e7a 100644 --- a/crypto/evp/e_ecb_d.c +++ b/crypto/evp/e_ecb_d.c @@ -62,9 +62,9 @@ #include #include -static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_ecb_cipher= { @@ -86,23 +86,24 @@ EVP_CIPHER *EVP_des_ecb(void) return(&d_ecb_cipher); } -static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; if (deskey != NULL) des_set_key_unchecked(deskey,ctx->c.des_ks); + return 1; } -static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { unsigned int i; des_cblock *output /* = (des_cblock *)out */; des_cblock *input /* = (des_cblock *)in */; - if (inl < 8) return; + if (inl < 8) return 1; inl-=8; for (i=0; i<=inl; i+=8) { @@ -116,5 +117,6 @@ static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, /* output++; */ /* input++; */ } + return 1; } #endif diff --git a/crypto/evp/e_ecb_i.c b/crypto/evp/e_ecb_i.c index 7e614c6439..a9bc977a5e 100644 --- a/crypto/evp/e_ecb_i.c +++ b/crypto/evp/e_ecb_i.c @@ -63,9 +63,9 @@ #include #include -static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER i_ecb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_idea_ecb(void) return(&i_ecb_cipher); } -static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { if (key != NULL) @@ -104,20 +104,22 @@ static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, sizeof(IDEA_KEY_SCHEDULE)); } } + return 1; } -static void idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { unsigned int i; - if (inl < 8) return; + if (inl < 8) return 1; inl-=8; for (i=0; i<=inl; i+=8) { idea_ecb_encrypt( &(in[i]),&(out[i]),&(ctx->c.idea_ks)); } + return 1; } #endif diff --git a/crypto/evp/e_ecb_r2.c b/crypto/evp/e_ecb_r2.c index 41d6337fc6..b6ff7b77a5 100644 --- a/crypto/evp/e_ecb_r2.c +++ b/crypto/evp/e_ecb_r2.c @@ -63,9 +63,9 @@ #include #include -static void rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER r2_ecb_cipher= { @@ -87,20 +87,21 @@ EVP_CIPHER *EVP_rc2_ecb(void) return(&r2_ecb_cipher); } -static void rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +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); + return 1; } -static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { unsigned int i; - if (inl < 8) return; + if (inl < 8) return 1; inl-=8; for (i=0; i<=inl; i+=8) { @@ -108,6 +109,7 @@ static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, &(in[i]),&(out[i]), &(ctx->c.rc2_ks),ctx->encrypt); } + return 1; } #endif diff --git a/crypto/evp/e_ecb_r5.c b/crypto/evp/e_ecb_r5.c index 1bf19e6f95..ba55e41a6c 100644 --- a/crypto/evp/e_ecb_r5.c +++ b/crypto/evp/e_ecb_r5.c @@ -63,9 +63,9 @@ #include #include -static void rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER rc5_ecb_cipher= { @@ -87,20 +87,21 @@ EVP_CIPHER *EVP_rc5_32_12_16_ecb(void) return(&rc5_ecb_cipher); } -static void rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +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_12_ROUNDS); + return 1; } -static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { unsigned int i; - if (inl < 8) return; + if (inl < 8) return 1; inl-=8; for (i=0; i<=inl; i+=8) { @@ -108,6 +109,7 @@ static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, &(in[i]),&(out[i]), &(ctx->c.rc5_ks),ctx->encrypt); } + return 1; } #endif diff --git a/crypto/evp/e_null.c b/crypto/evp/e_null.c index 0d31a66061..d507337df6 100644 --- a/crypto/evp/e_null.c +++ b/crypto/evp/e_null.c @@ -61,9 +61,9 @@ #include #include -static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER n_cipher= { @@ -84,16 +84,18 @@ EVP_CIPHER *EVP_enc_null(void) return(&n_cipher); } -static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { memset(&(ctx->c),0,sizeof(ctx->c)); + return 1; } -static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { if (in != out) memcpy((char *)out,(char *)in,(int)inl); + return 1; } diff --git a/crypto/evp/e_ofb_3d.c b/crypto/evp/e_ofb_3d.c index c1714fda8d..f8b3141935 100644 --- a/crypto/evp/e_ofb_3d.c +++ b/crypto/evp/e_ofb_3d.c @@ -62,11 +62,11 @@ #include #include -static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_ede_ofb_cipher2= { @@ -108,7 +108,7 @@ EVP_CIPHER *EVP_des_ede3_ofb(void) return(&d_ede3_ofb_cipher3); } -static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -126,9 +126,10 @@ static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } + return 1; } -static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -144,13 +145,15 @@ static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3); } + return 1; } -static void des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { des_ede3_ofb64_encrypt(in,out,inl,ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, (des_cblock *)&(ctx->iv[0]),&ctx->num); + return 1; } #endif diff --git a/crypto/evp/e_ofb_bf.c b/crypto/evp/e_ofb_bf.c index 12d35c122b..f5507a22f7 100644 --- a/crypto/evp/e_ofb_bf.c +++ b/crypto/evp/e_ofb_bf.c @@ -62,9 +62,9 @@ #include #include -static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER bfish_ofb_cipher= { @@ -86,7 +86,7 @@ EVP_CIPHER *EVP_bf_ofb(void) return(&bfish_ofb_cipher); } -static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -96,9 +96,10 @@ static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 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); + return 1; } -static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { BF_ofb64_encrypt( @@ -106,6 +107,7 @@ static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.bf_ks), &(ctx->iv[0]), &ctx->num); + return 1; } #endif diff --git a/crypto/evp/e_ofb_c.c b/crypto/evp/e_ofb_c.c index fbdcf98c61..b84a42d7f5 100644 --- a/crypto/evp/e_ofb_c.c +++ b/crypto/evp/e_ofb_c.c @@ -63,9 +63,9 @@ #include #include -static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER cast5_ofb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_cast5_ofb(void) return(&cast5_ofb_cipher); } -static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -97,9 +97,10 @@ static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 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); + return 1; } -static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { CAST_ofb64_encrypt( @@ -107,6 +108,7 @@ static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.cast_ks), &(ctx->iv[0]), &ctx->num); + return 1; } #endif diff --git a/crypto/evp/e_ofb_d.c b/crypto/evp/e_ofb_d.c index 7ced394a2b..b52ebdc016 100644 --- a/crypto/evp/e_ofb_d.c +++ b/crypto/evp/e_ofb_d.c @@ -62,9 +62,9 @@ #include #include -static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_ofb_cipher= { @@ -86,7 +86,7 @@ EVP_CIPHER *EVP_des_ofb(void) return(&d_ofb_cipher); } -static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -98,12 +98,14 @@ static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (deskey != NULL) des_set_key_unchecked(deskey,ctx->c.des_ks); + return 1; } -static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { des_ofb64_encrypt(in,out,inl,ctx->c.des_ks, (des_cblock *)&(ctx->iv[0]),&ctx->num); + return 1; } #endif diff --git a/crypto/evp/e_ofb_i.c b/crypto/evp/e_ofb_i.c index 7c97cbd7b6..36c14b492e 100644 --- a/crypto/evp/e_ofb_i.c +++ b/crypto/evp/e_ofb_i.c @@ -63,9 +63,9 @@ #include #include -static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER i_ofb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_idea_ofb(void) return(&i_ofb_cipher); } -static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -97,15 +97,17 @@ static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (key != NULL) idea_set_encrypt_key(key,&(ctx->c.idea_ks)); + return 1; } -static void idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { idea_ofb64_encrypt( in,out,(long)inl, &(ctx->c.idea_ks),&(ctx->iv[0]), &ctx->num); + return 1; } #endif diff --git a/crypto/evp/e_ofb_r2.c b/crypto/evp/e_ofb_r2.c index 696d58b0c4..bfbd602616 100644 --- a/crypto/evp/e_ofb_r2.c +++ b/crypto/evp/e_ofb_r2.c @@ -63,9 +63,9 @@ #include #include -static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER r2_ofb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_rc2_ofb(void) return(&r2_ofb_cipher); } -static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -98,9 +98,10 @@ static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, if (key != NULL) RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx), key,EVP_CIPHER_key_length(ctx->cipher)*8); + return 1; } -static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { RC2_ofb64_encrypt( @@ -108,6 +109,7 @@ static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.rc2_ks), &(ctx->iv[0]), &ctx->num); + return 1; } #endif diff --git a/crypto/evp/e_ofb_r5.c b/crypto/evp/e_ofb_r5.c index 205aaf9cd7..d97d8843a4 100644 --- a/crypto/evp/e_ofb_r5.c +++ b/crypto/evp/e_ofb_r5.c @@ -63,9 +63,9 @@ #include #include -static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER rc5_ofb_cipher= { @@ -87,7 +87,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_ofb(void) return(&rc5_ofb_cipher); } -static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { ctx->num=0; @@ -98,9 +98,10 @@ static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, if (key != NULL) RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key, RC5_12_ROUNDS); + return 1; } -static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { RC5_32_ofb64_encrypt( @@ -108,6 +109,7 @@ static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, (long)inl, &(ctx->c.rc5_ks), &(ctx->iv[0]), &ctx->num); + return 1; } #endif diff --git a/crypto/evp/e_rc4.c b/crypto/evp/e_rc4.c index 1ac9f70691..bc108f4356 100644 --- a/crypto/evp/e_rc4.c +++ b/crypto/evp/e_rc4.c @@ -63,9 +63,9 @@ #include #include -static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER r4_cipher= { @@ -107,18 +107,20 @@ EVP_CIPHER *EVP_rc4_40(void) return(&r4_40_cipher); } -static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +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)); RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx), ctx->c.rc4.key); + return 1; } -static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { RC4(&(ctx->c.rc4.ks),inl,in,out); + return 1; } #endif diff --git a/crypto/evp/e_xcbc_d.c b/crypto/evp/e_xcbc_d.c index dd4cab7a4d..067b721a0f 100644 --- a/crypto/evp/e_xcbc_d.c +++ b/crypto/evp/e_xcbc_d.c @@ -62,9 +62,9 @@ #include #include -static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); -static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); static EVP_CIPHER d_xcbc_cipher= { @@ -86,7 +86,7 @@ EVP_CIPHER *EVP_desx_cbc(void) return(&d_xcbc_cipher); } -static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, +static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv, int enc) { des_cblock *deskey = (des_cblock *)key; @@ -100,9 +100,10 @@ static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); } + return 1; } -static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, +static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl) { des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks, @@ -110,5 +111,6 @@ static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, &ctx->c.desx_cbc.inw, &ctx->c.desx_cbc.outw, ctx->encrypt); + return 1; } #endif diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index 0d101162e0..110e02f41b 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -328,9 +328,9 @@ struct evp_cipher_st int key_len; /* Default value for variable length ciphers */ int iv_len; unsigned long flags; /* Various flags */ - void (*init)(EVP_CIPHER_CTX *, unsigned char *, unsigned char *, int); /* init key */ - void (*do_cipher)(EVP_CIPHER_CTX *, unsigned char *, unsigned char *, unsigned int);/* encrypt/decrypt data */ - void (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */ + int (*init)(EVP_CIPHER_CTX *, unsigned char *, unsigned char *, int); /* init key */ + int (*do_cipher)(EVP_CIPHER_CTX *, unsigned char *, unsigned char *, unsigned int);/* encrypt/decrypt data */ + int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */ int ctx_size; /* how big the ctx needs to be */ int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */ int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */ @@ -511,21 +511,21 @@ int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt, unsigned char *data, int datal, int count, unsigned char *key,unsigned char *iv); -void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, +int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, unsigned char *key, unsigned char *iv); -void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, +int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); -void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); +int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); -void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, +int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, unsigned char *key, unsigned char *iv); -void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, +int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); -void EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, +int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, unsigned char *key,unsigned char *iv,int enc); -void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, +int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); @@ -559,7 +559,7 @@ int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); void ERR_load_EVP_strings(void ); void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); -void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); +int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); #ifdef HEADER_BIO_H diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 3f69c6052f..dc1116ebbc 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -69,34 +69,29 @@ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) /* ctx->cipher=NULL; */ } -void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *data, +int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *data, unsigned char *key, unsigned char *iv, int enc) { - if (enc) - EVP_EncryptInit(ctx,data,key,iv); - else - EVP_DecryptInit(ctx,data,key,iv); + if (enc) return EVP_EncryptInit(ctx,data,key,iv); + else return EVP_DecryptInit(ctx,data,key,iv); } -void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, +int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl) { if (ctx->encrypt) - EVP_EncryptUpdate(ctx,out,outl,in,inl); - else EVP_DecryptUpdate(ctx,out,outl,in,inl); + return EVP_EncryptUpdate(ctx,out,outl,in,inl); + else return EVP_DecryptUpdate(ctx,out,outl,in,inl); } int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { if (ctx->encrypt) - { - EVP_EncryptFinal(ctx,out,outl); - return(1); - } + return EVP_EncryptFinal(ctx,out,outl); else return(EVP_DecryptFinal(ctx,out,outl)); } -void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, +int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, unsigned char *key, unsigned char *iv) { if (cipher != NULL) @@ -104,12 +99,13 @@ void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ctx->cipher=cipher; ctx->key_len = cipher->key_len; } - ctx->cipher->init(ctx,key,iv,1); + if(!ctx->cipher->init(ctx,key,iv,1)) return 0; ctx->encrypt=1; ctx->buf_len=0; + return 1; } -void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, +int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, unsigned char *key, unsigned char *iv) { if (cipher != NULL) @@ -117,13 +113,14 @@ void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ctx->cipher=cipher; ctx->key_len = cipher->key_len; } - ctx->cipher->init(ctx,key,iv,0); + if(!ctx->cipher->init(ctx,key,iv,0)) return 0; ctx->encrypt=0; ctx->buf_len=0; + return 1; } -void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, +int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl) { int i,j,bl; @@ -131,20 +128,20 @@ void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, i=ctx->buf_len; bl=ctx->cipher->block_size; *outl=0; - if ((inl == 0) && (i != bl)) return; + if ((inl == 0) && (i != bl)) return 1; if (i != 0) { if (i+inl < bl) { memcpy(&(ctx->buf[i]),in,inl); ctx->buf_len+=inl; - return; + return 1; } else { j=bl-i; if (j != 0) memcpy(&(ctx->buf[i]),in,j); - ctx->cipher->do_cipher(ctx,out,ctx->buf,bl); + if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0; inl-=j; in+=j; out+=bl; @@ -155,16 +152,17 @@ void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, inl-=i; if (inl > 0) { - ctx->cipher->do_cipher(ctx,out,in,inl); + if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0; *outl+=inl; } if (i != 0) memcpy(ctx->buf,&(in[inl]),i); ctx->buf_len=i; + return 1; } -void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) +int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int i,n,b,bl; @@ -172,24 +170,25 @@ void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) if (b == 1) { *outl=0; - return; + return 1; } bl=ctx->buf_len; n=b-bl; for (i=bl; ibuf[i]=n; - ctx->cipher->do_cipher(ctx,out,ctx->buf,b); + if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,b)) return 0; *outl=b; + return 1; } -void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, +int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl) { int b,bl,n; int keep_last=0; *outl=0; - if (inl == 0) return; + if (inl == 0) return 1; b=ctx->cipher->block_size; if (b > 1) @@ -204,13 +203,13 @@ void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, memcpy(&(ctx->buf[bl]),in,inl); ctx->buf_len=b; *outl=0; - return; + return 1; } keep_last=1; inl-=b; /* don't do the last block */ } } - EVP_EncryptUpdate(ctx,out,outl,in,inl); + if(!EVP_EncryptUpdate(ctx,out,outl,in,inl)) return 0; /* if we have 'decrypted' a multiple of block size, make sure * we have a copy of this last block */ @@ -225,6 +224,7 @@ void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, #endif ctx->buf_len=b; } + return 1; } int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) @@ -241,7 +241,7 @@ int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); return(0); } - EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0); + if(!EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0)) return 0; if (n != b) return(0); n=ctx->buf[b-1]; @@ -268,11 +268,14 @@ int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) return(1); } -void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) +int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) { if ((c->cipher != NULL) && (c->cipher->cleanup != NULL)) - c->cipher->cleanup(c); + { + if(!c->cipher->cleanup(c)) return 0; + } memset(c,0,sizeof(EVP_CIPHER_CTX)); + return 1; } int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen) -- 2.34.1