(type == NULL || (type->type == ctx->digest->type)))
goto skip_to_init;
+ if (type != NULL) {
+ /*
+ * Ensure an ENGINE left lying around from last time is cleared (the
+ * previous check attempted to avoid this if the same ENGINE and
+ * EVP_MD could be used).
+ */
+ ENGINE_finish(ctx->engine);
+ ctx->engine = NULL;
+ }
+
if (type != NULL && impl == NULL)
tmpimpl = ENGINE_get_digest_engine(type->type);
#endif
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
if (type) {
- /*
- * Ensure an ENGINE left lying around from last time is cleared (the
- * previous check attempted to avoid this if the same ENGINE and
- * EVP_MD could be used).
- */
- ENGINE_finish(ctx->engine);
if (impl != NULL) {
if (!ENGINE_init(impl)) {
EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);
return 0;
}
- params[i++] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_XOFLEN,
- &size, NULL);
+ params[i++] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_XOFLEN, &size);
params[i++] = OSSL_PARAM_construct_end();
if (EVP_MD_CTX_set_params(ctx, params) > 0)
out->provctx = NULL;
if (in->fetched_digest != NULL)
- EVP_MD_upref(in->fetched_digest);
+ EVP_MD_up_ref(in->fetched_digest);
out->provctx = in->digest->dupctx(in->provctx);
if (out->provctx == NULL) {
return ret;
}
+int EVP_MD_get_params(const EVP_MD *digest, OSSL_PARAM params[])
+{
+ if (digest != NULL && digest->get_params != NULL)
+ return digest->get_params(params);
+ return 0;
+}
+
+const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest)
+{
+ if (digest != NULL && digest->gettable_params != NULL)
+ return digest->gettable_params();
+ return NULL;
+}
+
int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[])
{
- if (ctx->digest != NULL && ctx->digest->set_params != NULL)
- return ctx->digest->set_params(ctx->provctx, params);
+ if (ctx->digest != NULL && ctx->digest->ctx_set_params != NULL)
+ return ctx->digest->ctx_set_params(ctx->provctx, params);
return 0;
}
-int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[])
+const OSSL_PARAM *EVP_MD_CTX_settable_params(const EVP_MD *digest)
+{
+ if (digest != NULL && digest->settable_ctx_params != NULL)
+ return digest->settable_ctx_params();
+ return NULL;
+}
+
+int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[])
{
if (ctx->digest != NULL && ctx->digest->get_params != NULL)
- return ctx->digest->get_params(ctx->provctx, params);
+ return ctx->digest->ctx_get_params(ctx->provctx, params);
return 0;
}
-#if !OPENSSL_API_3
+const OSSL_PARAM *EVP_MD_CTX_gettable_params(const EVP_MD *digest)
+{
+ if (digest != NULL && digest->gettable_ctx_params != NULL)
+ return digest->gettable_ctx_params();
+ return NULL;
+}
+
+/* TODO(3.0): Remove legacy code below - only used by engines & DigestSign */
int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
{
- if (ctx->digest != NULL) {
- OSSL_PARAM params[2];
- size_t i, sz, n = 0;
-
- switch (cmd) {
- case EVP_MD_CTRL_XOF_LEN:
- if (ctx->digest->set_params == NULL)
- break;
- i = (size_t)p1;
- params[n++] = OSSL_PARAM_construct_size_t(
- OSSL_DIGEST_PARAM_XOFLEN, &i, &sz);
- params[n++] = OSSL_PARAM_construct_end();
- return ctx->digest->set_params(ctx->provctx, params) > 0;
- case EVP_MD_CTRL_MICALG:
- if (ctx->digest->get_params == NULL)
- break;
- params[n++] = OSSL_PARAM_construct_utf8_string(
- OSSL_DIGEST_PARAM_MICALG, p2, p1 ? p1 : 9999,
- &sz);
- params[n++] = OSSL_PARAM_construct_end();
- return ctx->digest->get_params(ctx->provctx, params);
- }
- /* legacy code */
- if (ctx->digest->md_ctrl != NULL) {
- int ret = ctx->digest->md_ctrl(ctx, cmd, p1, p2);
- if (ret <= 0)
- return 0;
- return 1;
- }
+ int ret = EVP_CTRL_RET_UNSUPPORTED;
+ int set_params = 1;
+ size_t sz;
+ OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
+
+ if (ctx == NULL || ctx->digest == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_MESSAGE_DIGEST_IS_NULL);
+ return 0;
}
- return 0;
+
+ if (ctx->digest->prov == NULL)
+ goto legacy;
+
+ switch (cmd) {
+ case EVP_MD_CTRL_XOF_LEN:
+ sz = (size_t)p1;
+ params[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_XOFLEN, &sz);
+ break;
+ case EVP_MD_CTRL_MICALG:
+ set_params = 0;
+ params[0] = OSSL_PARAM_construct_utf8_string(OSSL_DIGEST_PARAM_MICALG,
+ p2, p1 ? p1 : 9999);
+ break;
+ default:
+ return EVP_CTRL_RET_UNSUPPORTED;
+ }
+
+ if (set_params)
+ ret = evp_do_md_ctx_setparams(ctx->digest, ctx->provctx, params);
+ else
+ ret = evp_do_md_ctx_getparams(ctx->digest, ctx->provctx, params);
+ return ret;
+
+
+/* TODO(3.0): Remove legacy code below */
+ legacy:
+ if (ctx->digest->md_ctrl == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_CTRL_NOT_IMPLEMENTED);
+ return 0;
+ }
+
+ ret = ctx->digest->md_ctrl(ctx, cmd, p1, p2);
+ if (ret <= 0)
+ return 0;
+ return ret;
}
-#endif
-static void *evp_md_from_dispatch(const OSSL_DISPATCH *fns,
+static void *evp_md_from_dispatch(const char *name, const OSSL_DISPATCH *fns,
OSSL_PROVIDER *prov)
{
EVP_MD *md = NULL;
int fncnt = 0;
/* EVP_MD_fetch() will set the legacy NID if available */
- if ((md = EVP_MD_meth_new(NID_undef, NID_undef)) == NULL)
+ if ((md = EVP_MD_meth_new(NID_undef, NID_undef)) == NULL
+ || (md->name = OPENSSL_strdup(name)) == NULL) {
+ EVP_MD_meth_free(md);
+ EVPerr(0, ERR_R_MALLOC_FAILURE);
return NULL;
+ }
for (; fns->function_id != 0; fns++) {
switch (fns->function_id) {
if (md->dupctx == NULL)
md->dupctx = OSSL_get_OP_digest_dupctx(fns);
break;
- case OSSL_FUNC_DIGEST_SIZE:
- if (md->size == NULL)
- md->size = OSSL_get_OP_digest_size(fns);
- break;
- case OSSL_FUNC_DIGEST_BLOCK_SIZE:
- if (md->dblock_size == NULL)
- md->dblock_size = OSSL_get_OP_digest_block_size(fns);
- break;
- case OSSL_FUNC_DIGEST_SET_PARAMS:
- if (md->set_params == NULL)
- md->set_params = OSSL_get_OP_digest_set_params(fns);
- break;
case OSSL_FUNC_DIGEST_GET_PARAMS:
if (md->get_params == NULL)
md->get_params = OSSL_get_OP_digest_get_params(fns);
break;
+ case OSSL_FUNC_DIGEST_CTX_SET_PARAMS:
+ if (md->ctx_set_params == NULL)
+ md->ctx_set_params = OSSL_get_OP_digest_ctx_set_params(fns);
+ break;
+ case OSSL_FUNC_DIGEST_CTX_GET_PARAMS:
+ if (md->ctx_get_params == NULL)
+ md->ctx_get_params = OSSL_get_OP_digest_ctx_get_params(fns);
+ break;
+ case OSSL_FUNC_DIGEST_GETTABLE_PARAMS:
+ if (md->gettable_params == NULL)
+ md->gettable_params = OSSL_get_OP_digest_gettable_params(fns);
+ break;
+ case OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS:
+ if (md->settable_ctx_params == NULL)
+ md->settable_ctx_params =
+ OSSL_get_OP_digest_settable_ctx_params(fns);
+ break;
+ case OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS:
+ if (md->gettable_ctx_params == NULL)
+ md->gettable_ctx_params =
+ OSSL_get_OP_digest_gettable_ctx_params(fns);
+ break;
}
}
if ((fncnt != 0 && fncnt != 5)
- || (fncnt == 0 && md->digest == NULL)
- || md->size == NULL) {
+ || (fncnt == 0 && md->digest == NULL)) {
/*
* In order to be a consistent set of functions we either need the
* whole set of init/update/final etc functions or none of them.
* generate digests.
*/
EVP_MD_meth_free(md);
+ ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS);
return NULL;
}
md->prov = prov;
if (prov != NULL)
- ossl_provider_upref(prov);
+ ossl_provider_up_ref(prov);
return md;
}
-static int evp_md_upref(void *md)
+static int evp_md_up_ref(void *md)
{
- return EVP_MD_upref(md);
+ return EVP_MD_up_ref(md);
}
static void evp_md_free(void *md)
{
EVP_MD *md =
evp_generic_fetch(ctx, OSSL_OP_DIGEST, algorithm, properties,
- evp_md_from_dispatch, evp_md_upref,
+ evp_md_from_dispatch, evp_md_up_ref,
evp_md_free);
#ifndef FIPS_MODE
return md;
}
+
+void EVP_MD_do_all_ex(OPENSSL_CTX *libctx,
+ void (*fn)(EVP_MD *mac, void *arg),
+ void *arg)
+{
+ evp_generic_do_all(libctx, OSSL_OP_DIGEST,
+ (void (*)(void *, void *))fn, arg,
+ evp_md_from_dispatch, evp_md_free);
+}