From: Pauli Date: Mon, 14 Jul 2025 01:07:21 +0000 (+1000) Subject: gmac: convert GMAC to use param decoder X-Git-Tag: openssl-3.6.0-alpha1~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5de2b13b2dadf40323919557b616e0c389174faf;p=thirdparty%2Fopenssl.git gmac: convert GMAC 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/gmac_prov.c.in b/providers/implementations/macs/gmac_prov.c.in index c56045e8045..8c33beec109 100644 --- a/providers/implementations/macs/gmac_prov.c.in +++ b/providers/implementations/macs/gmac_prov.c.in @@ -6,8 +6,12 @@ * 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 @@ -15,6 +19,7 @@ #include #include +#include "internal/cryptlib.h" #include "prov/implementations.h" #include "prov/provider_ctx.h" #include "prov/provider_util.h" @@ -165,36 +170,40 @@ static int gmac_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('gmac_get_params', + (['MAC_PARAM_SIZE', 'size', 'size_t'], + )); -} + static const OSSL_PARAM *gmac_gettable_params(void *provctx) { - return known_gettable_params; + return gmac_get_params_list; } static int gmac_get_params(OSSL_PARAM params[]) { - OSSL_PARAM *p; + struct gmac_get_params_st p; + + if (!gmac_get_params_decoder(params, &p)) + return 0; - if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL) - return OSSL_PARAM_set_size_t(p, gmac_size()); + if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, gmac_size())) + return 0; return 1; } -static const OSSL_PARAM known_settable_ctx_params[] = { - OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_CIPHER, NULL, 0), - OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_PROPERTIES, NULL, 0), - OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0), - OSSL_PARAM_octet_string(OSSL_MAC_PARAM_IV, NULL, 0), - OSSL_PARAM_END -}; +{- produce_param_decoder('gmac_set_ctx_params', + (['MAC_PARAM_CIPHER', 'cipher', 'utf8_string'], + ['ALG_PARAM_ENGINE', 'engine', 'utf8_string', 'hidden'], + ['MAC_PARAM_PROPERTIES', 'propq', 'utf8_string'], + ['MAC_PARAM_KEY', 'key', 'octet_string'], + ['MAC_PARAM_IV', 'iv', 'octet_string'], + )); -} + static const OSSL_PARAM *gmac_settable_ctx_params(ossl_unused void *ctx, ossl_unused void *provctx) { - return known_settable_ctx_params; + return gmac_set_ctx_params_list; } /* @@ -203,17 +212,20 @@ static const OSSL_PARAM *gmac_settable_ctx_params(ossl_unused void *ctx, static int gmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[]) { struct gmac_data_st *macctx = vmacctx; - EVP_CIPHER_CTX *ctx = macctx->ctx; - OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(macctx->provctx); - const OSSL_PARAM *p; + EVP_CIPHER_CTX *ctx; + OSSL_LIB_CTX *provctx; + struct gmac_set_ctx_params_st p; - if (ossl_param_is_empty(params)) - return 1; - if (ctx == NULL) + if (macctx == NULL || !gmac_set_ctx_params_decoder(params, &p)) + return 0; + + if ((ctx = macctx->ctx) == NULL) return 0; + provctx = PROV_LIBCTX_OF(macctx->provctx); - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CIPHER)) != NULL) { - if (!ossl_prov_cipher_load_from_params(&macctx->cipher, params, provctx)) + if (p.cipher != NULL) { + if (!ossl_prov_cipher_load(&macctx->cipher, p.cipher, p.propq, + p.engine, provctx)) return 0; if (EVP_CIPHER_get_mode(ossl_prov_cipher_cipher(&macctx->cipher)) != EVP_CIPH_GCM_MODE) { @@ -226,18 +238,18 @@ static int gmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[]) return 0; } - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) - if (p->data_type != OSSL_PARAM_OCTET_STRING - || !gmac_setkey(macctx, p->data, p->data_size)) + if (p.key != NULL) + if (p.key->data_type != OSSL_PARAM_OCTET_STRING + || !gmac_setkey(macctx, p.key->data, p.key->data_size)) return 0; - if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_IV)) != NULL) { - if (p->data_type != OSSL_PARAM_OCTET_STRING) + if (p.iv != NULL) { + if (p.iv->data_type != OSSL_PARAM_OCTET_STRING) return 0; if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, - (int)p->data_size, NULL) <= 0 - || !EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, p->data)) + (int)p.iv->data_size, NULL) <= 0 + || !EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, p.iv->data)) return 0; } return 1;