diff options
author | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 10:56:39 +0000 |
---|---|---|
committer | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 10:56:39 +0000 |
commit | 58964a492275ca9a59a0cd9c8155cb2491b4b909 (patch) | |
tree | c7b16876a5789463bbbb468ef4829c8129b3d718 /crypto/evp | |
parent | d02b48c63a58ea4367a0e905979f140b7d090f86 (diff) |
Import of old SSLeay release: SSLeay 0.9.0b
Diffstat (limited to 'crypto/evp')
63 files changed, 2236 insertions, 317 deletions
diff --git a/crypto/evp/Makefile.ssl b/crypto/evp/Makefile.ssl index 20338119ef..8bf2516458 100644 --- a/crypto/evp/Makefile.ssl +++ b/crypto/evp/Makefile.ssl @@ -29,10 +29,13 @@ LIBSRC= encode.c digest.c evp_enc.c evp_key.c \ e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c \ e_ecb_r2.c e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c \ e_ecb_bf.c e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c \ + e_ecb_c.c e_cbc_c.c e_cfb_c.c e_ofb_c.c \ + e_ecb_r5.c e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c \ m_null.c m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c m_dss1.c m_mdc2.c \ - p_open.c p_seal.c p_sign.c p_verify.c p_lib.c \ + m_ripemd.c \ + p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \ bio_md.c bio_b64.c bio_enc.c $(ERRC).c e_null.c \ - c_all.c + c_all.c evp_lib.c LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ e_ecb_d.o e_cbc_d.o e_cfb_d.o e_ofb_d.o \ @@ -41,10 +44,13 @@ LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ e_cfb_3d.o e_ofb_3d.o e_xcbc_d.o \ e_ecb_r2.o e_cbc_r2.o e_cfb_r2.o e_ofb_r2.o \ e_ecb_bf.o e_cbc_bf.o e_cfb_bf.o e_ofb_bf.o \ + e_ecb_c.o e_cbc_c.o e_cfb_c.o e_ofb_c.o \ + e_ecb_r5.o e_cbc_r5.o e_cfb_r5.o e_ofb_r5.o \ m_null.o m_md2.o m_md5.o m_sha.o m_sha1.o m_dss.o m_dss1.o m_mdc2.o \ - p_open.o p_seal.o p_sign.o p_verify.o p_lib.o \ + m_ripemd.o \ + p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \ bio_md.o bio_b64.o bio_enc.o $(ERRC).o e_null.o \ - c_all.o + c_all.o evp_lib.o SRC= $(LIBSRC) @@ -100,6 +106,6 @@ clean: errors: perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl $(ERR).h $(ERRC).c + perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c # DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/crypto/evp/bio_b64.c b/crypto/evp/bio_b64.c index e362dc3bfe..73172b9a07 100644 --- a/crypto/evp/bio_b64.c +++ b/crypto/evp/bio_b64.c @@ -1,5 +1,5 @@ /* crypto/evp/bio_b64.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -81,6 +81,7 @@ static int b64_free(); #endif #define B64_BLOCK_SIZE 1024 +#define B64_BLOCK_SIZE2 768 #define B64_NONE 0 #define B64_ENCODE 1 #define B64_DECODE 2 @@ -155,7 +156,7 @@ BIO *b; char *out; int outl; { - int ret=0,i,ii,j,k,x,n,num; + int ret=0,i,ii,j,k,x,n,num,ret_code=0; BIO_B64_CTX *ctx; unsigned char *p,*q; @@ -169,6 +170,7 @@ int outl; ctx->encode=B64_DECODE; ctx->buf_len=0; ctx->buf_off=0; + ctx->tmp_len=0; EVP_DecodeInit(&(ctx->base64)); } @@ -192,6 +194,7 @@ int outl; /* At this point, we have room of outl bytes and an empty * buffer, so we should read in some more. */ + ret_code=0; while (outl > 0) { if (ctx->cont <= 0) break; @@ -201,16 +204,24 @@ int outl; if (i <= 0) { + ret_code=i; + /* Should be continue next time we are called? */ if (!BIO_should_retry(b->next_bio)) ctx->cont=i; + /* else we should continue when called again */ break; } i+=ctx->tmp_len; /* We need to scan, a line at a time until we * have a valid line if we are starting. */ - if (ctx->start) + if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)) + { + /* ctx->start=1; */ + ctx->tmp_len=0; + } + else if (ctx->start) { q=p=(unsigned char *)ctx->tmp; for (j=0; j<i; j++) @@ -273,13 +284,51 @@ int outl; else ctx->tmp_len=0; } - i=EVP_DecodeUpdate(&(ctx->base64), - (unsigned char *)ctx->buf,&ctx->buf_len, - (unsigned char *)ctx->tmp,i); + + if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) + { + int z,jj; + + jj=(i>>2)<<2; + z=EVP_DecodeBlock((unsigned char *)ctx->buf, + (unsigned char *)ctx->tmp,jj); + if (jj > 2) + { + if (ctx->tmp[jj-1] == '=') + { + z--; + if (ctx->tmp[jj-2] == '=') + z--; + } + } + /* z is now number of output bytes and jj is the + * number consumed */ + if (jj != i) + { + memcpy((unsigned char *)ctx->tmp, + (unsigned char *)&(ctx->tmp[jj]),i-jj); + ctx->tmp_len=i-jj; + } + ctx->buf_len=0; + if (z > 0) + { + ctx->buf_len=z; + i=1; + } + else + i=z; + } + else + { + i=EVP_DecodeUpdate(&(ctx->base64), + (unsigned char *)ctx->buf,&ctx->buf_len, + (unsigned char *)ctx->tmp,i); + } ctx->cont=i; ctx->buf_off=0; if (i < 0) { + ret_code=0; ctx->buf_len=0; break; } @@ -302,7 +351,7 @@ int outl; } BIO_clear_retry_flags(b); BIO_copy_next_retry(b); - return((ret == 0)?ctx->cont:ret); + return((ret == 0)?ret_code:ret); } static int b64_write(b,in,inl) @@ -321,6 +370,7 @@ int inl; ctx->encode=B64_ENCODE; ctx->buf_len=0; ctx->buf_off=0; + ctx->tmp_len=0; EVP_EncodeInit(&(ctx->base64)); } @@ -344,9 +394,41 @@ int inl; while (inl > 0) { n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl; - EVP_EncodeUpdate(&(ctx->base64), - (unsigned char *)ctx->buf,&ctx->buf_len, - (unsigned char *)in,n); + + if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) + { + if (ctx->tmp_len > 0) + { + n=3-ctx->tmp_len; + memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); + ctx->tmp_len+=n; + n=ctx->tmp_len; + if (n < 3) + break; + ctx->buf_len=EVP_EncodeBlock( + (unsigned char *)ctx->buf, + (unsigned char *)ctx->tmp,n); + } + else + { + if (n < 3) + { + memcpy(&(ctx->tmp[0]),in,n); + ctx->tmp_len=n; + break; + } + n-=n%3; + ctx->buf_len=EVP_EncodeBlock( + (unsigned char *)ctx->buf, + (unsigned char *)in,n); + } + } + else + { + EVP_EncodeUpdate(&(ctx->base64), + (unsigned char *)ctx->buf,&ctx->buf_len, + (unsigned char *)in,n); + } inl-=n; in+=n; @@ -419,7 +501,20 @@ again: break; } } - if (ctx->base64.num != 0) + if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) + { + if (ctx->tmp_len != 0) + { + ctx->buf_len=EVP_EncodeBlock( + (unsigned char *)ctx->buf, + (unsigned char *)ctx->tmp, + ctx->tmp_len); + ctx->buf_off=0; + ctx->tmp_len=0; + goto again; + } + } + else if (ctx->base64.num != 0) { ctx->buf_off=0; EVP_EncodeFinal(&(ctx->base64), diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c index 6020736fd0..6c30ddfc54 100644 --- a/crypto/evp/bio_enc.c +++ b/crypto/evp/bio_enc.c @@ -1,5 +1,5 @@ /* crypto/evp/bio_enc.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -116,6 +116,7 @@ BIO *bi; BIO_ENC_CTX *ctx; ctx=(BIO_ENC_CTX *)Malloc(sizeof(BIO_ENC_CTX)); + EVP_CIPHER_CTX_init(&ctx->cipher); if (ctx == NULL) return(0); ctx->buf_len=0; @@ -377,6 +378,26 @@ again: return(ret); } +/* +void BIO_set_cipher_ctx(b,c) +BIO *b; +EVP_CIPHER_ctx *c; + { + if (b == NULL) return; + + if ((b->callback != NULL) && + (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) + return; + + b->init=1; + ctx=(BIO_ENC_CTX *)b->ptr; + memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX)); + + if (b->callback != NULL) + b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); + } +*/ + void BIO_set_cipher(b,c,k,i,e) BIO *b; EVP_CIPHER *c; diff --git a/crypto/evp/bio_md.c b/crypto/evp/bio_md.c index 0d6508c988..fa5fdc055b 100644 --- a/crypto/evp/bio_md.c +++ b/crypto/evp/bio_md.c @@ -1,5 +1,5 @@ /* crypto/evp/bio_md.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/evp/c_all.c b/crypto/evp/c_all.c index b618d8d259..e77d1c896b 100644 --- a/crypto/evp/c_all.c +++ b/crypto/evp/c_all.c @@ -1,5 +1,5 @@ /* crypto/evp/c_all.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -97,6 +97,7 @@ void SSLeay_add_all_ciphers() #ifndef NO_RC4 EVP_add_cipher(EVP_rc4()); + EVP_add_cipher(EVP_rc4_40()); #endif #ifndef NO_IDEA @@ -113,6 +114,7 @@ void SSLeay_add_all_ciphers() EVP_add_cipher(EVP_rc2_cfb()); 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"); #endif @@ -126,6 +128,28 @@ void SSLeay_add_all_ciphers() EVP_add_alias(SN_bf_cbc,"bf"); EVP_add_alias(SN_bf_cbc,"blowfish"); #endif + +#ifndef NO_CAST + EVP_add_cipher(EVP_cast5_ecb()); + 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"); +#endif + +#ifndef NO_RC5 + EVP_add_cipher(EVP_rc5_32_12_16_ecb()); + 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"); +#endif } @@ -134,8 +158,10 @@ void SSLeay_add_all_digests() #ifndef NO_MD2 EVP_add_digest(EVP_md2()); #endif -#ifndef NO_MD2 +#ifndef NO_MD5 EVP_add_digest(EVP_md5()); + EVP_add_alias(SN_md5,"ssl2-md5"); + EVP_add_alias(SN_md5,"ssl3-md5"); #endif #ifndef NO_SHA EVP_add_digest(EVP_sha()); @@ -145,11 +171,20 @@ void SSLeay_add_all_digests() #endif #ifndef NO_SHA1 EVP_add_digest(EVP_sha1()); + EVP_add_alias(SN_sha1,"ssl3-sha1"); #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"); #endif #endif #if !defined(NO_MDC2) && !defined(NO_DES) EVP_add_digest(EVP_mdc2()); #endif +#ifndef NO_RIPEMD160 + EVP_add_digest(EVP_ripemd160()); + EVP_add_alias(SN_ripemd160,"ripemd"); + EVP_add_alias(SN_ripemd160,"rmd160"); +#endif } diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 035218d431..d65f0036f7 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -1,5 +1,5 @@ /* crypto/evp/digest.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/evp/e_cbc_3d.c b/crypto/evp/e_cbc_3d.c index 3749759e28..5761bf186a 100644 --- a/crypto/evp/e_cbc_3d.c +++ b/crypto/evp/e_cbc_3d.c @@ -1,5 +1,5 @@ /* crypto/evp/e_cbc_3d.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -80,6 +80,11 @@ static EVP_CIPHER d_cbc_ede_cipher2= 8,16,8, des_cbc_ede_init_key, des_cbc_ede_cipher, + NULL, + sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ + sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ede)), + EVP_CIPHER_get_asn1_iv, + EVP_CIPHER_set_asn1_iv, }; static EVP_CIPHER d_cbc_ede_cipher3= @@ -88,6 +93,11 @@ static EVP_CIPHER d_cbc_ede_cipher3= 8,24,8, des_cbc_ede3_init_key, des_cbc_ede_cipher, + NULL, + sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ + sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ede)), + EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, }; EVP_CIPHER *EVP_des_ede_cbc() @@ -107,8 +117,8 @@ unsigned char *iv; int enc; { if (iv != NULL) - memcpy(&(ctx->c.des_ede.oiv[0]),iv,8); - memcpy(&(ctx->c.des_ede.iv[0]),&(ctx->c.des_ede.oiv[0]),8); + memcpy(&(ctx->oiv[0]),iv,8); + memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (key != NULL) { @@ -127,8 +137,8 @@ unsigned char *iv; int enc; { if (iv != NULL) - memcpy(&(ctx->c.des_ede.oiv[0]),iv,8); - memcpy(&(ctx->c.des_ede.iv[0]),&(ctx->c.des_ede.oiv[0]),8); + memcpy(&(ctx->oiv[0]),iv,8); + memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (key != NULL) { @@ -148,6 +158,6 @@ unsigned int inl; (des_cblock *)in,(des_cblock *)out, (long)inl, ctx->c.des_ede.ks1, ctx->c.des_ede.ks2,ctx->c.des_ede.ks3, - (des_cblock *)&(ctx->c.des_ede.iv[0]), + (des_cblock *)&(ctx->iv[0]), ctx->encrypt); } diff --git a/crypto/evp/e_cbc_bf.c b/crypto/evp/e_cbc_bf.c index d6278e2488..be605f4a13 100644 --- a/crypto/evp/e_cbc_bf.c +++ b/crypto/evp/e_cbc_bf.c @@ -1,5 +1,5 @@ /* crypto/evp/e_cbc_bf.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -79,6 +79,11 @@ static EVP_CIPHER bfish_cbc_cipher= 8,EVP_BLOWFISH_KEY_SIZE,8, bf_cbc_init_key, bf_cbc_cipher, + NULL, + sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ + sizeof((((EVP_CIPHER_CTX *)NULL)->c.bf_ks)), + EVP_CIPHER_get_asn1_iv, + EVP_CIPHER_set_asn1_iv, }; EVP_CIPHER *EVP_bf_cbc() @@ -93,10 +98,10 @@ unsigned char *iv; int enc; { if (iv != NULL) - memcpy(&(ctx->c.bf_cbc.oiv[0]),iv,8); - memcpy(&(ctx->c.bf_cbc.iv[0]),&(ctx->c.bf_cbc.oiv[0]),8); + memcpy(&(ctx->oiv[0]),iv,8); + memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (key != NULL) - BF_set_key(&(ctx->c.bf_cbc.ks),EVP_BLOWFISH_KEY_SIZE,key); + BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); } static void bf_cbc_cipher(ctx,out,in,inl) @@ -107,7 +112,7 @@ unsigned int inl; { BF_cbc_encrypt( in,out,(long)inl, - &(ctx->c.bf_cbc.ks),&(ctx->c.bf_cbc.iv[0]), + &(ctx->c.bf_ks),&(ctx->iv[0]), ctx->encrypt); } diff --git a/crypto/evp/e_cbc_c.c b/crypto/evp/e_cbc_c.c new file mode 100644 index 0000000000..b50c7874b3 --- /dev/null +++ b/crypto/evp/e_cbc_c.c @@ -0,0 +1,119 @@ +/* crypto/evp/e_cbc_c.c */ +/* Copyright (C) 1995-1998 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 EXPR |