]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
ec kem: convert to using generated param decoders
authorPauli <ppzgs1@gmail.com>
Fri, 25 Jul 2025 03:15:26 +0000 (13:15 +1000)
committerPauli <ppzgs1@gmail.com>
Wed, 13 Aug 2025 02:06:00 +0000 (12:06 +1000)
Reviewed-by: Paul Yang <paulyang.inf@gmail.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28149)

providers/implementations/kem/ec_kem.c.in

index 86fe6b73b03e21b4159cf455cb698514336190fe..ef73e9ceb303f75831f90c3a1d42a469fb60703b 100644 (file)
@@ -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);
+-}
 
 /*
  * The following implementation is part of RFC 9180 related to DHKEM using
@@ -25,6 +28,7 @@
 #include <openssl/proverr.h>
 #include <openssl/kdf.h>
 #include <openssl/rand.h>
+#include "internal/cryptlib.h"
 #include "prov/provider_ctx.h"
 #include "prov/implementations.h"
 #include "prov/securitycheck.h"
@@ -284,22 +288,27 @@ static int eckem_auth_decapsulate_init(void *vctx, void *vecx, void *vauthpub,
     return eckem_init(vctx, EVP_PKEY_OP_DECAPSULATE, vecx, vauthpub, params);
 }
 
+
+{- produce_param_decoder('eckem_set_ctx_params',
+                         (['KEM_PARAM_OPERATION',   'op',   'utf8_string'],
+                          ['KEM_PARAM_IKME',        'ikme', 'octet_string'],
+                         )); -}
+
 static int eckem_set_ctx_params(void *vctx, const OSSL_PARAM params[])
 {
     PROV_EC_CTX *ctx = (PROV_EC_CTX *)vctx;
-    const OSSL_PARAM *p;
+    struct eckem_set_ctx_params_st p;
     int mode;
 
-    if (ossl_param_is_empty(params))
-        return 1;
+    if (ctx == NULL || !eckem_set_ctx_params_decoder(params, &p))
+        return 0;
 
-    p = OSSL_PARAM_locate_const(params, OSSL_KEM_PARAM_IKME);
-    if (p != NULL) {
+    if (p.ikme != NULL) {
         void *tmp = NULL;
         size_t tmplen = 0;
 
-        if (p->data != NULL && p->data_size != 0) {
-            if (!OSSL_PARAM_get_octet_string(p, &tmp, 0, &tmplen))
+        if (p.ikme->data != NULL && p.ikme->data_size != 0) {
+            if (!OSSL_PARAM_get_octet_string(p.ikme, &tmp, 0, &tmplen))
                 return 0;
         }
         OPENSSL_clear_free(ctx->ikm, ctx->ikmlen);
@@ -308,11 +317,10 @@ static int eckem_set_ctx_params(void *vctx, const OSSL_PARAM params[])
         ctx->ikmlen = tmplen;
     }
 
-    p = OSSL_PARAM_locate_const(params, OSSL_KEM_PARAM_OPERATION);
-    if (p != NULL) {
-        if (p->data_type != OSSL_PARAM_UTF8_STRING)
+    if (p.op != NULL) {
+        if (p.op->data_type != OSSL_PARAM_UTF8_STRING)
             return 0;
-        mode = ossl_eckem_modename2id(p->data);
+        mode = ossl_eckem_modename2id(p.op->data);
         if (mode == KEM_MODE_UNDEFINED)
             return 0;
         ctx->mode = mode;
@@ -320,16 +328,10 @@ static int eckem_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     return 1;
 }
 
-static const OSSL_PARAM known_settable_eckem_ctx_params[] = {
-    OSSL_PARAM_utf8_string(OSSL_KEM_PARAM_OPERATION, NULL, 0),
-    OSSL_PARAM_octet_string(OSSL_KEM_PARAM_IKME, NULL, 0),
-    OSSL_PARAM_END
-};
-
 static const OSSL_PARAM *eckem_settable_ctx_params(ossl_unused void *vctx,
                                                    ossl_unused void *provctx)
 {
-    return known_settable_eckem_ctx_params;
+    return eckem_set_ctx_params_list;
 }
 
 /*