| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_RAND_INTERNAL_H |
| 16 | #define OPENSSL_HEADER_CRYPTO_FIPSMODULE_RAND_INTERNAL_H |
| 17 |
| 18 | #include <openssl/aes.h> |
| 19 | #include <openssl/ctrdrbg.h> |
| 20 |
| 21 | #include "../../bcm_support.h" |
| 22 | #include "../aes/internal.h" |
| 23 |
| 24 | #if defined(__cplusplus) |
| 25 | extern "C" { |
| 26 | #endif |
| 27 |
| 28 | // rand_fork_unsafe_buffering_enabled returns whether fork-unsafe buffering has |
| 29 | // been enabled via |RAND_enable_fork_unsafe_buffering|. |
| 30 | int rand_fork_unsafe_buffering_enabled(void); |
| 31 |
| 32 | // CTR_DRBG_STATE contains the state of a CTR_DRBG based on AES-256. See SP |
| 33 | // 800-90Ar1. |
| 34 | struct ctr_drbg_state_st { |
| 35 | AES_KEY ks; |
| 36 | block128_f block; |
| 37 | ctr128_f ctr; |
| 38 | uint8_t counter[16]; |
| 39 | uint64_t reseed_counter; |
| 40 | }; |
| 41 |
| 42 | // CTR_DRBG_init initialises |*drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of |
| 43 | // entropy in |entropy| and, optionally, a personalization string up to |
| 44 | // |CTR_DRBG_ENTROPY_LEN| bytes in length. It returns one on success and zero |
| 45 | // on error. |
| 46 | OPENSSL_EXPORT int CTR_DRBG_init(CTR_DRBG_STATE *drbg, |
| 47 | const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], |
| 48 | const uint8_t *personalization, |
| 49 | size_t personalization_len); |
| 50 |
| 51 | #if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM) |
| 52 |
| 53 | inline int have_rdrand(void) { return CRYPTO_is_RDRAND_capable(); } |
| 54 |
| 55 | // have_fast_rdrand returns true if RDRAND is supported and it's reasonably |
| 56 | // fast. Concretely the latter is defined by whether the chip is Intel (fast) or |
| 57 | // not (assumed slow). |
| 58 | inline int have_fast_rdrand(void) { |
| 59 | return CRYPTO_is_RDRAND_capable() && CRYPTO_is_intel_cpu(); |
| 60 | } |
| 61 |
| 62 | // CRYPTO_rdrand writes eight bytes of random data from the hardware RNG to |
| 63 | // |out|. It returns one on success or zero on hardware failure. |
| 64 | int CRYPTO_rdrand(uint8_t out[8]); |
| 65 |
| 66 | // CRYPTO_rdrand_multiple8_buf fills |len| bytes at |buf| with random data from |
| 67 | // the hardware RNG. The |len| argument must be a multiple of eight. It returns |
| 68 | // one on success and zero on hardware failure. |
| 69 | int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len); |
| 70 |
| 71 | #else // OPENSSL_X86_64 && !OPENSSL_NO_ASM |
| 72 |
| 73 | inline int have_rdrand(void) { return 0; } |
| 74 |
| 75 | inline int have_fast_rdrand(void) { return 0; } |
| 76 |
| 77 | #endif // OPENSSL_X86_64 && !OPENSSL_NO_ASM |
| 78 |
| 79 |
| 80 | #if defined(__cplusplus) |
| 81 | } // extern C |
| 82 | #endif |
| 83 |
| 84 | #endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_RAND_INTERNAL_H |
| 85 |