Import OpenSSL 1.1.1i
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -286,7 +286,6 @@ static int instantiate(RAND_DRBG *drbg, DRBG_SELFTEST_DATA *td,
|
||||
*/
|
||||
static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
{
|
||||
static char zero[sizeof(RAND_DRBG)];
|
||||
RAND_DRBG *drbg = NULL;
|
||||
TEST_CTX t;
|
||||
unsigned char buff[1024];
|
||||
@@ -302,7 +301,7 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
|
||||
/* Test detection of too large personalisation string */
|
||||
if (!init(drbg, td, &t)
|
||||
|| RAND_DRBG_instantiate(drbg, td->pers, drbg->max_perslen + 1) > 0)
|
||||
|| !TEST_false(RAND_DRBG_instantiate(drbg, td->pers, drbg->max_perslen + 1)))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
@@ -311,7 +310,7 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
|
||||
/* Test entropy source failure detection: i.e. returns no data */
|
||||
t.entropylen = 0;
|
||||
if (TEST_int_le(RAND_DRBG_instantiate(drbg, td->pers, td->perslen), 0))
|
||||
if (!TEST_false(RAND_DRBG_instantiate(drbg, td->pers, td->perslen)))
|
||||
goto err;
|
||||
|
||||
/* Try to generate output from uninstantiated DRBG */
|
||||
@@ -321,16 +320,18 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
goto err;
|
||||
|
||||
/* Test insufficient entropy */
|
||||
if (!init(drbg, td, &t))
|
||||
goto err;
|
||||
t.entropylen = drbg->min_entropylen - 1;
|
||||
if (!init(drbg, td, &t)
|
||||
|| RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
|
||||
if (!TEST_false(RAND_DRBG_instantiate(drbg, td->pers, td->perslen))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
|
||||
/* Test too much entropy */
|
||||
if (!init(drbg, td, &t))
|
||||
goto err;
|
||||
t.entropylen = drbg->max_entropylen + 1;
|
||||
if (!init(drbg, td, &t)
|
||||
|| RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
|
||||
if (!TEST_false(RAND_DRBG_instantiate(drbg, td->pers, td->perslen))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
|
||||
@@ -340,18 +341,20 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
|
||||
/* Test too small nonce */
|
||||
if (drbg->min_noncelen) {
|
||||
if (!init(drbg, td, &t))
|
||||
goto err;
|
||||
t.noncelen = drbg->min_noncelen - 1;
|
||||
if (!init(drbg, td, &t)
|
||||
|| RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
|
||||
if (!TEST_false(RAND_DRBG_instantiate(drbg, td->pers, td->perslen))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Test too large nonce */
|
||||
if (drbg->max_noncelen) {
|
||||
if (!init(drbg, td, &t))
|
||||
goto err;
|
||||
t.noncelen = drbg->max_noncelen + 1;
|
||||
if (!init(drbg, td, &t)
|
||||
|| RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
|
||||
if (!TEST_false(RAND_DRBG_instantiate(drbg, td->pers, td->perslen))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
}
|
||||
@@ -377,7 +380,7 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
* failure.
|
||||
*/
|
||||
t.entropylen = 0;
|
||||
if (TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,
|
||||
if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,
|
||||
td->adin, td->adinlen))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
@@ -385,15 +388,15 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
/* Instantiate again with valid data */
|
||||
if (!instantiate(drbg, td, &t))
|
||||
goto err;
|
||||
reseed_counter_tmp = drbg->reseed_gen_counter;
|
||||
drbg->reseed_gen_counter = drbg->reseed_interval;
|
||||
reseed_counter_tmp = drbg->generate_counter;
|
||||
drbg->generate_counter = drbg->reseed_interval;
|
||||
|
||||
/* Generate output and check entropy has been requested for reseed */
|
||||
t.entropycnt = 0;
|
||||
if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
|
||||
td->adin, td->adinlen))
|
||||
|| !TEST_int_eq(t.entropycnt, 1)
|
||||
|| !TEST_int_eq(drbg->reseed_gen_counter, reseed_counter_tmp + 1)
|
||||
|| !TEST_int_eq(drbg->generate_counter, reseed_counter_tmp + 1)
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
|
||||
@@ -410,15 +413,15 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
/* Test reseed counter works */
|
||||
if (!instantiate(drbg, td, &t))
|
||||
goto err;
|
||||
reseed_counter_tmp = drbg->reseed_gen_counter;
|
||||
drbg->reseed_gen_counter = drbg->reseed_interval;
|
||||
reseed_counter_tmp = drbg->generate_counter;
|
||||
drbg->generate_counter = drbg->reseed_interval;
|
||||
|
||||
/* Generate output and check entropy has been requested for reseed */
|
||||
t.entropycnt = 0;
|
||||
if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
|
||||
td->adin, td->adinlen))
|
||||
|| !TEST_int_eq(t.entropycnt, 1)
|
||||
|| !TEST_int_eq(drbg->reseed_gen_counter, reseed_counter_tmp + 1)
|
||||
|| !TEST_int_eq(drbg->generate_counter, reseed_counter_tmp + 1)
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
|
||||
@@ -428,12 +431,12 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
|
||||
/* Test explicit reseed with too large additional input */
|
||||
if (!instantiate(drbg, td, &t)
|
||||
|| RAND_DRBG_reseed(drbg, td->adin, drbg->max_adinlen + 1, 0) > 0)
|
||||
|| !TEST_false(RAND_DRBG_reseed(drbg, td->adin, drbg->max_adinlen + 1, 0)))
|
||||
goto err;
|
||||
|
||||
/* Test explicit reseed with entropy source failure */
|
||||
t.entropylen = 0;
|
||||
if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0), 0)
|
||||
if (!TEST_false(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
|
||||
@@ -441,7 +444,7 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
if (!instantiate(drbg, td, &t))
|
||||
goto err;
|
||||
t.entropylen = drbg->max_entropylen + 1;
|
||||
if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0), 0)
|
||||
if (!TEST_false(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
|
||||
@@ -449,14 +452,10 @@ static int error_check(DRBG_SELFTEST_DATA *td)
|
||||
if (!instantiate(drbg, td, &t))
|
||||
goto err;
|
||||
t.entropylen = drbg->min_entropylen - 1;
|
||||
if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0), 0)
|
||||
if (!TEST_false(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0))
|
||||
|| !uninstantiate(drbg))
|
||||
goto err;
|
||||
|
||||
/* Standard says we have to check uninstantiate really zeroes */
|
||||
if (!TEST_mem_eq(zero, sizeof(drbg->data), &drbg->data, sizeof(drbg->data)))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
@@ -483,7 +482,7 @@ static int test_error_checks(int i)
|
||||
DRBG_SELFTEST_DATA *td = &drbg_test[i];
|
||||
int rv = 0;
|
||||
|
||||
if (error_check(td))
|
||||
if (!error_check(td))
|
||||
goto err;
|
||||
rv = 1;
|
||||
|
||||
@@ -601,14 +600,14 @@ static int test_drbg_reseed(int expect_success,
|
||||
*/
|
||||
|
||||
/* Test whether seed propagation is enabled */
|
||||
if (!TEST_int_ne(master->reseed_prop_counter, 0)
|
||||
|| !TEST_int_ne(public->reseed_prop_counter, 0)
|
||||
|| !TEST_int_ne(private->reseed_prop_counter, 0))
|
||||
if (!TEST_int_ne(master->reseed_counter, 0)
|
||||
|| !TEST_int_ne(public->reseed_counter, 0)
|
||||
|| !TEST_int_ne(private->reseed_counter, 0))
|
||||
return 0;
|
||||
|
||||
/* Check whether the master DRBG's reseed counter is the largest one */
|
||||
if (!TEST_int_le(public->reseed_prop_counter, master->reseed_prop_counter)
|
||||
|| !TEST_int_le(private->reseed_prop_counter, master->reseed_prop_counter))
|
||||
if (!TEST_int_le(public->reseed_counter, master->reseed_counter)
|
||||
|| !TEST_int_le(private->reseed_counter, master->reseed_counter))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
@@ -656,8 +655,8 @@ static int test_drbg_reseed(int expect_success,
|
||||
|
||||
if (expect_success == 1) {
|
||||
/* Test whether all three reseed counters are synchronized */
|
||||
if (!TEST_int_eq(public->reseed_prop_counter, master->reseed_prop_counter)
|
||||
|| !TEST_int_eq(private->reseed_prop_counter, master->reseed_prop_counter))
|
||||
if (!TEST_int_eq(public->reseed_counter, master->reseed_counter)
|
||||
|| !TEST_int_eq(private->reseed_counter, master->reseed_counter))
|
||||
return 0;
|
||||
|
||||
/* Test whether reseed time of master DRBG is set correctly */
|
||||
@@ -771,7 +770,7 @@ static int test_rand_drbg_reseed(void)
|
||||
* Test whether the public and private DRBG are both reseeded when their
|
||||
* reseed counters differ from the master's reseed counter.
|
||||
*/
|
||||
master->reseed_prop_counter++;
|
||||
master->reseed_counter++;
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 1, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
@@ -780,8 +779,8 @@ static int test_rand_drbg_reseed(void)
|
||||
* Test whether the public DRBG is reseeded when its reseed counter differs
|
||||
* from the master's reseed counter.
|
||||
*/
|
||||
master->reseed_prop_counter++;
|
||||
private->reseed_prop_counter++;
|
||||
master->reseed_counter++;
|
||||
private->reseed_counter++;
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 0, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
@@ -790,8 +789,8 @@ static int test_rand_drbg_reseed(void)
|
||||
* Test whether the private DRBG is reseeded when its reseed counter differs
|
||||
* from the master's reseed counter.
|
||||
*/
|
||||
master->reseed_prop_counter++;
|
||||
public->reseed_prop_counter++;
|
||||
master->reseed_counter++;
|
||||
public->reseed_counter++;
|
||||
if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 1, 0)))
|
||||
goto error;
|
||||
reset_drbg_hook_ctx();
|
||||
@@ -824,7 +823,7 @@ static int test_rand_drbg_reseed(void)
|
||||
* Test whether none of the DRBGs is reseed if the master fails to reseed
|
||||
*/
|
||||
master_ctx.fail = 1;
|
||||
master->reseed_prop_counter++;
|
||||
master->reseed_counter++;
|
||||
RAND_add(rand_add_buf, sizeof(rand_add_buf), sizeof(rand_add_buf));
|
||||
if (!TEST_true(test_drbg_reseed(0, master, public, private, 0, 0, 0, 0)))
|
||||
goto error;
|
||||
|
||||
Reference in New Issue
Block a user