From e77b362e87b4db2554824e19ba15bdb07f02cc08 Mon Sep 17 00:00:00 2001 From: Pauli Date: Mon, 21 Jul 2025 10:09:13 +1000 Subject: [PATCH] crngt: update to use generated param handling Reviewed-by: Paul Yang Reviewed-by: Shane Lontis Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/28143) --- .../implementations/rands/fips_crng_test.c.in | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/providers/implementations/rands/fips_crng_test.c.in b/providers/implementations/rands/fips_crng_test.c.in index 2a2b996fe5b..0ed90951f29 100644 --- a/providers/implementations/rands/fips_crng_test.c.in +++ b/providers/implementations/rands/fips_crng_test.c.in @@ -10,6 +10,9 @@ /* * Implementation of SP 800-90B section 4.4 Approved Continuous Health Tests. */ +{- +use OpenSSL::paramnames qw(produce_param_decoder); +-} #include #include @@ -20,9 +23,10 @@ #include "prov/providercommon.h" #include "prov/provider_ctx.h" #include "prov/implementations.h" +#include "internal/common.h" #include "internal/cryptlib.h" #include "crypto/rand_pool.h" -#include "drbg_local.h" +#include "prov/drbg.h" #include "prov/seeding.h" #include "crypto/context.h" @@ -109,7 +113,7 @@ static int RCT_test(CRNG_TEST *crngt, uint8_t next) /* * Critical values for this test are computed using: * - * C = 1 + \left\lceil\frac{-log_2 \alpha}H\right\rceil + * C = 1 + \left\lceil\frac{ -log_2 \alpha}H\right\rceil * * where alpha = 2^-20 and H is the expected entropy per sample. */ @@ -361,29 +365,38 @@ static void crng_test_unlock(ossl_unused void *vcrngt) CRYPTO_THREAD_unlock(crngt->lock); } +{- produce_param_decoder('crng_test_get_ctx_params', + (['RAND_PARAM_STATE', 'state', 'int'], + ['RAND_PARAM_STRENGTH', 'str', 'uint'], + ['RAND_PARAM_MAX_REQUEST', 'maxreq', 'size_t'], + ['RAND_PARAM_FIPS_APPROVED_INDICATOR', 'ind', 'int'], + )); -} + static int crng_test_get_ctx_params(void *vcrngt, OSSL_PARAM params[]) { CRNG_TEST *crngt = (CRNG_TEST *)vcrngt; - OSSL_PARAM *p; + struct crng_test_get_ctx_params_st p; + + if (crngt == NULL) + return 0; if (crngt->parent != NULL && crngt->parent_get_ctx_params != NULL) return crngt->parent_get_ctx_params(crngt->parent, params); /* No parent means we are using call backs for entropy */ - p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_STATE); - if (p != NULL && !OSSL_PARAM_set_int(p, crngt->state)) + if (!crng_test_get_ctx_params_decoder(params, &p)) return 0; - p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_STRENGTH); - if (p != NULL && !OSSL_PARAM_set_int(p, 1024)) + if (p.state != NULL && !OSSL_PARAM_set_int(p.state, crngt->state)) return 0; - p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_MAX_REQUEST); - if (p != NULL && !OSSL_PARAM_set_size_t(p, 128)) + if (p.str != NULL && !OSSL_PARAM_set_uint(p.str, 1024)) return 0; - p = OSSL_PARAM_locate(params, OSSL_RAND_PARAM_FIPS_APPROVED_INDICATOR); - if (p != NULL && !OSSL_PARAM_set_int(p, 0)) + if (p.maxreq != NULL && !OSSL_PARAM_set_size_t(p.maxreq, 128)) + return 0; + + if (p.ind != NULL && !OSSL_PARAM_set_int(p.ind, 0)) return 0; return 1; } @@ -392,17 +405,10 @@ static const OSSL_PARAM *crng_test_gettable_ctx_params(void *vcrngt, void *provctx) { CRNG_TEST *crngt = (CRNG_TEST *)vcrngt; - 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_int(OSSL_RAND_PARAM_FIPS_APPROVED_INDICATOR, NULL), - OSSL_PARAM_END - }; if (crngt->parent != NULL && crngt->parent_gettable_ctx_params != NULL) return crngt->parent_gettable_ctx_params(crngt->parent, provctx); - return known_gettable_ctx_params; + return crng_test_get_ctx_params_list; } const OSSL_DISPATCH ossl_crng_test_functions[] = { -- 2.47.3