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.
17 /******************************************************************************
19 * @brief Header File for AES Driver
22 ******************************************************************************/
31 #include <drv_common.h>
32 #include <drv_errno.h>
35 /// definition for aes handle.
36 typedef void *aes_handle_t;
38 /****** AES specific error codes *****/
40 AES_ERROR_MODE = (EDRV_SPECIFIC + 1) , ///< Specified Mode not supported
41 AES_ERROR_DATA_BITS , ///< Specified number of Data bits not supported
42 AES_ERROR_ENDIAN ///< Specified endian not supported
45 /*----- AES Control Codes: Mode -----*/
47 AES_MODE_ECB = 0, ///< ECB Mode
48 AES_MODE_CBC , ///< CBC Mode
49 AES_MODE_CFB , ///< CFB Mode
50 AES_MODE_OFB , ///< OFB Mode
51 AES_MODE_CTR ///< CTR Mode
54 /*----- AES Control Codes: Crypto Mode -----*/
56 AES_CRYPTO_MODE_ENCRYPT = 0, ///< encrypt Mode
57 AES_CRYPTO_MODE_DECRYPT , ///< decrypt Mode
60 /*----- AES Control Codes: Padding Mode -----*/
62 AES_PADDING_MODE_NO = 0, ///< NO-PADDING
63 AES_PADDING_MODE_ZERO , ///< ZERO-PADDING
64 AES_PADDING_MODE_PKCS5 ///< PKCS5-PADDING
67 /*----- AES Control Codes: Mode Parameters: Key length -----*/
69 AES_KEY_LEN_BITS_128 = 0, ///< 128 Data bits
70 AES_KEY_LEN_BITS_192 , ///< 192 Data bits
71 AES_KEY_LEN_BITS_256 ///< 256 Data bits
74 /*----- AES Control Codes: Mode Parameters: Endian -----*/
76 AES_ENDIAN_LITTLE = 0, ///< Little Endian
77 AES_ENDIAN_BIG ///< Big Endian
84 uint32_t busy : 1; ///< busy flag
87 /****** AES Event *****/
89 AES_EVENT_CRYPTO_COMPLETE = 0 ///< Encrypt completed
91 typedef void (*aes_event_cb_t)(aes_event_e event); ///< Pointer to \ref aes_event_cb_t : AES Event call back.
95 \brief AES Device Driver Capabilities.
98 uint32_t ecb_mode : 1; ///< supports ECB mode
99 uint32_t cbc_mode : 1; ///< supports CBC mode
100 uint32_t cfb_mode : 1; ///< supports CFB mode
101 uint32_t ofb_mode : 1; ///< supports OFB mode
102 uint32_t ctr_mode : 1; ///< supports CTR mode
103 uint32_t bits_128 : 1; ///< supports 128bits key length
104 uint32_t bits_192 : 1; ///< supports 192bits key length
105 uint32_t bits_256 : 1; ///< supports 256bits key length
106 } aes_capabilities_t;
109 // Function documentation
112 \brief get aes instance count.
113 \return aes handle count
115 int32_t csi_aes_get_instance_count(void);
118 \brief Initialize AES Interface. 1. Initializes the resources needed for the AES interface 2.registers event callback function
119 \param[in] idx must not exceed return value of csi_aes_get_instance_count().
120 \param[in] cb_event Pointer to \ref aes_event_cb_t
121 \return return aes handle if success
123 aes_handle_t csi_aes_initialize(int32_t idx, aes_event_cb_t cb_event);
126 \brief De-initialize AES Interface. stops operation and releases the software resources used by the interface
127 \param[in] handle aes handle to operate.
130 int32_t csi_aes_uninitialize(aes_handle_t handle);
133 \brief Get driver capabilities.
134 \param[in] handle aes handle to operate.
135 \return \ref aes_capabilities_t
137 aes_capabilities_t csi_aes_get_capabilities(aes_handle_t handle);
140 \brief config aes mode.
141 \param[in] handle aes handle to operate.
142 \param[in] mode \ref aes_mode_e
143 \param[in] keylen_bits \ref aes_key_len_bits_e
144 \param[in] endian \ref aes_endian_mode_e
145 \param[in] arg Pointer to the iv address when mode is cbc_mode
148 int32_t csi_aes_config(aes_handle_t handle,
150 aes_key_len_bits_e keylen_bits,
151 aes_endian_mode_e endian,
156 \brief set crypto key.
157 \param[in] handle aes handle to operate.
158 \param[in] context aes information context(NULL when hardware implementation)
159 \param[in] key Pointer to the key buf
160 \param[in] key_len Pointer to \ref aes_key_len_bits_e
161 \param[in] enc \ref aes_crypto_mode_e
164 int32_t csi_aes_set_key(aes_handle_t handle, void *context, void *key, aes_key_len_bits_e key_len, aes_crypto_mode_e enc);
167 \brief encrypt or decrypt
168 \param[in] handle aes handle to operate.
169 \param[in] context aes information context(NULL when hardware implementation)
170 \param[in] in Pointer to the Source data
171 \param[out] out Pointer to the Result data.
172 \param[in] len the Source data len.
173 \param[in] padding \ref aes_padding_mode_e.
176 int32_t csi_aes_crypto(aes_handle_t handle, void *context, void *in, void *out, uint32_t len, aes_padding_mode_e padding);
179 \brief Get AES status.
180 \param[in] handle aes handle to operate.
181 \return AES status \ref aes_status_t
183 aes_status_t csi_aes_get_status(aes_handle_t handle);
189 #endif /* _CSI_AES_H_ */