diff options
| author | markus <> | 2003-05-12 02:18:40 +0000 |
|---|---|---|
| committer | markus <> | 2003-05-12 02:18:40 +0000 |
| commit | d4fcd82bb7f6d603bd61e19a81ba97337b89dfca (patch) | |
| tree | d52e3a0f1f08f65ad283027e560e17ed0d720462 /src/lib/libcrypto/evp | |
| parent | 582bbd139cd2afd58d10dc051c5b0b989b441074 (diff) | |
| download | openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.gz openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.bz2 openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.zip | |
merge 0.9.7b with local changes; crank majors for libssl/libcrypto
Diffstat (limited to 'src/lib/libcrypto/evp')
| -rw-r--r-- | src/lib/libcrypto/evp/Makefile.ssl | 30 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/bio_b64.c | 1 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/bio_enc.c | 9 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/bio_ok.c | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/c_all.c | 6 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/digest.c | 17 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_aes.c | 1 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_idea.c | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_rc2.c | 1 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_rc4.c | 5 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/encode.c | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_acnf.c | 1 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_enc.c | 30 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_key.c | 6 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_lib.c | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_pbe.c | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_test.c | 58 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/p5_crpt.c | 8 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/p5_crpt2.c | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/p_open.c | 2 |
20 files changed, 119 insertions, 69 deletions
diff --git a/src/lib/libcrypto/evp/Makefile.ssl b/src/lib/libcrypto/evp/Makefile.ssl index 58843f61a9..b4172406ae 100644 --- a/src/lib/libcrypto/evp/Makefile.ssl +++ b/src/lib/libcrypto/evp/Makefile.ssl | |||
| @@ -70,7 +70,7 @@ links: | |||
| 70 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | 70 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile |
| 71 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | 71 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) |
| 72 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | 72 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) |
| 73 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TESTDATA) | 73 | cp $(TESTDATA) ../../test |
| 74 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | 74 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) |
| 75 | 75 | ||
| 76 | install: | 76 | install: |
| @@ -89,7 +89,7 @@ lint: | |||
| 89 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 89 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
| 90 | 90 | ||
| 91 | depend: | 91 | depend: |
| 92 | $(MAKEDEPEND) $(CFLAG) $(INCLUDES) $(DEPFLAG) $(LIBSRC) | 92 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC) |
| 93 | 93 | ||
| 94 | dclean: | 94 | dclean: |
| 95 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | 95 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new |
| @@ -496,21 +496,19 @@ evp_acnf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | |||
| 496 | evp_acnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | 496 | evp_acnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h |
| 497 | evp_acnf.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | 497 | evp_acnf.o: ../../include/openssl/des.h ../../include/openssl/des_old.h |
| 498 | evp_acnf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | 498 | evp_acnf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h |
| 499 | evp_acnf.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | 499 | evp_acnf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
| 500 | evp_acnf.o: ../../include/openssl/err.h ../../include/openssl/evp.h | 500 | evp_acnf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h |
| 501 | evp_acnf.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | 501 | evp_acnf.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h |
| 502 | evp_acnf.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | 502 | evp_acnf.o: ../../include/openssl/md4.h ../../include/openssl/md5.h |
| 503 | evp_acnf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | 503 | evp_acnf.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h |
| 504 | evp_acnf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | 504 | evp_acnf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h |
| 505 | evp_acnf.o: ../../include/openssl/opensslconf.h | ||
| 506 | evp_acnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | 505 | evp_acnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
| 507 | evp_acnf.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | 506 | evp_acnf.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h |
| 508 | evp_acnf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | 507 | evp_acnf.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h |
| 509 | evp_acnf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | 508 | evp_acnf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h |
| 510 | evp_acnf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | 509 | evp_acnf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h |
| 511 | evp_acnf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | 510 | evp_acnf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h |
| 512 | evp_acnf.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | 511 | evp_acnf.o: ../../include/openssl/ui_compat.h ../cryptlib.h evp_acnf.c |
| 513 | evp_acnf.o: ../cryptlib.h evp_acnf.c | ||
| 514 | evp_enc.o: ../../e_os.h ../../include/openssl/aes.h | 512 | evp_enc.o: ../../e_os.h ../../include/openssl/aes.h |
| 515 | evp_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | 513 | evp_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h |
| 516 | evp_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | 514 | evp_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h |
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c index f12eac1b55..6e550f6a43 100644 --- a/src/lib/libcrypto/evp/bio_b64.c +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
| @@ -165,6 +165,7 @@ static int b64_read(BIO *b, char *out, int outl) | |||
| 165 | { | 165 | { |
| 166 | i=ctx->buf_len-ctx->buf_off; | 166 | i=ctx->buf_len-ctx->buf_off; |
| 167 | if (i > outl) i=outl; | 167 | if (i > outl) i=outl; |
| 168 | OPENSSL_assert(ctx->buf_off+i < sizeof ctx->buf); | ||
| 168 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | 169 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); |
| 169 | ret=i; | 170 | ret=i; |
| 170 | out+=i; | 171 | out+=i; |
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c index 64fb2353af..ab81851503 100644 --- a/src/lib/libcrypto/evp/bio_enc.c +++ b/src/lib/libcrypto/evp/bio_enc.c | |||
| @@ -132,7 +132,7 @@ static int enc_free(BIO *a) | |||
| 132 | if (a == NULL) return(0); | 132 | if (a == NULL) return(0); |
| 133 | b=(BIO_ENC_CTX *)a->ptr; | 133 | b=(BIO_ENC_CTX *)a->ptr; |
| 134 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); | 134 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); |
| 135 | memset(a->ptr,0,sizeof(BIO_ENC_CTX)); | 135 | OPENSSL_cleanse(a->ptr,sizeof(BIO_ENC_CTX)); |
| 136 | OPENSSL_free(a->ptr); | 136 | OPENSSL_free(a->ptr); |
| 137 | a->ptr=NULL; | 137 | a->ptr=NULL; |
| 138 | a->init=0; | 138 | a->init=0; |
| @@ -271,7 +271,7 @@ static int enc_write(BIO *b, const char *in, int inl) | |||
| 271 | if (i <= 0) | 271 | if (i <= 0) |
| 272 | { | 272 | { |
| 273 | BIO_copy_next_retry(b); | 273 | BIO_copy_next_retry(b); |
| 274 | return(i); | 274 | return (ret == inl) ? i : ret - inl; |
| 275 | } | 275 | } |
| 276 | n-=i; | 276 | n-=i; |
| 277 | ctx->buf_off+=i; | 277 | ctx->buf_off+=i; |
| @@ -325,10 +325,7 @@ again: | |||
| 325 | { | 325 | { |
| 326 | i=enc_write(b,NULL,0); | 326 | i=enc_write(b,NULL,0); |
| 327 | if (i < 0) | 327 | if (i < 0) |
| 328 | { | 328 | return i; |
| 329 | ret=i; | ||
| 330 | break; | ||
| 331 | } | ||
| 332 | } | 329 | } |
| 333 | 330 | ||
| 334 | if (!ctx->finished) | 331 | if (!ctx->finished) |
diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c index d2be03be82..4e3f10141b 100644 --- a/src/lib/libcrypto/evp/bio_ok.c +++ b/src/lib/libcrypto/evp/bio_ok.c | |||
| @@ -211,7 +211,7 @@ static int ok_free(BIO *a) | |||
| 211 | { | 211 | { |
| 212 | if (a == NULL) return(0); | 212 | if (a == NULL) return(0); |
| 213 | EVP_MD_CTX_cleanup(&((BIO_OK_CTX *)a->ptr)->md); | 213 | EVP_MD_CTX_cleanup(&((BIO_OK_CTX *)a->ptr)->md); |
| 214 | memset(a->ptr,0,sizeof(BIO_OK_CTX)); | 214 | OPENSSL_cleanse(a->ptr,sizeof(BIO_OK_CTX)); |
| 215 | OPENSSL_free(a->ptr); | 215 | OPENSSL_free(a->ptr); |
| 216 | a->ptr=NULL; | 216 | a->ptr=NULL; |
| 217 | a->init=0; | 217 | a->init=0; |
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c index 3d59812e20..1b31a14e37 100644 --- a/src/lib/libcrypto/evp/c_all.c +++ b/src/lib/libcrypto/evp/c_all.c | |||
| @@ -73,5 +73,9 @@ void OPENSSL_add_all_algorithms_noconf(void) | |||
| 73 | { | 73 | { |
| 74 | OpenSSL_add_all_ciphers(); | 74 | OpenSSL_add_all_ciphers(); |
| 75 | OpenSSL_add_all_digests(); | 75 | OpenSSL_add_all_digests(); |
| 76 | ENGINE_setup_openbsd(); | 76 | #ifndef OPENSSL_NO_ENGINE |
| 77 | # if defined(__OpenBSD__) || defined(__FreeBSD__) | ||
| 78 | ENGINE_setup_bsd_cryptodev(); | ||
| 79 | # endif | ||
| 80 | #endif | ||
| 77 | } | 81 | } |
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index a969ac69ed..b22eed4421 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
| @@ -113,7 +113,9 @@ | |||
| 113 | #include "cryptlib.h" | 113 | #include "cryptlib.h" |
| 114 | #include <openssl/objects.h> | 114 | #include <openssl/objects.h> |
| 115 | #include <openssl/evp.h> | 115 | #include <openssl/evp.h> |
| 116 | #ifndef OPENSSL_NO_ENGINE | ||
| 116 | #include <openssl/engine.h> | 117 | #include <openssl/engine.h> |
| 118 | #endif | ||
| 117 | 119 | ||
| 118 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) | 120 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) |
| 119 | { | 121 | { |
| @@ -138,6 +140,7 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) | |||
| 138 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | 140 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) |
| 139 | { | 141 | { |
| 140 | EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); | 142 | EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); |
| 143 | #ifndef OPENSSL_NO_ENGINE | ||
| 141 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | 144 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts |
| 142 | * so this context may already have an ENGINE! Try to avoid releasing | 145 | * so this context may already have an ENGINE! Try to avoid releasing |
| 143 | * the previous handle, re-querying for an ENGINE, and having a | 146 | * the previous handle, re-querying for an ENGINE, and having a |
| @@ -183,11 +186,13 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
| 183 | else | 186 | else |
| 184 | ctx->engine = NULL; | 187 | ctx->engine = NULL; |
| 185 | } | 188 | } |
| 186 | else if(!ctx->digest) | 189 | else |
| 190 | if(!ctx->digest) | ||
| 187 | { | 191 | { |
| 188 | EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET); | 192 | EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET); |
| 189 | return 0; | 193 | return 0; |
| 190 | } | 194 | } |
| 195 | #endif | ||
| 191 | if (ctx->digest != type) | 196 | if (ctx->digest != type) |
| 192 | { | 197 | { |
| 193 | if (ctx->digest && ctx->digest->ctx_size) | 198 | if (ctx->digest && ctx->digest->ctx_size) |
| @@ -196,7 +201,9 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
| 196 | if (type->ctx_size) | 201 | if (type->ctx_size) |
| 197 | ctx->md_data=OPENSSL_malloc(type->ctx_size); | 202 | ctx->md_data=OPENSSL_malloc(type->ctx_size); |
| 198 | } | 203 | } |
| 204 | #ifndef OPENSSL_NO_ENGINE | ||
| 199 | skip_to_init: | 205 | skip_to_init: |
| 206 | #endif | ||
| 200 | return ctx->digest->init(ctx); | 207 | return ctx->digest->init(ctx); |
| 201 | } | 208 | } |
| 202 | 209 | ||
| @@ -219,6 +226,8 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | |||
| 219 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | 226 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) |
| 220 | { | 227 | { |
| 221 | int ret; | 228 | int ret; |
| 229 | |||
| 230 | OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); | ||
| 222 | ret=ctx->digest->final(ctx,md); | 231 | ret=ctx->digest->final(ctx,md); |
| 223 | if (size != NULL) | 232 | if (size != NULL) |
| 224 | *size=ctx->digest->md_size; | 233 | *size=ctx->digest->md_size; |
| @@ -244,12 +253,14 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
| 244 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); | 253 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); |
| 245 | return 0; | 254 | return 0; |
| 246 | } | 255 | } |
| 256 | #ifndef OPENSSL_NO_ENGINE | ||
| 247 | /* Make sure it's safe to copy a digest context using an ENGINE */ | 257 | /* Make sure it's safe to copy a digest context using an ENGINE */ |
| 248 | if (in->engine && !ENGINE_init(in->engine)) | 258 | if (in->engine && !ENGINE_init(in->engine)) |
| 249 | { | 259 | { |
| 250 | EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB); | 260 | EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB); |
| 251 | return 0; | 261 | return 0; |
| 252 | } | 262 | } |
| 263 | #endif | ||
| 253 | 264 | ||
| 254 | EVP_MD_CTX_cleanup(out); | 265 | EVP_MD_CTX_cleanup(out); |
| 255 | memcpy(out,in,sizeof *out); | 266 | memcpy(out,in,sizeof *out); |
| @@ -299,13 +310,15 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
| 299 | ctx->digest->cleanup(ctx); | 310 | ctx->digest->cleanup(ctx); |
| 300 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) | 311 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) |
| 301 | { | 312 | { |
| 302 | memset(ctx->md_data,0,ctx->digest->ctx_size); | 313 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); |
| 303 | OPENSSL_free(ctx->md_data); | 314 | OPENSSL_free(ctx->md_data); |
| 304 | } | 315 | } |
| 316 | #ifndef OPENSSL_NO_ENGINE | ||
| 305 | if(ctx->engine) | 317 | if(ctx->engine) |
| 306 | /* The EVP_MD we used belongs to an ENGINE, release the | 318 | /* The EVP_MD we used belongs to an ENGINE, release the |
| 307 | * functional reference we held for this reason. */ | 319 | * functional reference we held for this reason. */ |
| 308 | ENGINE_finish(ctx->engine); | 320 | ENGINE_finish(ctx->engine); |
| 321 | #endif | ||
| 309 | memset(ctx,'\0',sizeof *ctx); | 322 | memset(ctx,'\0',sizeof *ctx); |
| 310 | 323 | ||
| 311 | return 1; | 324 | return 1; |
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index c323fa2892..fe8bcda631 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
| @@ -52,7 +52,6 @@ | |||
| 52 | #include <openssl/evp.h> | 52 | #include <openssl/evp.h> |
| 53 | #include <openssl/err.h> | 53 | #include <openssl/err.h> |
| 54 | #include <string.h> | 54 | #include <string.h> |
| 55 | #include <assert.h> | ||
| 56 | #include <openssl/aes.h> | 55 | #include <openssl/aes.h> |
| 57 | #include "evp_locl.h" | 56 | #include "evp_locl.h" |
| 58 | 57 | ||
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c index ed838d3e62..b9efa75ae7 100644 --- a/src/lib/libcrypto/evp/e_idea.c +++ b/src/lib/libcrypto/evp/e_idea.c | |||
| @@ -109,7 +109,7 @@ static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
| 109 | 109 | ||
| 110 | idea_set_encrypt_key(key,&tmp); | 110 | idea_set_encrypt_key(key,&tmp); |
| 111 | idea_set_decrypt_key(&tmp,ctx->cipher_data); | 111 | idea_set_decrypt_key(&tmp,ctx->cipher_data); |
| 112 | memset((unsigned char *)&tmp,0, | 112 | OPENSSL_cleanse((unsigned char *)&tmp, |
| 113 | sizeof(IDEA_KEY_SCHEDULE)); | 113 | sizeof(IDEA_KEY_SCHEDULE)); |
| 114 | } | 114 | } |
| 115 | return 1; | 115 | return 1; |
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c index 4685198e2e..d42cbfd17e 100644 --- a/src/lib/libcrypto/evp/e_rc2.c +++ b/src/lib/libcrypto/evp/e_rc2.c | |||
| @@ -174,6 +174,7 @@ static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
| 174 | if (type != NULL) | 174 | if (type != NULL) |
| 175 | { | 175 | { |
| 176 | l=EVP_CIPHER_CTX_iv_length(c); | 176 | l=EVP_CIPHER_CTX_iv_length(c); |
| 177 | OPENSSL_assert(l <= sizeof iv); | ||
| 177 | i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); | 178 | i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); |
| 178 | if (i != l) | 179 | if (i != l) |
| 179 | return(-1); | 180 | return(-1); |
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c index 4064cc5fa0..d58f507837 100644 --- a/src/lib/libcrypto/evp/e_rc4.c +++ b/src/lib/libcrypto/evp/e_rc4.c | |||
| @@ -69,8 +69,6 @@ | |||
| 69 | 69 | ||
| 70 | typedef struct | 70 | typedef struct |
| 71 | { | 71 | { |
| 72 | /* FIXME: what is the key for? */ | ||
| 73 | unsigned char key[EVP_RC4_KEY_SIZE]; | ||
| 74 | RC4_KEY ks; /* working key */ | 72 | RC4_KEY ks; /* working key */ |
| 75 | } EVP_RC4_KEY; | 73 | } EVP_RC4_KEY; |
| 76 | 74 | ||
| @@ -121,9 +119,8 @@ const EVP_CIPHER *EVP_rc4_40(void) | |||
| 121 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 119 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
| 122 | const unsigned char *iv, int enc) | 120 | const unsigned char *iv, int enc) |
| 123 | { | 121 | { |
| 124 | memcpy(&data(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx)); | ||
| 125 | RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), | 122 | RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), |
| 126 | data(ctx)->key); | 123 | key); |
| 127 | return 1; | 124 | return 1; |
| 128 | } | 125 | } |
| 129 | 126 | ||
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c index 12c6379df1..08209357ce 100644 --- a/src/lib/libcrypto/evp/encode.c +++ b/src/lib/libcrypto/evp/encode.c | |||
| @@ -136,6 +136,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | |||
| 136 | 136 | ||
| 137 | *outl=0; | 137 | *outl=0; |
| 138 | if (inl == 0) return; | 138 | if (inl == 0) return; |
| 139 | OPENSSL_assert(ctx->length <= sizeof ctx->enc_data); | ||
| 139 | if ((ctx->num+inl) < ctx->length) | 140 | if ((ctx->num+inl) < ctx->length) |
| 140 | { | 141 | { |
| 141 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); | 142 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); |
| @@ -258,6 +259,7 @@ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | |||
| 258 | /* only save the good data :-) */ | 259 | /* only save the good data :-) */ |
| 259 | if (!B64_NOT_BASE64(v)) | 260 | if (!B64_NOT_BASE64(v)) |
| 260 | { | 261 | { |
| 262 | OPENSSL_assert(n < sizeof ctx->enc_data); | ||
| 261 | d[n++]=tmp; | 263 | d[n++]=tmp; |
| 262 | ln++; | 264 | ln++; |
| 263 | } | 265 | } |
diff --git a/src/lib/libcrypto/evp/evp_acnf.c b/src/lib/libcrypto/evp/evp_acnf.c index a68b979bdb..ff3e311cc5 100644 --- a/src/lib/libcrypto/evp/evp_acnf.c +++ b/src/lib/libcrypto/evp/evp_acnf.c | |||
| @@ -59,7 +59,6 @@ | |||
| 59 | #include "cryptlib.h" | 59 | #include "cryptlib.h" |
| 60 | #include <openssl/evp.h> | 60 | #include <openssl/evp.h> |
| 61 | #include <openssl/conf.h> | 61 | #include <openssl/conf.h> |
| 62 | #include <openssl/engine.h> | ||
| 63 | 62 | ||
| 64 | 63 | ||
| 65 | /* Load all algorithms and configure OpenSSL. | 64 | /* Load all algorithms and configure OpenSSL. |
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index 32a1c7a2e9..be0758a879 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
| @@ -60,11 +60,11 @@ | |||
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include <openssl/evp.h> | 61 | #include <openssl/evp.h> |
| 62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
| 63 | #ifndef OPENSSL_NO_ENGINE | ||
| 63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
| 65 | #endif | ||
| 64 | #include "evp_locl.h" | 66 | #include "evp_locl.h" |
| 65 | 67 | ||
| 66 | #include <assert.h> | ||
| 67 | |||
| 68 | const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; | 68 | const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; |
| 69 | 69 | ||
| 70 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) | 70 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) |
| @@ -93,6 +93,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
| 93 | enc = 1; | 93 | enc = 1; |
| 94 | ctx->encrypt = enc; | 94 | ctx->encrypt = enc; |
| 95 | } | 95 | } |
| 96 | #ifndef OPENSSL_NO_ENGINE | ||
| 96 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | 97 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts |
| 97 | * so this context may already have an ENGINE! Try to avoid releasing | 98 | * so this context may already have an ENGINE! Try to avoid releasing |
| 98 | * the previous handle, re-querying for an ENGINE, and having a | 99 | * the previous handle, re-querying for an ENGINE, and having a |
| @@ -100,6 +101,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
| 100 | if (ctx->engine && ctx->cipher && (!cipher || | 101 | if (ctx->engine && ctx->cipher && (!cipher || |
| 101 | (cipher && (cipher->nid == ctx->cipher->nid)))) | 102 | (cipher && (cipher->nid == ctx->cipher->nid)))) |
| 102 | goto skip_to_init; | 103 | goto skip_to_init; |
| 104 | #endif | ||
| 103 | if (cipher) | 105 | if (cipher) |
| 104 | { | 106 | { |
| 105 | /* Ensure a context left lying around from last time is cleared | 107 | /* Ensure a context left lying around from last time is cleared |
| @@ -109,6 +111,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
| 109 | 111 | ||
| 110 | /* Restore encrypt field: it is zeroed by cleanup */ | 112 | /* Restore encrypt field: it is zeroed by cleanup */ |
| 111 | ctx->encrypt = enc; | 113 | ctx->encrypt = enc; |
| 114 | #ifndef OPENSSL_NO_ENGINE | ||
| 112 | if(impl) | 115 | if(impl) |
| 113 | { | 116 | { |
| 114 | if (!ENGINE_init(impl)) | 117 | if (!ENGINE_init(impl)) |
| @@ -142,6 +145,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
| 142 | } | 145 | } |
| 143 | else | 146 | else |
| 144 | ctx->engine = NULL; | 147 | ctx->engine = NULL; |
| 148 | #endif | ||
| 145 | 149 | ||
| 146 | ctx->cipher=cipher; | 150 | ctx->cipher=cipher; |
| 147 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); | 151 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); |
| @@ -161,11 +165,13 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
| 161 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET); | 165 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET); |
| 162 | return 0; | 166 | return 0; |
| 163 | } | 167 | } |
| 168 | #ifndef OPENSSL_NO_ENGINE | ||
| 164 | skip_to_init: | 169 | skip_to_init: |
| 170 | #endif | ||
| 165 | /* we assume block size is a power of 2 in *cryptUpdate */ | 171 | /* we assume block size is a power of 2 in *cryptUpdate */ |
| 166 | assert(ctx->cipher->block_size == 1 | 172 | OPENSSL_assert(ctx->cipher->block_size == 1 |
| 167 | || ctx->cipher->block_size == 8 | 173 | || ctx->cipher->block_size == 8 |
| 168 | || ctx->cipher->block_size == 16); | 174 | || ctx->cipher->block_size == 16); |
| 169 | 175 | ||
| 170 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { | 176 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { |
| 171 | switch(EVP_CIPHER_CTX_mode(ctx)) { | 177 | switch(EVP_CIPHER_CTX_mode(ctx)) { |
| @@ -181,6 +187,7 @@ skip_to_init: | |||
| 181 | 187 | ||
| 182 | case EVP_CIPH_CBC_MODE: | 188 | case EVP_CIPH_CBC_MODE: |
| 183 | 189 | ||
| 190 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof ctx->iv); | ||
| 184 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); | 191 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); |
| 185 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); | 192 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); |
| 186 | break; | 193 | break; |
| @@ -237,7 +244,7 @@ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *imp | |||
| 237 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | 244 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, |
| 238 | const unsigned char *key, const unsigned char *iv) | 245 | const unsigned char *key, const unsigned char *iv) |
| 239 | { | 246 | { |
| 240 | return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 0); | 247 | return EVP_CipherInit(ctx, cipher, key, iv, 0); |
| 241 | } | 248 | } |
| 242 | 249 | ||
| 243 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | 250 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, |
| @@ -251,6 +258,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
| 251 | { | 258 | { |
| 252 | int i,j,bl; | 259 | int i,j,bl; |
| 253 | 260 | ||
| 261 | OPENSSL_assert(inl > 0); | ||
| 254 | if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) | 262 | if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) |
| 255 | { | 263 | { |
| 256 | if(ctx->cipher->do_cipher(ctx,out,in,inl)) | 264 | if(ctx->cipher->do_cipher(ctx,out,in,inl)) |
| @@ -266,6 +274,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
| 266 | } | 274 | } |
| 267 | i=ctx->buf_len; | 275 | i=ctx->buf_len; |
| 268 | bl=ctx->cipher->block_size; | 276 | bl=ctx->cipher->block_size; |
| 277 | OPENSSL_assert(bl <= sizeof ctx->buf); | ||
| 269 | if (i != 0) | 278 | if (i != 0) |
| 270 | { | 279 | { |
| 271 | if (i+inl < bl) | 280 | if (i+inl < bl) |
| @@ -314,6 +323,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
| 314 | int i,n,b,bl,ret; | 323 | int i,n,b,bl,ret; |
| 315 | 324 | ||
| 316 | b=ctx->cipher->block_size; | 325 | b=ctx->cipher->block_size; |
| 326 | OPENSSL_assert(b <= sizeof ctx->buf); | ||
| 317 | if (b == 1) | 327 | if (b == 1) |
| 318 | { | 328 | { |
| 319 | *outl=0; | 329 | *outl=0; |
| @@ -358,6 +368,7 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
| 358 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); | 368 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); |
| 359 | 369 | ||
| 360 | b=ctx->cipher->block_size; | 370 | b=ctx->cipher->block_size; |
| 371 | OPENSSL_assert(b <= sizeof ctx->final); | ||
| 361 | 372 | ||
| 362 | if(ctx->final_used) | 373 | if(ctx->final_used) |
| 363 | { | 374 | { |
| @@ -420,6 +431,7 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
| 420 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); | 431 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); |
| 421 | return(0); | 432 | return(0); |
| 422 | } | 433 | } |
| 434 | OPENSSL_assert(b <= sizeof ctx->final); | ||
| 423 | n=ctx->final[b-1]; | 435 | n=ctx->final[b-1]; |
| 424 | if (n > b) | 436 | if (n > b) |
| 425 | { | 437 | { |
| @@ -450,16 +462,18 @@ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | |||
| 450 | { | 462 | { |
| 451 | if(c->cipher->cleanup && !c->cipher->cleanup(c)) | 463 | if(c->cipher->cleanup && !c->cipher->cleanup(c)) |
| 452 | return 0; | 464 | return 0; |
| 453 | /* Zero cipher context data */ | 465 | /* Cleanse cipher context data */ |
| 454 | if (c->cipher_data) | 466 | if (c->cipher_data) |
| 455 | memset(c->cipher_data, 0, c->cipher->ctx_size); | 467 | OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size); |
| 456 | } | 468 | } |
| 457 | if (c->cipher_data) | 469 | if (c->cipher_data) |
| 458 | OPENSSL_free(c->cipher_data); | 470 | OPENSSL_free(c->cipher_data); |
| 471 | #ifndef OPENSSL_NO_ENGINE | ||
| 459 | if (c->engine) | 472 | if (c->engine) |
| 460 | /* The EVP_CIPHER we used belongs to an ENGINE, release the | 473 | /* The EVP_CIPHER we used belongs to an ENGINE, release the |
| 461 | * functional reference we held for this reason. */ | 474 | * functional reference we held for this reason. */ |
| 462 | ENGINE_finish(c->engine); | 475 | ENGINE_finish(c->engine); |
| 476 | #endif | ||
| 463 | memset(c,0,sizeof(EVP_CIPHER_CTX)); | 477 | memset(c,0,sizeof(EVP_CIPHER_CTX)); |
| 464 | return 1; | 478 | return 1; |
| 465 | } | 479 | } |
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c index 4271393069..5f387a94d3 100644 --- a/src/lib/libcrypto/evp/evp_key.c +++ b/src/lib/libcrypto/evp/evp_key.c | |||
| @@ -103,7 +103,7 @@ int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) | |||
| 103 | buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); | 103 | buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); |
| 104 | ret = UI_process(ui); | 104 | ret = UI_process(ui); |
| 105 | UI_free(ui); | 105 | UI_free(ui); |
| 106 | memset(buff,0,BUFSIZ); | 106 | OPENSSL_cleanse(buff,BUFSIZ); |
| 107 | return ret; | 107 | return ret; |
| 108 | } | 108 | } |
| 109 | 109 | ||
| @@ -118,6 +118,8 @@ int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, | |||
| 118 | 118 | ||
| 119 | nkey=type->key_len; | 119 | nkey=type->key_len; |
| 120 | niv=type->iv_len; | 120 | niv=type->iv_len; |
| 121 | OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH); | ||
| 122 | OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH); | ||
| 121 | 123 | ||
| 122 | if (data == NULL) return(nkey); | 124 | if (data == NULL) return(nkey); |
| 123 | 125 | ||
| @@ -166,7 +168,7 @@ int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, | |||
| 166 | if ((nkey == 0) && (niv == 0)) break; | 168 | if ((nkey == 0) && (niv == 0)) break; |
| 167 | } | 169 | } |
| 168 | EVP_MD_CTX_cleanup(&c); | 170 | EVP_MD_CTX_cleanup(&c); |
| 169 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); | 171 | OPENSSL_cleanse(&(md_buf[0]),EVP_MAX_MD_SIZE); |
| 170 | return(type->key_len); | 172 | return(type->key_len); |
| 171 | } | 173 | } |
| 172 | 174 | ||
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c index a431945ef5..52a3b287be 100644 --- a/src/lib/libcrypto/evp/evp_lib.c +++ b/src/lib/libcrypto/evp/evp_lib.c | |||
| @@ -90,6 +90,7 @@ int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
| 90 | if (type != NULL) | 90 | if (type != NULL) |
| 91 | { | 91 | { |
| 92 | l=EVP_CIPHER_CTX_iv_length(c); | 92 | l=EVP_CIPHER_CTX_iv_length(c); |
| 93 | OPENSSL_assert(l <= sizeof c->iv); | ||
| 93 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); | 94 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); |
| 94 | if (i != l) | 95 | if (i != l) |
| 95 | return(-1); | 96 | return(-1); |
| @@ -106,6 +107,7 @@ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
| 106 | if (type != NULL) | 107 | if (type != NULL) |
| 107 | { | 108 | { |
| 108 | j=EVP_CIPHER_CTX_iv_length(c); | 109 | j=EVP_CIPHER_CTX_iv_length(c); |
| 110 | OPENSSL_assert(j <= sizeof c->iv); | ||
| 109 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); | 111 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); |
| 110 | } | 112 | } |
| 111 | return(i); | 113 | return(i); |
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c index 4234cd7684..bc98e63363 100644 --- a/src/lib/libcrypto/evp/evp_pbe.c +++ b/src/lib/libcrypto/evp/evp_pbe.c | |||
| @@ -88,7 +88,7 @@ int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | |||
| 88 | char obj_tmp[80]; | 88 | char obj_tmp[80]; |
| 89 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); | 89 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); |
| 90 | if (!pbe_obj) strlcpy (obj_tmp, "NULL", sizeof obj_tmp); | 90 | if (!pbe_obj) strlcpy (obj_tmp, "NULL", sizeof obj_tmp); |
| 91 | else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj); | 91 | else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj); |
| 92 | ERR_add_error_data(2, "TYPE=", obj_tmp); | 92 | ERR_add_error_data(2, "TYPE=", obj_tmp); |
| 93 | return 0; | 93 | return 0; |
| 94 | } | 94 | } |
diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c index 90294ef686..28460173f7 100644 --- a/src/lib/libcrypto/evp/evp_test.c +++ b/src/lib/libcrypto/evp/evp_test.c | |||
| @@ -49,8 +49,14 @@ | |||
| 49 | 49 | ||
| 50 | #include <stdio.h> | 50 | #include <stdio.h> |
| 51 | #include <string.h> | 51 | #include <string.h> |
| 52 | |||
| 53 | #include "../e_os.h" | ||
| 54 | |||
| 52 | #include <openssl/evp.h> | 55 | #include <openssl/evp.h> |
| 56 | #ifndef OPENSSL_NO_ENGINE | ||
| 53 | #include <openssl/engine.h> | 57 | #include <openssl/engine.h> |
| 58 | #endif | ||
| 59 | #include <openssl/err.h> | ||
| 54 | #include <openssl/conf.h> | 60 | #include <openssl/conf.h> |
| 55 | 61 | ||
| 56 | static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) | 62 | static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) |
| @@ -78,7 +84,7 @@ static int convert(unsigned char *s) | |||
| 78 | if(!s[1]) | 84 | if(!s[1]) |
| 79 | { | 85 | { |
| 80 | fprintf(stderr,"Odd number of hex digits!"); | 86 | fprintf(stderr,"Odd number of hex digits!"); |
| 81 | exit(4); | 87 | EXIT(4); |
| 82 | } | 88 | } |
| 83 | sscanf((char *)s,"%2x",&n); | 89 | sscanf((char *)s,"%2x",&n); |
| 84 | *d=(unsigned char)n; | 90 | *d=(unsigned char)n; |
| @@ -120,6 +126,12 @@ static char *sstrsep(char **string, const char *delim) | |||
| 120 | static unsigned char *ustrsep(char **p,const char *sep) | 126 | static unsigned char *ustrsep(char **p,const char *sep) |
| 121 | { return (unsigned char *)sstrsep(p,sep); } | 127 | { return (unsigned char *)sstrsep(p,sep); } |
| 122 | 128 | ||
| 129 | static int test1_exit(int ec) | ||
| 130 | { | ||
| 131 | EXIT(ec); | ||
| 132 | return(0); /* To keep some compilers quiet */ | ||
| 133 | } | ||
| 134 | |||
| 123 | static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | 135 | static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, |
| 124 | const unsigned char *iv,int in, | 136 | const unsigned char *iv,int in, |
| 125 | const unsigned char *plaintext,int pn, | 137 | const unsigned char *plaintext,int pn, |
| @@ -142,7 +154,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
| 142 | { | 154 | { |
| 143 | fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn, | 155 | fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn, |
| 144 | c->key_len); | 156 | c->key_len); |
| 145 | exit(5); | 157 | test1_exit(5); |
| 146 | } | 158 | } |
| 147 | EVP_CIPHER_CTX_init(&ctx); | 159 | EVP_CIPHER_CTX_init(&ctx); |
| 148 | if (encdec != 0) | 160 | if (encdec != 0) |
| @@ -150,26 +162,26 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
| 150 | if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) | 162 | if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) |
| 151 | { | 163 | { |
| 152 | fprintf(stderr,"EncryptInit failed\n"); | 164 | fprintf(stderr,"EncryptInit failed\n"); |
| 153 | exit(10); | 165 | test1_exit(10); |
| 154 | } | 166 | } |
| 155 | EVP_CIPHER_CTX_set_padding(&ctx,0); | 167 | EVP_CIPHER_CTX_set_padding(&ctx,0); |
| 156 | 168 | ||
| 157 | if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) | 169 | if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) |
| 158 | { | 170 | { |
| 159 | fprintf(stderr,"Encrypt failed\n"); | 171 | fprintf(stderr,"Encrypt failed\n"); |
| 160 | exit(6); | 172 | test1_exit(6); |
| 161 | } | 173 | } |
| 162 | if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) | 174 | if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) |
| 163 | { | 175 | { |
| 164 | fprintf(stderr,"EncryptFinal failed\n"); | 176 | fprintf(stderr,"EncryptFinal failed\n"); |
| 165 | exit(7); | 177 | test1_exit(7); |
| 166 | } | 178 | } |
| 167 | 179 | ||
| 168 | if(outl+outl2 != cn) | 180 | if(outl+outl2 != cn) |
| 169 | { | 181 | { |
| 170 | fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", | 182 | fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", |
| 171 | outl+outl2,cn); | 183 | outl+outl2,cn); |
| 172 | exit(8); | 184 | test1_exit(8); |
| 173 | } | 185 | } |
| 174 | 186 | ||
| 175 | if(memcmp(out,ciphertext,cn)) | 187 | if(memcmp(out,ciphertext,cn)) |
| @@ -177,7 +189,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
| 177 | fprintf(stderr,"Ciphertext mismatch\n"); | 189 | fprintf(stderr,"Ciphertext mismatch\n"); |
| 178 | hexdump(stderr,"Got",out,cn); | 190 | hexdump(stderr,"Got",out,cn); |
| 179 | hexdump(stderr,"Expected",ciphertext,cn); | 191 | hexdump(stderr,"Expected",ciphertext,cn); |
| 180 | exit(9); | 192 | test1_exit(9); |
| 181 | } | 193 | } |
| 182 | } | 194 | } |
| 183 | 195 | ||
| @@ -186,26 +198,26 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
| 186 | if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) | 198 | if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) |
| 187 | { | 199 | { |
| 188 | fprintf(stderr,"DecryptInit failed\n"); | 200 | fprintf(stderr,"DecryptInit failed\n"); |
| 189 | exit(11); | 201 | test1_exit(11); |
| 190 | } | 202 | } |
| 191 | EVP_CIPHER_CTX_set_padding(&ctx,0); | 203 | EVP_CIPHER_CTX_set_padding(&ctx,0); |
| 192 | 204 | ||
| 193 | if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) | 205 | if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) |
| 194 | { | 206 | { |
| 195 | fprintf(stderr,"Decrypt failed\n"); | 207 | fprintf(stderr,"Decrypt failed\n"); |
| 196 | exit(6); | 208 | test1_exit(6); |
| 197 | } | 209 | } |
| 198 | if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) | 210 | if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) |
| 199 | { | 211 | { |
| 200 | fprintf(stderr,"DecryptFinal failed\n"); | 212 | fprintf(stderr,"DecryptFinal failed\n"); |
| 201 | exit(7); | 213 | test1_exit(7); |
| 202 | } | 214 | } |
| 203 | 215 | ||
| 204 | if(outl+outl2 != cn) | 216 | if(outl+outl2 != cn) |
| 205 | { | 217 | { |
| 206 | fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", | 218 | fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", |
| 207 | outl+outl2,cn); | 219 | outl+outl2,cn); |
| 208 | exit(8); | 220 | test1_exit(8); |
| 209 | } | 221 | } |
| 210 | 222 | ||
| 211 | if(memcmp(out,plaintext,cn)) | 223 | if(memcmp(out,plaintext,cn)) |
| @@ -213,7 +225,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
| 213 | fprintf(stderr,"Plaintext mismatch\n"); | 225 | fprintf(stderr,"Plaintext mismatch\n"); |
| 214 | hexdump(stderr,"Got",out,cn); | 226 | hexdump(stderr,"Got",out,cn); |
| 215 | hexdump(stderr,"Expected",plaintext,cn); | 227 | hexdump(stderr,"Expected",plaintext,cn); |
| 216 | exit(9); | 228 | test1_exit(9); |
| 217 | } | 229 | } |
| 218 | } | 230 | } |
| 219 | 231 | ||
| @@ -260,24 +272,24 @@ static int test_digest(const char *digest, | |||
| 260 | if(!EVP_DigestInit_ex(&ctx,d, NULL)) | 272 | if(!EVP_DigestInit_ex(&ctx,d, NULL)) |
| 261 | { | 273 | { |
| 262 | fprintf(stderr,"DigestInit failed\n"); | 274 | fprintf(stderr,"DigestInit failed\n"); |
| 263 | exit(100); | 275 | EXIT(100); |
| 264 | } | 276 | } |
| 265 | if(!EVP_DigestUpdate(&ctx,plaintext,pn)) | 277 | if(!EVP_DigestUpdate(&ctx,plaintext,pn)) |
| 266 | { | 278 | { |
| 267 | fprintf(stderr,"DigestUpdate failed\n"); | 279 | fprintf(stderr,"DigestUpdate failed\n"); |
| 268 | exit(101); | 280 | EXIT(101); |
| 269 | } | 281 | } |
| 270 | if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) | 282 | if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) |
| 271 | { | 283 | { |
| 272 | fprintf(stderr,"DigestFinal failed\n"); | 284 | fprintf(stderr,"DigestFinal failed\n"); |
| 273 | exit(101); | 285 | EXIT(101); |
| 274 | } | 286 | } |
| 275 | EVP_MD_CTX_cleanup(&ctx); | 287 | EVP_MD_CTX_cleanup(&ctx); |
| 276 | 288 | ||
| 277 | if(mdn != cn) | 289 | if(mdn != cn) |
| 278 | { | 290 | { |
| 279 | fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); | 291 | fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); |
| 280 | exit(102); | 292 | EXIT(102); |
| 281 | } | 293 | } |
| 282 | 294 | ||
| 283 | if(memcmp(md,ciphertext,cn)) | 295 | if(memcmp(md,ciphertext,cn)) |
| @@ -285,7 +297,7 @@ static int test_digest(const char *digest, | |||
| 285 | fprintf(stderr,"Digest mismatch\n"); | 297 | fprintf(stderr,"Digest mismatch\n"); |
| 286 | hexdump(stderr,"Got",md,cn); | 298 | hexdump(stderr,"Got",md,cn); |
| 287 | hexdump(stderr,"Expected",ciphertext,cn); | 299 | hexdump(stderr,"Expected",ciphertext,cn); |
| 288 | exit(103); | 300 | EXIT(103); |
| 289 | } | 301 | } |
| 290 | 302 | ||
| 291 | printf("\n"); | 303 | printf("\n"); |
| @@ -303,7 +315,7 @@ int main(int argc,char **argv) | |||
| 303 | if(argc != 2) | 315 | if(argc != 2) |
| 304 | { | 316 | { |
| 305 | fprintf(stderr,"%s <test file>\n",argv[0]); | 317 | fprintf(stderr,"%s <test file>\n",argv[0]); |
| 306 | exit(1); | 318 | EXIT(1); |
| 307 | } | 319 | } |
| 308 | CRYPTO_malloc_debug_init(); | 320 | CRYPTO_malloc_debug_init(); |
| 309 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); | 321 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); |
| @@ -315,17 +327,20 @@ int main(int argc,char **argv) | |||
| 315 | if(!f) | 327 | if(!f) |
| 316 | { | 328 | { |
| 317 | perror(szTestFile); | 329 | perror(szTestFile); |
| 318 | exit(2); | 330 | EXIT(2); |
| 319 | } | 331 | } |
| 320 | 332 | ||
| 321 | /* Load up the software EVP_CIPHER and EVP_MD definitions */ | 333 | /* Load up the software EVP_CIPHER and EVP_MD definitions */ |
| 322 | OpenSSL_add_all_ciphers(); | 334 | OpenSSL_add_all_ciphers(); |
| 323 | OpenSSL_add_all_digests(); | 335 | OpenSSL_add_all_digests(); |
| 336 | #ifndef OPENSSL_NO_ENGINE | ||
| 324 | /* Load all compiled-in ENGINEs */ | 337 | /* Load all compiled-in ENGINEs */ |
| 325 | ENGINE_load_builtin_engines(); | 338 | ENGINE_load_builtin_engines(); |
| 339 | #endif | ||
| 326 | #if 0 | 340 | #if 0 |
| 327 | OPENSSL_config(); | 341 | OPENSSL_config(); |
| 328 | #endif | 342 | #endif |
| 343 | #ifndef OPENSSL_NO_ENGINE | ||
| 329 | /* Register all available ENGINE implementations of ciphers and digests. | 344 | /* Register all available ENGINE implementations of ciphers and digests. |
| 330 | * This could perhaps be changed to "ENGINE_register_all_complete()"? */ | 345 | * This could perhaps be changed to "ENGINE_register_all_complete()"? */ |
| 331 | ENGINE_register_all_ciphers(); | 346 | ENGINE_register_all_ciphers(); |
| @@ -334,6 +349,7 @@ int main(int argc,char **argv) | |||
| 334 | * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if | 349 | * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if |
| 335 | * they weren't already initialised. */ | 350 | * they weren't already initialised. */ |
| 336 | /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ | 351 | /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ |
| 352 | #endif | ||
| 337 | 353 | ||
| 338 | for( ; ; ) | 354 | for( ; ; ) |
| 339 | { | 355 | { |
| @@ -371,11 +387,13 @@ int main(int argc,char **argv) | |||
| 371 | && !test_digest(cipher,plaintext,pn,ciphertext,cn)) | 387 | && !test_digest(cipher,plaintext,pn,ciphertext,cn)) |
| 372 | { | 388 | { |
| 373 | fprintf(stderr,"Can't find %s\n",cipher); | 389 | fprintf(stderr,"Can't find %s\n",cipher); |
| 374 | exit(3); | 390 | EXIT(3); |
| 375 | } | 391 | } |
| 376 | } | 392 | } |
| 377 | 393 | ||
| 394 | #ifndef OPENSSL_NO_ENGINE | ||
| 378 | ENGINE_cleanup(); | 395 | ENGINE_cleanup(); |
| 396 | #endif | ||
| 379 | EVP_cleanup(); | 397 | EVP_cleanup(); |
| 380 | CRYPTO_cleanup_all_ex_data(); | 398 | CRYPTO_cleanup_all_ex_data(); |
| 381 | ERR_remove_state(0); | 399 | ERR_remove_state(0); |
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c index 27a8286489..a1874e83b2 100644 --- a/src/lib/libcrypto/evp/p5_crpt.c +++ b/src/lib/libcrypto/evp/p5_crpt.c | |||
| @@ -140,12 +140,14 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen, | |||
| 140 | EVP_DigestFinal_ex (&ctx, md_tmp, NULL); | 140 | EVP_DigestFinal_ex (&ctx, md_tmp, NULL); |
| 141 | } | 141 | } |
| 142 | EVP_MD_CTX_cleanup(&ctx); | 142 | EVP_MD_CTX_cleanup(&ctx); |
| 143 | OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= sizeof md_tmp); | ||
| 143 | memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); | 144 | memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); |
| 145 | OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16); | ||
| 144 | memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), | 146 | memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), |
| 145 | EVP_CIPHER_iv_length(cipher)); | 147 | EVP_CIPHER_iv_length(cipher)); |
| 146 | EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de); | 148 | EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de); |
| 147 | memset(md_tmp, 0, EVP_MAX_MD_SIZE); | 149 | OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE); |
| 148 | memset(key, 0, EVP_MAX_KEY_LENGTH); | 150 | OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); |
| 149 | memset(iv, 0, EVP_MAX_IV_LENGTH); | 151 | OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); |
| 150 | return 1; | 152 | return 1; |
| 151 | } | 153 | } |
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c index 7485d6a278..1f94e1ef88 100644 --- a/src/lib/libcrypto/evp/p5_crpt2.c +++ b/src/lib/libcrypto/evp/p5_crpt2.c | |||
| @@ -190,6 +190,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
| 190 | goto err; | 190 | goto err; |
| 191 | } | 191 | } |
| 192 | keylen = EVP_CIPHER_CTX_key_length(ctx); | 192 | keylen = EVP_CIPHER_CTX_key_length(ctx); |
| 193 | OPENSSL_assert(keylen <= sizeof key); | ||
| 193 | 194 | ||
| 194 | /* Now decode key derivation function */ | 195 | /* Now decode key derivation function */ |
| 195 | 196 | ||
| @@ -230,7 +231,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
| 230 | iter = ASN1_INTEGER_get(kdf->iter); | 231 | iter = ASN1_INTEGER_get(kdf->iter); |
| 231 | PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); | 232 | PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); |
| 232 | EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); | 233 | EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); |
| 233 | memset(key, 0, keylen); | 234 | OPENSSL_cleanse(key, keylen); |
| 234 | PBKDF2PARAM_free(kdf); | 235 | PBKDF2PARAM_free(kdf); |
| 235 | return 1; | 236 | return 1; |
| 236 | 237 | ||
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c index 6976f2a867..5a933d1cda 100644 --- a/src/lib/libcrypto/evp/p_open.c +++ b/src/lib/libcrypto/evp/p_open.c | |||
| @@ -101,7 +101,7 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char *ek, | |||
| 101 | 101 | ||
| 102 | ret=1; | 102 | ret=1; |
| 103 | err: | 103 | err: |
| 104 | if (key != NULL) memset(key,0,size); | 104 | if (key != NULL) OPENSSL_cleanse(key,size); |
| 105 | OPENSSL_free(key); | 105 | OPENSSL_free(key); |
| 106 | return(ret); | 106 | return(ret); |
| 107 | } | 107 | } |
