From: Pauli Date: Wed, 2 Jul 2025 00:07:19 +0000 (+1000) Subject: pvkkdf: convert to generated OSSL_PARAM parser X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb6ab5b78a18ef2c1fb8211380ccd933019dfedc;p=thirdparty%2Fopenssl.git pvkkdf: convert to generated OSSL_PARAM parser Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27923) --- diff --git a/providers/implementations/kdfs/pvkkdf.c.in b/providers/implementations/kdfs/pvkkdf.c.in index f60092d7717..2ce8d2ebc78 100644 --- a/providers/implementations/kdfs/pvkkdf.c.in +++ b/providers/implementations/kdfs/pvkkdf.c.in @@ -6,11 +6,16 @@ * 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 #include #include #include #include +#include "internal/common.h" #include "internal/numbers.h" /* SIZE_MAX */ #include "prov/provider_ctx.h" #include "prov/providercommon.h" @@ -176,26 +181,32 @@ static int kdf_pvk_derive(void *vctx, unsigned char *key, size_t keylen, return res; } +{- produce_param_decoder('pvk_set_ctx_params', + (['KDF_PARAM_PROPERTIES', 'propq', 'utf8_string'], + ['ALG_PARAM_ENGINE', 'engine', 'utf8_string'], + ['KDF_PARAM_DIGEST', 'digest', 'utf8_string'], + ['KDF_PARAM_PASSWORD', 'pass', 'octet_string'], + ['KDF_PARAM_SALT', 'salt', 'octet_string'], + )); -} + static int kdf_pvk_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { - const OSSL_PARAM *p; + struct pvk_set_ctx_params_st p; KDF_PVK *ctx = vctx; OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx); - if (ossl_param_is_empty(params)) - return 1; + if (ctx == NULL || !pvk_set_ctx_params_decoder(params, &p)) + return 0; - if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx)) + if (!ossl_prov_digest_load(&ctx->digest, p.digest, p.propq, p.engine, + provctx)) return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PASSWORD)) != NULL) - if (!pvk_set_membuf(&ctx->pass, &ctx->pass_len, p)) - return 0; + if (p.pass != NULL && !pvk_set_membuf(&ctx->pass, &ctx->pass_len, p.pass)) + return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL) { - if (!pvk_set_membuf(&ctx->salt, &ctx->salt_len, p)) - return 0; - } + if (p.salt != NULL && !pvk_set_membuf(&ctx->salt, &ctx->salt_len, p.salt)) + return 0; return 1; } @@ -203,33 +214,30 @@ static int kdf_pvk_set_ctx_params(void *vctx, const OSSL_PARAM params[]) static const OSSL_PARAM *kdf_pvk_settable_ctx_params(ossl_unused void *ctx, ossl_unused void *p_ctx) { - static const OSSL_PARAM known_settable_ctx_params[] = { - OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0), - OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST, NULL, 0), - OSSL_PARAM_octet_string(OSSL_KDF_PARAM_PASSWORD, NULL, 0), - OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT, NULL, 0), - OSSL_PARAM_END - }; - return known_settable_ctx_params; + return pvk_set_ctx_params_list; } +{- produce_param_decoder('pvk_get_ctx_params', + (['KDF_PARAM_SIZE', 'size', 'size_t'], + )); -} + static int kdf_pvk_get_ctx_params(void *vctx, OSSL_PARAM params[]) { - OSSL_PARAM *p; + struct pvk_get_ctx_params_st p; + KDF_PVK *ctx = vctx; - if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL) - return OSSL_PARAM_set_size_t(p, SIZE_MAX); - return -2; + if (ctx == NULL || !pvk_get_ctx_params_decoder(params, &p)) + return 0; + + if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, SIZE_MAX)) + return 0; + return 1; } static const OSSL_PARAM *kdf_pvk_gettable_ctx_params(ossl_unused void *ctx, ossl_unused void *p_ctx) { - static const OSSL_PARAM known_gettable_ctx_params[] = { - OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL), - OSSL_PARAM_END - }; - return known_gettable_ctx_params; + return pvk_get_ctx_params_list; } const OSSL_DISPATCH ossl_kdf_pvk_functions[] = {