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 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #include <stdint.h> 30 #include <drv_common.h> 31 #include <drv_errno.h> 32 33 34 /// definition for sha handle. 35 typedef void *sha_handle_t; 36 37 /****** SHA specific error codes *****/ 38 typedef enum { 39 SHA_ERROR_MODE = (EDRV_SPECIFIC + 1), ///< Specified Mode not supported 40 SHA_ERROR_ENDIAN ///< Specified endian not supported 41 } drv_sha_error_e; 42 43 /*----- SHA Control Codes: Mode -----*/ 44 typedef enum { 45 SHA_MODE_1 = 1, ///< SHA_1 mode 46 SHA_MODE_256 , ///< SHA_256 mode 47 SHA_MODE_224 , ///< SHA_224 mode 48 SHA_MODE_512 , ///< SHA_512 mode 49 SHA_MODE_384 , ///< SHA_384 mode 50 SHA_MODE_512_256 , ///< SHA_512_256 mode 51 SHA_MODE_512_224 ///< SHA_512_224 mode 52 } sha_mode_e; 53 54 /*----- SHA Control Codes: Mode Parameters: Endian -----*/ 55 typedef enum { 56 SHA_ENDIAN_MODE_BIG = 0, ///< Big Endian Mode 57 SHA_ENDIAN_MODE_LITTLE , ///< Little Endian Mode 58 } sha_endian_mode_e; 59 60 /** 61 \brief SHA Status 62 */ 63 typedef struct { 64 uint32_t busy : 1; ///< calculate busy flag 65 } sha_status_t; 66 67 /****** SHA Event *****/ 68 typedef enum { 69 SHA_EVENT_COMPLETE = 0 ///< calculate completed 70 } sha_event_e; 71 72 typedef void (*sha_event_cb_t)(sha_event_e event); ///< Pointer to \ref sha_event_cb_t : SHA Event call back. 73 74 75 /** 76 \brief SHA Device Driver Capabilities. 77 */ 78 typedef struct { 79 uint32_t sha1 : 1; ///< supports sha1 mode 80 uint32_t sha224 : 1; ///< supports sha224 mode 81 uint32_t sha256 : 1; ///< supports sha256 mode 82 uint32_t sha384 : 1; ///< supports sha384 mode 83 uint32_t sha512 : 1; ///< supports sha512 mode 84 uint32_t sha512_224 : 1; ///< supports sha512_224 mode 85 uint32_t sha512_256 : 1; ///< supports sha512_256 mode 86 uint32_t endianmode : 1; ///< supports endian mode control 87 uint32_t interruptmode : 1; ///< supports interrupt mode 88 } sha_capabilities_t; 89 90 91 // Function documentation 92 93 /** 94 \brief get sha handle count. 95 \return sha handle count 96 */ 97 int32_t csi_sha_get_instance_count(void); 98 99 /** 100 \brief Initialize SHA Interface. 1. Initializes the resources needed for the SHA interface 2.registers event callback function 101 \param[in] idx must not exceed return value of csi_sha_get_instance_count() 102 \param[in] cb_event Pointer to \ref sha_event_cb_t 103 \return return sha handle if success 104 */ 105 sha_handle_t csi_sha_initialize(int32_t idx, sha_event_cb_t cb_event); 106 107 /** 108 \brief De-initialize SHA Interface. stops operation and releases the software resources used by the interface 109 \param[in] handle sha handle to operate. 110 \return error code 111 */ 112 int32_t csi_sha_uninitialize(sha_handle_t handle); 113 114 /** 115 \brief Get driver capabilities. 116 \param[in] handle sha handle to operate. 117 \return \ref sha_capabilities_t 118 */ 119 sha_capabilities_t csi_sha_get_capabilities(sha_handle_t handle); 120 121 /** 122 \brief config sha mode. 123 \param[in] handle sha handle to operate. 124 \param[in] mode \ref sha_mode_e 125 \param[in] endian \ref sha_endian_mode_e 126 \return error code 127 */ 128 int32_t csi_sha_config(sha_handle_t handle, 129 sha_mode_e mode, 130 sha_endian_mode_e endian 131 ); 132 133 /** 134 \brief start the engine 135 \param[in] handle sha handle to operate. 136 \param[in] context Pointer to the sha context. 137 \return error code 138 */ 139 int32_t csi_sha_starts(sha_handle_t handle, void *context); 140 141 /** 142 \brief updata the engine 143 \param[in] handle sha handle to operate. 144 \param[in] context Pointer to the sha context. 145 \param[in] input Pointer to the Source data 146 \param[in] len the data len 147 \return error code 148 */ 149 int32_t csi_sha_update(sha_handle_t handle, void *context, const void *input, uint32_t len); 150 151 /** 152 \brief finish the engine 153 \param[in] handle sha handle to operate. 154 \param[in] context Pointer to the sha context. 155 \param[out] output Pointer to the dest data 156 \return error code 157 */ 158 int32_t csi_sha_finish(sha_handle_t handle, void *context, void *output); 159 160 /** 161 \brief Get SHA status. 162 \param[in] handle sha handle to operate. 163 \return SHA status \ref sha_status_t 164 */ 165 sha_status_t csi_sha_get_status(sha_handle_t handle); 166 167 168 #ifdef __cplusplus 169 } 170 #endif 171 172 #endif /* _CSI_SHA_H_ */ 173