hw_rng.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef __HW_RNG_H__
  11. #define __HW_RNG_H__
  12. #include <hwcrypto.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. struct hwcrypto_rng;
  17. struct hwcrypto_rng_ops
  18. {
  19. rt_uint32_t (*update)(struct hwcrypto_rng *ctx); /**< Return a random number */
  20. };
  21. /**
  22. * @brief random context. Hardware driver usage
  23. */
  24. struct hwcrypto_rng
  25. {
  26. struct rt_hwcrypto_ctx parent; /**< Inheritance from hardware crypto context */
  27. const struct hwcrypto_rng_ops *ops; /**< !! Hardware initializes this value when creating context !! */
  28. };
  29. /**
  30. * @brief Creating RNG Context
  31. *
  32. * @param device Hardware crypto device
  33. *
  34. * @return RNG context
  35. */
  36. struct rt_hwcrypto_ctx *rt_hwcrypto_rng_create(struct rt_hwcrypto_device *device);
  37. /**
  38. * @brief Destroy RNG Context
  39. *
  40. * @param ctx RNG context
  41. */
  42. void rt_hwcrypto_rng_destroy(struct rt_hwcrypto_ctx *ctx);
  43. /**
  44. * @brief Setting RNG default devices
  45. *
  46. * @return RT_EOK on success.
  47. */
  48. rt_err_t rt_hwcrypto_rng_default(struct rt_hwcrypto_device *device);
  49. /**
  50. * @brief Getting Random Numbers from RNG Context
  51. *
  52. * @param ctx RNG context
  53. *
  54. * @return Random number
  55. */
  56. rt_uint32_t rt_hwcrypto_rng_update_ctx(struct rt_hwcrypto_ctx *ctx);
  57. /**
  58. * @brief Return a random number
  59. *
  60. * @return Random number
  61. */
  62. rt_uint32_t rt_hwcrypto_rng_update(void);
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif