From: Pauli Date: Wed, 2 Jul 2025 06:45:10 +0000 (+1000) Subject: pbkdf1: convert to generated OSSL_PARAM parser X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d77651bc099711fcb0a8752363fbccbda082909b;p=thirdparty%2Fopenssl.git pbkdf1: 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/pbkdf1.c.in b/providers/implementations/kdfs/pbkdf1.c.in index 1b7e4d8a2ea..ea3baae76e1 100644 --- a/providers/implementations/kdfs/pbkdf1.c.in +++ b/providers/implementations/kdfs/pbkdf1.c.in @@ -6,6 +6,9 @@ * 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 @@ -15,6 +18,7 @@ #include #include #include +#include "internal/common.h" #include "internal/cryptlib.h" #include "internal/numbers.h" #include "crypto/evp.h" @@ -198,25 +202,35 @@ static int kdf_pbkdf1_derive(void *vctx, unsigned char *key, size_t keylen, ctx->iter, md, key, keylen); } +{- produce_param_decoder('pbkdf1_set_ctx_params', + (['KDF_PARAM_PROPERTIES', 'propq', 'utf8_string'], + ['ALG_PARAM_ENGINE', 'engine', 'utf8_string'], + ['KDF_PARAM_DIGEST', 'digest', 'utf8_string'], + ['KDF_PARAM_PASSWORD', 'pw', 'octet_string'], + ['KDF_PARAM_SALT', 'salt', 'octet_string'], + ['KDF_PARAM_ITER', 'iter', 'uint64'], + )); -} + static int kdf_pbkdf1_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { - const OSSL_PARAM *p; + struct pbkdf1_set_ctx_params_st p; KDF_PBKDF1 *ctx = vctx; OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); - if (!ossl_prov_digest_load_from_params(&ctx->digest, params, libctx)) + if (ctx == NULL || !pbkdf1_set_ctx_params_decoder(params, &p)) return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PASSWORD)) != NULL) - if (!kdf_pbkdf1_set_membuf(&ctx->pass, &ctx->pass_len, p)) - return 0; + if (!ossl_prov_digest_load(&ctx->digest, p.digest, + p.propq, p.engine, libctx)) + return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_SALT)) != NULL) - if (!kdf_pbkdf1_set_membuf(&ctx->salt, &ctx->salt_len, p)) - return 0; + if (p.pw != NULL && !kdf_pbkdf1_set_membuf(&ctx->pass, &ctx->pass_len, p.pw)) + return 0; + + if (p.salt != NULL && !kdf_pbkdf1_set_membuf(&ctx->salt, &ctx->salt_len, p.salt)) + return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_ITER)) != NULL) - if (!OSSL_PARAM_get_uint64(p, &ctx->iter)) + if (p.iter != NULL && !OSSL_PARAM_get_uint64(p.iter, &ctx->iter)) return 0; return 1; } @@ -224,34 +238,30 @@ static int kdf_pbkdf1_set_ctx_params(void *vctx, const OSSL_PARAM params[]) static const OSSL_PARAM *kdf_pbkdf1_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_uint64(OSSL_KDF_PARAM_ITER, NULL), - OSSL_PARAM_END - }; - return known_settable_ctx_params; + return pbkdf1_set_ctx_params_list; } +{- produce_param_decoder('pbkdf1_get_ctx_params', + (['KDF_PARAM_SIZE', 'size', 'size_t'], + )); -} + static int kdf_pbkdf1_get_ctx_params(void *vctx, OSSL_PARAM params[]) { - OSSL_PARAM *p; + struct pbkdf1_get_ctx_params_st p; + KDF_PBKDF1 *ctx = vctx; + + if (ctx == NULL || !pbkdf1_get_ctx_params_decoder(params, &p)) + return 0; - if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL) - return OSSL_PARAM_set_size_t(p, SIZE_MAX); - return -2; + if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, SIZE_MAX)) + return 0; + return 1; } static const OSSL_PARAM *kdf_pbkdf1_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 pbkdf1_get_ctx_params_list; } const OSSL_DISPATCH ossl_kdf_pbkdf1_functions[] = {