2 * Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/nelem.h"
12 #include <openssl/crypto.h>
13 #include <openssl/err.h>
14 #include <openssl/rand.h>
15 #include <openssl/obj_mac.h>
16 #include <openssl/evp.h>
17 #include <openssl/aes.h>
18 #include "../crypto/rand/rand_local.h"
19 #include "../include/crypto/rand.h"
20 #include "../include/crypto/evp.h"
21 #include "../providers/implementations/rands/drbg_local.h"
22 #include "../crypto/evp/evp_local.h"
29 # if defined(OPENSSL_TANDEM_FLOSS)
30 # include <floss.h(floss_fork)>
34 #if defined(OPENSSL_SYS_UNIX)
35 # include <sys/types.h>
36 # include <sys/wait.h>
44 * DRBG generate wrappers
46 static int gen_bytes(EVP_RAND_CTX *drbg, unsigned char *buf, int num)
48 const RAND_METHOD *meth = RAND_get_rand_method();
50 if (meth != NULL && meth != RAND_OpenSSL()) {
51 if (meth->bytes != NULL)
52 return meth->bytes(buf, num);
57 return EVP_RAND_generate(drbg, buf, num, 0, 0, NULL, 0);
61 static int rand_bytes(unsigned char *buf, int num)
63 return gen_bytes(RAND_get0_public(NULL), buf, num);
66 static int rand_priv_bytes(unsigned char *buf, int num)
68 return gen_bytes(RAND_get0_private(NULL), buf, num);
72 /* size of random output generated in test_drbg_reseed() */
73 #define RANDOM_SIZE 16
76 * DRBG query functions
78 static int state(EVP_RAND_CTX *drbg)
80 return EVP_RAND_state(drbg);
83 static unsigned int query_rand_uint(EVP_RAND_CTX *drbg, const char *name)
85 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
88 *params = OSSL_PARAM_construct_uint(name, &n);
89 if (EVP_RAND_get_ctx_params(drbg, params))
94 #define DRBG_UINT(name) \
95 static unsigned int name(EVP_RAND_CTX *drbg) \
97 return query_rand_uint(drbg, #name); \
99 DRBG_UINT(reseed_counter)
101 static PROV_DRBG *prov_rand(EVP_RAND_CTX *drbg)
103 return (PROV_DRBG *)drbg->data;
106 static void set_reseed_counter(EVP_RAND_CTX *drbg, unsigned int n)
108 PROV_DRBG *p = prov_rand(drbg);
110 p->reseed_counter = n;
113 static void inc_reseed_counter(EVP_RAND_CTX *drbg)
115 set_reseed_counter(drbg, reseed_counter(drbg) + 1);
118 static time_t reseed_time(EVP_RAND_CTX *drbg)
120 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
123 *params = OSSL_PARAM_construct_time_t(OSSL_DRBG_PARAM_RESEED_TIME, &t);
124 if (EVP_RAND_get_ctx_params(drbg, params))
130 * When building the FIPS module, it isn't possible to disable the continuous
131 * RNG tests. Tests that require this are skipped.
133 static int crngt_skip(void)
143 * Disable CRNG testing if it is enabled.
144 * This stub remains to indicate the calling locations where it is necessary.
145 * Once the RNG infrastructure is able to disable these tests, it should be
148 static int disable_crngt(EVP_RAND_CTX *drbg)
154 * Generates random output using rand_bytes() and rand_priv_bytes()
155 * and checks whether the three shared DRBGs were reseeded as
158 * |expect_success|: expected outcome (as reported by RAND_status())
159 * |primary|, |public|, |private|: pointers to the three shared DRBGs
160 * |public_random|, |private_random|: generated random output
161 * |expect_xxx_reseed| =
162 * 1: it is expected that the specified DRBG is reseeded
163 * 0: it is expected that the specified DRBG is not reseeded
164 * -1: don't check whether the specified DRBG was reseeded or not
165 * |reseed_when|: if nonzero, used instead of time(NULL) to set the
166 * |before_reseed| time.
168 static int test_drbg_reseed(int expect_success,
169 EVP_RAND_CTX *primary,
170 EVP_RAND_CTX *public,
171 EVP_RAND_CTX *private,
172 unsigned char *public_random,
173 unsigned char *private_random,
174 int expect_primary_reseed,
175 int expect_public_reseed,
176 int expect_private_reseed,
180 time_t before_reseed, after_reseed;
181 int expected_state = (expect_success ? DRBG_READY : DRBG_ERROR);
182 unsigned int primary_reseed, public_reseed, private_reseed;
183 unsigned char dummy[RANDOM_SIZE];
185 if (public_random == NULL)
186 public_random = dummy;
188 if (private_random == NULL)
189 private_random = dummy;
192 * step 1: check preconditions
195 /* Test whether seed propagation is enabled */
196 if (!TEST_int_ne(primary_reseed = reseed_counter(primary), 0)
197 || !TEST_int_ne(public_reseed = reseed_counter(public), 0)
198 || !TEST_int_ne(private_reseed = reseed_counter(private), 0))
202 * step 2: generate random output
205 if (reseed_when == 0)
206 reseed_when = time(NULL);
208 /* Generate random output from the public and private DRBG */
209 before_reseed = expect_primary_reseed == 1 ? reseed_when : 0;
210 if (!TEST_int_eq(rand_bytes((unsigned char*)public_random,
211 RANDOM_SIZE), expect_success)
212 || !TEST_int_eq(rand_priv_bytes((unsigned char*) private_random,
213 RANDOM_SIZE), expect_success))
215 after_reseed = time(NULL);
219 * step 3: check postconditions
222 /* Test whether reseeding succeeded as expected */
223 if (!TEST_int_eq(state(primary), expected_state)
224 || !TEST_int_eq(state(public), expected_state)
225 || !TEST_int_eq(state(private), expected_state))
228 if (expect_primary_reseed >= 0) {
229 /* Test whether primary DRBG was reseeded as expected */
230 if (!TEST_int_ge(reseed_counter(primary), primary_reseed))
234 if (expect_public_reseed >= 0) {
235 /* Test whether public DRBG was reseeded as expected */
236 if (!TEST_int_ge(reseed_counter(public), public_reseed)
237 || !TEST_uint_ge(reseed_counter(public),
238 reseed_counter(primary)))
242 if (expect_private_reseed >= 0) {
243 /* Test whether public DRBG was reseeded as expected */
244 if (!TEST_int_ge(reseed_counter(private), private_reseed)
245 || !TEST_uint_ge(reseed_counter(private),
246 reseed_counter(primary)))
250 if (expect_success == 1) {
251 /* Test whether reseed time of primary DRBG is set correctly */
252 if (!TEST_time_t_le(before_reseed, reseed_time(primary))
253 || !TEST_time_t_le(reseed_time(primary), after_reseed))
256 /* Test whether reseed times of child DRBGs are synchronized with primary */
257 if (!TEST_time_t_ge(reseed_time(public), reseed_time(primary))
258 || !TEST_time_t_ge(reseed_time(private), reseed_time(primary)))
268 #if defined(OPENSSL_SYS_UNIX)
269 /* number of children to fork */
270 #define DRBG_FORK_COUNT 9
271 /* two results per child, two for the parent */
272 #define DRBG_FORK_RESULT_COUNT (2 * (DRBG_FORK_COUNT + 1))
274 typedef struct drbg_fork_result_st {
276 unsigned char random[RANDOM_SIZE]; /* random output */
278 int pindex; /* process index (0: parent, 1,2,3...: children)*/
279 pid_t pid; /* process id */
280 int private; /* true if the private drbg was used */
281 char name[10]; /* 'parent' resp. 'child 1', 'child 2', ... */
285 * Sort the drbg_fork_result entries in lexicographical order
287 * This simplifies finding duplicate random output and makes
288 * the printout in case of an error more readable.
290 static int compare_drbg_fork_result(const void * left, const void * right)
293 const drbg_fork_result *l = left;
294 const drbg_fork_result *r = right;
296 /* separate public and private results */
297 result = l->private - r->private;
300 result = memcmp(l->random, r->random, RANDOM_SIZE);
303 result = l->pindex - r->pindex;
309 * Sort two-byte chunks of random data
311 * Used for finding collisions in two-byte chunks
313 static int compare_rand_chunk(const void * left, const void * right)
315 return memcmp(left, right, 2);
319 * Test whether primary, public and private DRBG are reseeded
320 * in the child after forking the process. Collect the random
321 * output of the public and private DRBG and send it back to
322 * the parent process.
324 static int test_drbg_reseed_in_child(EVP_RAND_CTX *primary,
325 EVP_RAND_CTX *public,
326 EVP_RAND_CTX *private,
327 drbg_fork_result result[2])
332 unsigned char random[2 * RANDOM_SIZE];
334 if (!TEST_int_ge(pipe(fd), 0))
337 if (!TEST_int_ge(pid = fork(), 0)) {
341 } else if (pid > 0) {
343 /* I'm the parent; close the write end */
346 /* wait for children to terminate and collect their random output */
347 if (TEST_int_eq(waitpid(pid, &status, 0), pid)
348 && TEST_int_eq(status, 0)
349 && TEST_true(read(fd[0], &random[0], sizeof(random))
350 == sizeof(random))) {
352 /* random output of public drbg */
354 result[0].private = 0;
355 memcpy(result[0].random, &random[0], RANDOM_SIZE);
357 /* random output of private drbg */
359 result[1].private = 1;
360 memcpy(result[1].random, &random[RANDOM_SIZE], RANDOM_SIZE);
365 /* close the read end */
372 /* I'm the child; close the read end */
375 /* check whether all three DRBGs reseed and send output to parent */
376 if (TEST_true(test_drbg_reseed(1, primary, public, private,
377 &random[0], &random[RANDOM_SIZE],
379 && TEST_true(write(fd[1], random, sizeof(random))
380 == sizeof(random))) {
385 /* close the write end */
388 /* convert boolean to exit code */
393 static int test_rand_reseed_on_fork(EVP_RAND_CTX *primary,
394 EVP_RAND_CTX *public,
395 EVP_RAND_CTX *private)
398 pid_t pid = getpid();
399 int verbose = (getenv("V") != NULL);
401 int duplicate[2] = {0, 0};
402 unsigned char random[2 * RANDOM_SIZE];
403 unsigned char sample[DRBG_FORK_RESULT_COUNT * RANDOM_SIZE];
404 unsigned char *psample = &sample[0];
405 drbg_fork_result result[DRBG_FORK_RESULT_COUNT];
406 drbg_fork_result *presult = &result[2];
408 memset(&result, 0, sizeof(result));
410 for (i = 1 ; i <= DRBG_FORK_COUNT ; ++i) {
412 presult[0].pindex = presult[1].pindex = i;
414 sprintf(presult[0].name, "child %d", i);
415 strcpy(presult[1].name, presult[0].name);
417 /* collect the random output of the children */
418 if (!TEST_true(test_drbg_reseed_in_child(primary,
427 /* collect the random output of the parent */
428 if (!TEST_true(test_drbg_reseed(1,
429 primary, public, private,
430 &random[0], &random[RANDOM_SIZE],
434 strcpy(result[0].name, "parent");
435 strcpy(result[1].name, "parent");
437 /* output of public drbg */
439 result[0].private = 0;
440 memcpy(result[0].random, &random[0], RANDOM_SIZE);
442 /* output of private drbg */
444 result[1].private = 1;
445 memcpy(result[1].random, &random[RANDOM_SIZE], RANDOM_SIZE);
447 /* collect all sampled random data in a single buffer */
448 for (i = 0 ; i < DRBG_FORK_RESULT_COUNT ; ++i) {
449 memcpy(psample, &result[i].random[0], RANDOM_SIZE);
450 psample += RANDOM_SIZE;
453 /* sort the results... */
454 qsort(result, DRBG_FORK_RESULT_COUNT, sizeof(drbg_fork_result),
455 compare_drbg_fork_result);
457 /* ...and count duplicate prefixes by looking at the first byte only */
458 for (i = 1 ; i < DRBG_FORK_RESULT_COUNT ; ++i) {
459 if (result[i].random[0] == result[i-1].random[0]) {
460 /* count public and private duplicates separately */
461 ++duplicate[result[i].private];
465 if (duplicate[0] >= DRBG_FORK_COUNT - 1) {
466 /* just too many duplicates to be a coincidence */
467 TEST_note("ERROR: %d duplicate prefixes in public random output", duplicate[0]);
471 if (duplicate[1] >= DRBG_FORK_COUNT - 1) {
472 /* just too many duplicates to be a coincidence */
473 TEST_note("ERROR: %d duplicate prefixes in private random output", duplicate[1]);
479 /* sort the two-byte chunks... */
480 qsort(sample, sizeof(sample)/2, 2, compare_rand_chunk);
482 /* ...and count duplicate chunks */
483 for (i = 2, psample = sample + 2 ; i < sizeof(sample) ; i += 2, psample += 2) {
484 if (compare_rand_chunk(psample - 2, psample) == 0)
488 if (duplicate[0] >= DRBG_FORK_COUNT - 1) {
489 /* just too many duplicates to be a coincidence */
490 TEST_note("ERROR: %d duplicate chunks in random output", duplicate[0]);
494 if (verbose || !success) {
496 for (i = 0 ; i < DRBG_FORK_RESULT_COUNT ; ++i) {
497 char *rand_hex = OPENSSL_buf2hexstr(result[i].random, RANDOM_SIZE);
499 TEST_note(" random: %s, pid: %d (%s, %s)",
503 result[i].private ? "private" : "public"
506 OPENSSL_free(rand_hex);
513 static int test_rand_fork_safety(int i)
516 unsigned char random[1];
517 EVP_RAND_CTX *primary, *public, *private;
519 /* All three DRBGs should be non-null */
520 if (!TEST_ptr(primary = RAND_get0_primary(NULL))
521 || !TEST_ptr(public = RAND_get0_public(NULL))
522 || !TEST_ptr(private = RAND_get0_private(NULL)))
525 /* run the actual test */
526 if (!TEST_true(test_rand_reseed_on_fork(primary, public, private)))
529 /* request a single byte from each of the DRBGs before the next run */
530 if (!TEST_true(RAND_bytes(random, 1) && RAND_priv_bytes(random, 1)))
538 * Test whether the default rand_method (RAND_OpenSSL()) is
539 * setup correctly, in particular whether reseeding works
542 static int test_rand_reseed(void)
544 EVP_RAND_CTX *primary, *public, *private;
545 unsigned char rand_add_buf[256];
547 time_t before_reseed;
550 return TEST_skip("CRNGT cannot be disabled");
552 /* Check whether RAND_OpenSSL() is the default method */
553 if (!TEST_ptr_eq(RAND_get_rand_method(), RAND_OpenSSL()))
556 /* All three DRBGs should be non-null */
557 if (!TEST_ptr(primary = RAND_get0_primary(NULL))
558 || !TEST_ptr(public = RAND_get0_public(NULL))
559 || !TEST_ptr(private = RAND_get0_private(NULL)))
562 /* There should be three distinct DRBGs, two of them chained to primary */
563 if (!TEST_ptr_ne(public, private)
564 || !TEST_ptr_ne(public, primary)
565 || !TEST_ptr_ne(private, primary)
566 || !TEST_ptr_eq(prov_rand(public)->parent, prov_rand(primary))
567 || !TEST_ptr_eq(prov_rand(private)->parent, prov_rand(primary)))
570 /* Disable CRNG testing for the primary DRBG */
571 if (!TEST_true(disable_crngt(primary)))
574 /* uninstantiate the three global DRBGs */
575 EVP_RAND_uninstantiate(primary);
576 EVP_RAND_uninstantiate(private);
577 EVP_RAND_uninstantiate(public);
581 * Test initial seeding of shared DRBGs
583 if (!TEST_true(test_drbg_reseed(1,
584 primary, public, private,
591 * Test initial state of shared DRBGs
593 if (!TEST_true(test_drbg_reseed(1,
594 primary, public, private,
600 * Test whether the public and private DRBG are both reseeded when their
601 * reseed counters differ from the primary's reseed counter.
603 inc_reseed_counter(primary);
604 if (!TEST_true(test_drbg_reseed(1,
605 primary, public, private,
611 * Test whether the public DRBG is reseeded when its reseed counter differs
612 * from the primary's reseed counter.
614 inc_reseed_counter(primary);
615 inc_reseed_counter(private);
616 if (!TEST_true(test_drbg_reseed(1,
617 primary, public, private,
623 * Test whether the private DRBG is reseeded when its reseed counter differs
624 * from the primary's reseed counter.
626 inc_reseed_counter(primary);
627 inc_reseed_counter(public);
628 if (!TEST_true(test_drbg_reseed(1,
629 primary, public, private,
634 /* fill 'randomness' buffer with some arbitrary data */
635 memset(rand_add_buf, 'r', sizeof(rand_add_buf));
639 * Test whether all three DRBGs are reseeded by RAND_add().
640 * The before_reseed time has to be measured here and passed into the
641 * test_drbg_reseed() test, because the primary DRBG gets already reseeded
642 * in RAND_add(), whence the check for the condition
643 * before_reseed <= reseed_time(primary) will fail if the time value happens
644 * to increase between the RAND_add() and the test_drbg_reseed() call.
646 before_reseed = time(NULL);
647 RAND_add(rand_add_buf, sizeof(rand_add_buf), sizeof(rand_add_buf));
648 if (!TEST_true(test_drbg_reseed(1,
649 primary, public, private,
654 #else /* FIPS_MODULE */
656 * In FIPS mode, random data provided by the application via RAND_add()
657 * is not considered a trusted entropy source. It is only treated as
658 * additional_data and no reseeding is forced. This test assures that
659 * no reseeding occurs.
661 before_reseed = time(NULL);
662 RAND_add(rand_add_buf, sizeof(rand_add_buf), sizeof(rand_add_buf));
663 if (!TEST_true(test_drbg_reseed(1,
664 primary, public, private,
677 #if defined(OPENSSL_THREADS)
678 static int multi_thread_rand_bytes_succeeded = 1;
679 static int multi_thread_rand_priv_bytes_succeeded = 1;
681 static int set_reseed_time_interval(EVP_RAND_CTX *drbg, int t)
683 OSSL_PARAM params[2];
685 params[0] = OSSL_PARAM_construct_int(OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL,
687 params[1] = OSSL_PARAM_construct_end();
688 return EVP_RAND_set_ctx_params(drbg, params);
691 static void run_multi_thread_test(void)
693 unsigned char buf[256];
694 time_t start = time(NULL);
695 EVP_RAND_CTX *public = NULL, *private = NULL;
697 if (!TEST_ptr(public = RAND_get0_public(NULL))
698 || !TEST_ptr(private = RAND_get0_private(NULL))
699 || !TEST_true(set_reseed_time_interval(private, 1))
700 || !TEST_true(set_reseed_time_interval(public, 1))) {
701 multi_thread_rand_bytes_succeeded = 0;
706 if (rand_bytes(buf, sizeof(buf)) <= 0)
707 multi_thread_rand_bytes_succeeded = 0;
708 if (rand_priv_bytes(buf, sizeof(buf)) <= 0)
709 multi_thread_rand_priv_bytes_succeeded = 0;
711 while (time(NULL) - start < 5);
714 # if defined(OPENSSL_SYS_WINDOWS)
716 typedef HANDLE thread_t;
718 static DWORD WINAPI thread_run(LPVOID arg)
720 run_multi_thread_test();
722 * Because we're linking with a static library, we must stop each
723 * thread explicitly, or so says OPENSSL_thread_stop(3)
725 OPENSSL_thread_stop();
729 static int run_thread(thread_t *t)
731 *t = CreateThread(NULL, 0, thread_run, NULL, 0, NULL);
735 static int wait_for_thread(thread_t thread)
737 return WaitForSingleObject(thread, INFINITE) == 0;
742 typedef pthread_t thread_t;
744 static void *thread_run(void *arg)
746 run_multi_thread_test();
748 * Because we're linking with a static library, we must stop each
749 * thread explicitly, or so says OPENSSL_thread_stop(3)
751 OPENSSL_thread_stop();
755 static int run_thread(thread_t *t)
757 return pthread_create(t, NULL, thread_run, NULL) == 0;
760 static int wait_for_thread(thread_t thread)
762 return pthread_join(thread, NULL) == 0;
768 * The main thread will also run the test, so we'll have THREADS+1 parallel
773 static int test_multi_thread(void)
778 for (i = 0; i < THREADS; i++)
780 run_multi_thread_test();
781 for (i = 0; i < THREADS; i++)
782 wait_for_thread(t[i]);
784 if (!TEST_true(multi_thread_rand_bytes_succeeded))
786 if (!TEST_true(multi_thread_rand_priv_bytes_succeeded))
793 static EVP_RAND_CTX *new_drbg(EVP_RAND_CTX *parent)
795 OSSL_PARAM params[2];
796 EVP_RAND *rand = NULL;
797 EVP_RAND_CTX *drbg = NULL;
799 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_DRBG_PARAM_CIPHER,
801 params[1] = OSSL_PARAM_construct_end();
803 if (!TEST_ptr(rand = EVP_RAND_fetch(NULL, "CTR-DRBG", NULL))
804 || !TEST_ptr(drbg = EVP_RAND_CTX_new(rand, parent))
805 || !TEST_true(EVP_RAND_set_ctx_params(drbg, params))) {
806 EVP_RAND_CTX_free(drbg);
813 static int test_rand_prediction_resistance(void)
815 EVP_RAND_CTX *x = NULL, *y = NULL, *z = NULL;
816 unsigned char buf1[51], buf2[sizeof(buf1)];
817 int ret = 0, xreseed, yreseed, zreseed;
820 return TEST_skip("CRNGT cannot be disabled");
822 /* Initialise a three long DRBG chain */
823 if (!TEST_ptr(x = new_drbg(NULL))
824 || !TEST_true(disable_crngt(x))
825 || !TEST_true(EVP_RAND_instantiate(x, 0, 0, NULL, 0))
826 || !TEST_ptr(y = new_drbg(x))
827 || !TEST_true(EVP_RAND_instantiate(y, 0, 0, NULL, 0))
828 || !TEST_ptr(z = new_drbg(y))
829 || !TEST_true(EVP_RAND_instantiate(z, 0, 0, NULL, 0)))
833 * During a normal reseed, only the last DRBG in the chain should
836 inc_reseed_counter(y);
837 xreseed = reseed_counter(x);
838 yreseed = reseed_counter(y);
839 zreseed = reseed_counter(z);
840 if (!TEST_true(EVP_RAND_reseed(z, 0, NULL, 0, NULL, 0))
841 || !TEST_int_eq(reseed_counter(x), xreseed)
842 || !TEST_int_eq(reseed_counter(y), yreseed)
843 || !TEST_int_gt(reseed_counter(z), zreseed))
847 * When prediction resistance is requested, the request should be
848 * propagated to the primary, so that the entire DRBG chain reseeds.
850 zreseed = reseed_counter(z);
851 if (!TEST_true(EVP_RAND_reseed(z, 1, NULL, 0, NULL, 0))
852 || !TEST_int_gt(reseed_counter(x), xreseed)
853 || !TEST_int_gt(reseed_counter(y), yreseed)
854 || !TEST_int_gt(reseed_counter(z), zreseed))
858 * During a normal generate, only the last DRBG should be reseed */
859 inc_reseed_counter(y);
860 xreseed = reseed_counter(x);
861 yreseed = reseed_counter(y);
862 zreseed = reseed_counter(z);
863 if (!TEST_true(EVP_RAND_generate(z, buf1, sizeof(buf1), 0, 0, NULL, 0))
864 || !TEST_int_eq(reseed_counter(x), xreseed)
865 || !TEST_int_eq(reseed_counter(y), yreseed)
866 || !TEST_int_gt(reseed_counter(z), zreseed))
870 * When a prediction resistant generate is requested, the request
871 * should be propagated to the primary, reseeding the entire DRBG chain.
873 zreseed = reseed_counter(z);
874 if (!TEST_true(EVP_RAND_generate(z, buf2, sizeof(buf2), 0, 1, NULL, 0))
875 || !TEST_int_gt(reseed_counter(x), xreseed)
876 || !TEST_int_gt(reseed_counter(y), yreseed)
877 || !TEST_int_gt(reseed_counter(z), zreseed)
878 || !TEST_mem_ne(buf1, sizeof(buf1), buf2, sizeof(buf2)))
881 /* Verify that a normal reseed still only reseeds the last DRBG */
882 inc_reseed_counter(y);
883 xreseed = reseed_counter(x);
884 yreseed = reseed_counter(y);
885 zreseed = reseed_counter(z);
886 if (!TEST_true(EVP_RAND_reseed(z, 0, NULL, 0, NULL, 0))
887 || !TEST_int_eq(reseed_counter(x), xreseed)
888 || !TEST_int_eq(reseed_counter(y), yreseed)
889 || !TEST_int_gt(reseed_counter(z), zreseed))
894 EVP_RAND_CTX_free(z);
895 EVP_RAND_CTX_free(y);
896 EVP_RAND_CTX_free(x);
900 int setup_tests(void)
902 ADD_TEST(test_rand_reseed);
903 #if defined(OPENSSL_SYS_UNIX)
904 ADD_ALL_TESTS(test_rand_fork_safety, RANDOM_SIZE);
906 ADD_TEST(test_rand_prediction_resistance);
907 #if defined(OPENSSL_THREADS)
908 ADD_TEST(test_multi_thread);