drv_sha.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file drv_sha.h
  18. * @brief header file for sha driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_SHA_H_
  23. #define _CSI_SHA_H_
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdint.h>
  28. #include <drv_common.h>
  29. #include <drv_errno.h>
  30. /// definition for sha handle.
  31. typedef void *sha_handle_t;
  32. /****** SHA specific error codes *****/
  33. typedef enum {
  34. SHA_ERROR_MODE = (EDRV_SPECIFIC + 1), ///< Specified Mode not supported
  35. SHA_ERROR_ENDIAN ///< Specified endian not supported
  36. } drv_sha_error_e;
  37. /*----- SHA Control Codes: Mode -----*/
  38. typedef enum {
  39. SHA_MODE_1 = 1, ///< SHA_1 mode
  40. SHA_MODE_256 , ///< SHA_256 mode
  41. SHA_MODE_224 , ///< SHA_224 mode
  42. SHA_MODE_512 , ///< SHA_512 mode
  43. SHA_MODE_384 , ///< SHA_384 mode
  44. SHA_MODE_512_256 , ///< SHA_512_256 mode
  45. SHA_MODE_512_224 ///< SHA_512_224 mode
  46. } sha_mode_e;
  47. /*----- SHA Control Codes: Mode Parameters: Endian -----*/
  48. typedef enum {
  49. SHA_ENDIAN_MODE_BIG = 0, ///< Big Endian Mode
  50. SHA_ENDIAN_MODE_LITTLE , ///< Little Endian Mode
  51. } sha_endian_mode_e;
  52. /**
  53. \brief SHA Status
  54. */
  55. typedef struct {
  56. uint32_t busy : 1; ///< calculate busy flag
  57. } sha_status_t;
  58. /****** SHA Event *****/
  59. typedef enum {
  60. SHA_EVENT_COMPLETE = 0 ///< calculate completed
  61. } sha_event_e;
  62. typedef void (*sha_event_cb_t)(sha_event_e event); ///< Pointer to \ref sha_event_cb_t : SHA Event call back.
  63. /**
  64. \brief SHA Device Driver Capabilities.
  65. */
  66. typedef struct {
  67. uint32_t sha1 : 1; ///< supports sha1 mode
  68. uint32_t sha224 : 1; ///< supports sha224 mode
  69. uint32_t sha256 : 1; ///< supports sha256 mode
  70. uint32_t sha384 : 1; ///< supports sha384 mode
  71. uint32_t sha512 : 1; ///< supports sha512 mode
  72. uint32_t sha512_224 : 1; ///< supports sha512_224 mode
  73. uint32_t sha512_256 : 1; ///< supports sha512_256 mode
  74. uint32_t endianmode : 1; ///< supports endian mode control
  75. uint32_t interruptmode : 1; ///< supports interrupt mode
  76. } sha_capabilities_t;
  77. // Function documentation
  78. /**
  79. \brief get sha handle count.
  80. \return sha handle count
  81. */
  82. int32_t csi_sha_get_instance_count(void);
  83. /**
  84. \brief Initialize SHA Interface. 1. Initializes the resources needed for the SHA interface 2.registers event callback function
  85. \param[in] idx must not exceed return value of csi_sha_get_instance_count()
  86. \param[in] cb_event Pointer to \ref sha_event_cb_t
  87. \return return sha handle if success
  88. */
  89. sha_handle_t csi_sha_initialize(int32_t idx, sha_event_cb_t cb_event);
  90. /**
  91. \brief De-initialize SHA Interface. stops operation and releases the software resources used by the interface
  92. \param[in] handle sha handle to operate.
  93. \return error code
  94. */
  95. int32_t csi_sha_uninitialize(sha_handle_t handle);
  96. /**
  97. \brief Get driver capabilities.
  98. \param[in] handle sha handle to operate.
  99. \return \ref sha_capabilities_t
  100. */
  101. sha_capabilities_t csi_sha_get_capabilities(sha_handle_t handle);
  102. /**
  103. \brief config sha mode.
  104. \param[in] handle sha handle to operate.
  105. \param[in] mode \ref sha_mode_e
  106. \param[in] endian \ref sha_endian_mode_e
  107. \return error code
  108. */
  109. int32_t csi_sha_config(sha_handle_t handle,
  110. sha_mode_e mode,
  111. sha_endian_mode_e endian
  112. );
  113. /**
  114. \brief start the engine
  115. \param[in] handle sha handle to operate.
  116. \param[in] context Pointer to the sha context.
  117. \return error code
  118. */
  119. int32_t csi_sha_starts(sha_handle_t handle, void *context);
  120. /**
  121. \brief updata the engine
  122. \param[in] handle sha handle to operate.
  123. \param[in] context Pointer to the sha context.
  124. \param[in] input Pointer to the Source data
  125. \param[in] len the data len
  126. \return error code
  127. */
  128. int32_t csi_sha_update(sha_handle_t handle, void *context, const void *input, uint32_t len);
  129. /**
  130. \brief finish the engine
  131. \param[in] handle sha handle to operate.
  132. \param[in] context Pointer to the sha context.
  133. \param[out] output Pointer to the dest data
  134. \return error code
  135. */
  136. int32_t csi_sha_finish(sha_handle_t handle, void *context, void *output);
  137. /**
  138. \brief Get SHA status.
  139. \param[in] handle sha handle to operate.
  140. \return SHA status \ref sha_status_t
  141. */
  142. sha_status_t csi_sha_get_status(sha_handle_t handle);
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif /* _CSI_SHA_H_ */