1 /***************************************************************************//** 2 * \file cy_cryptolite_aes_ccm.h 3 * \version 2.20 4 * 5 * \brief 6 * This file provides common constants and parameters 7 * for the Cryptolite AES CCM driver. 8 * 9 ******************************************************************************** 10 * Copyright 2023 Cypress Semiconductor Corporation 11 * SPDX-License-Identifier: Apache-2.0 12 * 13 * Licensed under the Apache License, Version 2.0 (the "License"); 14 * you may not use this file except in compliance with the License. 15 * You may obtain a copy of the License at 16 * 17 * http://www.apache.org/licenses/LICENSE-2.0 18 * 19 * Unless required by applicable law or agreed to in writing, software 20 * distributed under the License is distributed on an "AS IS" BASIS, 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the License for the specific language governing permissions and 23 * limitations under the License. 24 *******************************************************************************/ 25 26 #if !defined (CY_CRYPTOLITE_AES_CCM_H) 27 #define CY_CRYPTOLITE_AES_CCM_H 28 29 #include "cy_device.h" 30 31 #if defined (CY_IP_MXCRYPTOLITE) 32 33 #if defined(__cplusplus) 34 extern "C" { 35 #endif 36 37 #include "cy_cryptolite_common.h" 38 39 #if defined(CY_CRYPTOLITE_CFG_AES_C) 40 #if (CRYPTOLITE_AES_PRESENT == 1) 41 #if defined(CY_CRYPTOLITE_CFG_CIPHER_MODE_CCM) 42 43 #include "cy_cryptolite_aes.h" 44 #include "cy_cryptolite_vu.h" 45 46 /** 47 * \addtogroup group_cryptolite_lld_aes_functions 48 * \{ 49 */ 50 51 /******************************************************************************* 52 * Function Name: Cy_Cryptolite_Aes_Ccm_Init 53 ****************************************************************************//** 54 * 55 * Performs an AES CCM Init operation. 56 * 57 * \param base 58 * The pointer to the CRYPTOLITE instance. 59 * 60 * \param aesCcm_buffer The buffers should be a SAHB mapped addresses. 61 * The pointer to the memory buffers storage. 62 * 63 * \param aesCcmState 64 * The pointer to the AES CCM state structure allocated by the user. The user 65 * must not modify anything in this structure. 66 * 67 * \return 68 * \ref cy_en_cryptolite_status_t 69 * 70 *******************************************************************************/ 71 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Init(CRYPTOLITE_Type *base, 72 cy_stc_cryptolite_aes_ccm_buffers_t * aesCcm_buffer, cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 73 74 75 /******************************************************************************* 76 * Function Name: Cy_Cryptolite_Aes_Ccm_SetKey 77 ****************************************************************************//** 78 * 79 * Sets AES CCM Key for the operation. 80 * 81 * \param base 82 * The pointer to the CRYPTOLITE instance. 83 * 84 * \param key 85 * The pointer to the CCM key. 86 * 87 * \param aesCcmState 88 * The pointer to the AES CCM state structure allocated by the user. The user 89 * must not modify anything in this structure. 90 * 91 * 92 * \return 93 * \ref cy_en_cryptolite_status_t 94 * 95 *******************************************************************************/ 96 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_SetKey(CRYPTOLITE_Type *base, 97 uint8_t const *key, cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 98 99 100 /******************************************************************************* 101 * Function Name: Cy_Cryptolite_Aes_Ccm_Set_Length 102 ****************************************************************************//** 103 * 104 * Sets the length for Additional authentication data, plain text and Tag for AES CCM operation. 105 * 106 * \param base 107 * The pointer to the CRYPTOLITE instance. 108 * 109 * \param aadSize 110 * The Size of the Additional Authentication Data. 111 * 112 * \param textSize 113 * The Size of the Text. 114 * 115 * \param tagLength 116 * The Size of the Tag. 117 * 118 * \param aesCcmState 119 * The pointer to the AES CCM state structure allocated by the user. The user 120 * must not modify anything in this structure. 121 * 122 * 123 * \return 124 * \ref cy_en_cryptolite_status_t 125 * 126 *******************************************************************************/ 127 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Set_Length(CRYPTOLITE_Type *base, 128 uint32_t aadSize, uint32_t textSize, uint32_t tagLength, 129 cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 130 131 132 /******************************************************************************* 133 * Function Name: Cy_Cryptolite_Aes_Ccm_Start 134 ****************************************************************************//** 135 * 136 * Function to set IV for the AES CCM operation. 137 * 138 * \param base 139 * The pointer to the CRYPTOLITE instance. 140 * 141 * \param dirMode 142 * Can be \ref CY_CRYPTOLITE_ENCRYPT or \ref CY_CRYPTOLITE_DECRYPT 143 * (\ref cy_en_cryptolite_dir_mode_t) 144 * 145 * \param ivSize 146 * The size of the IV. 147 * 148 * \param iv 149 * The pointer to the IV. 150 * 151 * \param aesCcmState 152 * The pointer to the AES CCM state structure allocated by the user. The user 153 * must not modify anything in this structure. 154 * 155 * \return 156 * \ref cy_en_cryptolite_status_t 157 * 158 *******************************************************************************/ 159 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Start(CRYPTOLITE_Type *base, 160 cy_en_cryptolite_dir_mode_t dirMode, 161 uint32_t ivSize, uint8_t const * iv, 162 cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 163 164 165 /******************************************************************************* 166 * Function Name: Cy_Cryptolite_Aes_Ccm_Update_Aad 167 ****************************************************************************//** 168 * 169 * Performs an AES CCM update AAD Multistage operation. 170 * 171 * \param base 172 * The pointer to the CRYPTOLITE instance. 173 * 174 * \param aadSize 175 * The size of the AAD. 176 * 177 * \param aad 178 * The pointer to a AAD. 179 * 180 * \param aesCcmState 181 * The pointer to the AES CCM state structure allocated by the user. The user 182 * must not modify anything in this structure. 183 * 184 * \return 185 * \ref cy_en_cryptolite_status_t 186 * 187 *******************************************************************************/ 188 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Update_Aad(CRYPTOLITE_Type *base, 189 uint32_t aadSize, 190 uint8_t const *aad, 191 cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 192 193 194 /******************************************************************************* 195 * Function Name: Cy_Cryptolite_Aes_Ccm_Update 196 ****************************************************************************//** 197 * 198 * Performs an AES CCM Update Multistage update operation. 199 * 200 * \param base 201 * The pointer to the CRYPTOLITE instance. 202 * 203 * \param srcSize 204 * The size of the source block. 205 * 206 * \param dst 207 * The pointer to a destination block. 208 * 209 * \param src 210 * The pointer to a source block. 211 * 212 * \param aesCcmState 213 * The pointer to the AES CCM state structure allocated by the user. The user 214 * must not modify anything in this structure. 215 * 216 * \return 217 * \ref cy_en_cryptolite_status_t 218 * 219 *******************************************************************************/ 220 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Update(CRYPTOLITE_Type *base, 221 uint32_t srcSize, 222 uint8_t *dst, 223 uint8_t const *src, 224 cy_stc_cryptolite_aes_ccm_state_t *aesCcmState) ; 225 226 227 /******************************************************************************* 228 * Function Name: Cy_Cryptolite_Aes_Ccm_Finish 229 ****************************************************************************//** 230 * 231 * Performs an AES CCM finish operation. 232 * 233 * \param base 234 * The pointer to the CRYPTOLITE instance. 235 * 236 * \param tag 237 * The pointer to the CCM Tag. 238 * 239 * \param aesCcmState 240 * The pointer to the AES CCM state structure allocated by the user. The user 241 * must not modify anything in this structure. 242 * 243 * \return 244 * \ref cy_en_cryptolite_status_t 245 * 246 *******************************************************************************/ 247 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Finish(CRYPTOLITE_Type *base, uint8_t *tag, cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 248 249 250 /******************************************************************************* 251 * Function Name: Cy_Cryptolite_Aes_Ccm_Encrypt_Tag 252 ****************************************************************************//** 253 * 254 * Performs an AES CCM Encrypt operation. 255 * \note Cy_Cryptolite_Aes_Ccm_Init() and Cy_Cryptolite_Aes_Ccm_SetKey() should be called before calling this function 256 * 257 * \param base 258 * The pointer to the CRYPTOLITE instance. 259 * 260 * \param ivSize 261 * The size of the IV. 262 * 263 * \param iv 264 * The pointer to the IV. 265 * 266 * \param aadSize 267 * The size of the AAD. 268 * 269 * \param aad 270 * The pointer to a AAD. 271 * 272 * \param srcSize 273 * The size of the source block. 274 * 275 * \param cipherTxt 276 * The pointer to a cipher text block. 277 * 278 * \param plainTxt 279 * The pointer to a plain text block. 280 * 281 * \param tagSize 282 * The size of the Tag. 283 * 284 * \param tag 285 * The pointer to the tags. 286 * 287 * \param aesCcmState 288 * The pointer to the AES CCM state structure allocated by the user. The user 289 * must not modify anything in this structure. 290 * 291 * \return 292 * \ref cy_en_cryptolite_status_t 293 * 294 *******************************************************************************/ 295 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Encrypt_Tag(CRYPTOLITE_Type *base, 296 uint32_t ivSize, uint8_t const * iv, 297 uint32_t aadSize, uint8_t const *aad, 298 uint32_t srcSize, uint8_t *cipherTxt, uint8_t const *plainTxt, 299 uint32_t tagSize, uint8_t *tag, 300 cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 301 302 303 /******************************************************************************* 304 * Function Name: Cy_Cryptolite_Aes_Ccm_Decrypt 305 ****************************************************************************//** 306 * 307 * Performs an AES CCM Decrypt operation. 308 * \note Cy_Cryptolite_Aes_Ccm_Init() and Cy_Cryptolite_Aes_Ccm_SetKey() should be called before calling this function 309 * 310 * \param base 311 * The pointer to the CRYPTOLITE instance. 312 * 313 * \param ivSize 314 * The size of the IV. 315 * 316 * \param iv 317 * The pointer to the IV. 318 * 319 * \param aadSize 320 * The size of the AAD. 321 * 322 * \param aad 323 * The pointer to a AAD. 324 * 325 * \param srcSize 326 * The size of the source block. 327 * 328 * \param plainTxt 329 * The pointer to a plain text block. 330 * 331 * \param cipherTxt 332 * The pointer to a cipher text block. 333 * 334 * \param tagSize 335 * The size of the Tag. 336 * 337 * \param tag 338 * The pointer to the tags. 339 * 340 * \param isValid 341 * The pointer Store the authentication status. 342 * 343 * \param aesCcmState 344 * The pointer to the AES CCM state structure allocated by the user. The user 345 * must not modify anything in this structure. 346 * 347 * \return 348 * \ref cy_en_cryptolite_status_t 349 * 350 *******************************************************************************/ 351 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Decrypt(CRYPTOLITE_Type *base, 352 uint32_t ivSize, uint8_t const * iv, 353 uint32_t aadSize, uint8_t const *aad, 354 uint32_t srcSize, uint8_t *plainTxt, uint8_t const *cipherTxt, 355 uint32_t tagSize, uint8_t *tag, cy_en_cryptolite_ccm_auth_result_t *isValid, 356 cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 357 358 359 /******************************************************************************* 360 * Function Name: Cy_Cryptolite_Aes_Ccm_Free 361 ****************************************************************************//** 362 * 363 * Clears AES CCM operation context. 364 * 365 * \param base 366 * The pointer to the CRYPTOLITE instance. 367 * 368 * \param aesCcmState 369 * The pointer to the AES CCM state structure allocated by the user. The user 370 * must not modify anything in this structure. 371 * 372 * \return 373 * \ref cy_en_cryptolite_status_t 374 * 375 *******************************************************************************/ 376 cy_en_cryptolite_status_t Cy_Cryptolite_Aes_Ccm_Free(CRYPTOLITE_Type *base, cy_stc_cryptolite_aes_ccm_state_t *aesCcmState); 377 378 379 380 #endif /*CY_CRYPTOLITE_CFG_CIPHER_MODE_CCM*/ 381 #endif /* #if (CY_CRYPTOLITE_CFG_AES_C)*/ 382 #endif /* #if CRYPTOLITE_AES_PRESENT*/ 383 /** \} group_cryptolite_lld_aes_functions */ 384 385 #if defined(__cplusplus) 386 } 387 #endif 388 389 #endif /* CY_IP_MXCRYPTOLITE */ 390 391 #endif /* #if !defined (CY_CRYPTOLITE_AES_CCM_H) */ 392 393 /* [] END OF FILE */ 394