From: Vitezslav Cizek Date: Mon, 1 Jun 2020 09:45:09 +0000 (+0200) Subject: Fix DRBG reseed counter condition. X-Git-Tag: openssl-3.0.0-alpha6~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fb6692c1b129fa61277ae0482975a935274c6fd;p=thirdparty%2Fopenssl.git 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) --- diff --git a/providers/implementations/rands/drbg.c b/providers/implementations/rands/drbg.c index 3394271835f..929b32e7087 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 5486813dc7c..118677c2edb 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;