1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  *
4*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert  * this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert  * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert  */
9*e0c4386eSCy Schubert 
10*e0c4386eSCy Schubert #if defined(_WIN32)
11*e0c4386eSCy Schubert # include <windows.h>
12*e0c4386eSCy Schubert #endif
13*e0c4386eSCy Schubert 
14*e0c4386eSCy Schubert #include "testutil.h"
15*e0c4386eSCy Schubert #include "threadstest.h"
16*e0c4386eSCy Schubert 
17*e0c4386eSCy Schubert static int success;
18*e0c4386eSCy Schubert 
thread_fips_rand_fetch(void)19*e0c4386eSCy Schubert static void thread_fips_rand_fetch(void)
20*e0c4386eSCy Schubert {
21*e0c4386eSCy Schubert     EVP_MD *md;
22*e0c4386eSCy Schubert 
23*e0c4386eSCy Schubert     if (!TEST_true(md = EVP_MD_fetch(NULL, "SHA2-256", NULL)))
24*e0c4386eSCy Schubert         success = 0;
25*e0c4386eSCy Schubert     EVP_MD_free(md);
26*e0c4386eSCy Schubert }
27*e0c4386eSCy Schubert 
test_fips_rand_leak(void)28*e0c4386eSCy Schubert static int test_fips_rand_leak(void)
29*e0c4386eSCy Schubert {
30*e0c4386eSCy Schubert     thread_t thread;
31*e0c4386eSCy Schubert 
32*e0c4386eSCy Schubert     success = 1;
33*e0c4386eSCy Schubert 
34*e0c4386eSCy Schubert     if (!TEST_true(run_thread(&thread, thread_fips_rand_fetch)))
35*e0c4386eSCy Schubert         return 0;
36*e0c4386eSCy Schubert     if (!TEST_true(wait_for_thread(thread)))
37*e0c4386eSCy Schubert         return 0;
38*e0c4386eSCy Schubert     return TEST_true(success);
39*e0c4386eSCy Schubert }
40*e0c4386eSCy Schubert 
setup_tests(void)41*e0c4386eSCy Schubert int setup_tests(void)
42*e0c4386eSCy Schubert {
43*e0c4386eSCy Schubert     /*
44*e0c4386eSCy Schubert      * This test MUST be run first.  Once the default library context is set
45*e0c4386eSCy Schubert      * up, this test will always pass.
46*e0c4386eSCy Schubert      */
47*e0c4386eSCy Schubert     ADD_TEST(test_fips_rand_leak);
48*e0c4386eSCy Schubert     return 1;
49*e0c4386eSCy Schubert }
50