From c18f2ba0a3c2a8c3c8bb4c7a17cd4439fdbedadb Mon Sep 17 00:00:00 2001 From: Pauli Date: Fri, 19 Sep 2025 11:12:18 +1000 Subject: [PATCH] xts: convert to generated param name decodering Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/28616) --- .../ciphers/cipher_aes_xts.c.in | 23 ++++++++-------- .../ciphers/cipher_sm4_xts.c.in | 27 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/providers/implementations/ciphers/cipher_aes_xts.c.in b/providers/implementations/ciphers/cipher_aes_xts.c.in index 1e0081da94e..b408aa33ebd 100644 --- a/providers/implementations/ciphers/cipher_aes_xts.c.in +++ b/providers/implementations/ciphers/cipher_aes_xts.c.in @@ -7,6 +7,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); +-} /* * AES low level APIs are deprecated for public use, but still ok for internal @@ -241,30 +244,28 @@ static int aes_xts_stream_final(void *vctx, unsigned char *out, size_t *outl, return 1; } -static const OSSL_PARAM aes_xts_known_settable_ctx_params[] = { - OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL), - OSSL_PARAM_END -}; +{- produce_param_decoder('aes_xts_set_ctx_params', + (['OSSL_CIPHER_PARAM_KEYLEN', 'keylen', 'size_t'], + )); -} static const OSSL_PARAM *aes_xts_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { - return aes_xts_known_settable_ctx_params; + return aes_xts_set_ctx_params_list; } static int aes_xts_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx; - const OSSL_PARAM *p; + struct aes_xts_set_ctx_params_st p; - if (ossl_param_is_empty(params)) - return 1; + if (ctx == NULL || !aes_xts_set_ctx_params_decoder(params, &p)) + return 0; - p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN); - if (p != NULL) { + if (p.keylen != NULL) { size_t keylen; - if (!OSSL_PARAM_get_size_t(p, &keylen)) { + if (!OSSL_PARAM_get_size_t(p.keylen, &keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } diff --git a/providers/implementations/ciphers/cipher_sm4_xts.c.in b/providers/implementations/ciphers/cipher_sm4_xts.c.in index 31e86d6a8a0..427e553a4d3 100644 --- a/providers/implementations/ciphers/cipher_sm4_xts.c.in +++ b/providers/implementations/ciphers/cipher_sm4_xts.c.in @@ -1,4 +1,3 @@ - /* * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved. * @@ -7,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); +-} /* Dispatch functions for SM4 XTS mode */ @@ -189,24 +191,23 @@ static int sm4_xts_stream_final(void *vctx, unsigned char *out, size_t *outl, return 1; } -static const OSSL_PARAM sm4_xts_known_settable_ctx_params[] = { - OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_XTS_STANDARD, NULL, 0), - OSSL_PARAM_END -}; +{- produce_param_decoder('sm4_xts_set_ctx_params', + (['OSSL_CIPHER_PARAM_XTS_STANDARD', 'std', 'utf8_string'], + )); -} static const OSSL_PARAM *sm4_xts_settable_ctx_params(ossl_unused void *cctx, ossl_unused void *provctx) { - return sm4_xts_known_settable_ctx_params; + return sm4_xts_set_ctx_params_list; } static int sm4_xts_set_ctx_params(void *vxctx, const OSSL_PARAM params[]) { PROV_SM4_XTS_CTX *xctx = (PROV_SM4_XTS_CTX *)vxctx; - const OSSL_PARAM *p; + struct sm4_xts_set_ctx_params_st p; - if (ossl_param_is_empty(params)) - return 1; + if (xctx == NULL || !sm4_xts_set_ctx_params_decoder(params, &p)) + return 0; /*- * Sets the XTS standard to use with SM4-XTS algorithm. @@ -215,15 +216,13 @@ static int sm4_xts_set_ctx_params(void *vxctx, const OSSL_PARAM params[]) * "GB" means the GB/T 17964-2021 standard * "IEEE" means the IEEE Std 1619-2007 standard */ - p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_XTS_STANDARD); - - if (p != NULL) { + if (p.std != NULL) { const char *xts_standard = NULL; - if (p->data_type != OSSL_PARAM_UTF8_STRING) + if (p.std->data_type != OSSL_PARAM_UTF8_STRING) return 0; - if (!OSSL_PARAM_get_utf8_string_ptr(p, &xts_standard)) { + if (!OSSL_PARAM_get_utf8_string_ptr(p.std, &xts_standard)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } -- 2.47.3