]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
jitter: update to use generated param handling
authorPauli <ppzgs1@gmail.com>
Sun, 20 Jul 2025 23:44:14 +0000 (09:44 +1000)
committerPauli <ppzgs1@gmail.com>
Wed, 13 Aug 2025 01:55:49 +0000 (11:55 +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/28143)

providers/implementations/rands/seed_src_jitter.c.in

index ac57f1c14bff4fb2bd008f9f0fbf1a9f302c842f..1139c7395a474276a27c3d6c67cc550deb98b887 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);
+-}
 
 #include <string.h>
 #include <openssl/rand.h>
@@ -18,6 +21,7 @@
 #include <openssl/randerr.h>
 #include <openssl/proverr.h>
 #include <openssl/self_test.h>
+#include "internal/common.h"
 #include "prov/implementations.h"
 #include "prov/provider_ctx.h"
 #include "prov/providercommon.h"
@@ -227,21 +231,27 @@ static int jitter_reseed(void *vseed,
     return 1;
 }
 
+{- produce_param_decoder('jitter_get_ctx_params',
+                         (['RAND_PARAM_STATE',                   'state',  'int'],
+                          ['RAND_PARAM_STRENGTH',                'str',    'uint'],
+                          ['RAND_PARAM_MAX_REQUEST',             'maxreq', 'size_t'],
+                        )); -}
+
 static int jitter_get_ctx_params(void *vseed, OSSL_PARAM params[])
 {
     PROV_JITTER *s = (PROV_JITTER *)vseed;
-    OSSL_PARAM *p;
+    struct jitter_get_ctx_params_st p;
+
+    if (s == NULL || !jitter_get_ctx_params_decoder(params, &p))
+        return 0;
 
-    p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_STATE);
-    if (p != NULL && !OSSL_PARAM_set_int(p, s->state))
+    if (p.state != NULL && !OSSL_PARAM_set_int(p.state, s->state))
         return 0;
 
-    p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_STRENGTH);
-    if (p != NULL && !OSSL_PARAM_set_int(p, 1024))
+    if (p.str != NULL && !OSSL_PARAM_set_uint(p.str, 1024))
         return 0;
 
-    p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_MAX_REQUEST);
-    if (p != NULL && !OSSL_PARAM_set_size_t(p, 128))
+    if (p.maxreq != NULL && !OSSL_PARAM_set_size_t(p.maxreq, 128))
         return 0;
     return 1;
 }
@@ -249,13 +259,7 @@ static int jitter_get_ctx_params(void *vseed, OSSL_PARAM params[])
 static const OSSL_PARAM *jitter_gettable_ctx_params(ossl_unused void *vseed,
                                                     ossl_unused void *provctx)
 {
-    static const OSSL_PARAM known_gettable_ctx_params[] = {
-        OSSL_PARAM_int(OSSL_RAND_PARAM_STATE, NULL),
-        OSSL_PARAM_uint(OSSL_RAND_PARAM_STRENGTH, NULL),
-        OSSL_PARAM_size_t(OSSL_RAND_PARAM_MAX_REQUEST, NULL),
-        OSSL_PARAM_END
-    };
-    return known_gettable_ctx_params;
+    return jitter_get_ctx_params_list;
 }
 
 static int jitter_verify_zeroization(ossl_unused void *vseed)