From: Pauli Date: Mon, 14 Jul 2025 01:22:56 +0000 (+1000) Subject: poly1305: convert poly1305 to use param decoder X-Git-Tag: openssl-3.6.0-alpha1~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acb316bc20fe26b2f1042fd620a0c7c89d53eeeb;p=thirdparty%2Fopenssl.git poly1305: convert poly1305 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/poly1305_prov.c.in b/providers/implementations/macs/poly1305_prov.c.in index 19974f9289b..87537d54cf6 100644 --- a/providers/implementations/macs/poly1305_prov.c.in +++ b/providers/implementations/macs/poly1305_prov.c.in @@ -6,6 +6,11 @@ * 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 @@ -14,6 +19,7 @@ #include #include +#include "internal/cryptlib.h" #include "crypto/poly1305.h" #include "prov/implementations.h" @@ -131,43 +137,50 @@ static int poly1305_final(void *vmacctx, unsigned char *out, size_t *outl, return 1; } -static const OSSL_PARAM known_gettable_params[] = { - OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL), - OSSL_PARAM_END -}; +{- produce_param_decoder('poly1305_get_params', + (['MAC_PARAM_SIZE', 'size', 'size_t'], + )); -} + static const OSSL_PARAM *poly1305_gettable_params(void *provctx) { - return known_gettable_params; + return poly1305_get_params_list; } static int poly1305_get_params(OSSL_PARAM params[]) { - OSSL_PARAM *p; + struct poly1305_get_params_st p; - if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL) - return OSSL_PARAM_set_size_t(p, poly1305_size()); + if (!poly1305_get_params_decoder(params, &p)) + return 0; + + if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, poly1305_size())) + return 0; return 1; } -static const OSSL_PARAM known_settable_ctx_params[] = { - OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0), - OSSL_PARAM_END -}; +{- produce_param_decoder('poly1305_set_ctx_params', + (['MAC_PARAM_KEY', 'key', 'octet_string'], + )); -} + static const OSSL_PARAM *poly1305_settable_ctx_params(ossl_unused void *ctx, ossl_unused void *provctx) { - return known_settable_ctx_params; + return poly1305_set_ctx_params_list; } static int poly1305_set_ctx_params(void *vmacctx, const OSSL_PARAM *params) { struct poly1305_data_st *ctx = vmacctx; - const OSSL_PARAM *p; + struct poly1305_set_ctx_params_st p; - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL - && !poly1305_setkey(ctx, p->data, p->data_size)) + if (ctx == NULL || !poly1305_set_ctx_params_decoder(params, &p)) return 0; + + if (p.key != NULL) + if (p.key->data_type != OSSL_PARAM_OCTET_STRING + || !poly1305_setkey(ctx, p.key->data, p.key->data_size)) + return 0; return 1; }