1 /* 2 * Copyright (c) 2021-2023, The TrustedFirmware-M Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef CC3XX_RNG_H 9 #define CC3XX_RNG_H 10 11 #include "cc3xx_error.h" 12 13 #include <stdint.h> 14 #include <stddef.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /** 21 * @brief Get random bytes from the CC3XX TRNG. 22 * 23 * @note This function may take a variable amount of 24 * time to execute. This function may take a 25 * considerable amount of time to execute if the 26 * current TRNG entropy pool is depleted and more 27 * entropy needs generating. 28 * 29 * @param[out] buf Buffer to fill with random bytes. 30 * @param[in] length Size of the buffer. 31 * 32 * @return CC3XX_ERR_SUCCESS on success, another 33 * cc3xx_err_t on error. 34 */ 35 cc3xx_err_t cc3xx_lowlevel_rng_get_random(uint8_t* buf, size_t length); 36 37 /** 38 * @brief Get a random unsigned integer from the CC3XX 39 * TRNG. The value is uniformly distributed 40 * between 0 and bound - 1. 41 * 42 * @note This function may take a variable amount of 43 * time to execute. 44 * 45 * @param[in] bound A value N such that 0 <= output < N 46 * @param[out] uint A pointer to the uint32_t to output into. 47 * 48 * @return CC3XX_ERR_SUCCESS on success, another 49 * cc3xx_err_t on error. 50 */ 51 cc3xx_err_t cc3xx_lowlevel_rng_get_random_uint(uint32_t bound, uint32_t *uint); 52 53 #ifdef __cplusplus 54 } 55 #endif 56 57 #endif /* CC3XX_RNG_H */ 58