aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/evp/digest.c
diff options
context:
space:
mode:
authorBen Laurie <ben@openssl.org>2001-09-26 15:15:03 +0000
committerBen Laurie <ben@openssl.org>2001-09-26 15:15:03 +0000
commit0fea7ed4a449f503c7b265d0a1a6199745ea1a26 (patch)
treec85339d79e422b4d2f973f7b85461d13b47d2f84 /crypto/evp/digest.c
parentdbeac560aa111c9fb71e2c9993d59f264c3c0bd7 (diff)
downloadopenssl-0fea7ed4a449f503c7b265d0a1a6199745ea1a26.tar.gz
Don't clean up stuff twice.
Diffstat (limited to 'crypto/evp/digest.c')
-rw-r--r--crypto/evp/digest.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 5178df6eb2..aa1729012e 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -133,8 +133,10 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
{
return EVP_DigestInit_ex(ctx, type, NULL);
}
+
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
{
+ EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
/* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
* so this context may already have an ENGINE! Try to avoid releasing
* the previous handle, re-querying for an ENGINE, and having a
@@ -202,7 +204,11 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
ret=ctx->digest->final(ctx,md);
if (size != NULL)
*size=ctx->digest->md_size;
- /* FIXME: add a cleanup function to the ctx? */
+ if (ctx->digest->cleanup)
+ {
+ ctx->digest->cleanup(ctx);
+ EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
+ }
memset(ctx->md_data,0,ctx->digest->ctx_size);
return ret;
}
@@ -264,7 +270,8 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
/* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
* because sometimes only copies of the context are ever finalised.
*/
- if (ctx->digest && ctx->digest->cleanup)
+ if (ctx->digest && ctx->digest->cleanup
+ && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
ctx->digest->cleanup(ctx);
if (ctx->digest && ctx->digest->ctx_size && ctx->md_data)
{