From 0602e8d341e9c41256237e043f9173cf098aec09 Mon Sep 17 00:00:00 2001 From: torben-hansen <50673096+torben-hansen@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:50:28 -0700 Subject: [PATCH] Ensure array length assumption agree (#1246) PASSIVE_ENTROPY_LOAD_LENGTH and CTR_DRBG_ENTROPY_LEN are currently equal. This assumption is used implicitly in RAND_load_entropy(). Statically ensure this continues to be true while assumed. --- crypto/fipsmodule/rand/rand.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crypto/fipsmodule/rand/rand.c b/crypto/fipsmodule/rand/rand.c index 0e390dc764..53de6867a8 100644 --- a/crypto/fipsmodule/rand/rand.c +++ b/crypto/fipsmodule/rand/rand.c @@ -316,6 +316,12 @@ static int rdrand(uint8_t *buf, size_t len) { #if defined(BORINGSSL_FIPS) #if defined(FIPS_ENTROPY_SOURCE_PASSIVE) + +// Currently, we assume that the length of externally loaded entropy has the +// same length as the seed used in the ctr-drbg. +OPENSSL_STATIC_ASSERT(CTR_DRBG_ENTROPY_LEN == PASSIVE_ENTROPY_LOAD_LENGTH, + passive_entropy_load_length_different_from_ctr_drbg_seed_length) + void RAND_load_entropy(uint8_t out_entropy[CTR_DRBG_ENTROPY_LEN], uint8_t entropy[PASSIVE_ENTROPY_LOAD_LENGTH]) { OPENSSL_memcpy(out_entropy, entropy, CTR_DRBG_ENTROPY_LEN);