1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file drv_sha.h 7 * @brief header file for sha driver 8 * @version V1.0 9 * @date 02. June 2017 10 * @model sha 11 ******************************************************************************/ 12 #ifndef _CSI_SHA_H_ 13 #define _CSI_SHA_H_ 14 15 16 #include <stdint.h> 17 #include <drv/common.h> 18 #include <drv/errno.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /// definition for sha handle. 25 typedef void *sha_handle_t; 26 27 /****** SHA specific error codes *****/ 28 typedef enum { 29 SHA_ERROR_MODE = (DRV_ERROR_SPECIFIC + 1), ///< Specified Mode not supported 30 SHA_ERROR_ENDIAN ///< Specified endian not supported 31 } sha_error_e; 32 33 /*----- SHA Control Codes: Mode -----*/ 34 typedef enum { 35 SHA_MODE_1 = 1, ///< SHA_1 mode 36 SHA_MODE_256, ///< SHA_256 mode 37 SHA_MODE_224, ///< SHA_224 mode 38 SHA_MODE_512, ///< SHA_512 mode 39 SHA_MODE_384, ///< SHA_384 mode 40 SHA_MODE_512_256, ///< SHA_512_256 mode 41 SHA_MODE_512_224 ///< SHA_512_224 mode 42 } sha_mode_e; 43 44 /*----- SHA Control Codes: Mode Parameters: Endian -----*/ 45 typedef enum { 46 SHA_ENDIAN_MODE_BIG = 0, ///< Big Endian Mode 47 SHA_ENDIAN_MODE_LITTLE, ///< Little Endian Mode 48 } sha_endian_mode_e; 49 50 /** 51 \brief SHA Status 52 */ 53 typedef struct { 54 uint32_t busy : 1; ///< calculate busy flag 55 } sha_status_t; 56 57 /****** SHA Event *****/ 58 typedef enum { 59 SHA_EVENT_COMPLETE = 0 ///< calculate completed 60 } sha_event_e; 61 62 typedef void (*sha_event_cb_t)(int32_t idx, sha_event_e event); ///< Pointer to \ref sha_event_cb_t : SHA Event call back. 63 64 65 /** 66 \brief SHA Device Driver Capabilities. 67 */ 68 typedef struct { 69 uint32_t sha1 : 1; ///< supports sha1 mode 70 uint32_t sha224 : 1; ///< supports sha224 mode 71 uint32_t sha256 : 1; ///< supports sha256 mode 72 uint32_t sha384 : 1; ///< supports sha384 mode 73 uint32_t sha512 : 1; ///< supports sha512 mode 74 uint32_t sha512_224 : 1; ///< supports sha512_224 mode 75 uint32_t sha512_256 : 1; ///< supports sha512_256 mode 76 uint32_t endianmode : 1; ///< supports endian mode control 77 uint32_t interruptmode : 1; ///< supports interrupt mode 78 } sha_capabilities_t; 79 80 81 // Function documentation 82 83 /** 84 \brief Initialize SHA Interface. 1. Initializes the resources needed for the SHA interface 2.registers event callback function 85 \param[in] idx index of sha 86 \param[in] context Pointer to the buffer storing the sha context 87 \param[in] cb_event event callback function \ref sha_event_cb_t 88 \return return sha handle if success 89 */ 90 sha_handle_t csi_sha_initialize(int32_t idx, void *context, sha_event_cb_t cb_event); 91 92 /** 93 \brief De-initialize SHA Interface. stops operation and releases the software resources used by the interface 94 \param[in] handle sha handle to operate. 95 \return error code 96 */ 97 int32_t csi_sha_uninitialize(sha_handle_t handle); 98 99 /** 100 \brief control sha power. 101 \param[in] handle sha handle to operate. 102 \param[in] state power state.\ref csi_power_stat_e. 103 \return error code 104 */ 105 int32_t csi_sha_power_control(sha_handle_t handle, csi_power_stat_e state); 106 107 /** 108 \brief Get driver capabilities. 109 \param[in] idx device id 110 \return \ref sha_capabilities_t 111 */ 112 sha_capabilities_t csi_sha_get_capabilities(int32_t idx); 113 114 /** 115 \brief config sha mode. 116 \param[in] handle sha handle to operate. 117 \param[in] mode \ref sha_mode_e 118 \param[in] endian \ref sha_endian_mode_e 119 \return error code 120 */ 121 int32_t csi_sha_config(sha_handle_t handle, 122 sha_mode_e mode, 123 sha_endian_mode_e endian 124 ); 125 126 /** 127 \brief start the engine 128 \param[in] handle sha handle to operate. 129 \param[in] context Pointer to the buffer storing the sha context 130 \return error code 131 */ 132 int32_t csi_sha_start(sha_handle_t handle, void *context); 133 134 /** 135 \brief update the engine 136 \param[in] handle sha handle to operate. 137 \param[in] context Pointer to the buffer storing the sha context 138 \param[in] input Pointer to the Source data 139 \param[in] len the data len 140 \return error code 141 */ 142 int32_t csi_sha_update(sha_handle_t handle, void *context, const void *input, uint32_t len); 143 144 /** 145 \brief finish the engine 146 \param[in] handle sha handle to operate. 147 \param[in] context Pointer to the buffer storing the sha context 148 \param[out] output Pointer to the result data 149 \return error code 150 */ 151 int32_t csi_sha_finish(sha_handle_t handle, void *context, void *output); 152 153 /** 154 \brief Get SHA status. 155 \param[in] handle sha handle to operate. 156 \return SHA status \ref sha_status_t 157 */ 158 sha_status_t csi_sha_get_status(sha_handle_t handle); 159 160 161 #ifdef __cplusplus 162 } 163 #endif 164 165 #endif /* _CSI_SHA_H_ */ 166