Merge pull request #8922 from JacobBarthelmeh/rng

altering macro guards and test case for RNG test on alternate builds
This commit is contained in:
Daniel Pouzzner
2025-06-24 22:15:14 -05:00
committed by GitHub
2 changed files with 12 additions and 10 deletions

View File

@ -25515,7 +25515,7 @@ static int wolfSSL_RAND_InitMutex(void)
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \ #if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || defined(HAVE_SELFTEST)) ((defined(HAVE_FIPS) && FIPS_VERSION3_LE(6,0,0)) || defined(HAVE_SELFTEST))
/* In older FIPS bundles add check for reseed here since it does not exist in /* In older FIPS bundles add check for reseed here since it does not exist in
* the older random.c certified files. */ * the older random.c certified files. */
static pid_t currentRandPid = 0; static pid_t currentRandPid = 0;
@ -25534,7 +25534,7 @@ int wolfSSL_RAND_Init(void)
ret = wc_InitRng(&globalRNG); ret = wc_InitRng(&globalRNG);
if (ret == 0) { if (ret == 0) {
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \ #if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || \ ((defined(HAVE_FIPS) && FIPS_VERSION3_LE(6,0,0)) || \
defined(HAVE_SELFTEST)) defined(HAVE_SELFTEST))
currentRandPid = getpid(); currentRandPid = getpid();
@ -26017,7 +26017,7 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
*/ */
if (initGlobalRNG) { if (initGlobalRNG) {
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \ #if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || \ ((defined(HAVE_FIPS) && FIPS_VERSION3_LE(6,0,0)) || \
defined(HAVE_SELFTEST)) defined(HAVE_SELFTEST))
pid_t p; pid_t p;

View File

@ -33199,7 +33199,8 @@ static int test_wolfSSL_RAND_bytes(void)
const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */ const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */
int max_bufsize; int max_bufsize;
byte *my_buf = NULL; byte *my_buf = NULL;
#if defined(HAVE_GETPID) #if defined(OPENSSL_EXTRA) && defined(HAVE_GETPID) && !defined(__MINGW64__) && \
!defined(__MINGW32__)
byte seed[16] = {0}; byte seed[16] = {0};
byte randbuf[8] = {0}; byte randbuf[8] = {0};
int pipefds[2] = {0}; int pipefds[2] = {0};
@ -33225,7 +33226,8 @@ static int test_wolfSSL_RAND_bytes(void)
ExpectIntEQ(RAND_bytes(my_buf, size4), 1); ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
XFREE(my_buf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(my_buf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#if defined(OPENSSL_EXTRA) && defined(HAVE_GETPID) #if defined(OPENSSL_EXTRA) && defined(HAVE_GETPID) && !defined(__MINGW64__) && \
!defined(__MINGW32__)
XMEMSET(seed, 0, sizeof(seed)); XMEMSET(seed, 0, sizeof(seed));
RAND_cleanup(); RAND_cleanup();
@ -33247,17 +33249,17 @@ static int test_wolfSSL_RAND_bytes(void)
} }
else { else {
/* Parent process. */ /* Parent process. */
word64 childrand64 = 0; byte childrand[8] = {0};
int waitstatus = 0; int waitstatus = 0;
close(pipefds[1]); close(pipefds[1]);
ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1); ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1);
ExpectIntEQ(read(pipefds[0], &childrand64, sizeof(childrand64)), ExpectIntEQ(read(pipefds[0], childrand, sizeof(childrand)),
sizeof(childrand64)); sizeof(childrand));
#ifdef WOLFSSL_NO_GETPID #ifdef WOLFSSL_NO_GETPID
ExpectBufEQ(randbuf, &childrand64, sizeof(randbuf)); ExpectBufEQ(randbuf, childrand, sizeof(randbuf));
#else #else
ExpectBufNE(randbuf, &childrand64, sizeof(randbuf)); ExpectBufNE(randbuf, childrand, sizeof(randbuf));
#endif #endif
close(pipefds[0]); close(pipefds[0]);
waitpid(pid, &waitstatus, 0); waitpid(pid, &waitstatus, 0);