mirror of https://github.com/wolfSSL/wolfssl.git
adding additional RAND test cases
parent
fbbb6b7707
commit
4207affc72
|
@ -48,6 +48,7 @@ jobs:
|
||||||
'--enable-sniffer --enable-curve25519 --enable-curve448 --enable-enckeys CFLAGS=-DWOLFSSL_DH_EXTRA',
|
'--enable-sniffer --enable-curve25519 --enable-curve448 --enable-enckeys CFLAGS=-DWOLFSSL_DH_EXTRA',
|
||||||
'--enable-dtls --enable-dtls13 --enable-dtls-frag-ch
|
'--enable-dtls --enable-dtls13 --enable-dtls-frag-ch
|
||||||
--enable-dtls-mtu CPPFLAGS=-DWOLFSSL_DTLS_RECORDS_CAN_SPAN_DATAGRAMS',
|
--enable-dtls-mtu CPPFLAGS=-DWOLFSSL_DTLS_RECORDS_CAN_SPAN_DATAGRAMS',
|
||||||
|
'--enable-opensslall --enable-opensslextra CPPFLAGS=-DWC_RNG_SEED_CB',
|
||||||
]
|
]
|
||||||
name: make check
|
name: make check
|
||||||
if: github.repository_owner == 'wolfssl'
|
if: github.repository_owner == 'wolfssl'
|
||||||
|
|
124
tests/api.c
124
tests/api.c
|
@ -33105,6 +33105,12 @@ 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)
|
||||||
|
byte seed[16] = {0};
|
||||||
|
byte randbuf[8] = {0};
|
||||||
|
int pipefds[2] = {0};
|
||||||
|
pid_t pid = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* sanity check */
|
/* sanity check */
|
||||||
ExpectIntEQ(RAND_bytes(NULL, 16), 0);
|
ExpectIntEQ(RAND_bytes(NULL, 16), 0);
|
||||||
|
@ -33124,6 +33130,42 @@ static int test_wolfSSL_RAND_bytes(void)
|
||||||
ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
|
ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
|
||||||
ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
|
ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
|
||||||
|
|
||||||
|
#if defined(OPENSSL_EXTRA) && defined(HAVE_GETPID)
|
||||||
|
XMEMSET(seed, 0, sizeof(seed));
|
||||||
|
RAND_cleanup();
|
||||||
|
|
||||||
|
/* No global methods set. */
|
||||||
|
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
|
||||||
|
|
||||||
|
ExpectIntEQ(pipe(pipefds), 0);
|
||||||
|
pid = fork();
|
||||||
|
ExpectIntGE(pid, 0);
|
||||||
|
if (pid == 0) {
|
||||||
|
ssize_t n_written = 0;
|
||||||
|
|
||||||
|
/* Child process. */
|
||||||
|
close(pipefds[0]);
|
||||||
|
RAND_bytes(randbuf, sizeof(randbuf));
|
||||||
|
n_written = write(pipefds[1], randbuf, sizeof(randbuf));
|
||||||
|
close(pipefds[1]);
|
||||||
|
exit(n_written == sizeof(randbuf) ? 0 : 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Parent process. */
|
||||||
|
word64 childrand64 = 0;
|
||||||
|
int waitstatus = 0;
|
||||||
|
|
||||||
|
close(pipefds[1]);
|
||||||
|
ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1);
|
||||||
|
ExpectIntEQ(read(pipefds[0], &childrand64, sizeof(childrand64)),
|
||||||
|
sizeof(childrand64));
|
||||||
|
ExpectBufNE(randbuf, &childrand64, sizeof(randbuf));
|
||||||
|
close(pipefds[0]);
|
||||||
|
waitpid(pid, &waitstatus, 0);
|
||||||
|
}
|
||||||
|
RAND_cleanup();
|
||||||
|
#endif
|
||||||
|
|
||||||
XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
#endif
|
#endif
|
||||||
return EXPECT_RESULT();
|
return EXPECT_RESULT();
|
||||||
|
@ -33156,50 +33198,60 @@ static int test_wolfSSL_RAND(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WC_RNG_SEED_CB
|
||||||
|
static int wc_DummyGenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||||
|
{
|
||||||
|
word32 i;
|
||||||
|
for (i = 0; i < sz; i++ )
|
||||||
|
output[i] = (byte)i;
|
||||||
|
|
||||||
|
(void)os;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* WC_RNG_SEED_CB */
|
||||||
|
|
||||||
|
|
||||||
static int test_wolfSSL_RAND_poll(void)
|
static int test_wolfSSL_RAND_poll(void)
|
||||||
{
|
{
|
||||||
EXPECT_DECLS;
|
EXPECT_DECLS;
|
||||||
|
|
||||||
#if defined(OPENSSL_EXTRA) && defined(__linux__)
|
#if defined(OPENSSL_EXTRA)
|
||||||
byte seed[16] = {0};
|
byte seed[16];
|
||||||
byte randbuf[8] = {0};
|
byte rand1[16];
|
||||||
int pipefds[2] = {0};
|
#ifdef WC_RNG_SEED_CB
|
||||||
pid_t pid = 0;
|
byte rand2[16];
|
||||||
|
#endif
|
||||||
|
|
||||||
XMEMSET(seed, 0, sizeof(seed));
|
XMEMSET(seed, 0, sizeof(seed));
|
||||||
|
|
||||||
/* No global methods set. */
|
|
||||||
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
|
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
|
||||||
|
|
||||||
ExpectIntEQ(pipe(pipefds), 0);
|
|
||||||
pid = fork();
|
|
||||||
ExpectIntGE(pid, 0);
|
|
||||||
if (pid == 0)
|
|
||||||
{
|
|
||||||
ssize_t n_written = 0;
|
|
||||||
|
|
||||||
/* Child process. */
|
|
||||||
close(pipefds[0]);
|
|
||||||
RAND_poll();
|
|
||||||
RAND_bytes(randbuf, sizeof(randbuf));
|
|
||||||
n_written = write(pipefds[1], randbuf, sizeof(randbuf));
|
|
||||||
close(pipefds[1]);
|
|
||||||
exit(n_written == sizeof(randbuf) ? 0 : 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Parent process. */
|
|
||||||
word64 childrand64 = 0;
|
|
||||||
int waitstatus = 0;
|
|
||||||
|
|
||||||
close(pipefds[1]);
|
|
||||||
ExpectIntEQ(RAND_poll(), 1);
|
ExpectIntEQ(RAND_poll(), 1);
|
||||||
ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1);
|
ExpectIntEQ(RAND_bytes(rand1, 16), 1);
|
||||||
ExpectIntEQ(read(pipefds[0], &childrand64, sizeof(childrand64)), sizeof(childrand64));
|
RAND_cleanup();
|
||||||
ExpectBufNE(randbuf, &childrand64, sizeof(randbuf));
|
|
||||||
close(pipefds[0]);
|
#ifdef WC_RNG_SEED_CB
|
||||||
waitpid(pid, &waitstatus, 0);
|
/* Test with custom seed and poll */
|
||||||
}
|
wc_SetSeed_Cb(wc_DummyGenerateSeed);
|
||||||
|
|
||||||
|
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
|
||||||
|
ExpectIntEQ(RAND_bytes(rand1, 16), 1);
|
||||||
|
RAND_cleanup();
|
||||||
|
|
||||||
|
/* test that the same value is generated twice with dummy seed function */
|
||||||
|
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
|
||||||
|
ExpectIntEQ(RAND_bytes(rand2, 16), 1);
|
||||||
|
ExpectIntEQ(XMEMCMP(rand1, rand2, 16), 0);
|
||||||
|
RAND_cleanup();
|
||||||
|
|
||||||
|
/* test that doing a poll is reseeding RNG */
|
||||||
|
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
|
||||||
|
ExpectIntEQ(RAND_poll(), 1);
|
||||||
|
ExpectIntEQ(RAND_bytes(rand2, 16), 1);
|
||||||
|
ExpectIntNE(XMEMCMP(rand1, rand2, 16), 0);
|
||||||
|
|
||||||
|
/* reset the seed function used */
|
||||||
|
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||||
|
#endif
|
||||||
RAND_cleanup();
|
RAND_cleanup();
|
||||||
|
|
||||||
ExpectIntEQ(RAND_egd(NULL), -1);
|
ExpectIntEQ(RAND_egd(NULL), -1);
|
||||||
|
|
Loading…
Reference in New Issue