PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
if (!ossl_prov_is_running()
- || pdsactx == NULL
- || vdsa == NULL
- || !DSA_up_ref(vdsa))
+ || pdsactx == NULL)
return 0;
- DSA_free(pdsactx->dsa);
- pdsactx->dsa = vdsa;
+
+ if (vdsa == NULL && pdsactx->dsa == NULL) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
+ return 0;
+ }
+
+ if (vdsa != NULL) {
+ if (!ossl_dsa_check_key(pdsactx->libctx, vdsa,
+ operation == EVP_PKEY_OP_SIGN)) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
+ return 0;
+ }
+ if (!DSA_up_ref(vdsa))
+ return 0;
+ DSA_free(pdsactx->dsa);
+ pdsactx->dsa = vdsa;
+ }
+
pdsactx->operation = operation;
if (!dsa_set_ctx_params(pdsactx, params))
return 0;
- if (!ossl_dsa_check_key(pdsactx->libctx, vdsa,
- operation == EVP_PKEY_OP_SIGN)) {
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
- return 0;
- }
return 1;
}
return 0;
pdsactx->flag_allow_md = 0;
- pdsactx->mdctx = EVP_MD_CTX_new();
- if (pdsactx->mdctx == NULL)
- goto error;
+
+ if (pdsactx->mdctx == NULL) {
+ pdsactx->mdctx = EVP_MD_CTX_new();
+ if (pdsactx->mdctx == NULL)
+ goto error;
+ }
if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
goto error;
error:
EVP_MD_CTX_free(pdsactx->mdctx);
- EVP_MD_free(pdsactx->md);
pdsactx->mdctx = NULL;
- pdsactx->md = NULL;
return 0;
}
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
if (!ossl_prov_is_running()
- || ctx == NULL
- || ec == NULL
- || !EC_KEY_up_ref(ec))
+ || ctx == NULL)
return 0;
- EC_KEY_free(ctx->ec);
- ctx->ec = ec;
+
+ if (ec == NULL && ctx->ec == NULL) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
+ return 0;
+ }
+
+ if (ec != NULL) {
+ if (!ossl_ec_check_key(ctx->libctx, ec, operation == EVP_PKEY_OP_SIGN))
+ return 0;
+ if (!EC_KEY_up_ref(ec))
+ return 0;
+ EC_KEY_free(ctx->ec);
+ ctx->ec = ec;
+ }
+
ctx->operation = operation;
+
if (!ecdsa_set_ctx_params(ctx, params))
return 0;
- return ossl_ec_check_key(ctx->libctx, ec, operation == EVP_PKEY_OP_SIGN);
+
+ return 1;
}
static int ecdsa_sign_init(void *vctx, void *ec, const OSSL_PARAM params[])
return 0;
ctx->flag_allow_md = 0;
- ctx->mdctx = EVP_MD_CTX_new();
- if (ctx->mdctx == NULL)
- goto error;
+
+ if (ctx->mdctx == NULL) {
+ ctx->mdctx = EVP_MD_CTX_new();
+ if (ctx->mdctx == NULL)
+ goto error;
+ }
if (!EVP_DigestInit_ex2(ctx->mdctx, ctx->md, params))
goto error;
return 1;
error:
EVP_MD_CTX_free(ctx->mdctx);
- EVP_MD_free(ctx->md);
ctx->mdctx = NULL;
- ctx->md = NULL;
return 0;
}
return 0;
}
+ if (edkey == NULL) {
+ if (peddsactx->key != NULL)
+ /* there is nothing to do on reinit */
+ return 1;
+ ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
+ return 0;
+ }
+
if (!ossl_ecx_key_up_ref(edkey)) {
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
return 0;
default:
/* Should never happen */
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
+ ossl_ecx_key_free(edkey);
return 0;
}
if (ret && WPACKET_finish(&pkt)) {
#include <openssl/core_names.h>
#include <openssl/params.h>
#include <openssl/err.h>
+#include <openssl/proverr.h>
#ifndef FIPS_MODULE
# include <openssl/engine.h>
#endif
const char *ciphername = NULL, *engine = NULL;
if (!ossl_prov_is_running()
- || pmacctx == NULL
- || (pmacctx->key == NULL && vkey == NULL))
+ || pmacctx == NULL)
return 0;
+ if (pmacctx->key == NULL && vkey == NULL) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
+ return 0;
+ }
+
if (vkey != NULL) {
if (!ossl_mac_key_up_ref(vkey))
return 0;
{
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
- if (!ossl_prov_is_running())
+ if (!ossl_prov_is_running() || prsactx == NULL)
return 0;
- if (prsactx == NULL || vrsa == NULL)
+ if (vrsa == NULL && prsactx->rsa == NULL) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
return 0;
+ }
- if (!ossl_rsa_check_key(prsactx->libctx, vrsa, operation))
- return 0;
+ if (vrsa != NULL) {
+ if (!ossl_rsa_check_key(prsactx->libctx, vrsa, operation))
+ return 0;
+
+ if (!RSA_up_ref(vrsa))
+ return 0;
+ RSA_free(prsactx->rsa);
+ prsactx->rsa = vrsa;
+ }
- if (!RSA_up_ref(vrsa))
- return 0;
- RSA_free(prsactx->rsa);
- prsactx->rsa = vrsa;
prsactx->operation = operation;
if (!rsa_set_ctx_params(prsactx, params))
if (!rsa_signverify_init(vprsactx, vrsa, params, operation))
return 0;
+
if (mdname != NULL
/* was rsa_setup_md already called in rsa_signverify_init()? */
&& (mdname[0] == '\0' || strcasecmp(prsactx->mdname, mdname) != 0)
return 0;
prsactx->flag_allow_md = 0;
- prsactx->mdctx = EVP_MD_CTX_new();
+
if (prsactx->mdctx == NULL) {
- ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
- goto error;
+ prsactx->mdctx = EVP_MD_CTX_new();
+ if (prsactx->mdctx == NULL)
+ goto error;
}
if (!EVP_DigestInit_ex2(prsactx->mdctx, prsactx->md, params))
error:
EVP_MD_CTX_free(prsactx->mdctx);
- EVP_MD_free(prsactx->md);
prsactx->mdctx = NULL;
- prsactx->md = NULL;
return 0;
}
#include "internal/cryptlib.h"
#include "internal/sm3.h"
#include "prov/implementations.h"
+#include "prov/providercommon.h"
#include "prov/provider_ctx.h"
#include "crypto/ec.h"
#include "crypto/sm2.h"
if (psm2ctx->md == NULL)
return 0;
+ if (mdname == NULL)
+ return 1;
+
if (strlen(mdname) >= sizeof(psm2ctx->mdname)
|| !EVP_MD_is_a(psm2ctx->md, mdname)) {
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, "digest=%s",
{
PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
- if (psm2ctx == NULL || ec == NULL || !EC_KEY_up_ref(ec))
+ if (!ossl_prov_is_running()
+ || psm2ctx == NULL)
+ return 0;
+
+ if (ec == NULL && psm2ctx->ec == NULL) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
return 0;
- EC_KEY_free(psm2ctx->ec);
- psm2ctx->ec = ec;
+ }
+
+ if (ec != NULL) {
+ if (!EC_KEY_up_ref(ec))
+ return 0;
+ EC_KEY_free(psm2ctx->ec);
+ psm2ctx->ec = ec;
+ }
+
return sm2sig_set_ctx_params(psm2ctx, params);
}
|| !sm2sig_set_mdname(ctx, mdname))
return ret;
- EVP_MD_CTX_free(ctx->mdctx);
- ctx->mdctx = EVP_MD_CTX_new();
- if (ctx->mdctx == NULL)
- goto error;
+ if (ctx->mdctx == NULL) {
+ ctx->mdctx = EVP_MD_CTX_new();
+ if (ctx->mdctx == NULL)
+ goto error;
+ }
md_nid = EVP_MD_get_type(ctx->md);
ret = 1;
error:
- if (!ret)
- free_md(ctx);
return ret;
}