1 /* Copyright (c) 2017, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15 #include <openssl/rand.h>
16
17 #include <stdlib.h>
18
19 #include "../fipsmodule/rand/internal.h"
20 #include "../internal.h"
21
22
23 // g_buffering_enabled is one if fork-unsafe buffering has been enabled and zero
24 // otherwise.
25 static CRYPTO_atomic_u32 g_buffering_enabled = 0;
26
27 #if !defined(OPENSSL_WINDOWS)
RAND_enable_fork_unsafe_buffering(int fd)28 void RAND_enable_fork_unsafe_buffering(int fd) {
29 // We no longer support setting the file-descriptor with this function.
30 if (fd != -1) {
31 abort();
32 }
33
34 CRYPTO_atomic_store_u32(&g_buffering_enabled, 1);
35 }
36
RAND_disable_fork_unsafe_buffering(void)37 void RAND_disable_fork_unsafe_buffering(void) {
38 CRYPTO_atomic_store_u32(&g_buffering_enabled, 0);
39 }
40 #endif
41
rand_fork_unsafe_buffering_enabled(void)42 int rand_fork_unsafe_buffering_enabled(void) {
43 return CRYPTO_atomic_load_u32(&g_buffering_enabled) != 0;
44 }
45