|
51 | 51 | #endif |
52 | 52 |
|
53 | 53 | #include <stdlib.h> |
| 54 | + |
| 55 | +#ifdef __linux__ |
| 56 | +#include <unistd.h> |
| 57 | +#include <sys/wait.h> |
| 58 | +#endif |
| 59 | + |
54 | 60 | #include <wolfssl/ssl.h> /* compatibility layer */ |
55 | 61 | #include <wolfssl/error-ssl.h> |
56 | 62 |
|
@@ -33150,6 +33156,59 @@ static int test_wolfSSL_RAND(void) |
33150 | 33156 | } |
33151 | 33157 |
|
33152 | 33158 |
|
| 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 | + |
33153 | 33212 | static int test_wolfSSL_PKCS8_Compat(void) |
33154 | 33213 | { |
33155 | 33214 | EXPECT_DECLS; |
@@ -67679,6 +67738,7 @@ TEST_CASE testCases[] = { |
67679 | 67738 | TEST_DECL(test_wolfSSL_RAND_set_rand_method), |
67680 | 67739 | TEST_DECL(test_wolfSSL_RAND_bytes), |
67681 | 67740 | TEST_DECL(test_wolfSSL_RAND), |
| 67741 | + TEST_DECL(test_wolfSSL_RAND_poll), |
67682 | 67742 |
|
67683 | 67743 | /* BN compatibility API */ |
67684 | 67744 | TEST_DECL(test_wolfSSL_BN_CTX), |
|
0 commit comments