1 /* 2 * Copyright (c) 2006-2023, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2019-04-25 tyx the first version 9 */ 10 11 #ifndef __HW_RNG_H__ 12 #define __HW_RNG_H__ 13 14 #include <hwcrypto.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 struct hwcrypto_rng; 21 22 struct hwcrypto_rng_ops 23 { 24 rt_uint32_t (*update)(struct hwcrypto_rng *ctx); /**< Return a random number */ 25 }; 26 27 /** 28 * @brief random context. Hardware driver usage 29 */ 30 struct hwcrypto_rng 31 { 32 struct rt_hwcrypto_ctx parent; /**< Inheritance from hardware crypto context */ 33 const struct hwcrypto_rng_ops *ops; /**< !! Hardware initializes this value when creating context !! */ 34 }; 35 36 /** 37 * @brief Creating RNG Context 38 * 39 * @param device Hardware crypto device 40 * 41 * @return RNG context 42 */ 43 struct rt_hwcrypto_ctx *rt_hwcrypto_rng_create(struct rt_hwcrypto_device *device); 44 45 /** 46 * @brief Destroy RNG Context 47 * 48 * @param ctx RNG context 49 */ 50 void rt_hwcrypto_rng_destroy(struct rt_hwcrypto_ctx *ctx); 51 52 /** 53 * @brief Setting RNG default devices 54 * 55 * @return RT_EOK on success. 56 */ 57 rt_err_t rt_hwcrypto_rng_default(struct rt_hwcrypto_device *device); 58 59 /** 60 * @brief Getting Random Numbers from RNG Context 61 * 62 * @param ctx RNG context 63 * 64 * @return Random number 65 */ 66 rt_uint32_t rt_hwcrypto_rng_update_ctx(struct rt_hwcrypto_ctx *ctx); 67 68 /** 69 * @brief Return a random number 70 * 71 * @return Random number 72 */ 73 rt_uint32_t rt_hwcrypto_rng_update(void); 74 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif 80