2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 /******************************************************************************
18 * @brief header file for sha driver
21 ******************************************************************************/
30 #include <drv_common.h>
31 #include <drv_errno.h>
34 /// definition for sha handle.
35 typedef void *sha_handle_t;
37 /****** SHA specific error codes *****/
39 SHA_ERROR_MODE = (EDRV_SPECIFIC + 1), ///< Specified Mode not supported
40 SHA_ERROR_ENDIAN ///< Specified endian not supported
43 /*----- SHA Control Codes: Mode -----*/
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
54 /*----- SHA Control Codes: Mode Parameters: Endian -----*/
56 SHA_ENDIAN_MODE_BIG = 0, ///< Big Endian Mode
57 SHA_ENDIAN_MODE_LITTLE , ///< Little Endian Mode
64 uint32_t busy : 1; ///< calculate busy flag
67 /****** SHA Event *****/
69 SHA_EVENT_COMPLETE = 0 ///< calculate completed
72 typedef void (*sha_event_cb_t)(sha_event_e event); ///< Pointer to \ref sha_event_cb_t : SHA Event call back.
76 \brief SHA Device Driver Capabilities.
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
91 // Function documentation
94 \brief get sha handle count.
95 \return sha handle count
97 int32_t csi_sha_get_instance_count(void);
100 \brief Initialize SHA Interface. 1. Initializes the resources needed for the SHA interface 2.registers event callback function
101 \param[in] handle Pointer to the buffer store the sha context
102 \param[in] cb_event Pointer to \ref sha_event_cb_t
103 \return return sha handle if success
105 sha_handle_t csi_sha_initialize(sha_handle_t handle, sha_event_cb_t cb_event);
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.
112 int32_t csi_sha_uninitialize(sha_handle_t handle);
115 \brief Get driver capabilities.
116 \param[in] handle sha handle to operate.
117 \return \ref sha_capabilities_t
119 sha_capabilities_t csi_sha_get_capabilities(sha_handle_t handle);
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
128 int32_t csi_sha_config(sha_handle_t handle,
130 sha_endian_mode_e endian
134 \brief start the engine
135 \param[in] handle sha handle to operate.
136 \param[in] context Pointer to the sha context.
139 int32_t csi_sha_starts(sha_handle_t handle, void *context);
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
149 int32_t csi_sha_update(sha_handle_t handle, void *context, const void *input, uint32_t len);
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
158 int32_t csi_sha_finish(sha_handle_t handle, void *context, void *output);
161 \brief Get SHA status.
162 \param[in] handle sha handle to operate.
163 \return SHA status \ref sha_status_t
165 sha_status_t csi_sha_get_status(sha_handle_t handle);
172 #endif /* _CSI_SHA_H_ */