]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
xts: convert to generated param name decodering
authorPauli <paul.dale@oracle.com>
Fri, 19 Sep 2025 01:12:18 +0000 (11:12 +1000)
committerTomas Mraz <tomas@openssl.org>
Wed, 1 Oct 2025 15:45:46 +0000 (17:45 +0200)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28616)

providers/implementations/ciphers/cipher_aes_xts.c.in
providers/implementations/ciphers/cipher_sm4_xts.c.in

index 1e0081da94ec5f0e32f6b1a7e40088d915422b34..b408aa33ebdb610c2fa42e10d32fb1f968f861db 100644 (file)
@@ -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;
         }
index 31e86d6a8a0a832de1b7b1c9f4ac2f343845332d..427e553a4d3a7e0a3e6c4ab96191d6f89384284a 100644 (file)
@@ -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;
         }