1 /* 2 * Copyright (c) 2013-2014 Wind River Systems, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Random number generator header file 10 * 11 * This header file declares prototypes for the kernel's random number 12 * generator APIs. 13 * 14 * Typically, a platform enables the appropriate source for the random 15 * number generation based on the hardware platform's capabilities or 16 * (for testing purposes only) enables the TEST_RANDOM_GENERATOR 17 * configuration option. 18 */ 19 20 #ifndef ZEPHYR_INCLUDE_RANDOM_RAND32_H_ 21 #define ZEPHYR_INCLUDE_RANDOM_RAND32_H_ 22 23 #include <zephyr/types.h> 24 #include <stddef.h> 25 #include <zephyr/kernel.h> 26 27 /** 28 * @brief Random Function APIs 29 * @defgroup random_api Random Function APIs 30 * @ingroup crypto 31 * @{ 32 */ 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /** 39 * @brief Return a 32-bit random value that should pass general 40 * randomness tests. 41 * 42 * @note The random value returned is not a cryptographically secure 43 * random number value. 44 * 45 * @return 32-bit random value. 46 */ 47 __syscall uint32_t sys_rand32_get(void); 48 49 /** 50 * @brief Fill the destination buffer with random data values that should 51 * pass general randomness tests. 52 * 53 * @note The random values returned are not considered cryptographically 54 * secure random number values. 55 * 56 * @param [out] dst destination buffer to fill with random data. 57 * @param len size of the destination buffer. 58 * 59 */ 60 __syscall void sys_rand_get(void *dst, size_t len); 61 62 /** 63 * @brief Fill the destination buffer with cryptographically secure 64 * random data values. 65 * 66 * @note If the random values requested do not need to be cryptographically 67 * secure then use sys_rand_get() instead. 68 * 69 * @param [out] dst destination buffer to fill. 70 * @param len size of the destination buffer. 71 * 72 * @return 0 if success, -EIO if entropy reseed error 73 * 74 */ 75 __syscall int sys_csrand_get(void *dst, size_t len); 76 77 #ifdef __cplusplus 78 } 79 #endif 80 81 /** 82 * @} 83 */ 84 85 #include <syscalls/rand32.h> 86 #endif /* ZEPHYR_INCLUDE_RANDOM_RAND32_H_ */ 87