diff --git a/lib/hcrypto/evp-pkcs11.c b/lib/hcrypto/evp-pkcs11.c index ea47dd871..7d792b84d 100644 --- a/lib/hcrypto/evp-pkcs11.c +++ b/lib/hcrypto/evp-pkcs11.c @@ -362,12 +362,18 @@ p11_cleanup(EVP_CIPHER_CTX *ctx) return 1; } +static int +p11_md_cleanup(EVP_MD_CTX *ctx); + static int p11_md_hash_init(CK_MECHANISM_TYPE mechanismType, EVP_MD_CTX *ctx) { struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx; CK_RV rv; + if (p11ctx->hSession != CK_INVALID_HANDLE) + p11_md_cleanup(ctx); + rv = p11_session_init(mechanismType, &p11ctx->hSession); if (rv == CKR_OK) { CK_MECHANISM mechanism = { mechanismType, NULL, 0 };