From: Pauli Date: Mon, 14 Jul 2025 01:15:43 +0000 (+1000) Subject: siphash: convert siphash to use param decoder X-Git-Tag: openssl-3.6.0-alpha1~171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=969011c3c5708c56a1950e09ee0202371cb0d2a8;p=thirdparty%2Fopenssl.git siphash: convert siphash to use param decoder Reviewed-by: Paul Yang Reviewed-by: Shane Lontis Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/28142) --- diff --git a/providers/implementations/macs/siphash_prov.c.in b/providers/implementations/macs/siphash_prov.c.in index 08a393c39c6..1d8c7faa8b0 100644 --- a/providers/implementations/macs/siphash_prov.c.in +++ b/providers/implementations/macs/siphash_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 @@ -15,6 +18,7 @@ #include #include +#include "internal/cryptlib.h" #include "crypto/siphash.h" #include "prov/implementations.h" @@ -148,74 +152,70 @@ static int siphash_final(void *vmacctx, unsigned char *out, size_t *outl, return SipHash_Final(&ctx->siphash, out, hlen); } +{- produce_param_decoder('siphash_get_ctx_params', + (['MAC_PARAM_SIZE', 'size', 'size_t'], + ['MAC_PARAM_C_ROUNDS', 'c', 'uint'], + ['MAC_PARAM_D_ROUNDS', 'd', 'uint'], + )); -} + static const OSSL_PARAM *siphash_gettable_ctx_params(ossl_unused void *ctx, ossl_unused void *provctx) { - static const OSSL_PARAM known_gettable_ctx_params[] = { - OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL), - OSSL_PARAM_uint(OSSL_MAC_PARAM_C_ROUNDS, NULL), - OSSL_PARAM_uint(OSSL_MAC_PARAM_D_ROUNDS, NULL), - OSSL_PARAM_END - }; - - return known_gettable_ctx_params; + return siphash_get_ctx_params_list; } static int siphash_get_ctx_params(void *vmacctx, OSSL_PARAM params[]) { struct siphash_data_st *ctx = vmacctx; - OSSL_PARAM *p; + struct siphash_get_ctx_params_st p; + + if (ctx == NULL || !siphash_get_ctx_params_decoder(params, &p)) + return 0; - if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL - && !OSSL_PARAM_set_size_t(p, siphash_size(vmacctx))) + if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, siphash_size(vmacctx))) return 0; - if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_C_ROUNDS)) != NULL - && !OSSL_PARAM_set_uint(p, crounds(ctx))) + if (p.c != NULL && !OSSL_PARAM_set_uint(p.c, crounds(ctx))) return 0; - if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_D_ROUNDS)) != NULL - && !OSSL_PARAM_set_uint(p, drounds(ctx))) + if (p.d != NULL && !OSSL_PARAM_set_uint(p.d, drounds(ctx))) return 0; return 1; } +{- produce_param_decoder('siphash_set_params', + (['MAC_PARAM_SIZE', 'size', 'size_t'], + ['MAC_PARAM_KEY', 'key', 'octet_string'], + ['MAC_PARAM_C_ROUNDS', 'c', 'uint'], + ['MAC_PARAM_D_ROUNDS', 'd', 'uint'], + )); -} + static const OSSL_PARAM *siphash_settable_ctx_params(ossl_unused void *ctx, void *provctx) { - static const OSSL_PARAM known_settable_ctx_params[] = { - OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL), - OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0), - OSSL_PARAM_uint(OSSL_MAC_PARAM_C_ROUNDS, NULL), - OSSL_PARAM_uint(OSSL_MAC_PARAM_D_ROUNDS, NULL), - OSSL_PARAM_END - }; - - return known_settable_ctx_params; + return siphash_set_params_list; } static int siphash_set_params(void *vmacctx, const OSSL_PARAM *params) { struct siphash_data_st *ctx = vmacctx; - const OSSL_PARAM *p = NULL; + struct siphash_set_params_st p; size_t size; - if (ossl_param_is_empty(params)) - return 1; + if (ctx == NULL || !siphash_set_params_decoder(params, &p)) + return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_SIZE)) != NULL) { - if (!OSSL_PARAM_get_size_t(p, &size) + if (p.size != NULL) { + if (!OSSL_PARAM_get_size_t(p.size, &size) || !SipHash_set_hash_size(&ctx->siphash, size) || !SipHash_set_hash_size(&ctx->sipcopy, size)) return 0; } - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_C_ROUNDS)) != NULL - && !OSSL_PARAM_get_uint(p, &ctx->crounds)) + if (p.c != NULL && !OSSL_PARAM_get_uint(p.c, &ctx->crounds)) return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_D_ROUNDS)) != NULL - && !OSSL_PARAM_get_uint(p, &ctx->drounds)) + if (p.d != NULL && !OSSL_PARAM_get_uint(p.d, &ctx->drounds)) return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) - if (p->data_type != OSSL_PARAM_OCTET_STRING - || !siphash_setkey(ctx, p->data, p->data_size)) + if (p.key != NULL) + if (p.key->data_type != OSSL_PARAM_OCTET_STRING + || !siphash_setkey(ctx, p.key->data, p.key->data_size)) return 0; return 1; }