diff options
Diffstat (limited to 'src/lib/libcrypto/evp/evp_enc.c')
| -rw-r--r-- | src/lib/libcrypto/evp/evp_enc.c | 55 |
1 files changed, 1 insertions, 54 deletions
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index eb279b2378..172d8b4019 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: evp_enc.c,v 1.54 2023/11/18 09:37:15 tb Exp $ */ | 1 | /* $OpenBSD: evp_enc.c,v 1.55 2023/11/19 15:46:09 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -68,10 +68,6 @@ | |||
| 68 | #include <openssl/err.h> | 68 | #include <openssl/err.h> |
| 69 | #include <openssl/evp.h> | 69 | #include <openssl/evp.h> |
| 70 | 70 | ||
| 71 | #ifndef OPENSSL_NO_ENGINE | ||
| 72 | #include <openssl/engine.h> | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #include "evp_local.h" | 71 | #include "evp_local.h" |
| 76 | 72 | ||
| 77 | int | 73 | int |
| @@ -94,15 +90,6 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | |||
| 94 | enc = 1; | 90 | enc = 1; |
| 95 | ctx->encrypt = enc; | 91 | ctx->encrypt = enc; |
| 96 | } | 92 | } |
| 97 | #ifndef OPENSSL_NO_ENGINE | ||
| 98 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | ||
| 99 | * so this context may already have an ENGINE! Try to avoid releasing | ||
| 100 | * the previous handle, re-querying for an ENGINE, and having a | ||
| 101 | * reinitialisation, when it may all be unnecessary. */ | ||
| 102 | if (ctx->engine && ctx->cipher && | ||
| 103 | (!cipher || (cipher && (cipher->nid == ctx->cipher->nid)))) | ||
| 104 | goto skip_to_init; | ||
| 105 | #endif | ||
| 106 | if (cipher) { | 93 | if (cipher) { |
| 107 | /* Ensure a context left lying around from last time is cleared | 94 | /* Ensure a context left lying around from last time is cleared |
| 108 | * (the previous check attempted to avoid this if the same | 95 | * (the previous check attempted to avoid this if the same |
| @@ -114,32 +101,6 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | |||
| 114 | ctx->encrypt = enc; | 101 | ctx->encrypt = enc; |
| 115 | ctx->flags = flags; | 102 | ctx->flags = flags; |
| 116 | } | 103 | } |
| 117 | #ifndef OPENSSL_NO_ENGINE | ||
| 118 | if (impl) { | ||
| 119 | if (!ENGINE_init(impl)) { | ||
| 120 | EVPerror(EVP_R_INITIALIZATION_ERROR); | ||
| 121 | return 0; | ||
| 122 | } | ||
| 123 | } else | ||
| 124 | /* Ask if an ENGINE is reserved for this job */ | ||
| 125 | impl = ENGINE_get_cipher_engine(cipher->nid); | ||
| 126 | if (impl) { | ||
| 127 | /* There's an ENGINE for this job ... (apparently) */ | ||
| 128 | const EVP_CIPHER *c = | ||
| 129 | ENGINE_get_cipher(impl, cipher->nid); | ||
| 130 | if (!c) { | ||
| 131 | EVPerror(EVP_R_INITIALIZATION_ERROR); | ||
| 132 | return 0; | ||
| 133 | } | ||
| 134 | /* We'll use the ENGINE's private cipher definition */ | ||
| 135 | cipher = c; | ||
| 136 | /* Store the ENGINE functional reference so we know | ||
| 137 | * 'cipher' came from an ENGINE and we need to release | ||
| 138 | * it when done. */ | ||
| 139 | ctx->engine = impl; | ||
| 140 | } else | ||
| 141 | ctx->engine = NULL; | ||
| 142 | #endif | ||
| 143 | 104 | ||
| 144 | ctx->cipher = cipher; | 105 | ctx->cipher = cipher; |
| 145 | if (ctx->cipher->ctx_size) { | 106 | if (ctx->cipher->ctx_size) { |
| @@ -163,9 +124,6 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | |||
| 163 | EVPerror(EVP_R_NO_CIPHER_SET); | 124 | EVPerror(EVP_R_NO_CIPHER_SET); |
| 164 | return 0; | 125 | return 0; |
| 165 | } | 126 | } |
| 166 | #ifndef OPENSSL_NO_ENGINE | ||
| 167 | skip_to_init: | ||
| 168 | #endif | ||
| 169 | /* we assume block size is a power of 2 in *cryptUpdate */ | 127 | /* we assume block size is a power of 2 in *cryptUpdate */ |
| 170 | if (ctx->cipher->block_size != 1 && | 128 | if (ctx->cipher->block_size != 1 && |
| 171 | ctx->cipher->block_size != 8 && | 129 | ctx->cipher->block_size != 8 && |
| @@ -614,10 +572,6 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | |||
| 614 | /* XXX - store size of cipher_data so we can always freezero(). */ | 572 | /* XXX - store size of cipher_data so we can always freezero(). */ |
| 615 | free(c->cipher_data); | 573 | free(c->cipher_data); |
| 616 | 574 | ||
| 617 | #ifndef OPENSSL_NO_ENGINE | ||
| 618 | ENGINE_finish(c->engine); | ||
| 619 | #endif | ||
| 620 | |||
| 621 | explicit_bzero(c, sizeof(EVP_CIPHER_CTX)); | 575 | explicit_bzero(c, sizeof(EVP_CIPHER_CTX)); |
| 622 | 576 | ||
| 623 | return 1; | 577 | return 1; |
| @@ -688,13 +642,6 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) | |||
| 688 | EVPerror(EVP_R_INPUT_NOT_INITIALIZED); | 642 | EVPerror(EVP_R_INPUT_NOT_INITIALIZED); |
| 689 | return 0; | 643 | return 0; |
| 690 | } | 644 | } |
| 691 | #ifndef OPENSSL_NO_ENGINE | ||
| 692 | /* Make sure it's safe to copy a cipher context using an ENGINE */ | ||
| 693 | if (in->engine && !ENGINE_init(in->engine)) { | ||
| 694 | EVPerror(ERR_R_ENGINE_LIB); | ||
| 695 | return 0; | ||
| 696 | } | ||
| 697 | #endif | ||
| 698 | 645 | ||
| 699 | EVP_CIPHER_CTX_cleanup(out); | 646 | EVP_CIPHER_CTX_cleanup(out); |
| 700 | memcpy(out, in, sizeof *out); | 647 | memcpy(out, in, sizeof *out); |
