| 1 |
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 OR ISC |
| 3 |
|
| 4 |
#ifndef AWSLC_HEADER_CRYPTO_RAND_EXTRA_RAND_INTERNAL_H |
| 5 |
#define AWSLC_HEADER_CRYPTO_RAND_EXTRA_RAND_INTERNAL_H |
| 6 |
|
| 7 |
#include <openssl/ctrdrbg.h> |
| 8 |
|
| 9 |
#if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 10 |
#define OPENSSL_RAND_DETERMINISTIC |
| 11 |
#elif defined(OPENSSL_WINDOWS) |
| 12 |
#define OPENSSL_RAND_WINDOWS |
| 13 |
#elif defined(OPENSSL_MACOS) || defined(OPENSSL_OPENBSD) || \ |
| 14 |
defined(OPENSSL_FREEBSD) || defined(OPENSSL_NETBSD) || \ |
| 15 |
defined(OPENSSL_SOLARIS) || defined(OPENSSL_WASM) || \ |
| 16 |
(defined(OPENSSL_LINUX) && !defined(HAVE_LINUX_RANDOM_H)) |
| 17 |
#define OPENSSL_RAND_GETENTROPY |
| 18 |
// OPENSSL_APPLE is always defined when OPENSSL_MACOS is defined, so this |
| 19 |
// branch must come after the OPENSSL_MACOS branch above. |
| 20 |
#elif defined(OPENSSL_APPLE) |
| 21 |
#define OPENSSL_RAND_CCRANDOMGENERATEBYTES |
| 22 |
#else |
| 23 |
#define OPENSSL_RAND_URANDOM |
| 24 |
#endif |
| 25 |
|
| 26 |
#if defined(__cplusplus) |
| 27 |
extern "C" { |
| 28 |
#endif |
| 29 |
|
| 30 |
// Functions: |
| 31 |
// CRYPTO_sysrand |
| 32 |
// CRYPTO_sysrand_if_available |
| 33 |
// are the operating system entropy source interface used in the randomness |
| 34 |
// generation implementation. |
| 35 |
|
| 36 |
// CRYPTO_sysrand fills |len| bytes at |buf| with entropy from the operating |
| 37 |
// system. |
| 38 |
OPENSSL_EXPORT void CRYPTO_sysrand(uint8_t *buf, size_t len); |
| 39 |
|
| 40 |
#if defined(OPENSSL_RAND_URANDOM) |
| 41 |
// CRYPTO_sysrand_if_available fills |len| bytes at |buf| with entropy from the |
| 42 |
// operating system, or early /dev/urandom data, and returns 1, _if_ the entropy |
| 43 |
// pool is initialized or if getrandom() is not available. Otherwise it will not |
| 44 |
// block and will instead fill |buf| with all zeros and return 0. |
| 45 |
int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len); |
| 46 |
#else |
| 47 |
OPENSSL_INLINE int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len) { |
| 48 |
CRYPTO_sysrand(buf, len); |
| 49 |
return 1; |
| 50 |
} |
| 51 |
#endif // defined(OPENSSL_RAND_URANDOM) |
| 52 |
|
| 53 |
// Don't retry forever. There is no science in picking this number and can be |
| 54 |
// adjusted in the future if need be. We do not backoff forever, because we |
| 55 |
// believe that it is easier to detect failing calls than detecting infinite |
| 56 |
// spinning loops. |
| 57 |
#define MAX_BACKOFF_RETRIES 9 |
| 58 |
|
| 59 |
OPENSSL_EXPORT int vm_ube_fallback_get_seed( |
| 60 |
uint8_t seed[CTR_DRBG_ENTROPY_LEN]); |
| 61 |
|
| 62 |
#if defined(__cplusplus) |
| 63 |
} // extern C |
| 64 |
#endif |
| 65 |
|
| 66 |
#endif // AWSLC_HEADER_CRYPTO_RAND_EXTRA_RAND_INTERNAL_H |