From 9fb6692c1b129fa61277ae0482975a935274c6fd Mon Sep 17 00:00:00 2001 From: Vitezslav Cizek Date: Mon, 1 Jun 2020 11:45:09 +0200 Subject: [PATCH] Fix DRBG reseed counter condition. The reseed counter condition was broken since a93ba40, where the initial value was wrongly changed from one to zero. Commit 8bf3665 fixed the initialization, but also adjusted the check, so the problem remained. This change restores original (OpenSSL-fips-2_0-stable) behavior. Reviewed-by: Paul Dale Reviewed-by: Matthias St. Pierre (Merged from https://github.com/openssl/openssl/pull/11195) --- providers/implementations/rands/drbg.c | 2 +- test/drbgtest.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/providers/implementations/rands/drbg.c b/providers/implementations/rands/drbg.c index 3394271835..929b32e708 100644 --- a/providers/implementations/rands/drbg.c +++ b/providers/implementations/rands/drbg.c @@ -742,7 +742,7 @@ int PROV_DRBG_generate(PROV_DRBG *drbg, unsigned char *out, size_t outlen, } if (drbg->reseed_interval > 0) { - if (drbg->reseed_gen_counter > drbg->reseed_interval) + if (drbg->reseed_gen_counter >= drbg->reseed_interval) reseed_required = 1; } if (drbg->reseed_time_interval > 0) { diff --git a/test/drbgtest.c b/test/drbgtest.c index 5486813dc7..118677c2ed 100644 --- a/test/drbgtest.c +++ b/test/drbgtest.c @@ -515,7 +515,7 @@ static int error_check(DRBG_SELFTEST_DATA *td) if (!instantiate(drbg, td, &t)) goto err; reseed_counter_tmp = reseed_counter(drbg); - set_reseed_counter(drbg, reseed_requests(drbg) + 1); + set_reseed_counter(drbg, reseed_requests(drbg)); /* Generate output and check entropy has been requested for reseed */ t.entropycnt = 0; @@ -540,7 +540,7 @@ static int error_check(DRBG_SELFTEST_DATA *td) if (!instantiate(drbg, td, &t)) goto err; reseed_counter_tmp = reseed_counter(drbg); - set_reseed_counter(drbg, reseed_requests(drbg) + 1); + set_reseed_counter(drbg, reseed_requests(drbg)); /* Generate output and check entropy has been requested for reseed */ t.entropycnt = 0; -- 2.34.1