|
51 | 51 | #endif |
52 | 52 |
|
53 | 53 | #include <stdlib.h> |
| 54 | + |
| 55 | +#ifdef __linux__ |
| 56 | +#include <unistd.h> |
| 57 | +#endif |
| 58 | + |
54 | 59 | #include <wolfssl/ssl.h> /* compatibility layer */ |
55 | 60 | #include <wolfssl/error-ssl.h> |
56 | 61 |
|
@@ -33142,6 +33147,56 @@ static int test_wolfSSL_RAND(void) |
33142 | 33147 | } |
33143 | 33148 |
|
33144 | 33149 |
|
| 33150 | +static int test_wolfSSL_RAND_poll(void) |
| 33151 | +{ |
| 33152 | + EXPECT_DECLS; |
| 33153 | + |
| 33154 | +#if defined(OPENSSL_EXTRA) && defined(__linux__) |
| 33155 | + byte seed[16] = {0}; |
| 33156 | + byte randbuf[8] = {0}; |
| 33157 | + int pipefds[2] = {0}; |
| 33158 | + pid_t pid = 0; |
| 33159 | + |
| 33160 | + XMEMSET(seed, 0, sizeof(seed)); |
| 33161 | + |
| 33162 | + /* No global methods set. */ |
| 33163 | + ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1); |
| 33164 | + |
| 33165 | + ExpectIntEQ(pipe(pipefds), 0); |
| 33166 | + pid = fork(); |
| 33167 | + if (pid == 0) |
| 33168 | + { |
| 33169 | + ssize_t n_written = 0; |
| 33170 | + |
| 33171 | + /* Child process. */ |
| 33172 | + close(pipefds[0]); |
| 33173 | + RAND_poll(); |
| 33174 | + RAND_bytes(randbuf, sizeof(randbuf)); |
| 33175 | + n_written = write(pipefds[1], randbuf, sizeof(randbuf)); |
| 33176 | + close(pipefds[1]); |
| 33177 | + exit(n_written == sizeof(randbuf) ? 0 : 1); |
| 33178 | + } |
| 33179 | + else |
| 33180 | + { |
| 33181 | + /* Parent process. */ |
| 33182 | + word64 childrand64 = 0; |
| 33183 | + |
| 33184 | + close(pipefds[1]); |
| 33185 | + ExpectIntEQ(RAND_poll(), 1); |
| 33186 | + ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1); |
| 33187 | + ExpectIntEQ(read(pipefds[0], &childrand64, sizeof(childrand64)), sizeof(childrand64)); |
| 33188 | + ExpectBufNE(randbuf, &childrand64, sizeof(randbuf)); |
| 33189 | + close(pipefds[0]); |
| 33190 | + } |
| 33191 | + RAND_cleanup(); |
| 33192 | + |
| 33193 | + ExpectIntEQ(RAND_egd(NULL), -1); |
| 33194 | +#endif |
| 33195 | + |
| 33196 | + return EXPECT_RESULT(); |
| 33197 | +} |
| 33198 | + |
| 33199 | + |
33145 | 33200 | static int test_wolfSSL_PKCS8_Compat(void) |
33146 | 33201 | { |
33147 | 33202 | EXPECT_DECLS; |
@@ -67671,6 +67726,7 @@ TEST_CASE testCases[] = { |
67671 | 67726 | TEST_DECL(test_wolfSSL_RAND_set_rand_method), |
67672 | 67727 | TEST_DECL(test_wolfSSL_RAND_bytes), |
67673 | 67728 | TEST_DECL(test_wolfSSL_RAND), |
| 67729 | + TEST_DECL(test_wolfSSL_RAND_poll), |
67674 | 67730 |
|
67675 | 67731 | /* BN compatibility API */ |
67676 | 67732 | TEST_DECL(test_wolfSSL_BN_CTX), |
|
0 commit comments