Don't clean up stuff twice.

This commit is contained in:
Ben Laurie 2001-09-26 15:15:03 +00:00
parent dbeac560aa
commit 0fea7ed4a4
2 changed files with 13 additions and 2 deletions

View File

@ -133,8 +133,10 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
{ {
return EVP_DigestInit_ex(ctx, type, NULL); return EVP_DigestInit_ex(ctx, type, NULL);
} }
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) 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 /* 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 * so this context may already have an ENGINE! Try to avoid releasing
* the previous handle, re-querying for an ENGINE, and having a * 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); ret=ctx->digest->final(ctx,md);
if (size != NULL) if (size != NULL)
*size=ctx->digest->md_size; *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); memset(ctx->md_data,0,ctx->digest->ctx_size);
return ret; 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, /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
* because sometimes only copies of the context are ever finalised. * 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); ctx->digest->cleanup(ctx);
if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) if (ctx->digest && ctx->digest->ctx_size && ctx->md_data)
{ {

View File

@ -271,6 +271,8 @@ struct env_md_ctx_st
#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called #define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called
* once only */ * once only */
#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been
* cleaned */
struct evp_cipher_st struct evp_cipher_st
{ {
@ -457,6 +459,8 @@ EVP_MD_CTX *EVP_MD_CTX_create(void);
void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in); int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);
#define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs)) #define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
#define EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
#define EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d, int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,