diff options
author | Pauli <pauli@openssl.org> | 2021-05-14 15:41:14 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-05-24 09:39:15 +1000 |
commit | 235776b2c70fa2e283ea9fb47daf2cab4bc2309a (patch) | |
tree | 5c1e360a72797a4e3843d69b9f581192255b714f /test/threadstest.h | |
parent | b6f0f050fd6e40286eb33fcdf28507b0f9b79b26 (diff) | |
download | openssl-new-235776b2c70fa2e283ea9fb47daf2cab4bc2309a.tar.gz |
test: add test case to reliably reproduce RAND leak during POST
The FIPS provider leaks a RAND if the POST is run at initialisation time.
This test case reliably reproduces this event.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15278)
Diffstat (limited to 'test/threadstest.h')
-rw-r--r-- | test/threadstest.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/test/threadstest.h b/test/threadstest.h new file mode 100644 index 0000000000..8bdedd7052 --- /dev/null +++ b/test/threadstest.h @@ -0,0 +1,82 @@ +/* + * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#if defined(_WIN32) +# include <windows.h> +#endif + +#include <string.h> +#include "testutil.h" + +#if !defined(OPENSSL_THREADS) || defined(CRYPTO_TDEBUG) + +typedef unsigned int thread_t; + +static int run_thread(thread_t *t, void (*f)(void)) +{ + f(); + return 1; +} + +static int wait_for_thread(thread_t thread) +{ + return 1; +} + +#elif defined(OPENSSL_SYS_WINDOWS) + +typedef HANDLE thread_t; + +static DWORD WINAPI thread_run(LPVOID arg) +{ + void (*f)(void); + + *(void **) (&f) = arg; + + f(); + return 0; +} + +static int run_thread(thread_t *t, void (*f)(void)) +{ + *t = CreateThread(NULL, 0, thread_run, *(void **) &f, 0, NULL); + return *t != NULL; +} + +static int wait_for_thread(thread_t thread) +{ + return WaitForSingleObject(thread, INFINITE) == 0; +} + +#else + +typedef pthread_t thread_t; + +static void *thread_run(void *arg) +{ + void (*f)(void); + + *(void **) (&f) = arg; + + f(); + return NULL; +} + +static int run_thread(thread_t *t, void (*f)(void)) +{ + return pthread_create(t, NULL, thread_run, *(void **) &f) == 0; +} + +static int wait_for_thread(thread_t thread) +{ + return pthread_join(thread, NULL) == 0; +} + +#endif + |