# include "internal/provider_ctx.h"
# include "internal/providercommonerr.h"
# include "internal/provider_algs.h"
+# include "internal/provider_util.h"
# define X942KDF_MAX_INLEN (1 << 30)
typedef struct {
void *provctx;
- EVP_MD *md;
+ PROV_DIGEST digest;
unsigned char *secret;
size_t secret_len;
int cek_nid;
{
KDF_X942 *ctx = (KDF_X942 *)vctx;
- EVP_MD_meth_free(ctx->md);
+ ossl_prov_digest_reset(&ctx->digest);
OPENSSL_clear_free(ctx->secret, ctx->secret_len);
OPENSSL_clear_free(ctx->ukm, ctx->ukm_len);
memset(ctx, 0, sizeof(*ctx));
static size_t x942kdf_size(KDF_X942 *ctx)
{
int len;
+ const EVP_MD *md = ossl_prov_digest_md(&ctx->digest);
- if (ctx->md == NULL) {
+ if (md == NULL) {
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
return 0;
}
- len = EVP_MD_size(ctx->md);
+ len = EVP_MD_size(md);
return (len <= 0) ? 0 : (size_t)len;
}
static int x942kdf_derive(void *vctx, unsigned char *key, size_t keylen)
{
KDF_X942 *ctx = (KDF_X942 *)vctx;
+ const EVP_MD *md = ossl_prov_digest_md(&ctx->digest);
int ret = 0;
unsigned char *ctr;
unsigned char *der = NULL;
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_SECRET);
return 0;
}
- if (ctx->md == NULL) {
+ if (md == NULL) {
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
return 0;
}
ERR_raise(ERR_LIB_PROV, PROV_R_BAD_ENCODING);
return 0;
}
- ret = x942kdf_hash_kdm(ctx->md, ctx->secret, ctx->secret_len,
+ ret = x942kdf_hash_kdm(md, ctx->secret, ctx->secret_len,
der, der_len, ctr, key, keylen);
OPENSSL_free(der);
return ret;
{
const OSSL_PARAM *p;
KDF_X942 *ctx = vctx;
- EVP_MD *md;
- const char *properties = NULL;
+ OPENSSL_CTX *provctx = PROV_LIBRARY_CONTEXT_OF(ctx->provctx);
size_t i;
- /* Grab search properties, this should be before the digest lookup */
- if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PROPERTIES))
- != NULL) {
- if (p->data_type != OSSL_PARAM_UTF8_STRING)
- return 0;
- properties = p->data;
- }
- /* Handle aliasing of digest parameter names */
- if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_DIGEST)) != NULL) {
- if (p->data_type != OSSL_PARAM_UTF8_STRING)
- return 0;
- md = EVP_MD_fetch(PROV_LIBRARY_CONTEXT_OF(ctx->provctx), p->data,
- properties);
- if (md == NULL) {
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
- return 0;
- }
- EVP_MD_meth_free(ctx->md);
- ctx->md = md;
- }
+ if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
+ return 0;
if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SECRET)) != NULL
|| (p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_KEY)) != NULL)