prov: update rand implementations to have a params argument for the instantiate call
authorPauli <ppzgs1@gmail.com>
Fri, 26 Feb 2021 00:55:40 +0000 (10:55 +1000)
committerPauli <ppzgs1@gmail.com>
Sun, 28 Feb 2021 07:25:49 +0000 (17:25 +1000)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14310)

fuzz/fuzz_rand.c
providers/implementations/rands/drbg.c
providers/implementations/rands/drbg_ctr.c
providers/implementations/rands/drbg_hash.c
providers/implementations/rands/drbg_hmac.c
providers/implementations/rands/seed_src.c
providers/implementations/rands/test_rng.c
test/testutil/fake_random.c

index cd5371efbdefc780bd60476c4729bdc96575796d..5bd343d8ae999a078aceab437dcaae628d9cbc11 100644 (file)
@@ -41,7 +41,8 @@ static int fuzz_rand_instantiate(ossl_unused void *vrng,
                                  ossl_unused unsigned int strength,
                                  ossl_unused int prediction_resistance,
                                  ossl_unused const unsigned char *pstr,
-                                 ossl_unused size_t pstr_len)
+                                 ossl_unused size_t pstr_len,
+                                 ossl_unused const OSSL_PARAM params[])
 {
     *(int *)vrng = EVP_RAND_STATE_READY;
     return 1;
index fc8ac52ac23f2d681fd4f976d791c68452cd7ab2..a05c9397c8b5736c37b8059061de6476d18e5108 100644 (file)
@@ -365,9 +365,6 @@ int ossl_prov_drbg_instantiate(PROV_DRBG *drbg, unsigned int strength,
     size_t noncelen = 0, entropylen = 0;
     size_t min_entropy, min_entropylen, max_entropylen;
 
-    if (!ossl_prov_is_running())
-        return 0;
-
     if (strength > drbg->strength) {
         ERR_raise(ERR_LIB_PROV, PROV_R_INSUFFICIENT_DRBG_STRENGTH);
         goto end;
index 066775aa5231f930f19e3424f0ea9b5651241395..48e8677ec8c4d51a342587c62af57d5400663189 100644 (file)
@@ -18,6 +18,7 @@
 #include "crypto/modes.h"
 #include "internal/thread_once.h"
 #include "prov/implementations.h"
+#include "prov/providercommon.h"
 #include "prov/provider_ctx.h"
 #include "drbg_local.h"
 
@@ -326,10 +327,13 @@ static int drbg_ctr_instantiate(PROV_DRBG *drbg,
 static int drbg_ctr_instantiate_wrapper(void *vdrbg, unsigned int strength,
                                         int prediction_resistance,
                                         const unsigned char *pstr,
-                                        size_t pstr_len)
+                                        size_t pstr_len,
+                                        const OSSL_PARAM params[])
 {
     PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
 
+    if (!ossl_prov_is_running() || !drbg_ctr_set_ctx_params(drbg, params))
+        return 0;
     return ossl_prov_drbg_instantiate(drbg, strength, prediction_resistance,
                                       pstr, pstr_len);
 }
index c89b0cd5c3fc2700ddc95003eac0e8b93c4ccf65..4db104c7736d887946f6b9f7ef30e696cbf5e55f 100644 (file)
@@ -266,10 +266,13 @@ static int drbg_hash_instantiate(PROV_DRBG *drbg,
 static int drbg_hash_instantiate_wrapper(void *vdrbg, unsigned int strength,
                                          int prediction_resistance,
                                          const unsigned char *pstr,
-                                         size_t pstr_len)
+                                         size_t pstr_len,
+                                         const OSSL_PARAM params[])
 {
     PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
 
+    if (!ossl_prov_is_running() || !drbg_hash_set_ctx_params(drbg, params))
+        return 0;
     return ossl_prov_drbg_instantiate(drbg, strength, prediction_resistance,
                                       pstr, pstr_len);
 }
index 85b7adfe86dc95f8010544a27679bf5d273698d7..67c0339801d2f1081091a99c93251cf8e119c6dd 100644 (file)
@@ -143,10 +143,13 @@ static int drbg_hmac_instantiate(PROV_DRBG *drbg,
 static int drbg_hmac_instantiate_wrapper(void *vdrbg, unsigned int strength,
                                          int prediction_resistance,
                                          const unsigned char *pstr,
-                                         size_t pstr_len)
+                                         size_t pstr_len,
+                                         const OSSL_PARAM params[])
 {
     PROV_DRBG *drbg = (PROV_DRBG *)vdrbg;
 
+    if (!ossl_prov_is_running() || !drbg_hmac_set_ctx_params(drbg, params))
+        return 0;
     return ossl_prov_drbg_instantiate(drbg, strength, prediction_resistance,
                                       pstr, pstr_len);
 }
index b87aa0c6cdf69bf4fa366d94082004e3e6718fbb..ad315efb9b984ded4150b6ac21b5922f68c4a8a8 100644 (file)
@@ -70,7 +70,8 @@ static void seed_src_free(void *vseed)
 
 static int seed_src_instantiate(void *vseed, unsigned int strength,
                                 int prediction_resistance,
-                                const unsigned char *pstr, size_t pstr_len)
+                                const unsigned char *pstr, size_t pstr_len,
+                                ossl_unused const OSSL_PARAM params[])
 {
     PROV_SEED_SRC *s = (PROV_SEED_SRC *)vseed;
 
index d28f7e0937401c76d2cfcc8f24bf223510baf85e..1335de8681d047b4067fb13a14ca1bd0f0dd8962 100644 (file)
@@ -79,11 +79,12 @@ static void test_rng_free(void *vtest)
 
 static int test_rng_instantiate(void *vtest, unsigned int strength,
                                 int prediction_resistance,
-                                const unsigned char *pstr, size_t pstr_len)
+                                const unsigned char *pstr, size_t pstr_len,
+                                const OSSL_PARAM params[])
 {
     PROV_TEST_RNG *t = (PROV_TEST_RNG *)vtest;
 
-    if (strength > t->strength)
+    if (!test_rng_set_ctx_params(t, params) || strength > t->strength)
         return 0;
 
     t->state = EVP_RAND_STATE_READY;
index 9d9b10feb15334b4c1cdbb17881840b49f63ab2b..f8b97d2287e7ef665c6447b35d0deeea9c0ab41f 100644 (file)
@@ -48,7 +48,8 @@ static void fake_rand_freectx(void *vrng)
 static int fake_rand_instantiate(void *vrng, ossl_unused unsigned int strength,
                                  ossl_unused  int prediction_resistance,
                                  ossl_unused const unsigned char *pstr,
-                                 size_t pstr_len)
+                                 size_t pstr_len,
+                                 ossl_unused const OSSL_PARAM params[])
 {
     FAKE_RAND *frng = (FAKE_RAND *)vrng;