| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifdef __FreeBSD__ |
| 17 |
|
| 18 |
|
| 19 |
#undef _POSIX_C_SOURCE |
| 20 |
#else |
| 21 |
|
| 22 |
#define _GNU_SOURCE |
| 23 |
#endif |
| 24 |
|
| 25 |
#include "utils/s2n_random.h" |
| 26 |
|
| 27 |
#include <openssl/rand.h> |
| 28 |
#include <pthread.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <sys/wait.h> |
| 31 |
#include <unistd.h> |
| 32 |
|
| 33 |
#include "api/s2n.h" |
| 34 |
#include "crypto/s2n_fips.h" |
| 35 |
#include "crypto/s2n_libcrypto.h" |
| 36 |
#include "s2n_test.h" |
| 37 |
|
| 38 |
#define MAX_NUMBER_OF_TEST_THREADS 2 |
| 39 |
|
| 40 |
#define CLONE_TEST_NO 0 |
| 41 |
#define CLONE_TEST_YES 1 |
| 42 |
#define CLONE_TEST_DETERMINE_AT_RUNTIME 2 |
| 43 |
|
| 44 |
#define RANDOM_GENERATE_DATA_SIZE 100 |
| 45 |
#define MAX_RANDOM_GENERATE_DATA_SIZE 5120 |
| 46 |
|
| 47 |
#define NUMBER_OF_BOUNDS 10 |
| 48 |
#define NUMBER_OF_RANGE_FUNCTION_CALLS 200 |
| 49 |
#define MAX_REPEATED_OUTPUT 4 |
| 50 |
|
| 51 |
bool s2n_libcrypto_is_fips(void); |
| 52 |
bool s2n_libcrypto_is_openssl(void); |
| 53 |
S2N_RESULT s2n_rand_device_validate(struct s2n_rand_device *device); |
| 54 |
S2N_RESULT s2n_rand_get_urandom_for_test(struct s2n_rand_device **device); |
| 55 |
|
| 56 |
struct random_test_case { |
| 57 |
const char *test_case_label; |
| 58 |
int (*test_case_cb)(struct random_test_case *test_case); |
| 59 |
int test_case_must_pass_clone_test; |
| 60 |
int expected_return_status; |
| 61 |
}; |
| 62 |
|
| 63 |
struct random_communication { |
| 64 |
S2N_RESULT (*s2n_get_random_data_cb_1)(struct s2n_blob *blob); |
| 65 |
S2N_RESULT (*s2n_get_random_data_cb_2)(struct s2n_blob *blob); |
| 66 |
uint8_t thread_data[RANDOM_GENERATE_DATA_SIZE]; |
| 67 |
int *pipes; |
| 68 |
}; |
| 69 |
|
| 70 |
static void s2n_verify_child_exit_status(pid_t proc_pid, int expected_status) |
| 71 |
{ |
| 72 |
int status = 0; |
| 73 |
#if S2N_CLONE_SUPPORTED |
| 74 |
EXPECT_EQUAL(waitpid(proc_pid, &status, __WALL), proc_pid); |
| 75 |
#else |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
EXPECT_EQUAL(waitpid(proc_pid, &status, 0), proc_pid); |
| 80 |
#endif |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
EXPECT_NOT_EQUAL(WIFEXITED(status), 0); |
| 86 |
EXPECT_EQUAL(WEXITSTATUS(status), expected_status); |
| 87 |
} |
| 88 |
|
| 89 |
int qsort_comparator(const void *pval1, const void *pval2) |
| 90 |
{ |
| 91 |
const uint64_t val1 = *(const uint64_t *) pval1; |
| 92 |
const uint64_t val2 = *(const uint64_t *) pval2; |
| 93 |
|
| 94 |
if (val1 < val2) { |
| 95 |
return -1; |
| 96 |
} else if (val1 > val2) { |
| 97 |
return 1; |
| 98 |
} else { |
| 99 |
return 0; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
static S2N_RESULT s2n_tests_get_range(void) |
| 104 |
{ |
| 105 |
uint64_t range_results[NUMBER_OF_RANGE_FUNCTION_CALLS] = { 0 }; |
| 106 |
uint64_t current_output = 0; |
| 107 |
|
| 108 |
int64_t chosen_upper_bound = 0; |
| 109 |
struct s2n_blob upper_bound_blob = { 0 }; |
| 110 |
EXPECT_SUCCESS(s2n_blob_init(&upper_bound_blob, (void *) &chosen_upper_bound, sizeof(chosen_upper_bound))); |
| 111 |
|
| 112 |
|
| 113 |
chosen_upper_bound = 0; |
| 114 |
EXPECT_ERROR_WITH_ERRNO(s2n_public_random(chosen_upper_bound, ¤t_output), S2N_ERR_SAFETY); |
| 115 |
|
| 116 |
|
| 117 |
chosen_upper_bound = 1; |
| 118 |
EXPECT_OK(s2n_public_random(chosen_upper_bound, ¤t_output)); |
| 119 |
EXPECT_EQUAL(current_output, 0); |
| 120 |
|
| 121 |
|
| 122 |
chosen_upper_bound = 1; |
| 123 |
EXPECT_OK(s2n_public_random(chosen_upper_bound, ¤t_output)); |
| 124 |
EXPECT_TRUE((current_output == 0) || (current_output == 1)); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
int64_t minimal_upper_bound = (int64_t) 0x40000000 * (int64_t) NUMBER_OF_RANGE_FUNCTION_CALLS; |
| 134 |
for (size_t bound_ctr = 0; bound_ctr < NUMBER_OF_BOUNDS; bound_ctr++) { |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
do { |
| 140 |
EXPECT_OK(s2n_get_private_random_data(&upper_bound_blob)); |
| 141 |
} while (chosen_upper_bound < minimal_upper_bound); |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
for (size_t func_call_ctr = 0; func_call_ctr < NUMBER_OF_RANGE_FUNCTION_CALLS; func_call_ctr++) { |
| 147 |
EXPECT_OK(s2n_public_random(chosen_upper_bound, &range_results[func_call_ctr])); |
| 148 |
EXPECT_TRUE(range_results[func_call_ctr] < chosen_upper_bound); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
qsort(range_results, NUMBER_OF_RANGE_FUNCTION_CALLS, sizeof(uint64_t), |
| 172 |
qsort_comparator); |
| 173 |
uint64_t current_value = range_results[0]; |
| 174 |
uint64_t next_value = 0; |
| 175 |
size_t repeat_count = 1; |
| 176 |
for (size_t ctr = 1; ctr < NUMBER_OF_RANGE_FUNCTION_CALLS - 1; ctr++) { |
| 177 |
next_value = range_results[ctr]; |
| 178 |
|
| 179 |
if (current_value == next_value) { |
| 180 |
repeat_count = repeat_count + 1; |
| 181 |
} else { |
| 182 |
RESULT_ENSURE_LT(current_value, next_value); |
| 183 |
current_value = next_value; |
| 184 |
repeat_count = 1; |
| 185 |
} |
| 186 |
|
| 187 |
EXPECT_TRUE(repeat_count < MAX_REPEATED_OUTPUT); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
RESULT_CHECKED_MEMSET(&range_results[0], 0, sizeof(range_results)); |
| 192 |
} |
| 193 |
|
| 194 |
return S2N_RESULT_OK; |
| 195 |
} |
| 196 |
|
| 197 |
void *s2n_thread_test_cb(void *thread_comms) |
| 198 |
{ |
| 199 |
struct random_communication *thread_comms_ptr = (struct random_communication *) thread_comms; |
| 200 |
|
| 201 |
struct s2n_blob thread_blob = { 0 }; |
| 202 |
EXPECT_SUCCESS(s2n_blob_init(&thread_blob, thread_comms_ptr->thread_data, RANDOM_GENERATE_DATA_SIZE)); |
| 203 |
|
| 204 |
EXPECT_NOT_NULL(thread_comms_ptr->s2n_get_random_data_cb_1); |
| 205 |
EXPECT_OK(thread_comms_ptr->s2n_get_random_data_cb_1(&thread_blob)); |
| 206 |
|
| 207 |
return NULL; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
static S2N_RESULT s2n_thread_test( |
| 215 |
S2N_RESULT (*s2n_get_random_data_cb)(struct s2n_blob *blob), |
| 216 |
S2N_RESULT (*s2n_get_random_data_cb_thread)(struct s2n_blob *blob)) |
| 217 |
{ |
| 218 |
uint8_t data[RANDOM_GENERATE_DATA_SIZE]; |
| 219 |
struct s2n_blob blob = { 0 }; |
| 220 |
EXPECT_SUCCESS(s2n_blob_init(&blob, data, 0)); |
| 221 |
pthread_t threads[MAX_NUMBER_OF_TEST_THREADS]; |
| 222 |
|
| 223 |
struct random_communication thread_communication_0 = { .s2n_get_random_data_cb_1 = s2n_get_random_data_cb_thread }; |
| 224 |
struct random_communication thread_communication_1 = { .s2n_get_random_data_cb_1 = s2n_get_random_data_cb_thread }; |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
EXPECT_EQUAL(pthread_create(&threads[0], NULL, s2n_thread_test_cb, &thread_communication_0), 0); |
| 230 |
EXPECT_EQUAL(pthread_create(&threads[1], NULL, s2n_thread_test_cb, &thread_communication_1), 0); |
| 231 |
|
| 232 |
|
| 233 |
EXPECT_EQUAL(pthread_join(threads[0], NULL), 0); |
| 234 |
EXPECT_EQUAL(pthread_join(threads[1], NULL), 0); |
| 235 |
|
| 236 |
|
| 237 |
EXPECT_BYTEARRAY_NOT_EQUAL(thread_communication_0.thread_data, thread_communication_1.thread_data, RANDOM_GENERATE_DATA_SIZE); |
| 238 |
|
| 239 |
|
| 240 |
blob.size = RANDOM_GENERATE_DATA_SIZE; |
| 241 |
EXPECT_OK(s2n_get_random_data_cb(&blob)); |
| 242 |
EXPECT_BYTEARRAY_NOT_EQUAL(thread_communication_0.thread_data, data, RANDOM_GENERATE_DATA_SIZE); |
| 243 |
EXPECT_BYTEARRAY_NOT_EQUAL(thread_communication_1.thread_data, data, RANDOM_GENERATE_DATA_SIZE); |
| 244 |
|
| 245 |
return S2N_RESULT_OK; |
| 246 |
} |
| 247 |
|
| 248 |
static void s2n_fork_test_generate_randomness(int write_fd, S2N_RESULT (*s2n_get_random_data_cb)(struct s2n_blob *blob)) |
| 249 |
{ |
| 250 |
uint8_t data[RANDOM_GENERATE_DATA_SIZE]; |
| 251 |
|
| 252 |
struct s2n_blob blob = { 0 }; |
| 253 |
EXPECT_SUCCESS(s2n_blob_init(&blob, data, RANDOM_GENERATE_DATA_SIZE)); |
| 254 |
EXPECT_OK(s2n_get_random_data_cb(&blob)); |
| 255 |
|
| 256 |
|
| 257 |
if (write(write_fd, data, RANDOM_GENERATE_DATA_SIZE) != RANDOM_GENERATE_DATA_SIZE) { |
| 258 |
_exit(EXIT_FAILURE); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
close(write_fd); |
| 263 |
exit(EXIT_SUCCESS); |
| 264 |
} |
| 265 |
|
| 266 |
static S2N_RESULT s2n_fork_test_verify_result(int *pipes, int proc_id, S2N_RESULT (*s2n_get_random_data_cb)(struct s2n_blob *blob)) |
| 267 |
{ |
| 268 |
uint8_t child_data[RANDOM_GENERATE_DATA_SIZE]; |
| 269 |
uint8_t parent_data[RANDOM_GENERATE_DATA_SIZE]; |
| 270 |
struct s2n_blob parent_blob = { 0 }; |
| 271 |
EXPECT_SUCCESS(s2n_blob_init(&parent_blob, parent_data, RANDOM_GENERATE_DATA_SIZE)); |
| 272 |
|
| 273 |
|
| 274 |
EXPECT_NOT_EQUAL(proc_id, 0); |
| 275 |
|
| 276 |
|
| 277 |
EXPECT_SUCCESS(close(pipes[1])); |
| 278 |
|
| 279 |
|
| 280 |
EXPECT_EQUAL(read(pipes[0], child_data, RANDOM_GENERATE_DATA_SIZE), RANDOM_GENERATE_DATA_SIZE); |
| 281 |
|
| 282 |
|
| 283 |
EXPECT_OK(s2n_get_random_data_cb(&parent_blob)); |
| 284 |
|
| 285 |
|
| 286 |
EXPECT_BYTEARRAY_NOT_EQUAL(child_data, parent_data, RANDOM_GENERATE_DATA_SIZE); |
| 287 |
|
| 288 |
EXPECT_SUCCESS(close(pipes[0])); |
| 289 |
|
| 290 |
|
| 291 |
s2n_verify_child_exit_status(proc_id, S2N_SUCCESS); |
| 292 |
|
| 293 |
return S2N_RESULT_OK; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
static S2N_RESULT s2n_simple_fork_test(S2N_RESULT (*s2n_get_random_data_cb)(struct s2n_blob *blob)) |
| 300 |
{ |
| 301 |
pid_t proc_id = 0; |
| 302 |
int pipes[2]; |
| 303 |
|
| 304 |
EXPECT_SUCCESS(pipe(pipes)); |
| 305 |
proc_id = fork(); |
| 306 |
if (proc_id == 0) { |
| 307 |
|
| 308 |
EXPECT_SUCCESS(close(pipes[0])); |
| 309 |
s2n_fork_test_generate_randomness(pipes[1], s2n_get_random_data_cb); |
| 310 |
} |
| 311 |
EXPECT_OK(s2n_fork_test_verify_result(pipes, proc_id, s2n_get_random_data_cb)); |
| 312 |
|
| 313 |
return S2N_RESULT_OK; |
| 314 |
} |
| 315 |
|
| 316 |
static int s2n_random_test_case_failure_cb(struct random_test_case *test_case) |
| 317 |
{ |
| 318 |
EXPECT_SUCCESS(s2n_init()); |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
exit(1); |
| 327 |
|
| 328 |
EXPECT_SUCCESS(s2n_cleanup()); |
| 329 |
|
| 330 |
return EXIT_SUCCESS; |
| 331 |
} |
| 332 |
|
| 333 |
static int s2n_random_noop_destructor_test_cb(struct random_test_case *test_case) |
| 334 |
{ |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
return EXIT_SUCCESS; |
| 342 |
} |
| 343 |
|
| 344 |
static int s2n_random_rand_bytes_after_cleanup_cb(struct random_test_case *test_case) |
| 345 |
{ |
| 346 |
EXPECT_SUCCESS(s2n_init()); |
| 347 |
EXPECT_SUCCESS(s2n_cleanup_final()); |
| 348 |
|
| 349 |
unsigned char rndbytes[16]; |
| 350 |
EXPECT_EQUAL(RAND_bytes(rndbytes, sizeof(rndbytes)), 1); |
| 351 |
|
| 352 |
return S2N_SUCCESS; |
| 353 |
} |
| 354 |
|
| 355 |
static int s2n_random_invalid_urandom_fd_cb(struct random_test_case *test_case) |
| 356 |
{ |
| 357 |
struct s2n_rand_device *dev_urandom = NULL; |
| 358 |
EXPECT_OK(s2n_rand_get_urandom_for_test(&dev_urandom)); |
| 359 |
EXPECT_NOT_NULL(dev_urandom); |
| 360 |
|
| 361 |
EXPECT_EQUAL(dev_urandom->fd, -1); |
| 362 |
|
| 363 |
|
| 364 |
EXPECT_ERROR(s2n_rand_device_validate(dev_urandom)); |
| 365 |
|
| 366 |
EXPECT_SUCCESS(s2n_init()); |
| 367 |
|
| 368 |
if (!s2n_use_libcrypto_rand()) { |
| 369 |
|
| 370 |
EXPECT_OK(s2n_rand_device_validate(dev_urandom)); |
| 371 |
|
| 372 |
EXPECT_TRUE(dev_urandom->fd > STDERR_FILENO); |
| 373 |
|
| 374 |
|
| 375 |
EXPECT_EQUAL(close(dev_urandom->fd), 0); |
| 376 |
|
| 377 |
|
| 378 |
EXPECT_ERROR(s2n_rand_device_validate(dev_urandom)); |
| 379 |
|
| 380 |
s2n_stack_blob(rand_data, 16, 16); |
| 381 |
EXPECT_OK(s2n_get_public_random_data(&rand_data)); |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
EXPECT_OK(s2n_rand_device_validate(dev_urandom)); |
| 387 |
} |
| 388 |
|
| 389 |
EXPECT_SUCCESS(s2n_cleanup_final()); |
| 390 |
|
| 391 |
return S2N_SUCCESS; |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
static S2N_RESULT s2n_basic_generate_tests(void) |
| 398 |
{ |
| 399 |
uint8_t data1[RANDOM_GENERATE_DATA_SIZE]; |
| 400 |
uint8_t data2[RANDOM_GENERATE_DATA_SIZE]; |
| 401 |
struct s2n_blob blob1 = { 0 }; |
| 402 |
EXPECT_SUCCESS(s2n_blob_init(&blob1, data1, 0)); |
| 403 |
struct s2n_blob blob2 = { 0 }; |
| 404 |
EXPECT_SUCCESS(s2n_blob_init(&blob2, data2, 0)); |
| 405 |
|
| 406 |
|
| 407 |
blob1.size = RANDOM_GENERATE_DATA_SIZE; |
| 408 |
blob2.size = RANDOM_GENERATE_DATA_SIZE; |
| 409 |
EXPECT_OK(s2n_get_public_random_data(&blob1)); |
| 410 |
EXPECT_OK(s2n_get_public_random_data(&blob2)); |
| 411 |
EXPECT_BYTEARRAY_NOT_EQUAL(data1, data2, RANDOM_GENERATE_DATA_SIZE); |
| 412 |
EXPECT_OK(s2n_get_private_random_data(&blob1)); |
| 413 |
EXPECT_BYTEARRAY_NOT_EQUAL(data1, data2, RANDOM_GENERATE_DATA_SIZE); |
| 414 |
EXPECT_OK(s2n_get_private_random_data(&blob2)); |
| 415 |
EXPECT_BYTEARRAY_NOT_EQUAL(data1, data2, RANDOM_GENERATE_DATA_SIZE); |
| 416 |
|
| 417 |
return S2N_RESULT_OK; |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
static int s2n_random_common_tests_cb(struct random_test_case *test_case) |
| 424 |
{ |
| 425 |
EXPECT_SUCCESS(s2n_init()); |
| 426 |
|
| 427 |
|
| 428 |
EXPECT_OK(s2n_basic_generate_tests()); |
| 429 |
|
| 430 |
|
| 431 |
EXPECT_OK(s2n_thread_test(s2n_get_public_random_data, s2n_get_public_random_data)); |
| 432 |
EXPECT_OK(s2n_thread_test(s2n_get_private_random_data, s2n_get_private_random_data)); |
| 433 |
EXPECT_OK(s2n_thread_test(s2n_get_public_random_data, s2n_get_private_random_data)); |
| 434 |
EXPECT_OK(s2n_thread_test(s2n_get_private_random_data, s2n_get_public_random_data)); |
| 435 |
|
| 436 |
|
| 437 |
EXPECT_OK(s2n_simple_fork_test(s2n_get_public_random_data)); |
| 438 |
EXPECT_OK(s2n_simple_fork_test(s2n_get_private_random_data)); |
| 439 |
|
| 440 |
|
| 441 |
EXPECT_OK(s2n_tests_get_range()); |
| 442 |
|
| 443 |
EXPECT_SUCCESS(s2n_cleanup()); |
| 444 |
|
| 445 |
return EXIT_SUCCESS; |
| 446 |
} |
| 447 |
|
| 448 |
struct random_test_case random_test_cases[] = { |
| 449 |
{ "Random API: basic generate, thread, fork, and range tests.", s2n_random_common_tests_cb, CLONE_TEST_DETERMINE_AT_RUNTIME, EXIT_SUCCESS }, |
| 450 |
{ "Test destructor without s2n_init", s2n_random_noop_destructor_test_cb, CLONE_TEST_DETERMINE_AT_RUNTIME, EXIT_SUCCESS }, |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
{ "Test failure.", s2n_random_test_case_failure_cb, CLONE_TEST_DETERMINE_AT_RUNTIME, 1 }, |
| 455 |
{ "Test libcrypto's RAND engine is reset correctly after manual s2n_cleanup()", s2n_random_rand_bytes_after_cleanup_cb, CLONE_TEST_DETERMINE_AT_RUNTIME, EXIT_SUCCESS }, |
| 456 |
{ "Test getting entropy with an invalid file descriptor", s2n_random_invalid_urandom_fd_cb, CLONE_TEST_DETERMINE_AT_RUNTIME, EXIT_SUCCESS }, |
| 457 |
}; |
| 458 |
|
| 459 |
int main(int argc, char **argv) |
| 460 |
{ |
| 461 |
BEGIN_TEST_NO_INIT(); |
| 462 |
|
| 463 |
|
| 464 |
{ |
| 465 |
if (s2n_libcrypto_is_awslc()) { |
| 466 |
#if defined(S2N_LIBCRYPTO_SUPPORTS_ENGINE) |
| 467 |
FAIL_MSG("Expected ENGINE feature probe to be disabled with AWS-LC"); |
| 468 |
#endif |
| 469 |
} |
| 470 |
|
| 471 |
if (s2n_libcrypto_is_openssl_fips()) { |
| 472 |
#if !S2N_LIBCRYPTO_SUPPORTS_PRIVATE_RAND |
| 473 |
FAIL_MSG("Expected private rand support from openssl3 fips"); |
| 474 |
#endif |
| 475 |
} |
| 476 |
}; |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
{ |
| 486 |
#if defined(S2N_LIBCRYPTO_SUPPORTS_PRIVATE_RAND) || defined(S2N_LIBCRYPTO_SUPPORTS_PUBLIC_RAND) \ |
| 487 |
|| defined(OPENSSL_IS_AWSLC) |
| 488 |
bool expected = true; |
| 489 |
#else |
| 490 |
bool expected = false; |
| 491 |
#endif |
| 492 |
EXPECT_EQUAL(s2n_use_libcrypto_rand(), expected); |
| 493 |
}; |
| 494 |
|
| 495 |
|
| 496 |
for (size_t i = 0; i < s2n_array_len(random_test_cases); i++) { |
| 497 |
pid_t proc_id = 0; |
| 498 |
|
| 499 |
proc_id = fork(); |
| 500 |
EXPECT_TRUE(proc_id >= 0); |
| 501 |
|
| 502 |
if (proc_id == 0) { |
| 503 |
|
| 504 |
EXPECT_EQUAL(random_test_cases[i].test_case_cb(&random_test_cases[i]), EXIT_SUCCESS); |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
exit(EXIT_SUCCESS); |
| 512 |
} else { |
| 513 |
s2n_verify_child_exit_status(proc_id, random_test_cases[i].expected_return_status); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
EXPECT_EQUAL(random_test_cases[0].test_case_cb(&random_test_cases[0]), EXIT_SUCCESS); |
| 521 |
|
| 522 |
END_TEST_NO_INIT(); |
| 523 |
} |