From e8330cf5ac62d693bd0921dbb5e9dd3f73019512 Mon Sep 17 00:00:00 2001 From: Ben Laurie Date: Fri, 7 Sep 2001 12:03:24 +0000 Subject: [PATCH] Add a cleanup function for MDs. --- crypto/evp/digest.c | 2 ++ crypto/evp/evp.h | 1 + crypto/evp/m_dss.c | 1 + crypto/evp/m_dss1.c | 1 + crypto/evp/m_md2.c | 1 + crypto/evp/m_md4.c | 1 + crypto/evp/m_md5.c | 1 + crypto/evp/m_mdc2.c | 1 + crypto/evp/m_null.c | 1 + crypto/evp/m_ripemd.c | 1 + crypto/evp/m_sha.c | 1 + crypto/evp/m_sha1.c | 1 + crypto/evp/openbsd_hw.c | 33 ++++++++++++++++++++++++++------- 13 files changed, 39 insertions(+), 7 deletions(-) diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index c81f6e6cf8..69a0bdbe34 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -165,6 +165,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) + ctx->digest->cleanup(ctx); if(ctx->digest && ctx->digest->ctx_size && ctx->md_data) { memset(ctx->md_data,0,ctx->digest->ctx_size); diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index 7f798388f0..de642c64c8 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -222,6 +222,7 @@ struct env_md_st int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count); int (*final)(EVP_MD_CTX *ctx,unsigned char *md); int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from); + int (*cleanup)(EVP_MD_CTX *ctx); /* FIXME: prototype these some day */ int (*sign)(); diff --git a/crypto/evp/m_dss.c b/crypto/evp/m_dss.c index f50b35b072..beb8d7fc5c 100644 --- a/crypto/evp/m_dss.c +++ b/crypto/evp/m_dss.c @@ -82,6 +82,7 @@ static const EVP_MD dsa_md= update, final, NULL, + NULL, EVP_PKEY_DSA_method, SHA_CBLOCK, sizeof(EVP_MD *)+sizeof(SHA_CTX), diff --git a/crypto/evp/m_dss1.c b/crypto/evp/m_dss1.c index be27d63da0..f5668ebda0 100644 --- a/crypto/evp/m_dss1.c +++ b/crypto/evp/m_dss1.c @@ -82,6 +82,7 @@ static const EVP_MD dss1_md= update, final, NULL, + NULL, EVP_PKEY_DSA_method, SHA_CBLOCK, sizeof(EVP_MD *)+sizeof(SHA_CTX), diff --git a/crypto/evp/m_md2.c b/crypto/evp/m_md2.c index 8f95541c6a..50914c83b3 100644 --- a/crypto/evp/m_md2.c +++ b/crypto/evp/m_md2.c @@ -83,6 +83,7 @@ static const EVP_MD md2_md= update, final, NULL, + NULL, EVP_PKEY_RSA_method, MD2_BLOCK, sizeof(EVP_MD *)+sizeof(MD2_CTX), diff --git a/crypto/evp/m_md4.c b/crypto/evp/m_md4.c index 11458ee1cd..8565e5d529 100644 --- a/crypto/evp/m_md4.c +++ b/crypto/evp/m_md4.c @@ -83,6 +83,7 @@ static const EVP_MD md4_md= update, final, NULL, + NULL, EVP_PKEY_RSA_method, MD4_CBLOCK, sizeof(EVP_MD *)+sizeof(MD4_CTX), diff --git a/crypto/evp/m_md5.c b/crypto/evp/m_md5.c index 69ec8aa027..b00a03e048 100644 --- a/crypto/evp/m_md5.c +++ b/crypto/evp/m_md5.c @@ -83,6 +83,7 @@ static const EVP_MD md5_md= update, final, NULL, + NULL, EVP_PKEY_RSA_method, MD5_CBLOCK, sizeof(EVP_MD *)+sizeof(MD5_CTX), diff --git a/crypto/evp/m_mdc2.c b/crypto/evp/m_mdc2.c index d36a6e30b9..9f6467c931 100644 --- a/crypto/evp/m_mdc2.c +++ b/crypto/evp/m_mdc2.c @@ -83,6 +83,7 @@ static const EVP_MD mdc2_md= update, final, NULL, + NULL, EVP_PKEY_RSA_ASN1_OCTET_STRING_method, MDC2_BLOCK, sizeof(EVP_MD *)+sizeof(MDC2_CTX), diff --git a/crypto/evp/m_null.c b/crypto/evp/m_null.c index fa3a0301d9..f6f0a1d2c0 100644 --- a/crypto/evp/m_null.c +++ b/crypto/evp/m_null.c @@ -81,6 +81,7 @@ static const EVP_MD null_md= update, final, NULL, + NULL, EVP_PKEY_NULL_method, 0, sizeof(EVP_MD *), diff --git a/crypto/evp/m_ripemd.c b/crypto/evp/m_ripemd.c index 0bfc04c12f..64725528dc 100644 --- a/crypto/evp/m_ripemd.c +++ b/crypto/evp/m_ripemd.c @@ -83,6 +83,7 @@ static const EVP_MD ripemd160_md= update, final, NULL, + NULL, EVP_PKEY_RSA_method, RIPEMD160_CBLOCK, sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX), diff --git a/crypto/evp/m_sha.c b/crypto/evp/m_sha.c index acb7a44c5e..10697c7ed3 100644 --- a/crypto/evp/m_sha.c +++ b/crypto/evp/m_sha.c @@ -82,6 +82,7 @@ static const EVP_MD sha_md= update, final, NULL, + NULL, EVP_PKEY_RSA_method, SHA_CBLOCK, sizeof(EVP_MD *)+sizeof(SHA_CTX), diff --git a/crypto/evp/m_sha1.c b/crypto/evp/m_sha1.c index ea54adad5b..d6be3502f0 100644 --- a/crypto/evp/m_sha1.c +++ b/crypto/evp/m_sha1.c @@ -82,6 +82,7 @@ static const EVP_MD sha1_md= update, final, NULL, + NULL, EVP_PKEY_RSA_method, SHA_CBLOCK, sizeof(EVP_MD *)+sizeof(SHA_CTX), diff --git a/crypto/evp/openbsd_hw.c b/crypto/evp/openbsd_hw.c index 550145e494..2e4ad10560 100644 --- a/crypto/evp/openbsd_hw.c +++ b/crypto/evp/openbsd_hw.c @@ -291,6 +291,17 @@ static int dev_crypto_init_digest(MD_DATA *md_data,int mac) return 1; } +static int dev_crypto_cleanup_digest(MD_DATA *md_data) + { + if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1) + { + err("CIOCFSESSION failed"); + return 0; + } + + return 1; + } + /* FIXME: if device can do chained MACs, then don't accumulate */ /* FIXME: move accumulation to the framework */ static int dev_crypto_md5_init(EVP_MD_CTX *ctx) @@ -346,7 +357,7 @@ static int do_digest(int ses,unsigned char *md,const void *data,int len) return 0; } } - printf("done\n"); + // printf("done\n"); return 1; } @@ -374,13 +385,15 @@ static int dev_crypto_md5_final(EVP_MD_CTX *ctx,unsigned char *md) if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT) { memcpy(md,md_data->md,MD5_DIGEST_LENGTH); - return 1; + ret=1; + } + else + { + ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len); + OPENSSL_free(md_data->data); + md_data->data=NULL; + md_data->len=0; } - - ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len); - OPENSSL_free(md_data->data); - md_data->data=NULL; - md_data->len=0; return ret; } @@ -399,6 +412,11 @@ static int dev_crypto_md5_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from) return 1; } +static int dev_crypto_md5_cleanup(EVP_MD_CTX *ctx) + { + return dev_crypto_cleanup_digest(ctx->md_data); + } + static const EVP_MD md5_md= { NID_md5, @@ -409,6 +427,7 @@ static const EVP_MD md5_md= dev_crypto_md5_update, dev_crypto_md5_final, dev_crypto_md5_copy, + dev_crypto_md5_cleanup, EVP_PKEY_RSA_method, MD5_CBLOCK, sizeof(MD_DATA), -- 2.25.1