From d4dfd983e32b32b633aaa9edec422cc30419c6f7 Mon Sep 17 00:00:00 2001 From: Pauli Date: Mon, 25 Oct 2021 12:01:11 +1000 Subject: test-rand: return failure on not enough data, allow parent The test-rand RNG was returning success when it had some but insufficient data. Now, it returns failure and doesn't advance the data pointer. The test-rand RNG was failing when a parent was specified. This case is now ignored. Fixes #16785 Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/16905) --- providers/implementations/rands/test_rng.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'providers/implementations/rands') diff --git a/providers/implementations/rands/test_rng.c b/providers/implementations/rands/test_rng.c index bdad7ac9ac..4e7fed0fc7 100644 --- a/providers/implementations/rands/test_rng.c +++ b/providers/implementations/rands/test_rng.c @@ -52,9 +52,6 @@ static void *test_rng_new(void *provctx, void *parent, { PROV_TEST_RNG *t; - if (parent != NULL) - return NULL; - t = OPENSSL_zalloc(sizeof(*t)); if (t == NULL) return NULL; @@ -107,16 +104,11 @@ static int test_rng_generate(void *vtest, unsigned char *out, size_t outlen, const unsigned char *adin, size_t adin_len) { PROV_TEST_RNG *t = (PROV_TEST_RNG *)vtest; - size_t i; - if (strength > t->strength) + if (strength > t->strength || t->entropy_len - t->entropy_pos < outlen) return 0; - - for (i = 0; i < outlen; i++) { - out[i] = t->entropy[t->entropy_pos++]; - if (t->entropy_pos >= t->entropy_len) - break; - } + memcpy(out, t->entropy + t->entropy_pos, outlen); + t->entropy_pos += outlen; return 1; } -- cgit v1.2.3