aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/evp
diff options
context:
space:
mode:
authorRalf S. Engelschall <rse@openssl.org>1998-12-21 11:00:56 +0000
committerRalf S. Engelschall <rse@openssl.org>1998-12-21 11:00:56 +0000
commitdfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c (patch)
tree2f74e0cfd76a9e092548a9bf52e579aef984299b /crypto/evp
parent58964a492275ca9a59a0cd9c8155cb2491b4b909 (diff)
downloadopenssl-dfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c.tar.gz
Import of old SSLeay release: SSLeay 0.9.1b (unreleased)
Diffstat (limited to 'crypto/evp')
-rw-r--r--crypto/evp/abc.c124
-rw-r--r--crypto/evp/abcs.c108
-rw-r--r--crypto/evp/bio_enc.c7
-rw-r--r--crypto/evp/c_all.c60
-rw-r--r--crypto/evp/e_cbc_r2.c107
-rw-r--r--crypto/evp/e_cfb_r2.c4
-rw-r--r--crypto/evp/e_ecb_r2.c4
-rw-r--r--crypto/evp/e_ofb_r2.c4
-rw-r--r--crypto/evp/evp.err6
-rw-r--r--crypto/evp/evp.h28
-rw-r--r--crypto/evp/evp_enc.c2
-rw-r--r--crypto/evp/evp_err.c6
-rw-r--r--crypto/evp/evp_lib.c5
-rw-r--r--crypto/evp/names.c219
-rw-r--r--crypto/evp/p_lib.c2
15 files changed, 440 insertions, 246 deletions
diff --git a/crypto/evp/abc.c b/crypto/evp/abc.c
new file mode 100644
index 0000000000..d6cc1e1f6c
--- /dev/null
+++ b/crypto/evp/abc.c
@@ -0,0 +1,124 @@
+/* lib/evp/evp_err.c */
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ *
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to. The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * "This product includes cryptographic software written by
+ * Eric Young (eay@cryptsoft.com)"
+ * The word 'cryptographic' can be left out if the rouines from the library
+ * being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from
+ * the apps directory (application code) you must include an acknowledgement:
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+#include <stdio.h>
+#include "err.h"
+#include "evp.h"
+
+/* BEGIN ERROR CODES */
+#ifndef NO_ERR
+static ERR_STRING_DATA EVP_str_functs[]=
+ {
+{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
+{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
+{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
+{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
+{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
+{0,NULL},
+ };
+
+static ERR_STRING_DATA EVP_str_reasons[]=
+ {
+{EVP_R_BAD_DECRYPT ,"bad decrypt"},
+{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
+{EVP_R_IV_TOO_LARGE ,"iv too large"},
+{EVP_R_MISSING_PARMATERS ,"missing parmaters"},
+{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
+{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
+{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
+{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
+{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
+{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
+{0,NULL},
+ };
+
+#endif
+
+static int EVP_lib_error_code=0;
+
+void ERR_load_EVP_strings()
+ {
+ static int init=1;
+
+ if (EVP_lib_error_code == 0)
+ EVP_lib_error_code=ERR_get_next_error_library();
+
+ if (init);
+ {;
+ init=0;
+#ifndef NO_ERR
+ ERR_load_strings(EVP_lib_error_code,EVP_str_functs);
+ ERR_load_strings(EVP_lib_error_code,EVP_str_reasons);
+#endif
+
+ }
+ }
+
+void ERR_EVP_error(function,reason,file,line)
+int function;
+int reason;
+char *file;
+int line;
+ {
+ if (EVP_lib_error_code == 0)
+ EVP_lib_error_code=ERR_get_next_error_library();
+ ERR_PUT_error(EVP_lib_error_code,function,reason,file,line);
+ }
diff --git a/crypto/evp/abcs.c b/crypto/evp/abcs.c
new file mode 100644
index 0000000000..2b0a0ab93f
--- /dev/null
+++ b/crypto/evp/abcs.c
@@ -0,0 +1,108 @@
+/* lib/evp/evp_err.c */
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ *
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to. The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * "This product includes cryptographic software written by
+ * Eric Young (eay@cryptsoft.com)"
+ * The word 'cryptographic' can be left out if the rouines from the library
+ * being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from
+ * the apps directory (application code) you must include an acknowledgement:
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+#include <stdio.h>
+#include "err.h"
+#include "evp.h"
+
+/* BEGIN ERROR CODES */
+#ifndef NO_ERR
+static ERR_STRING_DATA EVP_str_functs[]=
+ {
+{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
+{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
+{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
+{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
+{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
+{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
+{0,NULL},
+ };
+
+static ERR_STRING_DATA EVP_str_reasons[]=
+ {
+{EVP_R_BAD_DECRYPT ,"bad decrypt"},
+{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
+{EVP_R_IV_TOO_LARGE ,"iv too large"},
+{EVP_R_MISSING_PARMATERS ,"missing parmaters"},
+{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
+{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
+{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
+{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
+{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
+{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
+{0,NULL},
+ };
+
+#endif
+
+void ERR_load_EVP_strings()
+ {
+ static int init=1;
+
+ if (init);
+ {;
+ init=0;
+#ifndef NO_ERR
+ ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
+ ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons);
+#endif
+
+ }
+ }
diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c
index 6c30ddfc54..ad09b94b1a 100644
--- a/crypto/evp/bio_enc.c
+++ b/crypto/evp/bio_enc.c
@@ -298,6 +298,7 @@ char *ptr;
BIO_ENC_CTX *ctx,*dctx;
long ret=1;
int i;
+ EVP_CIPHER_CTX **c_ctx;
ctx=(BIO_ENC_CTX *)b->ptr;
@@ -364,7 +365,11 @@ again:
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
BIO_copy_next_retry(b);
break;
-
+ case BIO_C_GET_CIPHER_CTX:
+ c_ctx=(EVP_CIPHER_CTX **)ptr;
+ (*c_ctx)= &(ctx->cipher);
+ b->init=1;
+ break;
case BIO_CTRL_DUP:
dbio=(BIO *)ptr;
dctx=(BIO_ENC_CTX *)dbio->ptr;
diff --git a/crypto/evp/c_all.c b/crypto/evp/c_all.c
index e77d1c896b..f2e0500dd3 100644
--- a/crypto/evp/c_all.c
+++ b/crypto/evp/c_all.c
@@ -79,16 +79,16 @@ void SSLeay_add_all_ciphers()
EVP_add_cipher(EVP_des_ede3_ofb());
EVP_add_cipher(EVP_desx_cbc());
- EVP_add_alias(SN_desx_cbc,"DESX");
- EVP_add_alias(SN_desx_cbc,"desx");
+ EVP_add_cipher_alias(SN_desx_cbc,"DESX");
+ EVP_add_cipher_alias(SN_desx_cbc,"desx");
EVP_add_cipher(EVP_des_cbc());
- EVP_add_alias(SN_des_cbc,"DES");
- EVP_add_alias(SN_des_cbc,"des");
+ EVP_add_cipher_alias(SN_des_cbc,"DES");
+ EVP_add_cipher_alias(SN_des_cbc,"des");
EVP_add_cipher(EVP_des_ede_cbc());
EVP_add_cipher(EVP_des_ede3_cbc());
- EVP_add_alias(SN_des_ede3_cbc,"DES3");
- EVP_add_alias(SN_des_ede3_cbc,"des3");
+ EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
+ EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
EVP_add_cipher(EVP_des_ecb());
EVP_add_cipher(EVP_des_ede());
@@ -105,8 +105,8 @@ void SSLeay_add_all_ciphers()
EVP_add_cipher(EVP_idea_cfb());
EVP_add_cipher(EVP_idea_ofb());
EVP_add_cipher(EVP_idea_cbc());
- EVP_add_alias(SN_idea_cbc,"IDEA");
- EVP_add_alias(SN_idea_cbc,"idea");
+ EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
+ EVP_add_cipher_alias(SN_idea_cbc,"idea");
#endif
#ifndef NO_RC2
@@ -115,8 +115,9 @@ void SSLeay_add_all_ciphers()
EVP_add_cipher(EVP_rc2_ofb());
EVP_add_cipher(EVP_rc2_cbc());
EVP_add_cipher(EVP_rc2_40_cbc());
- EVP_add_alias(SN_rc2_cbc,"RC2");
- EVP_add_alias(SN_rc2_cbc,"rc2");
+ EVP_add_cipher(EVP_rc2_64_cbc());
+ EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
+ EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
#endif
#ifndef NO_BLOWFISH
@@ -124,9 +125,9 @@ void SSLeay_add_all_ciphers()
EVP_add_cipher(EVP_bf_cfb());
EVP_add_cipher(EVP_bf_ofb());
EVP_add_cipher(EVP_bf_cbc());
- EVP_add_alias(SN_bf_cbc,"BF");
- EVP_add_alias(SN_bf_cbc,"bf");
- EVP_add_alias(SN_bf_cbc,"blowfish");
+ EVP_add_cipher_alias(SN_bf_cbc,"BF");
+ EVP_add_cipher_alias(SN_bf_cbc,"bf");
+ EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
#endif
#ifndef NO_CAST
@@ -134,10 +135,10 @@ void SSLeay_add_all_ciphers()
EVP_add_cipher(EVP_cast5_cfb());
EVP_add_cipher(EVP_cast5_ofb());
EVP_add_cipher(EVP_cast5_cbc());
- EVP_add_alias(SN_cast5_cbc,"CAST");
- EVP_add_alias(SN_cast5_cbc,"cast");
- EVP_add_alias(SN_cast5_cbc,"CAST-cbc");
- EVP_add_alias(SN_cast5_cbc,"cast-cbc");
+ EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
+ EVP_add_cipher_alias(SN_cast5_cbc,"cast");
+ EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
+ EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
#endif
#ifndef NO_RC5
@@ -145,10 +146,8 @@ void SSLeay_add_all_ciphers()
EVP_add_cipher(EVP_rc5_32_12_16_cfb());
EVP_add_cipher(EVP_rc5_32_12_16_ofb());
EVP_add_cipher(EVP_rc5_32_12_16_cbc());
- EVP_add_alias(SN_rc5_cbc,"rc5");
- EVP_add_alias(SN_rc5_cbc,"RC5");
- EVP_add_alias(SN_rc5_cbc,"rc5-cbc");
- EVP_add_alias(SN_rc5_cbc,"RC5-cbc");
+ EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
+ EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
#endif
}
@@ -160,8 +159,8 @@ void SSLeay_add_all_digests()
#endif
#ifndef NO_MD5
EVP_add_digest(EVP_md5());
- EVP_add_alias(SN_md5,"ssl2-md5");
- EVP_add_alias(SN_md5,"ssl3-md5");
+ EVP_add_digest_alias(SN_md5,"ssl2-md5");
+ EVP_add_digest_alias(SN_md5,"ssl3-md5");
#endif
#ifndef NO_SHA
EVP_add_digest(EVP_sha());
@@ -171,20 +170,21 @@ void SSLeay_add_all_digests()
#endif
#ifndef NO_SHA1
EVP_add_digest(EVP_sha1());
- EVP_add_alias(SN_sha1,"ssl3-sha1");
+ EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
+ EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
#ifndef NO_DSA
EVP_add_digest(EVP_dss1());
- EVP_add_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
- EVP_add_alias(SN_dsaWithSHA1,"DSS1");
- EVP_add_alias(SN_dsaWithSHA1,"dss1");
+ EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
+ EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
+ EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
#endif
#endif
#if !defined(NO_MDC2) && !defined(NO_DES)
EVP_add_digest(EVP_mdc2());
#endif
-#ifndef NO_RIPEMD160
+#ifndef NO_RMD160
EVP_add_digest(EVP_ripemd160());
- EVP_add_alias(SN_ripemd160,"ripemd");
- EVP_add_alias(SN_ripemd160,"rmd160");
+ EVP_add_digest_alias(SN_ripemd160,"ripemd");
+ EVP_add_digest_alias(SN_ripemd160,"rmd160");
#endif
}
diff --git a/crypto/evp/e_cbc_r2.c b/crypto/evp/e_cbc_r2.c
index 4f8002f16d..9175e53550 100644
--- a/crypto/evp/e_cbc_r2.c
+++ b/crypto/evp/e_cbc_r2.c
@@ -68,11 +68,25 @@ static void 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,
unsigned char *in, unsigned int inl);
+static int rc2_meth_to_magic(EVP_CIPHER *e);
+static EVP_CIPHER *rc2_magic_to_meth(int i);
+static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
+static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
+
#else
+
static void rc2_cbc_init_key();
static void rc2_cbc_cipher();
+static int rc2_meth_to_magic();
+static EVP_CIPHER *rc2_magic_to_meth();
+static int rc2_set_asn1_type_and_iv();
+static int rc2_get_asn1_type_and_iv();
#endif
+#define RC2_40_MAGIC 0xa0
+#define RC2_64_MAGIC 0x78
+#define RC2_128_MAGIC 0x3a
+
static EVP_CIPHER r2_cbc_cipher=
{
NID_rc2_cbc,
@@ -82,8 +96,21 @@ static EVP_CIPHER r2_cbc_cipher=
NULL,
sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)),
- EVP_CIPHER_get_asn1_iv,
- EVP_CIPHER_set_asn1_iv,
+ rc2_set_asn1_type_and_iv,
+ rc2_get_asn1_type_and_iv,
+ };
+
+static EVP_CIPHER r2_64_cbc_cipher=
+ {
+ NID_rc2_40_cbc,
+ 8,8 /* 64 bit */,8,
+ rc2_cbc_init_key,
+ rc2_cbc_cipher,
+ NULL,
+ sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)),
+ rc2_set_asn1_type_and_iv,
+ rc2_get_asn1_type_and_iv,
};
static EVP_CIPHER r2_40_cbc_cipher=
@@ -95,6 +122,8 @@ static EVP_CIPHER r2_40_cbc_cipher=
NULL,
sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)),
+ rc2_set_asn1_type_and_iv,
+ rc2_get_asn1_type_and_iv,
};
EVP_CIPHER *EVP_rc2_cbc()
@@ -102,6 +131,11 @@ EVP_CIPHER *EVP_rc2_cbc()
return(&r2_cbc_cipher);
}
+EVP_CIPHER *EVP_rc2_64_cbc()
+ {
+ return(&r2_64_cbc_cipher);
+ }
+
EVP_CIPHER *EVP_rc2_40_cbc()
{
return(&r2_40_cbc_cipher);
@@ -133,4 +167,73 @@ unsigned int inl;
ctx->encrypt);
}
+static int rc2_meth_to_magic(e)
+EVP_CIPHER *e;
+ {
+ int i;
+
+ i=EVP_CIPHER_key_length(e);
+ if (i == 128) return(RC2_128_MAGIC);
+ else if (i == 64) return(RC2_64_MAGIC);
+ else if (i == 40) return(RC2_40_MAGIC);
+ else return(0);
+ }
+
+static EVP_CIPHER *rc2_magic_to_meth(i)
+int i;
+ {
+ if (i == RC2_128_MAGIC) return(EVP_rc2_cbc());
+ else if (i == RC2_64_MAGIC) return(EVP_rc2_64_cbc());
+ else if (i == RC2_40_MAGIC) return(EVP_rc2_40_cbc());
+ else
+ {
+ EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE);
+ return(NULL);
+ }
+ }
+
+int rc2_get_asn1_type_and_iv(c,type)
+EVP_CIPHER_CTX *c;
+ASN1_TYPE *type;
+ {
+ long num=0;
+ int i=0,l;
+ EVP_CIPHER *e;
+
+ if (type != NULL)
+ {
+ l=EVP_CIPHER_CTX_iv_length(c);
+ i=ASN1_TYPE_get_int_octetstring(type,&num,c->oiv,l);
+ if (i != l)
+ return(-1);
+ else if (i > 0)
+ memcpy(c->iv,c->oiv,l);
+ e=rc2_magic_to_meth((int)num);
+ if (e == NULL)
+ return(-1);
+ if (e != EVP_CIPHER_CTX_cipher(c))
+ {
+ EVP_CIPHER_CTX_cipher(c)=e;
+ rc2_cbc_init_key(c,NULL,NULL,1);
+ }
+ }
+ return(i);
+ }
+
+static int rc2_set_asn1_type_and_iv(c,type)
+EVP_CIPHER_CTX *c;
+ASN1_TYPE *type;
+ {
+ long num;
+ int i=0,j;
+
+ if (type != NULL)
+ {
+ num=rc2_meth_to_magic(EVP_CIPHER_CTX_cipher(c));
+ j=EVP_CIPHER_CTX_iv_length(c);
+ i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j);
+ }
+ return(i);
+ }
+
#endif
diff --git a/crypto/evp/e_cfb_r2.c b/crypto/evp/e_cfb_r2.c
index af5a39d1f4..849be7e638 100644
--- a/crypto/evp/e_cfb_r2.c
+++ b/crypto/evp/e_cfb_r2.c
@@ -103,8 +103,8 @@ int enc;
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_RC2_KEY_SIZE,key,
- EVP_RC2_KEY_SIZE*8);
+ RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
+ key,EVP_CIPHER_CTX_key_length(ctx)*8);
}
static void rc2_cfb_cipher(ctx,out,in,inl)
diff --git a/crypto/evp/e_ecb_r2.c b/crypto/evp/e_ecb_r2.c
index e35b06dc6d..4e74af96bd 100644
--- a/crypto/evp/e_ecb_r2.c
+++ b/crypto/evp/e_ecb_r2.c
@@ -98,8 +98,8 @@ unsigned char *iv;
int enc;
{
if (key != NULL)
- RC2_set_key(&(ctx->c.rc2_ks),EVP_RC2_KEY_SIZE,key,
- EVP_RC2_KEY_SIZE*8);
+ RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
+ key,EVP_CIPHER_CTX_key_length(ctx)*8);
}
static void rc2_ecb_cipher(ctx,out,in,inl)
diff --git a/crypto/evp/e_ofb_r2.c b/crypto/evp/e_ofb_r2.c
index 0f6d729988..4ed67eacd5 100644
--- a/crypto/evp/e_ofb_r2.c
+++ b/crypto/evp/e_ofb_r2.c
@@ -103,8 +103,8 @@ int enc;
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_RC2_KEY_SIZE,key,
- EVP_RC2_KEY_SIZE*8);
+ RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
+ key,EVP_CIPHER_CTX_key_length(ctx)*8);
}
static void rc2_ofb_cipher(ctx,out,in,inl)
diff --git a/crypto/evp/evp.err b/crypto/evp/evp.err
index cfc17437bc..b6ed829482 100644
--- a/crypto/evp/evp.err
+++ b/crypto/evp/evp.err
@@ -10,6 +10,7 @@
#define EVP_F_EVP_PKEY_NEW 106
#define EVP_F_EVP_SIGNFINAL 107
#define EVP_F_EVP_VERIFYFINAL 108
+#define EVP_F_RC2_MAGIC_TO_METH 109
/* Reason codes. */
#define EVP_R_BAD_DECRYPT 100
@@ -20,5 +21,6 @@
#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
#define EVP_R_PUBLIC_KEY_NOT_RSA 106
#define EVP_R_UNSUPPORTED_CIPHER 107
-#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108
-#define EVP_R_WRONG_PUBLIC_KEY_TYPE 109
+#define EVP_R_UNSUPPORTED_KEY_SIZE 108
+#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
+#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h
index b39fad93a4..e6296ce834 100644
--- a/crypto/evp/evp.h
+++ b/crypto/evp/evp.h
@@ -72,7 +72,7 @@ extern "C" {
#if !defined(NO_SHA) || !defined(NO_SHA1)
#include "sha.h"
#endif
-#ifndef NO_RIPEMD
+#ifndef NO_RMD160
#include "ripemd.h"
#endif
#ifndef NO_DES
@@ -183,7 +183,7 @@ typedef struct evp_pkey_st
* This is required because for various smart-card perform the digest and
* signing/verification on-board. To handle this case, the specific
* EVP_MD and EVP_PKEY_METHODs need to be closely associated.
- * When a PKEY is created, it will have a EVP_PKEY_METHOD ossociated with it.
+ * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.
* This can either be software or a token to provide the required low level
* routines.
*/
@@ -296,7 +296,7 @@ typedef struct env_md_ctx_st
#ifndef NO_MD5
MD5_CTX md5;
#endif
-#ifndef NO_MD5
+#ifndef NO_RMD160
RIPEMD160_CTX ripemd160;
#endif
#if !defined(NO_SHA) || !defined(NO_SHA1)
@@ -445,9 +445,19 @@ typedef struct evp_Encode_Ctx_st
#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
+#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
+#define EVP_add_cipher_alias(n,alias) \
+ OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
+#define EVP_add_digest_alias(n,alias) \
+ OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
+#define EVP_delete_cipher_alias(alias) \
+ OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
+#define EVP_delete_digest_alias(alias) \
+ OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
+
#ifndef NOPROTO
void EVP_DigestInit(EVP_MD_CTX *ctx, EVP_MD *type);
@@ -556,6 +566,7 @@ EVP_CIPHER *EVP_idea_cbc(void);
EVP_CIPHER *EVP_rc2_ecb(void);
EVP_CIPHER *EVP_rc2_cbc(void);
EVP_CIPHER *EVP_rc2_40_cbc(void);
+EVP_CIPHER *EVP_rc2_64_cbc(void);
EVP_CIPHER *EVP_rc2_cfb(void);
EVP_CIPHER *EVP_rc2_ofb(void);
EVP_CIPHER *EVP_bf_ecb(void);
@@ -577,8 +588,6 @@ void SSLeay_add_all_digests(void);
int EVP_add_cipher(EVP_CIPHER *cipher);
int EVP_add_digest(EVP_MD *digest);
-int EVP_add_alias(char *name,char *alias);
-int EVP_delete_alias(char *name);
EVP_CIPHER *EVP_get_cipherbyname(char *name);
EVP_MD *EVP_get_digestbyname(char *name);
@@ -705,6 +714,7 @@ EVP_CIPHER *EVP_idea_cbc();
EVP_CIPHER *EVP_rc2_ecb();
EVP_CIPHER *EVP_rc2_cbc();
EVP_CIPHER *EVP_rc2_40_cbc();
+EVP_CIPHER *EVP_rc2_64_cbc();
EVP_CIPHER *EVP_rc2_cfb();
EVP_CIPHER *EVP_rc2_ofb();
EVP_CIPHER *EVP_bf_ecb();
@@ -726,8 +736,6 @@ void SSLeay_add_all_digests();
int EVP_add_cipher();
int EVP_add_digest();
-int EVP_add_alias();
-int EVP_delete_alias();
EVP_CIPHER *EVP_get_cipherbyname();
EVP_MD *EVP_get_digestbyname();
@@ -773,6 +781,7 @@ int EVP_CIPHER_get_asn1_iv();
#define EVP_F_EVP_PKEY_NEW 106
#define EVP_F_EVP_SIGNFINAL 107
#define EVP_F_EVP_VERIFYFINAL 108
+#define EVP_F_RC2_MAGIC_TO_METH 109
/* Reason codes. */
#define EVP_R_BAD_DECRYPT 100
@@ -783,8 +792,9 @@ int EVP_CIPHER_get_asn1_iv();
#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
#define EVP_R_PUBLIC_KEY_NOT_RSA 106
#define EVP_R_UNSUPPORTED_CIPHER 107
-#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108
-#define EVP_R_WRONG_PUBLIC_KEY_TYPE 109
+#define EVP_R_UNSUPPORTED_KEY_SIZE 108
+#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
+#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
#ifdef __cplusplus
}
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index 93cc3a9464..ea580b1df3 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -60,7 +60,7 @@
#include "cryptlib.h"
#include "evp.h"
-char *EVP_version="EVP part of SSLeay 0.9.0b 29-Jun-1998";
+char *EVP_version="EVP part of SSLeay 0.9.1a 06-Jul-1998";
void EVP_CIPHER_CTX_init(ctx)
EVP_CIPHER_CTX *ctx;
diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c
index 2b0a0ab93f..c7caa3b13b 100644
--- a/crypto/evp/evp_err.c
+++ b/crypto/evp/evp_err.c
@@ -72,6 +72,7 @@ static ERR_STRING_DATA EVP_str_functs[]=
{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
+{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"},
{0,NULL},
};
@@ -85,6 +86,7 @@ static ERR_STRING_DATA EVP_str_reasons[]=
{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
+{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"},
{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
{0,NULL},
@@ -96,8 +98,8 @@ void ERR_load_EVP_strings()
{
static int init=1;
- if (init);
- {;
+ if (init)
+ {
init=0;
#ifndef NO_ERR
ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c
index 69784eb555..729fc8f4e6 100644
--- a/crypto/evp/evp_lib.c
+++ b/crypto/evp/evp_lib.c
@@ -97,7 +97,10 @@ ASN1_TYPE *type;
{
l=EVP_CIPHER_CTX_iv_length(c);
i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
- memcpy(c->iv,c->oiv,l);
+ if (i != l)
+ return(-1);
+ else if (i > 0)
+ memcpy(c->iv,c->oiv,l);
}
return(i);
}
diff --git a/crypto/evp/names.c b/crypto/evp/names.c
index e0774da20d..4cc715606e 100644
--- a/crypto/evp/names.c
+++ b/crypto/evp/names.c
@@ -61,225 +61,60 @@
#include "evp.h"
#include "objects.h"
-typedef struct aliases_st {
- char *alias;
- /* This must be the last field becaue I will allocate things
- * so they go off the end of it */
- char name[4];
- } ALIASES;
-
-static STACK /* ALIASES */ *aliases=NULL;
-static STACK /* EVP_CIPHERS */ *ciphers=NULL;
-static STACK /* EVP_MD */ *digests=NULL;
-
-static int cipher_nid_cmp(a,b)
-EVP_CIPHER **a,**b;
- { return((*a)->nid - (*b)->nid); }
-
-static int digest_type_cmp(a,b)
-EVP_MD **a,**b;
- { return((*a)->pkey_type - (*b)->pkey_type); }
-
int EVP_add_cipher(c)
EVP_CIPHER *c;
{
- int i;
+ int r;
- if (ciphers == NULL)
- {
- ciphers=sk_new(cipher_nid_cmp);
- if (ciphers == NULL) return(0);
- }
- if ((i=sk_find(ciphers,(char *)c)) >= 0)
- {
- if (sk_value(ciphers,i) == (char *)c)
- return(1);
- sk_delete(ciphers,i);
- }
- return(sk_push(ciphers,(char *)c));
+ r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
+ if (r == 0) return(0);
+ r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
+ return(r);
}
int EVP_add_digest(md)
EVP_MD *md;
{
- int i;
- char *n;
+ int r;
+ char *name;
- if (digests == NULL)
- {
- digests=sk_new(digest_type_cmp);
- if (digests == NULL) return(0);
- }
- if ((i=sk_find(digests,(char *)md)) >= 0)
- {
- if (sk_value(digests,i) == (char *)md)
- return(1);
- sk_delete(digests,i);
- }
- if (md->type != md->pkey_type)
- {
- n=OBJ_nid2sn(md->pkey_type);
- EVP_add_alias(n,OBJ_nid2sn(md->type));
- EVP_add_alias(n,OBJ_nid2ln(md->type));
- }
- sk_push(digests,(char *)md);
- return(1);
- }
-
-static int alias_cmp(a,b)
-ALIASES **a,**b;
- {
- return(strcmp((*a)->alias,(*b)->alias));
- }
+ name=OBJ_nid2sn(md->type);
+ r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
+ if (r == 0) return(0);
+ r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
+ if (r == 0) return(0);
-int EVP_add_alias(name,aname)
-char *name;
-char *aname;
- {
- int l1,l2,i;
- ALIASES *a;
- char *p;
-
- if ((name == NULL) || (aname == NULL)) return(0);
- l1=strlen(name)+1;
- l2=strlen(aname)+1;
- i=sizeof(ALIASES)+l1+l2;
- if ((a=(ALIASES *)Malloc(i)) == NULL)
- return(0);
- strcpy(a->name,name);
- p= &(a->name[l1]);
- strcpy(p,aname);
- a->alias=p;
-
- if (aliases == NULL)
- {
- aliases=sk_new(alias_cmp);
- if (aliases == NULL) goto err;
- }
-
- if ((i=sk_find(aliases,(char *)a)) >= 0)
- {
- Free(sk_delete(aliases,i));
- }
- if (!sk_push(aliases,(char *)a)) goto err;
- return(1);
-err:
- return(0);
- }
-
-int EVP_delete_alias(name)
-char *name;
- {
- ALIASES a;
- int i;
-
- if (aliases != NULL)
+ if (md->type != md->pkey_type)
{
- a.alias=name;
- if ((i=sk_find(aliases,(char *)&a)) >= 0)
- {
- Free(sk_delete(aliases,i));
- return(1);
- }
+ r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
+ OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
+ if (r == 0) return(0);
+ r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
+ OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
}
- return(0);
+ return(r);
}
EVP_CIPHER *EVP_get_cipherbyname(name)
char *name;
{
- int nid,num=6,i;
- EVP_CIPHER c,*cp;
- ALIASES a,*ap;
+ EVP_CIPHER *cp;
- if (ciphers == NULL) return(NULL);
- for (;;)
- {
- if (num-- <= 0) return(NULL);
- if (aliases != NULL)
- {
- a.alias=name;
- i=sk_find(aliases,(char *)&a);
- if (i >= 0)
- {
- ap=(ALIASES *)sk_value(aliases,i);
- name=ap->name;
- continue;
- }
- }
-
- nid=OBJ_txt2nid(name);
- if (nid == NID_undef) return(NULL);
- c.nid=nid;
- i=sk_find(ciphers,(char *)&c);
- if (i >= 0)
- {
- cp=(EVP_CIPHER *)sk_value(ciphers,i);
- return(cp);
- }
- else
- return(NULL);
- }
+ cp=(EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
+ return(cp);
}
EVP_MD *EVP_get_digestbyname(name)
char *name;
{
- int nid,num=6,i;
- EVP_MD c,*cp;
- ALIASES a,*ap;
+ EVP_MD *cp;
- if (digests == NULL) return(NULL);
-
- for (;;)
- {
- if (num-- <= 0) return(NULL);
-
- if (aliases != NULL)
- {
- a.alias=name;
- i=sk_find(aliases,(char *)&a);
- if (i >= 0)
- {
- ap=(ALIASES *)sk_value(aliases,i);
- name=ap->name;
- continue;
- }
- }
-
- nid=OBJ_txt2nid(name);
- if (nid == NID_undef) return(NULL);
- c.pkey_type=nid;
- i=sk_find(digests,(char *)&c);
- if (i >= 0)
- {
- cp=(EVP_MD *)sk_value(digests,i);
- return(cp);
- }
- else
- return(NULL);
- }
+ cp=(EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
+ return(cp);
}
void EVP_cleanup()
{
- int i;
-
- if (aliases != NULL)
- {
- for (i=0; i<sk_num(aliases); i++)
- Free(sk_value(aliases,i));
- sk_free(aliases);
- aliases=NULL;
- }
- if (ciphers != NULL)
- {
- sk_free(ciphers);
- ciphers=NULL;
- }
- if (digests != NULL)
- {
- sk_free(digests);
- digests=NULL;
- }
+ OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
+ OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
}
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c
index 395351b373..581df867da 100644
--- a/crypto/evp/p_lib.c
+++ b/crypto/evp/p_lib.c
@@ -90,6 +90,8 @@ EVP_PKEY *pkey;
int EVP_PKEY_size(pkey)
EVP_PKEY *pkey;
{
+ if (pkey == NULL)
+ return(0);
#ifndef NO_RSA
if (pkey->type == EVP_PKEY_RSA)
return(RSA_size(pkey->pkey.rsa));