EVP_SIGNATURE *signature = NULL;
EVP_KEYMGMT *tmp_keymgmt = NULL;
const char *supported_sig = NULL;
+ char locmdname[80] = ""; /* 80 chars should be enough */
void *provkey = NULL;
int ret;
if (locpctx->keytype == NULL)
goto legacy;
- if (mdname == NULL) {
- if (type != NULL) {
- mdname = EVP_MD_name(type);
- } else if (pkey != NULL) {
- /*
- * TODO(v3.0) work out a better way for EVP_PKEYs with no legacy
- * component.
- */
- if (pkey->pkey.ptr != NULL) {
- int def_nid;
- if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
- mdname = OBJ_nid2sn(def_nid);
- }
- }
- }
-
/* Ensure that the key is provided. If not, go legacy */
tmp_keymgmt = locpctx->keymgmt;
provkey = evp_pkey_make_provided(locpctx->pkey, locpctx->libctx,
/* No more legacy from here down to legacy: */
+ if (pctx != NULL)
+ *pctx = locpctx;
+
locpctx->op.sig.signature = signature;
locpctx->operation = ver ? EVP_PKEY_OP_VERIFYCTX
: EVP_PKEY_OP_SIGNCTX;
}
if (type != NULL) {
ctx->reqdigest = type;
+ if (mdname == NULL)
+ mdname = EVP_MD_name(type);
} else {
- /*
- * This might be requested by a later call to EVP_MD_CTX_md(). In that
- * case the "explicit fetch" rules apply for that function (as per
- * man pages), i.e. the ref count is not updated so the EVP_MD should
- * not be used beyound the lifetime of the EVP_MD_CTX.
- */
- ctx->reqdigest = ctx->fetched_digest =
- EVP_MD_fetch(locpctx->libctx, mdname, props);
+ if (mdname == NULL
+ && EVP_PKEY_get_default_digest_name(locpctx->pkey, locmdname,
+ sizeof(locmdname)))
+ mdname = locmdname;
+
+ if (mdname != NULL) {
+ /*
+ * This might be requested by a later call to EVP_MD_CTX_md().
+ * In that case the "explicit fetch" rules apply for that
+ * function (as per man pages), i.e. the ref count is not updated
+ * so the EVP_MD should not be used beyound the lifetime of the
+ * EVP_MD_CTX.
+ */
+ ctx->reqdigest = ctx->fetched_digest =
+ EVP_MD_fetch(locpctx->libctx, mdname, props);
+ }
}
if (ver) {