From: Pauli Date: Mon, 28 Jul 2025 07:15:25 +0000 (+1000) Subject: shake: update to use generated param decoders X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc044f616ee42e31fd45714566155d8405f962b1;p=thirdparty%2Fopenssl.git shake: update to use generated param decoders Reviewed-by: Matt Caswell Reviewed-by: Dmitry Belyavskiy (Merged from https://github.com/openssl/openssl/pull/28151) --- diff --git a/providers/implementations/digests/sha3_prov.c.in b/providers/implementations/digests/sha3_prov.c.in index a006cf48514..fdf591f3526 100644 --- a/providers/implementations/digests/sha3_prov.c.in +++ b/providers/implementations/digests/sha3_prov.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 @@ -14,6 +17,7 @@ #include #include #include +#include "internal/cryptlib.h" #include "internal/numbers.h" #include "internal/sha3.h" #include "prov/digestcommon.h" @@ -582,68 +586,58 @@ static void *keccak_dupctx(void *ctx) return ret; } +{- produce_param_decoder('shake_get_ctx_params', + (['DIGEST_PARAM_XOFLEN', 'xoflen', 'size_t'], + ['DIGEST_PARAM_SIZE', 'size', 'size_t'], + )); -} + static const OSSL_PARAM *shake_gettable_ctx_params(ossl_unused void *ctx, ossl_unused void *provctx) { - static const OSSL_PARAM known_shake_gettable_ctx_params[] = { - {OSSL_DIGEST_PARAM_XOFLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0}, - {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0}, - OSSL_PARAM_END - }; - return known_shake_gettable_ctx_params; + return shake_get_ctx_params_list; } static int shake_get_ctx_params(void *vctx, OSSL_PARAM params[]) { - OSSL_PARAM *p; + struct shake_get_ctx_params_st p; KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx; - if (ctx == NULL) + if (ctx == NULL || !shake_get_ctx_params_decoder(params, &p)) return 0; - if (ossl_param_is_empty(params)) - return 1; - p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_XOFLEN); - if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->md_size)) { + if (p.xoflen != NULL && !OSSL_PARAM_set_size_t(p.xoflen, ctx->md_size)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } - /* Size is an alias of xoflen */ - p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE); - if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->md_size)) { + /* Size is an alias of xoflen but separate them for compatibility */ + if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, ctx->md_size)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } return 1; } +{- produce_param_decoder('shake_set_ctx_params', + (['DIGEST_PARAM_XOFLEN', 'xoflen', 'size_t'], + ['DIGEST_PARAM_SIZE', 'xoflen', 'size_t'], + )); -} + static const OSSL_PARAM *shake_settable_ctx_params(ossl_unused void *ctx, ossl_unused void *provctx) { - static const OSSL_PARAM known_shake_settable_ctx_params[] = { - {OSSL_DIGEST_PARAM_XOFLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0}, - {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0}, - OSSL_PARAM_END - }; - - return known_shake_settable_ctx_params; + return shake_set_ctx_params_list; } static int shake_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { - const OSSL_PARAM *p; + struct shake_set_ctx_params_st p; KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx; - if (ossl_unlikely(ctx == NULL)) + if (ossl_unlikely(ctx == NULL || !shake_set_ctx_params_decoder(params, &p))) return 0; - if (ossl_param_is_empty(params)) - return 1; - - p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_XOFLEN); - if (ossl_unlikely(p == NULL)) - p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SIZE); - if (ossl_unlikely(p != NULL && !OSSL_PARAM_get_size_t(p, &ctx->md_size))) { + if (ossl_unlikely(p.xoflen != NULL + && !OSSL_PARAM_get_size_t(p.xoflen, &ctx->md_size))) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; }