diff options
Diffstat (limited to 'src/lib/libcrypto/evp/digest.c')
-rw-r--r-- | src/lib/libcrypto/evp/digest.c | 15 |
1 files changed, 12 insertions, 3 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); |