|
@@ -375,6 +375,8 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
|
|
|
} else if (EVP_DigestSignInit(si->mctx, &si->pctx, md, NULL, pk) <=
|
|
|
0)
|
|
|
goto err;
|
|
|
+ else
|
|
|
+ EVP_MD_CTX_set_flags(si->mctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
|
|
|
}
|
|
|
|
|
|
if (!sd->signerInfos)
|
|
@@ -600,6 +602,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
|
|
|
unsigned char md[EVP_MAX_MD_SIZE];
|
|
|
unsigned int mdlen;
|
|
|
pctx = si->pctx;
|
|
|
+ si->pctx = NULL;
|
|
|
if (!EVP_DigestFinal_ex(mctx, md, &mdlen))
|
|
|
goto err;
|
|
|
siglen = EVP_PKEY_size(si->pkey);
|
|
@@ -680,6 +683,7 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
|
|
|
EVP_MD_CTX_reset(mctx);
|
|
|
if (EVP_DigestSignInit(mctx, &pctx, md, NULL, si->pkey) <= 0)
|
|
|
goto err;
|
|
|
+ EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
|
|
|
si->pctx = pctx;
|
|
|
}
|
|
|
|
|
@@ -745,8 +749,13 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
|
|
|
return -1;
|
|
|
}
|
|
|
mctx = si->mctx;
|
|
|
+ if (si->pctx != NULL) {
|
|
|
+ EVP_PKEY_CTX_free(si->pctx);
|
|
|
+ si->pctx = NULL;
|
|
|
+ }
|
|
|
if (EVP_DigestVerifyInit(mctx, &si->pctx, md, NULL, si->pkey) <= 0)
|
|
|
goto err;
|
|
|
+ EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
|
|
|
|
|
|
if (!cms_sd_asn1_ctrl(si, 1))
|
|
|
goto err;
|
|
@@ -859,8 +868,11 @@ int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
|
|
|
if (EVP_PKEY_CTX_set_signature_md(pkctx, md) <= 0)
|
|
|
goto err;
|
|
|
si->pctx = pkctx;
|
|
|
- if (!cms_sd_asn1_ctrl(si, 1))
|
|
|
+ if (!cms_sd_asn1_ctrl(si, 1)) {
|
|
|
+ si->pctx = NULL;
|
|
|
goto err;
|
|
|
+ }
|
|
|
+ si->pctx = NULL;
|
|
|
r = EVP_PKEY_verify(pkctx, si->signature->data,
|
|
|
si->signature->length, mval, mlen);
|
|
|
if (r <= 0) {
|