* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
+{-
+use OpenSSL::paramnames qw(produce_param_decoder);
+-}
#include <stdlib.h>
#include <string.h>
#include <openssl/kdf.h>
#include <openssl/proverr.h>
#include <openssl/core_names.h>
+#include "internal/common.h"
#include "prov/providercommon.h"
#include "prov/implementations.h"
#include "prov/hmac_drbg.h"
return ossl_drbg_hmac_generate(drbg, out, outlen, NULL, 0);
}
+{- produce_param_decoder('hmac_drbg_kdf_get_ctx_params',
+ (['KDF_PARAM_MAC', 'mac', 'utf8_string'],
+ ['KDF_PARAM_DIGEST', 'digest', 'utf8_string'],
+ )); -}
+
static int hmac_drbg_kdf_get_ctx_params(void *vctx, OSSL_PARAM params[])
{
KDF_HMAC_DRBG *hmac = (KDF_HMAC_DRBG *)vctx;
PROV_DRBG_HMAC *drbg = &hmac->base;
const char *name;
const EVP_MD *md;
- OSSL_PARAM *p;
+ struct hmac_drbg_kdf_get_ctx_params_st p;
+
+ if (hmac == NULL || !hmac_drbg_kdf_get_ctx_params_decoder(params, &p))
+ return 0;
- p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_MAC);
- if (p != NULL) {
+ if (p.mac != NULL) {
if (drbg->ctx == NULL)
return 0;
name = EVP_MAC_get0_name(EVP_MAC_CTX_get0_mac(drbg->ctx));
- if (!OSSL_PARAM_set_utf8_string(p, name))
+ if (!OSSL_PARAM_set_utf8_string(p.mac, name))
return 0;
}
- p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_DIGEST);
- if (p != NULL) {
+ if (p.digest != NULL) {
md = ossl_prov_digest_md(&drbg->digest);
- if (md == NULL || !OSSL_PARAM_set_utf8_string(p, EVP_MD_get0_name(md)))
+ if (md == NULL
+ || !OSSL_PARAM_set_utf8_string(p.digest, EVP_MD_get0_name(md)))
return 0;
}
return 1;
static const OSSL_PARAM *hmac_drbg_kdf_gettable_ctx_params(
ossl_unused void *vctx, ossl_unused void *p_ctx)
{
- static const OSSL_PARAM known_gettable_ctx_params[] = {
- OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_MAC, NULL, 0),
- OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0),
- OSSL_PARAM_END
- };
- return known_gettable_ctx_params;
+ return hmac_drbg_kdf_get_ctx_params_list;
}
+{- produce_param_decoder('hmac_drbg_kdf_set_ctx_params',
+ (['KDF_PARAM_PROPERTIES', 'propq', 'utf8_string'],
+ ['ALG_PARAM_ENGINE', 'engine', 'utf8_string'],
+ ['KDF_PARAM_DIGEST', 'digest', 'utf8_string'],
+ ['KDF_PARAM_HMACDRBG_ENTROPY', 'ent', 'octet_string'],
+ ['KDF_PARAM_HMACDRBG_NONCE', 'nonce', 'octet_string'],
+ )); -}
+
static int hmac_drbg_kdf_set_ctx_params(void *vctx,
const OSSL_PARAM params[])
{
PROV_DRBG_HMAC *drbg = &hmac->base;
OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(hmac->provctx);
const EVP_MD *md;
- const OSSL_PARAM *p;
+ struct hmac_drbg_kdf_set_ctx_params_st p;
void *ptr = NULL;
size_t size = 0;
int md_size;
- if (ossl_param_is_empty(params))
- return 1;
+ if (hmac == NULL || !hmac_drbg_kdf_set_ctx_params_decoder(params, &p))
+ return 0;
- p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_HMACDRBG_ENTROPY);
- if (p != NULL) {
- if (!OSSL_PARAM_get_octet_string(p, &ptr, 0, &size))
+ if (p.ent != NULL) {
+ if (!OSSL_PARAM_get_octet_string(p.ent, &ptr, 0, &size))
return 0;
OPENSSL_free(hmac->entropy);
hmac->entropy = ptr;
ptr = NULL;
}
- p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_HMACDRBG_NONCE);
- if (p != NULL) {
- if (!OSSL_PARAM_get_octet_string(p, &ptr, 0, &size))
+ if (p.nonce != NULL) {
+ if (!OSSL_PARAM_get_octet_string(p.nonce, &ptr, 0, &size))
return 0;
OPENSSL_free(hmac->nonce);
hmac->nonce = ptr;
hmac->init = 0;
}
- p = OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_DIGEST);
- if (p != NULL) {
- if (!ossl_prov_digest_load_from_params(&drbg->digest, params, libctx))
+ if (p.digest != NULL) {
+ if (!ossl_prov_digest_load(&drbg->digest, p.digest,
+ p.propq, p.engine, libctx))
return 0;
/* Confirm digest is allowed. Allow all digests that are not XOF */
return 0;
drbg->blocklen = (size_t)md_size;
}
- return ossl_prov_macctx_load_from_params(&drbg->ctx, params,
- "HMAC", NULL, NULL, libctx);
+ if (!ossl_prov_macctx_load(&drbg->ctx, NULL, NULL, p.digest, p.propq,
+ p.engine, "HMAC", NULL, NULL, libctx))
+ return 0;
}
return 1;
}
static const OSSL_PARAM *hmac_drbg_kdf_settable_ctx_params(
ossl_unused void *vctx, ossl_unused void *p_ctx)
{
- static const OSSL_PARAM known_settable_ctx_params[] = {
- OSSL_PARAM_octet_string(OSSL_KDF_PARAM_HMACDRBG_ENTROPY, NULL, 0),
- OSSL_PARAM_octet_string(OSSL_KDF_PARAM_HMACDRBG_NONCE, NULL, 0),
- OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0),
- OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
- OSSL_PARAM_END
- };
- return known_settable_ctx_params;
+ return hmac_drbg_kdf_set_ctx_params_list;
}
const OSSL_DISPATCH ossl_kdf_hmac_drbg_functions[] = {