hw_hash.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-04-23 tyx the first version
  9. */
  10. #ifndef __HW_HASH_H__
  11. #define __HW_HASH_H__
  12. #include <hwcrypto.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. struct hwcrypto_hash;
  17. struct hwcrypto_hash_ops
  18. {
  19. rt_err_t (*update)(struct hwcrypto_hash *hash_ctx,
  20. const rt_uint8_t *in, rt_size_t length); /**< Processing a packet of data */
  21. rt_err_t (*finish)(struct hwcrypto_hash *hash_ctx,
  22. rt_uint8_t *out, rt_size_t length); /**< Get the final hash value */
  23. };
  24. /**
  25. * @brief hash context. Hardware driver usage
  26. */
  27. struct hwcrypto_hash
  28. {
  29. struct rt_hwcrypto_ctx parent; /**< Inheritance from hardware crypto context */
  30. const struct hwcrypto_hash_ops *ops; /**< !! Hardware initializes this value when creating context !! */
  31. };
  32. /**
  33. * @brief Creating hash Context
  34. *
  35. * @param device Hardware crypto device
  36. * @param type Type of hash context
  37. *
  38. * @return Hash context
  39. */
  40. struct rt_hwcrypto_ctx *rt_hwcrypto_hash_create(struct rt_hwcrypto_device *device,
  41. hwcrypto_type type);
  42. /**
  43. * @brief Destroy hash Context
  44. *
  45. * @param ctx Hash context
  46. */
  47. void rt_hwcrypto_hash_destroy(struct rt_hwcrypto_ctx *ctx);
  48. /**
  49. * @brief Get the final hash value
  50. *
  51. * @param ctx Hash context
  52. * @param output Hash value buffer
  53. * @param length Hash value buffer length
  54. *
  55. * @return RT_EOK on success.
  56. */
  57. rt_err_t rt_hwcrypto_hash_finish(struct rt_hwcrypto_ctx *ctx, rt_uint8_t *output, rt_size_t length);
  58. /**
  59. * @brief Processing a packet of data
  60. *
  61. * @param ctx Hash context
  62. * @param input Data buffer to be Processed
  63. * @param length Data Buffer length
  64. *
  65. * @return RT_EOK on success.
  66. */
  67. rt_err_t rt_hwcrypto_hash_update(struct rt_hwcrypto_ctx *ctx, const rt_uint8_t *input, rt_size_t length);
  68. /**
  69. * @brief This function copy hash context
  70. *
  71. * @param des The destination hash context
  72. * @param src The hash context to be copy
  73. *
  74. * @return RT_EOK on success.
  75. */
  76. rt_err_t rt_hwcrypto_hash_cpy(struct rt_hwcrypto_ctx *des, const struct rt_hwcrypto_ctx *src);
  77. /**
  78. * @brief Reset hash context
  79. *
  80. * @param ctx Hash context
  81. */
  82. void rt_hwcrypto_hash_reset(struct rt_hwcrypto_ctx *ctx);
  83. /**
  84. * @brief Setting hash context type
  85. *
  86. * @param ctx Hash context
  87. * @param type Types of settings
  88. *
  89. * @return RT_EOK on success.
  90. */
  91. rt_err_t rt_hwcrypto_hash_set_type(struct rt_hwcrypto_ctx *ctx, hwcrypto_type type);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif