Skip to content

Commit eb3c324

Browse files
Merge pull request #8852 from holtrop/reseed-drbg-in-rand-poll-test
Add additional compatibility layer RAND tests
2 parents 94f5948 + 1c6e3d7 commit eb3c324

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/api.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
#endif
5252

5353
#include <stdlib.h>
54+
55+
#ifdef __linux__
56+
#include <unistd.h>
57+
#include <sys/wait.h>
58+
#endif
59+
5460
#include <wolfssl/ssl.h> /* compatibility layer */
5561
#include <wolfssl/error-ssl.h>
5662

@@ -33150,6 +33156,59 @@ static int test_wolfSSL_RAND(void)
3315033156
}
3315133157

3315233158

33159+
static int test_wolfSSL_RAND_poll(void)
33160+
{
33161+
EXPECT_DECLS;
33162+
33163+
#if defined(OPENSSL_EXTRA) && defined(__linux__)
33164+
byte seed[16] = {0};
33165+
byte randbuf[8] = {0};
33166+
int pipefds[2] = {0};
33167+
pid_t pid = 0;
33168+
33169+
XMEMSET(seed, 0, sizeof(seed));
33170+
33171+
/* No global methods set. */
33172+
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
33173+
33174+
ExpectIntEQ(pipe(pipefds), 0);
33175+
pid = fork();
33176+
ExpectIntGE(pid, 0);
33177+
if (pid == 0)
33178+
{
33179+
ssize_t n_written = 0;
33180+
33181+
/* Child process. */
33182+
close(pipefds[0]);
33183+
RAND_poll();
33184+
RAND_bytes(randbuf, sizeof(randbuf));
33185+
n_written = write(pipefds[1], randbuf, sizeof(randbuf));
33186+
close(pipefds[1]);
33187+
exit(n_written == sizeof(randbuf) ? 0 : 1);
33188+
}
33189+
else
33190+
{
33191+
/* Parent process. */
33192+
word64 childrand64 = 0;
33193+
int waitstatus = 0;
33194+
33195+
close(pipefds[1]);
33196+
ExpectIntEQ(RAND_poll(), 1);
33197+
ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1);
33198+
ExpectIntEQ(read(pipefds[0], &childrand64, sizeof(childrand64)), sizeof(childrand64));
33199+
ExpectBufNE(randbuf, &childrand64, sizeof(randbuf));
33200+
close(pipefds[0]);
33201+
waitpid(pid, &waitstatus, 0);
33202+
}
33203+
RAND_cleanup();
33204+
33205+
ExpectIntEQ(RAND_egd(NULL), -1);
33206+
#endif
33207+
33208+
return EXPECT_RESULT();
33209+
}
33210+
33211+
3315333212
static int test_wolfSSL_PKCS8_Compat(void)
3315433213
{
3315533214
EXPECT_DECLS;
@@ -67679,6 +67738,7 @@ TEST_CASE testCases[] = {
6767967738
TEST_DECL(test_wolfSSL_RAND_set_rand_method),
6768067739
TEST_DECL(test_wolfSSL_RAND_bytes),
6768167740
TEST_DECL(test_wolfSSL_RAND),
67741+
TEST_DECL(test_wolfSSL_RAND_poll),
6768267742

6768367743
/* BN compatibility API */
6768467744
TEST_DECL(test_wolfSSL_BN_CTX),

0 commit comments

Comments
 (0)