diff options
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r-- | src/lib/libcrypto/evp/digest.c | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp.h | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_enc.c | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_pbe.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_pkey.c | 2 |
5 files changed, 29 insertions, 6 deletions
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index b22eed4421..0623ddf1f0 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
@@ -248,6 +248,7 @@ int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
248 | 248 | ||
249 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | 249 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) |
250 | { | 250 | { |
251 | unsigned char *tmp_buf; | ||
251 | if ((in == NULL) || (in->digest == NULL)) | 252 | if ((in == NULL) || (in->digest == NULL)) |
252 | { | 253 | { |
253 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); | 254 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); |
@@ -262,15 +263,22 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
262 | } | 263 | } |
263 | #endif | 264 | #endif |
264 | 265 | ||
266 | if (out->digest == in->digest) | ||
267 | { | ||
268 | tmp_buf = out->md_data; | ||
269 | EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE); | ||
270 | } | ||
271 | else tmp_buf = NULL; | ||
265 | EVP_MD_CTX_cleanup(out); | 272 | EVP_MD_CTX_cleanup(out); |
266 | memcpy(out,in,sizeof *out); | 273 | memcpy(out,in,sizeof *out); |
267 | 274 | ||
268 | if (out->digest->ctx_size) | 275 | if (out->digest->ctx_size) |
269 | { | 276 | { |
270 | out->md_data=OPENSSL_malloc(out->digest->ctx_size); | 277 | if (tmp_buf) out->md_data = tmp_buf; |
278 | else out->md_data=OPENSSL_malloc(out->digest->ctx_size); | ||
271 | memcpy(out->md_data,in->md_data,out->digest->ctx_size); | 279 | memcpy(out->md_data,in->md_data,out->digest->ctx_size); |
272 | } | 280 | } |
273 | 281 | ||
274 | if (out->digest->copy) | 282 | if (out->digest->copy) |
275 | return out->digest->copy(out,in); | 283 | return out->digest->copy(out,in); |
276 | 284 | ||
@@ -308,7 +316,8 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
308 | if (ctx->digest && ctx->digest->cleanup | 316 | if (ctx->digest && ctx->digest->cleanup |
309 | && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED)) | 317 | && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED)) |
310 | ctx->digest->cleanup(ctx); | 318 | ctx->digest->cleanup(ctx); |
311 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) | 319 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data |
320 | && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) | ||
312 | { | 321 | { |
313 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); | 322 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); |
314 | OPENSSL_free(ctx->md_data); | 323 | OPENSSL_free(ctx->md_data); |
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h index 45a25f968d..4801d8eaa3 100644 --- a/src/lib/libcrypto/evp/evp.h +++ b/src/lib/libcrypto/evp/evp.h | |||
@@ -329,6 +329,8 @@ struct env_md_ctx_st | |||
329 | * once only */ | 329 | * once only */ |
330 | #define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been | 330 | #define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been |
331 | * cleaned */ | 331 | * cleaned */ |
332 | #define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data | ||
333 | * in EVP_MD_CTX_cleanup */ | ||
332 | 334 | ||
333 | struct evp_cipher_st | 335 | struct evp_cipher_st |
334 | { | 336 | { |
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index be0758a879..8ea5aa935d 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
@@ -148,7 +148,19 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
148 | #endif | 148 | #endif |
149 | 149 | ||
150 | ctx->cipher=cipher; | 150 | ctx->cipher=cipher; |
151 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); | 151 | if (ctx->cipher->ctx_size) |
152 | { | ||
153 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); | ||
154 | if (!ctx->cipher_data) | ||
155 | { | ||
156 | EVPerr(EVP_F_EVP_CIPHERINIT, ERR_R_MALLOC_FAILURE); | ||
157 | return 0; | ||
158 | } | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | ctx->cipher_data = NULL; | ||
163 | } | ||
152 | ctx->key_len = cipher->key_len; | 164 | ctx->key_len = cipher->key_len; |
153 | ctx->flags = 0; | 165 | ctx->flags = 0; |
154 | if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT) | 166 | if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT) |
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c index 0da88fdcff..91e545a141 100644 --- a/src/lib/libcrypto/evp/evp_pbe.c +++ b/src/lib/libcrypto/evp/evp_pbe.c | |||
@@ -87,7 +87,7 @@ int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | |||
87 | if (i == -1) { | 87 | if (i == -1) { |
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) strcpy (obj_tmp, "NULL"); | 90 | if (!pbe_obj) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp); |
91 | else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, 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; |
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c index 34b5b1d21c..eb481ec661 100644 --- a/src/lib/libcrypto/evp/evp_pkey.c +++ b/src/lib/libcrypto/evp/evp_pkey.c | |||
@@ -210,7 +210,7 @@ EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8) | |||
210 | #endif | 210 | #endif |
211 | default: | 211 | default: |
212 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); | 212 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); |
213 | if (!a->algorithm) strcpy (obj_tmp, "NULL"); | 213 | if (!a->algorithm) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp); |
214 | else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm); | 214 | else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm); |
215 | ERR_add_error_data(2, "TYPE=", obj_tmp); | 215 | ERR_add_error_data(2, "TYPE=", obj_tmp); |
216 | EVP_PKEY_free (pkey); | 216 | EVP_PKEY_free (pkey); |