2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * Licensed under the Apache License 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 * https://www.openssl.org/source/license.html
15 * or in the file LICENSE in the source distribution.
18 #ifndef OSSL_CRYPTO_RAND_H
19 # define OSSL_CRYPTO_RAND_H
21 # include <openssl/rand.h>
24 * Defines related to seed sources
28 * set this to a comma-separated list of 'random' device files to try out. By
29 * default, we will try to read at least one of these files
31 # define DEVRANDOM "/dev/urandom", "/dev/random", "/dev/hwrng", "/dev/srandom"
32 # if defined(__linux) && !defined(__ANDROID__)
33 # ifndef DEVRANDOM_WAIT
34 # define DEVRANDOM_WAIT "/dev/random"
37 * Linux kernels 4.8 and later changes how their random device works and there
38 * is no reliable way to tell that /dev/urandom has been seeded -- getentropy(2)
39 * should be used instead.
41 # ifndef DEVRANDOM_SAFE_KERNEL
42 # define DEVRANDOM_SAFE_KERNEL 4, 8
45 * Some operating systems do not permit select(2) on their random devices,
46 * defining this to zero will force the use of read(2) to extract one byte
49 # ifndef DEVRANDM_WAIT_USE_SELECT
50 # define DEVRANDM_WAIT_USE_SELECT 1
53 * Define the shared memory identifier used to indicate if the operating
54 * system has properly seeded the DEVRANDOM source.
56 # ifndef OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID
57 # define OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID 114
63 #if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
65 * set this to a comma-separated list of 'egd' sockets to try out. These
66 * sockets will be tried in the order listed in case accessing the device
67 * files listed in DEVRANDOM did not return enough randomness.
69 # define DEVRANDOM_EGD "/var/run/egd-pool", "/dev/egd-pool", "/etc/egd-pool", "/etc/entropy"
72 void rand_cleanup_int(void);
75 * Initialise the random pool reseeding sources.
77 * Returns 1 on success and 0 on failure.
79 int rand_pool_init(void);
82 * Finalise the random pool reseeding sources.
84 void rand_pool_cleanup(void);
87 * Control the random pool use of open file descriptors.
89 void rand_pool_keep_random_devices_open(int keep);