1 /***************************************************************************//**
2 * \file cy_crypto_core_aes.h
3 * \version 2.120
4 *
5 * \brief
6 *  This file provides constant and parameters for the API for the AES method
7 *  in the Crypto driver.
8 *
9 ********************************************************************************
10 * \copyright
11 * Copyright (c) (2020-2022), Cypress Semiconductor Corporation (an Infineon company) or
12 * an affiliate of Cypress Semiconductor Corporation.
13 * SPDX-License-Identifier: Apache-2.0
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 *    http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 *******************************************************************************/
27 
28 
29 #if !defined (CY_CRYPTO_CORE_AES_H)
30 #define CY_CRYPTO_CORE_AES_H
31 
32 #include "cy_device.h"
33 
34 #if defined (CY_IP_MXCRYPTO)
35 
36 #include "cy_crypto_common.h"
37 
38 #if defined(__cplusplus)
39 extern "C" {
40 #endif
41 
42 #if (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_AES_C)
43 
44 #include "cy_crypto_core_aes_v1.h"
45 #include "cy_crypto_core_aes_v2.h"
46 
47 #include "cy_crypto_core_hw.h"
48 
49 typedef cy_en_crypto_status_t (*cy_crypto_aes_init_func_t)(CRYPTO_Type *base,
50                                                  uint8_t const *key,
51                                                  cy_en_crypto_aes_key_length_t keyLength,
52                                                  cy_stc_crypto_aes_state_t *aesState,
53                                                  cy_stc_crypto_aes_buffers_t *aesBuffers);
54 
55 typedef cy_en_crypto_status_t (*cy_crypto_aes_ecb_func_t)(CRYPTO_Type *base,
56                                                 cy_en_crypto_dir_mode_t dirMode,
57                                                 uint8_t *dst,
58                                                 uint8_t const *src,
59                                                 cy_stc_crypto_aes_state_t *aesState);
60 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC)
61 typedef cy_en_crypto_status_t (*cy_crypto_aes_cbc_func_t)(CRYPTO_Type *base,
62                                                 cy_en_crypto_dir_mode_t dirMode,
63                                                 uint32_t srcSize,
64                                                 uint8_t *ivPtr,
65                                                 uint8_t *dst,
66                                                 uint8_t const *src,
67                                                 cy_stc_crypto_aes_state_t *aesState);
68 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC) */
69 
70 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB)
71 typedef cy_en_crypto_status_t (*cy_crypto_aes_cfb_func_t)(CRYPTO_Type *base,
72                                                 cy_en_crypto_dir_mode_t dirMode,
73                                                 uint32_t srcSize,
74                                                 uint8_t *ivPtr,
75                                                 uint8_t *dst,
76                                                 uint8_t const *src,
77                                                 cy_stc_crypto_aes_state_t *aesState);
78 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB) */
79 
80 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR)
81 typedef cy_en_crypto_status_t (*cy_crypto_aes_ctr_func_t)(CRYPTO_Type *base,
82                                                 uint32_t srcSize,
83                                                 uint32_t *srcOffset,
84                                                 uint8_t *ivPtr,
85                                                 uint8_t *streamBlock,
86                                                 uint8_t *dst,
87                                                 uint8_t const *src,
88                                                 cy_stc_crypto_aes_state_t *aesState);
89 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR) */
90 
91 /**
92 * \addtogroup group_crypto_lld_symmetric_functions
93 * \{
94 */
95 
96 /*******************************************************************************
97 * Function Name: Cy_Crypto_Core_Aes_Init
98 ****************************************************************************//**
99 *
100 * Initializes AES mode of operation and prepares an inverse key.
101 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters key must align and end in 32 byte boundary.
102 *
103 *
104 * \param base
105 * The pointer to the CRYPTO instance.
106 *
107 * \param key
108 * The pointer to the encryption/decryption key.
109 *
110 * \param keyLength
111 * \ref cy_en_crypto_aes_key_length_t
112 *
113 * \param aesState
114 * The pointer to the AES state structure allocated by the user. The user
115 * must not modify anything in this structure.
116 *
117 * \return
118 * \ref cy_en_crypto_status_t
119 *
120 * \funcusage
121 * \snippet crypto/snippet/main.c snippet_myCryptoCoreAesEcbUse
122 *
123 *******************************************************************************/
Cy_Crypto_Core_Aes_Init(CRYPTO_Type * base,uint8_t const * key,cy_en_crypto_aes_key_length_t keyLength,cy_stc_crypto_aes_state_t * aesState)124 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Init(CRYPTO_Type *base,
125                                                  uint8_t const *key,
126                                                  cy_en_crypto_aes_key_length_t keyLength,
127                                                  cy_stc_crypto_aes_state_t *aesState)
128 {
129     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
130 
131     #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE) || defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
132     cy_stc_crypto_aes_buffers_t *aesBuffers = (cy_stc_crypto_aes_buffers_t *)((void *)Cy_Crypto_Core_GetVuMemoryAddress(base));
133 
134     if (CY_CRYPTO_V1)
135     {
136         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
137         tmpResult = Cy_Crypto_Core_V1_Aes_Init(base, key, keyLength, aesState, aesBuffers);
138         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
139     }
140     else
141     {
142         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
143         tmpResult = Cy_Crypto_Core_V2_Aes_Init(base, key, keyLength, aesState, aesBuffers);
144         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
145     }
146     #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) || defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
147 
148     return tmpResult;
149 }
150 
151 /*******************************************************************************
152 * Function Name: Cy_Crypto_Core_Aes_InitContext
153 ****************************************************************************//**
154 *
155 * Initializes AES mode of operation and prepares an inverse key within a user
156 * specified buffer.
157 *
158 * \param base
159 * The pointer to the CRYPTO instance.
160 *
161 * \param key
162 * The pointer to the encryption/decryption key.
163 *
164 * \param keyLength
165 * \ref cy_en_crypto_aes_key_length_t
166 *
167 * \param aesState
168 * The pointer to the AES state structure allocated by the user. The user
169 * must not modify anything in this structure.
170 *
171 * \param aesBuffers
172 * The pointer to the AES buffer provided by the user. The user must not modify
173 * anything in this buffer during operation.
174 *
175 * \return
176 * \ref cy_en_crypto_status_t
177 *
178 *******************************************************************************/
Cy_Crypto_Core_Aes_InitContext(CRYPTO_Type * base,uint8_t const * key,cy_en_crypto_aes_key_length_t keyLength,cy_stc_crypto_aes_state_t * aesState,cy_stc_crypto_aes_buffers_t * aesBuffers)179 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_InitContext(CRYPTO_Type *base,
180                                                  uint8_t const *key,
181                                                  cy_en_crypto_aes_key_length_t keyLength,
182                                                  cy_stc_crypto_aes_state_t *aesState,
183                                                  cy_stc_crypto_aes_buffers_t *aesBuffers)
184 {
185     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
186 
187     if (CY_CRYPTO_V1)
188     {
189         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
190         tmpResult = Cy_Crypto_Core_V1_Aes_Init(base, key, keyLength, aesState, aesBuffers);
191         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
192     }
193     else
194     {
195         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
196         tmpResult = Cy_Crypto_Core_V2_Aes_Init(base, key, keyLength, aesState, aesBuffers);
197         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
198     }
199 
200     return tmpResult;
201 }
202 
203 /*******************************************************************************
204 * Function Name: Cy_Crypto_Core_Aes_Free
205 ****************************************************************************//**
206 *
207 * Clears AES operation context.
208 *
209 * \param base
210 * The pointer to the CRYPTO instance.
211 *
212 * \param aesState
213 * The pointer to the AES state structure allocated by the user. The user
214 * must not modify anything in this structure.
215 *
216 * \return
217 * \ref cy_en_crypto_status_t
218 *
219 * \funcusage
220 * \snippet crypto/snippet/main.c snippet_myCryptoCoreAesEcbUse
221 *
222 *******************************************************************************/
Cy_Crypto_Core_Aes_Free(CRYPTO_Type * base,cy_stc_crypto_aes_state_t * aesState)223 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Free(CRYPTO_Type *base,
224                                                  cy_stc_crypto_aes_state_t *aesState)
225 {
226     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
227 
228     if (CY_CRYPTO_V1)
229     {
230         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
231         tmpResult = Cy_Crypto_Core_V1_Aes_Free(base, aesState);
232         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
233     }
234     else
235     {
236         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
237         tmpResult = Cy_Crypto_Core_V2_Aes_Free(base, aesState);
238         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
239     }
240 
241     return tmpResult;
242 }
243 
244 /*******************************************************************************
245 * Function Name: Cy_Crypto_Core_Aes_Ecb
246 ****************************************************************************//**
247 *
248 * Performs the AES operation on a single block.
249 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters src & dst must align and end in 32 byte boundary.
250 *
251 * \param base
252 * The pointer to the CRYPTO instance.
253 *
254 * \param dirMode
255 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
256 * (\ref cy_en_crypto_dir_mode_t).
257 *
258 * \param dst
259 * The pointer to the destination cipher block.
260 *
261 * \param src
262 * The pointer to the source block.
263 *
264 * \param aesState
265 * The pointer to the AES state structure allocated by the user. The user
266 * must not modify anything in this structure.
267 *
268 * \return
269 * \ref cy_en_crypto_status_t
270 *
271 * \funcusage
272 * \snippet crypto/snippet/main.c snippet_myCryptoCoreAesEcbUse
273 *
274 *******************************************************************************/
Cy_Crypto_Core_Aes_Ecb(CRYPTO_Type * base,cy_en_crypto_dir_mode_t dirMode,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)275 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ecb(CRYPTO_Type *base,
276                                                 cy_en_crypto_dir_mode_t dirMode,
277                                                 uint8_t *dst,
278                                                 uint8_t const *src,
279                                                 cy_stc_crypto_aes_state_t *aesState)
280 {
281     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
282 
283     if (CY_CRYPTO_V1)
284     {
285         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
286         tmpResult = Cy_Crypto_Core_V1_Aes_Ecb(base, dirMode, dst, src, aesState);
287         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
288     }
289     else
290     {
291         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
292         tmpResult = Cy_Crypto_Core_V2_Aes_Ecb(base, dirMode, dst, src, aesState);
293         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
294     }
295 
296     return tmpResult;
297 }
298 
299 
300 /*******************************************************************************
301 * Function Name: Cy_Crypto_Core_Aes_Ecb_Setup
302 ****************************************************************************//**
303 *
304 * Performs an AES ECB init operation.
305 *
306 * \param base
307 * The pointer to the CRYPTO instance.
308 *
309 * \param dirMode
310 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
311 * (\ref cy_en_crypto_dir_mode_t).
312 *
313 *
314 * \param aesState
315 * The pointer to the AES state structure allocated by the user. The user
316 * must not modify anything in this structure.
317 *
318 * \return
319 * \ref cy_en_crypto_status_t
320 *
321 *******************************************************************************/
Cy_Crypto_Core_Aes_Ecb_Setup(CRYPTO_Type * base,cy_en_crypto_dir_mode_t dirMode,cy_stc_crypto_aes_state_t * aesState)322 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ecb_Setup(CRYPTO_Type *base,
323                                             cy_en_crypto_dir_mode_t dirMode,
324                                             cy_stc_crypto_aes_state_t *aesState)
325 
326 
327 {
328     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
329 
330     if (CY_CRYPTO_V1)
331     {
332         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
333         (void)base;
334         (void)dirMode;
335         (void)aesState;
336 
337         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
338         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
339     }
340     else
341     {
342         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
343         tmpResult = Cy_Crypto_Core_V2_Aes_Ecb_Setup(base, dirMode, aesState);
344         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
345     }
346 
347     return tmpResult;
348 }
349 
350 
351 /*******************************************************************************
352 * Function Name: Cy_Crypto_Core_Aes_Ecb_Update
353 ****************************************************************************//**
354 *
355 * Performs an AES ECB Multistage update operation.
356 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters src & dst must align and end in 32 byte boundary.
357 *
358 * \param base
359 * The pointer to the CRYPTO instance.
360 *
361 * \param srcSize
362 * The size of the source block.
363 *
364 * \param dst
365 * The pointer to a destination cipher block.
366 *
367 * \param src
368 * The pointer to a source block.
369 *
370 * \param aesState
371 * The pointer to the AES state structure allocated by the user. The user
372 * must not modify anything in this structure.
373 *
374 * \return
375 * \ref cy_en_crypto_status_t
376 *
377 *******************************************************************************/
Cy_Crypto_Core_Aes_Ecb_Update(CRYPTO_Type * base,uint32_t srcSize,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)378 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ecb_Update(CRYPTO_Type *base,
379                                             uint32_t srcSize,
380                                             uint8_t *dst,
381                                             uint8_t const *src,
382                                             cy_stc_crypto_aes_state_t *aesState)
383 
384 {
385     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
386 
387     if (CY_CRYPTO_V1)
388     {
389         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
390         (void)base;
391         (void)srcSize;
392         (void)dst;
393         (void)src;
394         (void)aesState;
395         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
396         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
397     }
398     else
399     {
400         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
401         tmpResult = Cy_Crypto_Core_V2_Aes_Ecb_Update(base, srcSize, dst, src, aesState);
402         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
403     }
404 
405     return tmpResult;
406 }
407 
408 
409 /*******************************************************************************
410 * Function Name: Cy_Crypto_Core_Aes_Ecb_Finish
411 ****************************************************************************//**
412 *
413 * Performs an AES ECB finish operation.
414 *
415 * \param base
416 * The pointer to the CRYPTO instance.
417 *
418 * \param aesState
419 * The pointer to the AES state structure allocated by the user. The user
420 * must not modify anything in this structure.
421 *
422 * \return
423 * \ref cy_en_crypto_status_t
424 *
425 *******************************************************************************/
Cy_Crypto_Core_Aes_Ecb_Finish(CRYPTO_Type * base,cy_stc_crypto_aes_state_t * aesState)426 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ecb_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState)
427 
428 {
429     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
430 
431     if (CY_CRYPTO_V1)
432     {
433         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
434         (void)base;
435         (void)aesState;
436         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
437         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
438     }
439     else
440     {
441         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
442         tmpResult = Cy_Crypto_Core_V2_Aes_Ecb_Finish(base, aesState);
443         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
444     }
445 
446     return tmpResult;
447 }
448 
449 
450 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC)
451 /*******************************************************************************
452 * Function Name: Cy_Crypto_Core_Aes_Cbc
453 ****************************************************************************//**
454 *
455 * Performs the AES-CBC operation defined in the dirMode parameter on a plain text
456 * defined in the src parameter.
457 *
458 * \param base
459 * The pointer to the CRYPTO instance.
460 *
461 * \param dirMode
462 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
463 * (\ref cy_en_crypto_dir_mode_t)
464 *
465 * \param srcSize
466 * The size of the source plain text.
467 *
468 * \param ivPtr
469 * The pointer to the initial vector.
470 *
471 * \param dst
472 * The pointer to the destination cipher text.
473 *
474 * \param src
475 * The pointer to the source plain text.
476 *
477 * \param aesState
478 * The pointer to the AES state structure allocated by the user. The user
479 * must not modify anything in this structure.
480 *
481 * \return
482 * \ref cy_en_crypto_status_t
483 *
484 *******************************************************************************/
Cy_Crypto_Core_Aes_Cbc(CRYPTO_Type * base,cy_en_crypto_dir_mode_t dirMode,uint32_t srcSize,uint8_t * ivPtr,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)485 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc(CRYPTO_Type *base,
486                                                 cy_en_crypto_dir_mode_t dirMode,
487                                                 uint32_t srcSize,
488                                                 uint8_t *ivPtr,
489                                                 uint8_t *dst,
490                                                 uint8_t const *src,
491                                                 cy_stc_crypto_aes_state_t *aesState)
492 {
493     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
494 
495     if (CY_CRYPTO_V1)
496     {
497         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
498         tmpResult = Cy_Crypto_Core_V1_Aes_Cbc(base, dirMode, srcSize, ivPtr, dst, src, aesState);
499         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
500     }
501     else
502     {
503         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
504         tmpResult = Cy_Crypto_Core_V2_Aes_Cbc(base, dirMode, srcSize, ivPtr, dst, src, aesState);
505         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
506     }
507 
508     return tmpResult;
509 }
510 
511 
512 
513 /*******************************************************************************
514 * Function Name: Cy_Crypto_Core_Aes_Cbc_Setup
515 ****************************************************************************//**
516 *
517 * Performs an AES CBC setup operation.
518 *
519 * \param base
520 * The pointer to the CRYPTO instance.
521 *
522 * \param dirMode
523 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
524 * (\ref cy_en_crypto_dir_mode_t).
525 *
526 * \param aesState
527 * The pointer to the AES state structure allocated by the user. The user
528 * must not modify anything in this structure.
529 *
530 * \return
531 * \ref cy_en_crypto_status_t
532 *
533 *******************************************************************************/
534 
Cy_Crypto_Core_Aes_Cbc_Setup(CRYPTO_Type * base,cy_en_crypto_dir_mode_t dirMode,cy_stc_crypto_aes_state_t * aesState)535 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc_Setup(CRYPTO_Type *base,
536                                             cy_en_crypto_dir_mode_t dirMode,
537                                             cy_stc_crypto_aes_state_t *aesState)
538 
539 {
540     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
541 
542     if (CY_CRYPTO_V1)
543     {
544         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
545         (void)base;
546         (void)dirMode;
547         (void)aesState;
548         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
549         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
550     }
551     else
552     {
553         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
554         tmpResult = Cy_Crypto_Core_V2_Aes_Cbc_Setup(base, dirMode, aesState);
555         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
556     }
557 
558     return tmpResult;
559 }
560 
561 
562 
563 
564 /*******************************************************************************
565 * Function Name: Cy_Crypto_Core_Aes_Cbc_Set_IV
566 ****************************************************************************//**
567 *
568 * Function to set AES CBC IV.
569 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters iv must align and end in 32 byte boundary.
570 *
571 * \param base
572 * The pointer to the CRYPTO instance.
573 *
574 * \param iv
575 * The pointer to the IV.
576 *
577 * \param aesState
578 * The pointer to the AES state structure allocated by the user. The user
579 * must not modify anything in this structure.
580 *
581 * \return
582 * \ref cy_en_crypto_status_t
583 *
584 *******************************************************************************/
585 
Cy_Crypto_Core_Aes_Cbc_Set_IV(CRYPTO_Type * base,uint8_t const * iv,cy_stc_crypto_aes_state_t * aesState)586 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc_Set_IV(CRYPTO_Type *base,
587                                             uint8_t const * iv,
588                                             cy_stc_crypto_aes_state_t *aesState)
589 {
590     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
591 
592     if (CY_CRYPTO_V1)
593     {
594         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
595         (void)base;
596         (void)iv;
597         (void)aesState;
598         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
599         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
600     }
601     else
602     {
603         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
604         tmpResult = Cy_Crypto_Core_V2_Aes_Cbc_Set_IV(base, iv, aesState);
605         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
606     }
607 
608     return tmpResult;
609 }
610 
611 
612 /*******************************************************************************
613 * Function Name: Cy_Crypto_Core_Aes_Cbc_Update
614 ****************************************************************************//**
615 *
616 * Performs an AES CBC Multistage update operation.
617 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters src & dst must align and end in 32 byte boundary.
618 *
619 * \param base
620 * The pointer to the CRYPTO instance.
621 *
622 * \param srcSize
623 * The size of the source block.
624 *
625 * \param dst
626 * The pointer to a destination cipher block.
627 *
628 * \param src
629 * The pointer to a source block.
630 *
631 * \param aesState
632 * The pointer to the AES state structure allocated by the user. The user
633 * must not modify anything in this structure.
634 *
635 * \return
636 * \ref cy_en_crypto_status_t
637 *
638 *******************************************************************************/
Cy_Crypto_Core_Aes_Cbc_Update(CRYPTO_Type * base,uint32_t srcSize,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)639 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc_Update(CRYPTO_Type *base,
640                                             uint32_t srcSize,
641                                             uint8_t *dst,
642                                             uint8_t const *src,
643                                             cy_stc_crypto_aes_state_t *aesState)
644 {
645     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
646 
647     if (CY_CRYPTO_V1)
648     {
649         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
650         (void)base;
651         (void)srcSize;
652         (void)dst;
653         (void)src;
654         (void)aesState;
655         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
656         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
657     }
658     else
659     {
660         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
661         tmpResult = Cy_Crypto_Core_V2_Aes_Cbc_Update(base, srcSize, dst, src, aesState);
662         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
663     }
664 
665     return tmpResult;
666 
667 }
668 
669 
670 /*******************************************************************************
671 * Function Name: Cy_Crypto_Core_Aes_Cbc_Finish
672 ****************************************************************************//**
673 *
674 * Performs an AES CBC finish operation.
675 *
676 * \param base
677 * The pointer to the CRYPTO instance.
678 *
679 * \param aesState
680 * The pointer to the AES state structure allocated by the user. The user
681 * must not modify anything in this structure.
682 *
683 * \return
684 * \ref cy_en_crypto_status_t
685 *
686 *******************************************************************************/
Cy_Crypto_Core_Aes_Cbc_Finish(CRYPTO_Type * base,cy_stc_crypto_aes_state_t * aesState)687 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState)
688 {
689     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
690 
691     if (CY_CRYPTO_V1)
692     {
693         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
694         (void)base;
695         (void)aesState;
696         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
697         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
698     }
699     else
700     {
701         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
702         tmpResult = Cy_Crypto_Core_V2_Aes_Cbc_Finish(base, aesState);
703         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
704     }
705 
706     return tmpResult;
707 
708 }
709 
710 
711 /*******************************************************************************
712 * Function Name: Cy_Crypto_Core_Aes_CbcMac_Setup
713 ****************************************************************************//**
714 *
715 * Performs an AES CBC MAC setup operation.
716 *
717 * \param base
718 * The pointer to the CRYPTO instance.
719 *
720 * \param aesState
721 * The pointer to the AES state structure allocated by the user. The user
722 * must not modify anything in this structure.
723 *
724 * \return
725 * \ref cy_en_crypto_status_t
726 *
727 *******************************************************************************/
Cy_Crypto_Core_Aes_CbcMac_Setup(CRYPTO_Type * base,cy_stc_crypto_aes_state_t * aesState)728 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_CbcMac_Setup(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState)
729 {
730     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
731 
732     if (CY_CRYPTO_V1)
733     {
734         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
735         (void)base;
736         (void)aesState;
737         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
738         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
739     }
740     else
741     {
742         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
743         tmpResult = Cy_Crypto_Core_V2_Aes_CbcMac_Setup(base, aesState);
744         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
745     }
746 
747     return tmpResult;
748 
749 }
750 
751 
752 /*******************************************************************************
753 * Function Name: Cy_Crypto_Core_Aes_CbcMac_Update
754 ****************************************************************************//**
755 *
756 * Performs an AES CBC MAC Multistage update operation.
757 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters src must align and end in 32 byte boundary.
758 *
759 * \param base
760 * The pointer to the CRYPTO instance.
761 *
762 * \param srcSize
763 * The size of the source block.
764 *
765 * \param src
766 * The pointer to a source block.
767 *
768 * \param aesState
769 * The pointer to the AES state structure allocated by the user. The user
770 * must not modify anything in this structure.
771 *
772 * \return
773 * \ref cy_en_crypto_status_t
774 *
775 *******************************************************************************/
Cy_Crypto_Core_Aes_CbcMac_Update(CRYPTO_Type * base,uint32_t srcSize,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)776 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_CbcMac_Update(CRYPTO_Type *base,
777                                             uint32_t srcSize,
778                                             uint8_t const *src,
779                                             cy_stc_crypto_aes_state_t *aesState)
780 {
781     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
782 
783     if (CY_CRYPTO_V1)
784     {
785         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
786         (void)base;
787         (void)srcSize;
788         (void)src;
789         (void)aesState;
790         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
791         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
792     }
793     else
794     {
795         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
796         tmpResult = Cy_Crypto_Core_V2_Aes_CbcMac_Update(base, srcSize, src, aesState);
797         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
798     }
799 
800     return tmpResult;
801 
802 }
803 
804 
805 /*******************************************************************************
806 * Function Name: Cy_Crypto_Core_Aes_CbcMac_Finish
807 ****************************************************************************//**
808 *
809 * Performs an AES CBC finish operation.
810 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters mac must align and end in 32 byte boundary.
811 *
812 *
813 * \param base
814 * The pointer to the CRYPTO instance.
815 *
816 * \param mac
817 * The pointer to the cbc-mac.
818 *
819 * \param aesState
820 * The pointer to the AES state structure allocated by the user. The user
821 * must not modify anything in this structure.
822 *
823 * \return
824 * \ref cy_en_crypto_status_t
825 *
826 *******************************************************************************/
Cy_Crypto_Core_Aes_CbcMac_Finish(CRYPTO_Type * base,uint8_t * mac,cy_stc_crypto_aes_state_t * aesState)827 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_CbcMac_Finish(CRYPTO_Type *base, uint8_t *mac, cy_stc_crypto_aes_state_t *aesState)
828 {
829     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
830 
831     if (CY_CRYPTO_V1)
832     {
833         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
834         (void)base;
835         (void)mac;
836         (void)aesState;
837         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
838         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
839     }
840     else
841     {
842         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
843         tmpResult = Cy_Crypto_Core_V2_Aes_CbcMac_Finish(base, mac, aesState);
844         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
845     }
846 
847     return tmpResult;
848 
849 }
850 
851 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC) */
852 
853 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB)
854 /*******************************************************************************
855 * Function Name: Cy_Crypto_Core_Aes_Cfb
856 ****************************************************************************//**
857 *
858 * Performs the AES-CFB operation defined in the dirMode parameter on a plain text
859 * defined in the SRC parameter.
860 *
861 * \param base
862 * The pointer to the CRYPTO instance.
863 *
864 * \param dirMode
865 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
866 * (\ref cy_en_crypto_dir_mode_t)
867 *
868 * \param srcSize
869 * The size of the source plain text.
870 *
871 * \param ivPtr
872 * The pointer to the initial vector.
873 *
874 * \param dst
875 * The pointer to the destination cipher text.
876 *
877 * \param src
878 * The pointer to the source plain text.
879 *
880 * \param aesState
881 * The pointer to the AES state structure allocated by the user. The user
882 * must not modify anything in this structure.
883 *
884 * \return
885 * \ref cy_en_crypto_status_t
886 *
887 *******************************************************************************/
Cy_Crypto_Core_Aes_Cfb(CRYPTO_Type * base,cy_en_crypto_dir_mode_t dirMode,uint32_t srcSize,uint8_t * ivPtr,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)888 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb(CRYPTO_Type *base,
889                                                 cy_en_crypto_dir_mode_t dirMode,
890                                                 uint32_t srcSize,
891                                                 uint8_t *ivPtr,
892                                                 uint8_t *dst,
893                                                 uint8_t const *src,
894                                                 cy_stc_crypto_aes_state_t *aesState)
895 {
896     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
897 
898     if (CY_CRYPTO_V1)
899     {
900         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
901         tmpResult = Cy_Crypto_Core_V1_Aes_Cfb(base, dirMode, srcSize, ivPtr, dst, src, aesState);
902         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
903     }
904     else
905     {
906         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
907         tmpResult = Cy_Crypto_Core_V2_Aes_Cfb(base, dirMode, srcSize, ivPtr, dst, src, aesState);
908         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
909     }
910 
911     return tmpResult;
912 }
913 
914 
915 
916 /*******************************************************************************
917 * Function Name: Cy_Crypto_Core_Aes_Cfb_Setup
918 ****************************************************************************//**
919 *
920 * Performs an AES CFB setup operation.
921 *
922 * \param base
923 * The pointer to the CRYPTO instance.
924 *
925 * \param dirMode
926 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
927 * (\ref cy_en_crypto_dir_mode_t).
928 *
929 * \param aesState
930 * The pointer to the AES state structure allocated by the user. The user
931 * must not modify anything in this structure.
932 *
933 * \return
934 * \ref cy_en_crypto_status_t
935 *
936 *******************************************************************************/
Cy_Crypto_Core_Aes_Cfb_Setup(CRYPTO_Type * base,cy_en_crypto_dir_mode_t dirMode,cy_stc_crypto_aes_state_t * aesState)937 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb_Setup(CRYPTO_Type *base,
938                                             cy_en_crypto_dir_mode_t dirMode,
939                                             cy_stc_crypto_aes_state_t *aesState)
940 {
941     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
942 
943     if (CY_CRYPTO_V1)
944     {
945         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
946         (void)base;
947         (void)dirMode;
948         (void)aesState;
949         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
950         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
951     }
952     else
953     {
954         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
955         tmpResult = Cy_Crypto_Core_V2_Aes_Cfb_Setup(base, dirMode, aesState);
956         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
957     }
958 
959     return tmpResult;
960 
961 }
962 
963 
964 /*******************************************************************************
965 * Function Name: Cy_Crypto_Core_Aes_Cfb_Set_IV
966 ****************************************************************************//**
967 *
968 * Sets IV for AES CFB mode.
969 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters iv must align and end in 32 byte boundary.
970 *
971 * \param base
972 * The pointer to the CRYPTO instance.
973 *
974 * \param iv
975 * The pointer to iv.
976 *
977 * \param aesState
978 * The pointer to the AES state structure allocated by the user. The user
979 * must not modify anything in this structure.
980 *
981 * \return
982 * \ref cy_en_crypto_status_t
983 *
984 *******************************************************************************/
Cy_Crypto_Core_Aes_Cfb_Set_IV(CRYPTO_Type * base,uint8_t const * iv,cy_stc_crypto_aes_state_t * aesState)985 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb_Set_IV(CRYPTO_Type *base,
986                                             uint8_t const * iv,
987                                             cy_stc_crypto_aes_state_t *aesState)
988 
989 {
990     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
991 
992     if (CY_CRYPTO_V1)
993     {
994         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
995         (void)base;
996         (void)iv;
997         (void)aesState;
998         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
999         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1000     }
1001     else
1002     {
1003         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1004         tmpResult = Cy_Crypto_Core_V2_Aes_Cfb_Set_IV(base, iv, aesState);
1005         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1006     }
1007 
1008     return tmpResult;
1009 
1010 }
1011 
1012 
1013 
1014 
1015 /*******************************************************************************
1016 * Function Name: Cy_Crypto_Core_Aes_Cfb_Update
1017 ****************************************************************************//**
1018 *
1019 * Performs an AES CFB Multistage update operation.
1020 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters src & dst must align and end in 32 byte boundary.
1021 *
1022 * \param base
1023 * The pointer to the CRYPTO instance.
1024 *
1025 * \param srcSize
1026 * The size of the source block.
1027 *
1028 * \param dst
1029 * The pointer to a destination cipher block.
1030 *
1031 * \param src
1032 * The pointer to a source block.
1033 *
1034 * \param aesState
1035 * The pointer to the AES state structure allocated by the user. The user
1036 * must not modify anything in this structure.
1037 *
1038 * \return
1039 * \ref cy_en_crypto_status_t
1040 *
1041 *******************************************************************************/
Cy_Crypto_Core_Aes_Cfb_Update(CRYPTO_Type * base,uint32_t srcSize,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)1042 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb_Update(CRYPTO_Type *base,
1043                                              uint32_t srcSize,
1044                                              uint8_t *dst,
1045                                              uint8_t const *src,
1046                                              cy_stc_crypto_aes_state_t *aesState)
1047 
1048 {
1049     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1050 
1051     if (CY_CRYPTO_V1)
1052     {
1053         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1054         (void)base;
1055         (void)srcSize;
1056         (void)dst;
1057         (void)src;
1058         (void)aesState;
1059         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1060         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1061     }
1062     else
1063     {
1064         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1065         tmpResult = Cy_Crypto_Core_V2_Aes_Cfb_Update(base, srcSize, dst, src, aesState);
1066         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1067     }
1068 
1069     return tmpResult;
1070 
1071 }
1072 
1073 
1074 
1075 /*******************************************************************************
1076 * Function Name: Cy_Crypto_Core_Aes_Cfb_Finish
1077 ****************************************************************************//**
1078 *
1079 * Performs an AES CFB finish operation.
1080 *
1081 * \param base
1082 * The pointer to the CRYPTO instance.
1083 *
1084 * \param aesState
1085 * The pointer to the AES state structure allocated by the user. The user
1086 * must not modify anything in this structure.
1087 *
1088 * \return
1089 * \ref cy_en_crypto_status_t
1090 *
1091 *******************************************************************************/
Cy_Crypto_Core_Aes_Cfb_Finish(CRYPTO_Type * base,cy_stc_crypto_aes_state_t * aesState)1092 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState)
1093 
1094 {
1095     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1096 
1097     if (CY_CRYPTO_V1)
1098     {
1099         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1100         (void)base;
1101         (void)aesState;
1102         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1103         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1104     }
1105     else
1106     {
1107         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1108         tmpResult = Cy_Crypto_Core_V2_Aes_Cfb_Finish(base, aesState);
1109         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1110     }
1111 
1112     return tmpResult;
1113 
1114 }
1115 
1116 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB) */
1117 
1118 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR)
1119 /*******************************************************************************
1120 * Function Name: Cy_Crypto_Core_Aes_Ctr
1121 ****************************************************************************//**
1122 *
1123 * Performs the AES-CTR operation on a plain text defined in the src parameter.
1124 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters iv must align and end in 32 byte boundary.
1125 *
1126 * \param base
1127 * The pointer to the CRYPTO instance.
1128 *
1129 * \param srcSize
1130 * The size of the source plain text.
1131 *
1132 * \param srcOffset
1133 * The size of an offset within the current block stream for resuming within the
1134 * current cipher stream.
1135 *
1136 * \param ivPtr
1137 * The 128-bit initial vector that contains a 64-bit nonce and 64-bit counter.
1138 *
1139 * \param streamBlock
1140 * The saved stream-block for resuming. Is over-written by the function.
1141 *
1142 * \param dst
1143 * The pointer to the destination cipher text.
1144 *
1145 * \param src
1146 * The pointer to the source plain text. Must be 4-Byte aligned.
1147 *
1148 * \param aesState
1149 * The pointer to the AES state structure allocated by the user. The user
1150 * must not modify anything in this structure.
1151 *
1152 * \return
1153 * \ref cy_en_crypto_status_t
1154 *
1155 *******************************************************************************/
Cy_Crypto_Core_Aes_Ctr(CRYPTO_Type * base,uint32_t srcSize,uint32_t * srcOffset,uint8_t * ivPtr,uint8_t * streamBlock,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)1156 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ctr(CRYPTO_Type *base,
1157                                                 uint32_t srcSize,
1158                                                 uint32_t *srcOffset,
1159                                                 uint8_t *ivPtr,
1160                                                 uint8_t *streamBlock,
1161                                                 uint8_t *dst,
1162                                                 uint8_t const *src,
1163                                                 cy_stc_crypto_aes_state_t *aesState)
1164 {
1165     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1166 
1167     if (CY_CRYPTO_V1)
1168     {
1169         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1170         tmpResult = Cy_Crypto_Core_V1_Aes_Ctr(base, srcSize, srcOffset, ivPtr, streamBlock, dst, src, aesState);
1171         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1172     }
1173     else
1174     {
1175         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1176         tmpResult = Cy_Crypto_Core_V2_Aes_Ctr(base, srcSize, srcOffset, ivPtr, streamBlock, dst, src, aesState);
1177         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1178     }
1179 
1180     return tmpResult;
1181 }
1182 
1183 
1184 
1185 
1186 /*******************************************************************************
1187 * Function Name: Cy_Crypto_Core_Aes_Ctr_Setup
1188 ****************************************************************************//**
1189 *
1190 * Performs an AES CTR Multistage update operation.
1191 *
1192 * \param base
1193 * The pointer to the CRYPTO instance.
1194 *
1195 * \param aesState
1196 * The pointer to the AES state structure allocated by the user. The user
1197 * must not modify anything in this structure.
1198 *
1199 * \return
1200 * \ref cy_en_crypto_status_t
1201 *
1202 *******************************************************************************/
Cy_Crypto_Core_Aes_Ctr_Setup(CRYPTO_Type * base,cy_stc_crypto_aes_state_t * aesState)1203 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ctr_Setup(CRYPTO_Type *base,
1204                                             cy_stc_crypto_aes_state_t *aesState)
1205 
1206 {
1207     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1208 
1209     if (CY_CRYPTO_V1)
1210     {
1211         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1212         (void)base;
1213         (void)aesState;
1214         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1215         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1216     }
1217     else
1218     {
1219         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1220         tmpResult = Cy_Crypto_Core_V2_Aes_Ctr_Setup(base, aesState);
1221         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1222     }
1223 
1224     return tmpResult;
1225 
1226 }
1227 
1228 /*******************************************************************************
1229 * Function Name: Cy_Crypto_Core_Aes_Ctr_Set_IV
1230 ****************************************************************************//**
1231 *
1232 * Sets IV for the AES CTR operation.
1233 *
1234 * \param base
1235 * The pointer to the CRYPTO instance.
1236 *
1237 * \param iv
1238 * The pointer to iv.
1239 *
1240 * \param aesState
1241 * The pointer to the AES state structure allocated by the user. The user
1242 * must not modify anything in this structure.
1243 *
1244 * \return
1245 * \ref cy_en_crypto_status_t
1246 *
1247 *******************************************************************************/
Cy_Crypto_Core_Aes_Ctr_Set_IV(CRYPTO_Type * base,const uint8_t * iv,cy_stc_crypto_aes_state_t * aesState)1248 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ctr_Set_IV(CRYPTO_Type *base,
1249                                             const uint8_t *iv,
1250                                             cy_stc_crypto_aes_state_t *aesState)
1251 {
1252     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1253 
1254     if (CY_CRYPTO_V1)
1255     {
1256         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1257         (void)base;
1258         (void)iv;
1259         (void)aesState;
1260         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1261         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1262     }
1263     else
1264     {
1265         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1266         tmpResult = Cy_Crypto_Core_V2_Aes_Ctr_Set_IV(base, iv, aesState);
1267         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1268     }
1269 
1270     return tmpResult;
1271 
1272 }
1273 
1274 
1275 
1276 /*******************************************************************************
1277 * Function Name: Cy_Crypto_Core_Aes_Ctr_Update
1278 ****************************************************************************//**
1279 *
1280 * Performs an AES CTR Multistage update operation.
1281 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters src & dst must align and end in 32 byte boundary.
1282 *
1283 * \param base
1284 * The pointer to the CRYPTO instance.
1285 *
1286 * \param srcSize
1287 * The size of the source block.
1288 *
1289 * \param dst
1290 * The pointer to a destination cipher block.
1291 *
1292 * \param src
1293 * The pointer to a source block.
1294 *
1295 * \param aesState
1296 * The pointer to the AES state structure allocated by the user. The user
1297 * must not modify anything in this structure.
1298 *
1299 * \return
1300 * \ref cy_en_crypto_status_t
1301 *
1302 *******************************************************************************/
Cy_Crypto_Core_Aes_Ctr_Update(CRYPTO_Type * base,uint32_t srcSize,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_state_t * aesState)1303 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ctr_Update(CRYPTO_Type *base,
1304                                             uint32_t srcSize,
1305                                             uint8_t *dst,
1306                                             uint8_t const *src,
1307                                             cy_stc_crypto_aes_state_t *aesState)
1308 
1309 {
1310     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1311 
1312     if (CY_CRYPTO_V1)
1313     {
1314         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1315         (void)base;
1316         (void)srcSize;
1317         (void)dst;
1318         (void)src;
1319         (void)aesState;
1320         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1321         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1322     }
1323     else
1324     {
1325         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1326         tmpResult = Cy_Crypto_Core_V2_Aes_Ctr_Update(base, srcSize, dst, src, aesState);
1327         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1328     }
1329 
1330     return tmpResult;
1331 
1332 }
1333 
1334 
1335 
1336 
1337 /*******************************************************************************
1338 * Function Name: Cy_Crypto_Core_Aes_Ctr_Finish
1339 ****************************************************************************//**
1340 *
1341 * Performs an AES CTR Finish operation.
1342 *
1343 * \param base
1344 * The pointer to the CRYPTO instance.
1345 *
1346 * \param aesState
1347 * The pointer to the AES state structure allocated by the user. The user
1348 * must not modify anything in this structure.
1349 *
1350 * \return
1351 * \ref cy_en_crypto_status_t
1352 *
1353 *******************************************************************************/
Cy_Crypto_Core_Aes_Ctr_Finish(CRYPTO_Type * base,cy_stc_crypto_aes_state_t * aesState)1354 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ctr_Finish(CRYPTO_Type *base, cy_stc_crypto_aes_state_t *aesState)
1355 
1356 {
1357     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1358 
1359     if (CY_CRYPTO_V1)
1360     {
1361         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1362         (void)base;
1363         (void)aesState;
1364         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1365         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1366     }
1367     else
1368     {
1369         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1370         tmpResult = Cy_Crypto_Core_V2_Aes_Ctr_Finish(base, aesState);
1371         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1372     }
1373 
1374     return tmpResult;
1375 
1376 }
1377 
1378 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR) */
1379 
1380 #if (CPUSS_CRYPTO_GCM == 1) && defined(CY_CRYPTO_CFG_GCM_C)
1381 
1382 /*******************************************************************************
1383 * Function Name: Cy_Crypto_Core_Aes_GCM_Init
1384 ****************************************************************************//**
1385 *
1386 * The function to initialize AES GCM operation.
1387 *
1388 * \param base
1389 * The pointer to the CRYPTO instance.
1390 *
1391 * \param aesGCMBuffers
1392 * The pointer to the AES GCM buffer provided by the user. The user must not modify anything in this structure.
1393 *
1394 * \param aesGCMctx
1395 * The pointer to the AES GCM state structure allocated by the user. The user
1396 * must not modify anything in this structure.
1397 *
1398 * \return
1399 * \ref cy_en_crypto_status_t
1400 *
1401 * \funcusage
1402 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_init_update_finish_free
1403 *******************************************************************************/
1404 
Cy_Crypto_Core_Aes_GCM_Init(CRYPTO_Type * base,cy_stc_crypto_aes_gcm_buffers_t * aesGCMBuffers,cy_stc_crypto_aes_gcm_state_t * aesGCMctx)1405 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_Init(CRYPTO_Type *base,cy_stc_crypto_aes_gcm_buffers_t *aesGCMBuffers,
1406                                                       cy_stc_crypto_aes_gcm_state_t* aesGCMctx)
1407 {
1408     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1409 
1410     if (CY_CRYPTO_V1)
1411     {
1412         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1413         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1414         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1415     }
1416     else
1417     {
1418         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1419         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_Init(base, aesGCMBuffers, aesGCMctx);
1420         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1421     }
1422 
1423     return tmpResult;
1424 }
1425 
1426 
1427 
1428 /*******************************************************************************
1429 * Function Name: Cy_Crypto_Core_Aes_GCM_SetKey
1430 ****************************************************************************//**
1431 *
1432 * The function to set AES GCM Key.
1433 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters aeskey must align and end in 32 byte boundary.
1434 *
1435 * \param base
1436 * The pointer to the CRYPTO instance.
1437 *
1438 * \param aesKey
1439 * The pointer to the AES key.
1440 *
1441 * \param keyLength
1442 * \ref cy_en_crypto_aes_key_length_t
1443 *
1444 * \param aesGCMctx
1445 * The pointer to the AES GCM state structure allocated by the user. The user
1446 * must not modify anything in this structure.
1447 *
1448 * \return
1449 * \ref cy_en_crypto_status_t
1450 *
1451 * \funcusage
1452 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_init_update_finish_free
1453 *******************************************************************************/
1454 
Cy_Crypto_Core_Aes_GCM_SetKey(CRYPTO_Type * base,uint8_t const * aesKey,cy_en_crypto_aes_key_length_t keyLength,cy_stc_crypto_aes_gcm_state_t * aesGCMctx)1455 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_SetKey(CRYPTO_Type *base, uint8_t const *aesKey, cy_en_crypto_aes_key_length_t keyLength,
1456                                                       cy_stc_crypto_aes_gcm_state_t* aesGCMctx)
1457 {
1458     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1459 
1460     if (CY_CRYPTO_V1)
1461     {
1462         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1463         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1464         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1465     }
1466     else
1467     {
1468         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1469         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_SetKey(base, aesKey, keyLength, aesGCMctx);
1470         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1471     }
1472 
1473     return tmpResult;
1474 }
1475 
1476 
1477 /*******************************************************************************
1478 * Function Name: Cy_Crypto_Core_Aes_GCM_Start
1479 ****************************************************************************//**
1480 *
1481 * The function to start AES GCM operation.
1482 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters iv must align and end in 32 byte boundary.
1483 *
1484 * \param base
1485 * The pointer to the CRYPTO instance.
1486 *
1487 * \param mode
1488 * \ref cy_en_crypto_dir_mode_t
1489 *
1490 * \param iv
1491 * The pointer to the Initialization vector.
1492 *
1493 * \param ivSize
1494 * The length of the iv.
1495 *
1496 * \param aesGCMctx
1497 * The pointer to the AES GCM state structure allocated by the user. The user
1498 * must not modify anything in this structure.
1499 *
1500 * \return
1501 * \ref cy_en_crypto_status_t
1502 *
1503 * \funcusage
1504 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_init_update_finish_free
1505 *******************************************************************************/
1506 
Cy_Crypto_Core_Aes_GCM_Start(CRYPTO_Type * base,cy_en_crypto_dir_mode_t mode,uint8_t const * iv,uint32_t ivSize,cy_stc_crypto_aes_gcm_state_t * aesGCMctx)1507 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_Start(CRYPTO_Type *base, cy_en_crypto_dir_mode_t mode,
1508                                                       uint8_t const *iv, uint32_t ivSize,
1509                                                       cy_stc_crypto_aes_gcm_state_t* aesGCMctx)
1510 {
1511     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1512 
1513     if (CY_CRYPTO_V1)
1514     {
1515         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1516         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1517         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1518     }
1519     else
1520     {
1521         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1522         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_Start(base, mode, iv, ivSize, aesGCMctx);
1523         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1524     }
1525 
1526     return tmpResult;
1527 }
1528 
1529 
1530 
1531 /*******************************************************************************
1532 * Function Name: Cy_Crypto_Core_Aes_GCM_AAD_Update
1533 ****************************************************************************//**
1534 *
1535 * The function to update the Additional Authentication Data.
1536 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters aad must align and end in 32 byte boundary.
1537 *
1538 * \param base
1539 * The pointer to the CRYPTO instance.
1540 *
1541 * \param aad
1542 * The pointer to the Additional Authentication Data.
1543 *
1544 * \param aadSize
1545 *  The length of the Additional Authentication Data
1546 *
1547 * \param aesGCMctx
1548 * The pointer to the AES GCM state structure allocated by the user. The user
1549 * must not modify anything in this structure.
1550 *
1551 * \return
1552 * \ref cy_en_crypto_status_t
1553 *
1554 * \funcusage
1555 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_init_update_finish_free
1556 *******************************************************************************/
1557 
Cy_Crypto_Core_Aes_GCM_AAD_Update(CRYPTO_Type * base,uint8_t * aad,uint32_t aadSize,cy_stc_crypto_aes_gcm_state_t * aesGCMctx)1558 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_AAD_Update(CRYPTO_Type *base, uint8_t *aad,
1559                                                                         uint32_t aadSize,
1560                                                                         cy_stc_crypto_aes_gcm_state_t* aesGCMctx)
1561 
1562 {
1563     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1564 
1565     if (CY_CRYPTO_V1)
1566     {
1567         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1568         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1569         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1570     }
1571     else
1572     {
1573         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1574         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_AAD_Update(base, aad, aadSize, aesGCMctx);
1575         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1576     }
1577 
1578     return tmpResult;
1579 }
1580 
1581 
1582 
1583 /*******************************************************************************
1584 * Function Name: Cy_Crypto_Core_Aes_GCM_Update
1585 ****************************************************************************//**
1586 *
1587 * The function to update the data
1588 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters input & output must align and end in 32 byte boundary.
1589 *
1590 * \param base
1591 * The pointer to the CRYPTO instance.
1592 *
1593 * \param input
1594 * The pointer to the input data to be encrypted/decrypted.
1595 *
1596 * \param inputSize
1597 *  The length of the input data.
1598 *
1599 * \param output
1600 * The pointer to the encrypted/decrypted output data.
1601 *
1602 * \param aesGCMctx
1603 * The pointer to the AES GCm state structure allocated by the user. The user
1604 * must not modify anything in this structure.
1605 *
1606 * \return
1607 * \ref cy_en_crypto_status_t
1608 *
1609 * \funcusage
1610 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_init_update_finish_free
1611 *******************************************************************************/
Cy_Crypto_Core_Aes_GCM_Update(CRYPTO_Type * base,const uint8_t * input,uint32_t inputSize,uint8_t * output,cy_stc_crypto_aes_gcm_state_t * aesGCMctx)1612 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_Update(CRYPTO_Type *base,  const uint8_t *input,
1613                                                        uint32_t inputSize,  uint8_t *output,
1614                                                        cy_stc_crypto_aes_gcm_state_t* aesGCMctx)
1615 
1616 {
1617     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1618 
1619     if (CY_CRYPTO_V1)
1620     {
1621         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1622         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1623         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1624     }
1625     else
1626     {
1627         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1628         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_Update(base, input, inputSize, output, aesGCMctx);
1629         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1630     }
1631 
1632     return tmpResult;
1633 }
1634 
1635 
1636 
1637 
1638 /*******************************************************************************
1639 * Function Name: Cy_Crypto_Core_Aes_GCM_Finish
1640 ****************************************************************************//**
1641 *
1642 * The function to finish the AES GCM operation and to calculate the tag.
1643 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters p_tag must align and end in 32 byte boundary.
1644 *
1645 * \param base
1646 * The pointer to the CRYPTO instance.
1647 *
1648 * \param p_tag
1649 * The pointer to the buffer for storing tag.
1650 *
1651 * \param tagSize
1652 *  The length of the p_tag.
1653 *
1654 * \param aesGCMctx
1655 * The pointer to the AES aesGCMctx structure allocated by the user. The user
1656 * must not modify anything in this structure.
1657 *
1658 * \return
1659 * \ref cy_en_crypto_status_t
1660 *
1661 * \funcusage
1662 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_init_update_finish_free
1663 *******************************************************************************/
1664 
Cy_Crypto_Core_Aes_GCM_Finish(CRYPTO_Type * base,uint8_t * p_tag,uint32_t tagSize,cy_stc_crypto_aes_gcm_state_t * aesGCMctx)1665 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_Finish(CRYPTO_Type *base,  uint8_t *p_tag,
1666                                                               uint32_t tagSize, cy_stc_crypto_aes_gcm_state_t* aesGCMctx)
1667 
1668 
1669 {
1670     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1671 
1672     if (CY_CRYPTO_V1)
1673     {
1674         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1675         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1676         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1677     }
1678     else
1679     {
1680         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1681         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_Finish(base, p_tag, tagSize, aesGCMctx);
1682         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1683     }
1684 
1685     return tmpResult;
1686 }
1687 
1688 
1689 
1690 /*******************************************************************************
1691 * Function Name: Cy_Crypto_Core_Aes_GCM_Free
1692 ****************************************************************************//**
1693 *
1694 * The function to finish the encryption process and calculate tag.
1695 *
1696 * \param base
1697 * The pointer to the CRYPTO instance.
1698 *
1699 * \param aesGCMctx
1700 * The pointer to the AES aesGCMctx structure allocated by the user. The user
1701 * must not modify anything in this structure.
1702 *
1703 * \return
1704 * \ref cy_en_crypto_status_t
1705 *
1706 * \funcusage
1707 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_init_update_finish_free
1708 *******************************************************************************/
1709 
Cy_Crypto_Core_Aes_GCM_Free(CRYPTO_Type * base,cy_stc_crypto_aes_gcm_state_t * aesGCMctx)1710 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_Free(CRYPTO_Type *base,  cy_stc_crypto_aes_gcm_state_t* aesGCMctx)
1711 
1712 
1713 {
1714     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1715 
1716     if (CY_CRYPTO_V1)
1717     {
1718         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1719         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1720         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1721     }
1722     else
1723     {
1724         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1725         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_Free(base, aesGCMctx);
1726         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1727     }
1728 
1729     return tmpResult;
1730 }
1731 
1732 
1733 /*******************************************************************************
1734 * Function Name: Cy_Crypto_Core_Aes_GCM_Encrypt_Tag
1735 ****************************************************************************//**
1736 *
1737 * Performs the AES GCM encryption operation on the input data, iv & aad data, generates the encrypted data and TAG.
1738 *
1739 * \param base
1740 * The pointer to the CRYPTO instance.
1741 *
1742 * \param aesKey
1743 * The pointer to the AES key.
1744 *
1745 * \param keyLength
1746 * \ref cy_en_crypto_aes_key_length_t
1747 *
1748 * \param iv
1749 * The pointer to the Initialization vector.
1750 *
1751 * \param ivSize
1752 * The length of the iv.
1753 *
1754 * \param aad
1755 * The pointer to the Additional Authentication Data.
1756 *
1757 * \param aadSize
1758 *  The length of the additional Authentication Data
1759 *
1760 * \param input
1761 * The pointer to the input data to be encrypted/decrypted.
1762 *
1763 * \param inputSize
1764 *  The length of the input data.
1765 *
1766 * \param output
1767 * The pointer to the encrypted/decrypted output data.
1768 *
1769 * \param tag
1770 * The pointer to the tag.
1771 *
1772 * \param tagSize
1773 *  The length of the p_tag.
1774 *
1775 * \return
1776 * \ref cy_en_crypto_status_t
1777 *
1778 * \funcusage
1779 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_Encrypt_Tag
1780 *******************************************************************************/
Cy_Crypto_Core_Aes_GCM_Encrypt_Tag(CRYPTO_Type * base,uint8_t const * aesKey,cy_en_crypto_aes_key_length_t keyLength,uint8_t const * iv,uint32_t ivSize,uint8_t * aad,uint32_t aadSize,const uint8_t * input,uint32_t inputSize,uint8_t * output,uint8_t * tag,uint32_t tagSize)1781 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_Encrypt_Tag(CRYPTO_Type *base, uint8_t const *aesKey, cy_en_crypto_aes_key_length_t keyLength,
1782                                                             uint8_t const *iv, uint32_t ivSize, uint8_t *aad,   uint32_t aadSize,
1783                                                             const uint8_t *input,   uint32_t inputSize,  uint8_t *output, uint8_t *tag, uint32_t tagSize)
1784 
1785 {
1786     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1787 
1788     if (CY_CRYPTO_V1)
1789     {
1790         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1791         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1792         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1793     }
1794     else
1795     {
1796         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1797         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_Encrypt_Tag(base, aesKey, keyLength,
1798                                                           iv, ivSize, aad, aadSize,
1799                                                           input, inputSize, output, tag, tagSize);
1800         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1801     }
1802 
1803     return tmpResult;
1804 }
1805 
1806 
1807 /*******************************************************************************
1808 * Function Name: Cy_Crypto_Core_Aes_GCM_Decrypt_Tag
1809 ****************************************************************************//**
1810 *
1811 * Performs the AES GCM decryption operation on the input data and verifies the TAG.
1812 *
1813 * \param base
1814 * The pointer to the CRYPTO instance.
1815 *
1816 * \param aesKey
1817 * The pointer to the AES key.
1818 *
1819 * \param keyLength
1820 * \ref cy_en_crypto_aes_key_length_t
1821 *
1822 * \param iv
1823 * The pointer to the Initialization vector.
1824 *
1825 * \param ivSize
1826 * The length of the iv.
1827 *
1828 * \param aad
1829 * The pointer to the Additional Authentication Data.
1830 *
1831 * \param aadSize
1832 *  The length of the additional Authentication Data
1833 *
1834 * \param input
1835 * The pointer to the input data to be encrypted/decrypted.
1836 *
1837 * \param inputSize
1838 *  The length of the input data.
1839 *
1840 * \param tag
1841 * The pointer to the tag.
1842 *
1843 * \param tagSize
1844 *  The length of the p_tag.
1845 *
1846 * \param output
1847 * The pointer to the encrypted/decrypted output data.
1848 *
1849 * \param isVerified
1850 * The status of the AES GCM verification.
1851 *
1852 * \return
1853 * \ref cy_en_crypto_status_t
1854 *
1855 * \funcusage
1856 * \snippet crypto/snippet/main.c snippet_Cy_Crypto_Core_Aes_GCM_Decrypt_Tag
1857 *******************************************************************************/
Cy_Crypto_Core_Aes_GCM_Decrypt_Tag(CRYPTO_Type * base,uint8_t const * aesKey,cy_en_crypto_aes_key_length_t keyLength,uint8_t const * iv,uint32_t ivSize,uint8_t * aad,uint32_t aadSize,const uint8_t * input,uint32_t inputSize,uint8_t * tag,uint32_t tagSize,uint8_t * output,cy_en_crypto_aesgcm_tag_verify_result_t * isVerified)1858 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_GCM_Decrypt_Tag(CRYPTO_Type *base, uint8_t const *aesKey, cy_en_crypto_aes_key_length_t keyLength,
1859                                                             uint8_t const *iv, uint32_t ivSize, uint8_t *aad,   uint32_t aadSize,
1860                                                             const uint8_t *input,   uint32_t inputSize, uint8_t *tag, uint32_t tagSize, uint8_t *output,
1861                                                             cy_en_crypto_aesgcm_tag_verify_result_t * isVerified)
1862 {
1863     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1864 
1865     if (CY_CRYPTO_V1)
1866     {
1867         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1868         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1869         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1870     }
1871     else
1872     {
1873         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1874         tmpResult = Cy_Crypto_Core_V2_Aes_GCM_Decrypt_Tag(base, aesKey, keyLength,
1875                                                             iv, ivSize, aad, aadSize,
1876                                                             input, inputSize, tag, tagSize, output, isVerified);
1877         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1878     }
1879 
1880     return tmpResult;
1881 }
1882 #endif /* (CPUSS_CRYPTO_GCM == 1) && defined(CY_CRYPTO_CFG_GCM_C)*/
1883 
1884 
1885 #if defined(CY_CRYPTO_CFG_CCM_C)
1886 
1887 /*******************************************************************************
1888 * Function Name: Cy_Crypto_Core_Aes_Ccm_Init
1889 ****************************************************************************//**
1890 *
1891 * Performs an AES CCM Init operation.
1892 *
1893 * \param base
1894 * The pointer to the CRYPTO instance.
1895 *
1896 * \param aesCcmBuffer The buffers should be a SAHB mapped addresses.
1897 * The pointer to the memory buffers storage.
1898 *
1899 * \param aesCcmState
1900 * The pointer to the AES CCM state structure allocated by the user. The user
1901 * must not modify anything in this structure.
1902 *
1903 * \return
1904 * \ref cy_en_crypto_status_t
1905 *
1906 *******************************************************************************/
1907 
Cy_Crypto_Core_Aes_Ccm_Init(CRYPTO_Type * base,cy_stc_crypto_aes_ccm_buffers_t * aesCcmBuffer,cy_stc_crypto_aes_ccm_state_t * aesCcmState)1908 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Init(CRYPTO_Type *base,
1909                                             cy_stc_crypto_aes_ccm_buffers_t * aesCcmBuffer, cy_stc_crypto_aes_ccm_state_t *aesCcmState)
1910 {
1911     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1912 
1913     if (CY_CRYPTO_V1)
1914     {
1915         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1916         (void)base;
1917         (void)aesCcmBuffer;
1918         (void)aesCcmState;
1919         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1920         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1921     }
1922     else
1923     {
1924         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1925         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Init(base, aesCcmBuffer, aesCcmState);
1926         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1927     }
1928 
1929     return tmpResult;
1930 }
1931 
1932 
1933 /*******************************************************************************
1934 * Function Name: Cy_Crypto_Core_Aes_Ccm_SetKey
1935 ****************************************************************************//**
1936 *
1937 * Sets AES CCM Key for the operation.
1938 *
1939 * \param base
1940 * The pointer to the CRYPTO instance.
1941 *
1942 * \param key
1943 * The pointer to the CCM key.
1944 *
1945 * \param keyLength
1946 * \ref cy_en_crypto_aes_key_length_t
1947 *
1948 * \param aesCcmState
1949 * The pointer to the AES CCM state structure allocated by the user. The user
1950 * must not modify anything in this structure.
1951 *
1952 * \return
1953 * \ref cy_en_crypto_status_t
1954 *
1955 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_SetKey(CRYPTO_Type * base,uint8_t const * key,cy_en_crypto_aes_key_length_t keyLength,cy_stc_crypto_aes_ccm_state_t * aesCcmState)1956 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_SetKey(CRYPTO_Type *base,
1957                                             uint8_t const *key, cy_en_crypto_aes_key_length_t keyLength,
1958                                             cy_stc_crypto_aes_ccm_state_t *aesCcmState)
1959 {
1960     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1961 
1962     if (CY_CRYPTO_V1)
1963     {
1964         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
1965         (void)base;
1966         (void)key;
1967         (void)keyLength;
1968         (void)aesCcmState;
1969         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
1970         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
1971     }
1972     else
1973     {
1974         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
1975         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_SetKey(base, key, keyLength, aesCcmState);
1976         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
1977     }
1978 
1979     return tmpResult;
1980 
1981 }
1982 
1983 
1984 
1985 /*******************************************************************************
1986 * Function Name: Cy_Crypto_Core_Aes_Ccm_Set_Length
1987 ****************************************************************************//**
1988 *
1989 * Sets the length for Additional authentication data, plain text and Tag for AES CCM operation.
1990 *
1991 * \param base
1992 * The pointer to the CRYPTO instance.
1993 *
1994 * \param aadSize
1995 * The Size of the Additional Authentication Data.
1996 *
1997 * \param textSize
1998 * The Size of the Text.
1999 *
2000 * \param tagLength
2001 * The Size of the Tag.
2002 *
2003 * \param aesCcmState
2004 * The pointer to the AES CCM state structure allocated by the user. The user
2005 * must not modify anything in this structure.
2006 *
2007 *
2008 * \return
2009 * \ref cy_en_crypto_status_t
2010 *
2011 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_Set_Length(CRYPTO_Type * base,uint32_t aadSize,uint32_t textSize,uint32_t tagLength,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2012 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Set_Length(CRYPTO_Type *base,
2013                                             uint32_t aadSize,  uint32_t textSize, uint32_t tagLength,
2014                                             cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2015 {
2016     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2017 
2018     if (CY_CRYPTO_V1)
2019     {
2020         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2021         (void)base;
2022         (void)aadSize;
2023         (void)textSize;
2024         (void)tagLength;
2025         (void)aesCcmState;
2026         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2027         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2028     }
2029     else
2030     {
2031         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2032         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Set_Length(base, aadSize, textSize, tagLength, aesCcmState);
2033         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2034     }
2035 
2036     return tmpResult;
2037 }
2038 
2039 
2040 
2041 /*******************************************************************************
2042 * Function Name: Cy_Crypto_Core_Aes_Ccm_Start
2043 ****************************************************************************//**
2044 *
2045 * Function to set IV for the AES CCM operation.
2046 *
2047 * \param base
2048 * The pointer to the CRYPTO instance.
2049 *
2050 * \param dirMode
2051 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
2052 * (\ref cy_en_crypto_dir_mode_t)
2053 *
2054 * \param ivSize
2055 * The size of the IV.
2056 *
2057 * \param iv
2058 * The pointer to the IV.
2059 *
2060 * \param aesCcmState
2061 * The pointer to the AES CCM state structure allocated by the user. The user
2062 * must not modify anything in this structure.
2063 *
2064 * \return
2065 * \ref cy_en_crypto_status_t
2066 *
2067 *******************************************************************************/
2068 
Cy_Crypto_Core_Aes_Ccm_Start(CRYPTO_Type * base,cy_en_crypto_dir_mode_t dirMode,uint32_t ivSize,uint8_t const * iv,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2069 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Start(CRYPTO_Type *base,
2070                                             cy_en_crypto_dir_mode_t dirMode,
2071                                              uint32_t ivSize, uint8_t const * iv,
2072                                             cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2073 {
2074 
2075     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2076 
2077     if (CY_CRYPTO_V1)
2078     {
2079         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2080         (void)base;
2081         (void)dirMode;
2082         (void)ivSize;
2083         (void)iv;
2084         (void)aesCcmState;
2085         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2086         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2087     }
2088     else
2089     {
2090         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2091         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Start(base, dirMode, ivSize, iv, aesCcmState);
2092         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2093     }
2094 
2095     return tmpResult;
2096 }
2097 
2098 
2099 /*******************************************************************************
2100 * Function Name: Cy_Crypto_Core_Aes_Ccm_Update_Aad
2101 ****************************************************************************//**
2102 *
2103 * Performs an AES CCM update AAD Multistage  operation.
2104 *
2105 * \param base
2106 * The pointer to the CRYPTO instance.
2107 *
2108 * \param aadSize
2109 * The size of the AAD.
2110 *
2111 * \param aad
2112 * The pointer to a AAD.
2113 *
2114 * \param aesCcmState
2115 * The pointer to the AES CCM state structure allocated by the user. The user
2116 * must not modify anything in this structure.
2117 *
2118 * \return
2119 * \ref cy_en_crypto_status_t
2120 *
2121 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_Update_Aad(CRYPTO_Type * base,uint32_t aadSize,uint8_t const * aad,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2122 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Update_Aad(CRYPTO_Type *base,
2123                                             uint32_t aadSize,
2124                                             uint8_t const *aad,
2125                                             cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2126 {
2127     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2128 
2129     if (CY_CRYPTO_V1)
2130     {
2131         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2132         (void)base;
2133         (void)aadSize;
2134         (void)aad;
2135         (void)aesCcmState;
2136         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2137         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2138     }
2139     else
2140     {
2141         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2142         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Update_Aad(base, aadSize, aad, aesCcmState);
2143         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2144     }
2145 
2146     return tmpResult;
2147 }
2148 
2149 
2150 
2151 /*******************************************************************************
2152 * Function Name: Cy_Crypto_Core_Aes_Ccm_Update
2153 ***************************************************************************//**
2154 *
2155 * Performs an AES CCM Update Multistage update operation.
2156 *
2157 * \param base
2158 * The pointer to the CRYPTO instance.
2159 *
2160 * \param srcSize
2161 * The size of the source block.
2162 *
2163 * \param dst
2164 * The pointer to a destination block.
2165 *
2166 * \param src
2167 * The pointer to a source block.
2168 *
2169 * \param aesCcmState
2170 * The pointer to the AES CCM state structure allocated by the user. The user
2171 * must not modify anything in this structure.
2172 *
2173 * \return
2174 * \ref cy_en_crypto_status_t
2175 *
2176 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_Update(CRYPTO_Type * base,uint32_t srcSize,uint8_t * dst,uint8_t const * src,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2177 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Update(CRYPTO_Type *base,
2178                                             uint32_t srcSize,
2179                                             uint8_t *dst,
2180                                             uint8_t const *src,
2181                                             cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2182 {
2183     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2184 
2185     if (CY_CRYPTO_V1)
2186     {
2187         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2188         (void)base;
2189         (void)srcSize;
2190         (void)dst;
2191         (void)src;
2192         (void)aesCcmState;
2193         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2194         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2195     }
2196     else
2197     {
2198         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2199         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Update(base, srcSize, dst, src, aesCcmState);
2200         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2201     }
2202 
2203     return tmpResult;
2204 }
2205 
2206 /*******************************************************************************
2207 * Function Name: Cy_Crypto_Core_Aes_Ccm_Finish
2208 ****************************************************************************//**
2209 *
2210 * Performs an AES CCM finish operation.
2211 *
2212 * \param base
2213 * The pointer to the CRYPTO instance.
2214 *
2215 * \param tag
2216 * The pointer to the CCM Tag.
2217 *
2218 * \param aesCcmState
2219 * The pointer to the AES CCM state structure allocated by the user. The user
2220 * must not modify anything in this structure.
2221 *
2222 * \return
2223 * \ref cy_en_crypto_status_t
2224 *
2225 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_Finish(CRYPTO_Type * base,uint8_t * tag,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2226 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Finish(CRYPTO_Type *base, uint8_t *tag, cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2227 {
2228     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2229 
2230     if (CY_CRYPTO_V1)
2231     {
2232         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2233         (void)base;
2234         (void)tag;
2235         (void)aesCcmState;
2236         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2237         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2238     }
2239     else
2240     {
2241         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2242         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Finish(base, tag, aesCcmState);
2243         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2244     }
2245 
2246     return tmpResult;
2247 
2248 }
2249 
2250 
2251 
2252 
2253 /*******************************************************************************
2254 * Function Name: Cy_Crypto_Core_Aes_Ccm_Encrypt_Tag
2255 ****************************************************************************//**
2256 *
2257 * Performs an AES CCM Encrypt operation.
2258 * \note Cy_Crypto_Core_Aes_Ccm_Init() and Cy_Crypto_Core_Aes_Ccm_SetKey() should be called before calling this function
2259 *
2260 * \param base
2261 * The pointer to the CRYPTO instance.
2262 *
2263 * \param ivSize
2264 * The size of the IV.
2265 *
2266 * \param iv
2267 * The pointer to the IV.
2268 *
2269 * \param aadSize
2270 * The size of the AAD.
2271 *
2272 * \param aad
2273 * The pointer to a AAD.
2274 *
2275 * \param srcSize
2276 * The size of the source block.
2277 *
2278 * \param cipherTxt
2279 * The pointer to a cipher text block.
2280 *
2281 * \param plainTxt
2282 * The pointer to a plain text block.
2283 *
2284 * \param tagSize
2285 * The size of the Tag.
2286 *
2287 * \param tag
2288 * The pointer to the tags.
2289 *
2290 * \param aesCcmState
2291 * The pointer to the AES CCM state structure allocated by the user. The user
2292 * must not modify anything in this structure.
2293 *
2294 * \return
2295 * \ref cy_en_crypto_status_t
2296 *
2297 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_Encrypt_Tag(CRYPTO_Type * base,uint32_t ivSize,uint8_t const * iv,uint32_t aadSize,uint8_t const * aad,uint32_t srcSize,uint8_t * cipherTxt,uint8_t const * plainTxt,uint32_t tagSize,uint8_t * tag,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2298 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Encrypt_Tag(CRYPTO_Type *base,
2299                                             uint32_t ivSize, uint8_t const * iv,
2300                                             uint32_t aadSize, uint8_t const *aad,
2301                                             uint32_t srcSize, uint8_t *cipherTxt, uint8_t const *plainTxt,
2302                                             uint32_t tagSize, uint8_t *tag,
2303                                             cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2304 {
2305 
2306     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2307 
2308     if (CY_CRYPTO_V1)
2309     {
2310         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2311         (void)base;
2312         (void)ivSize;
2313         (void)iv;
2314         (void)aadSize;
2315         (void)aad;
2316         (void)srcSize;
2317         (void)cipherTxt;
2318         (void)plainTxt;
2319         (void)tagSize;
2320         (void)tag;
2321         (void)aesCcmState;
2322         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2323         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2324     }
2325     else
2326     {
2327         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2328         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Encrypt_Tag(base, ivSize, iv, aadSize, aad, srcSize, cipherTxt, plainTxt, tagSize, tag, aesCcmState);
2329         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2330     }
2331 
2332     return tmpResult;
2333 }
2334 
2335 
2336 /*******************************************************************************
2337 * Function Name: Cy_Crypto_Core_Aes_Ccm_Decrypt
2338 ****************************************************************************//**
2339 *
2340 * Performs an AES CCM Decrypt operation.
2341 * \note Cy_Crypto_Core_Aes_Ccm_Init() and Cy_Crypto_Core_Aes_Ccm_SetKey() should be called before calling this function
2342 *
2343 * \param base
2344 * The pointer to the CRYPTO instance.
2345 *
2346 * \param ivSize
2347 * The size of the IV.
2348 *
2349 * \param iv
2350 * The pointer to the IV.
2351 *
2352 * \param aadSize
2353 * The size of the AAD.
2354 *
2355 * \param aad
2356 * The pointer to a AAD.
2357 *
2358 * \param srcSize
2359 * The size of the source block.
2360 *
2361 * \param plainTxt
2362 * The pointer to a plain text block.
2363 *
2364 * \param cipherTxt
2365 * The pointer to a cipher text block.
2366 *
2367 * \param tagSize
2368 * The size of the Tag.
2369 *
2370 * \param tag
2371 * The pointer to the tags.
2372 *
2373 * \param isValid
2374 * The pointer Store the authentication status.
2375 *
2376 * \param aesCcmState
2377 * The pointer to the AES CCM state structure allocated by the user. The user
2378 * must not modify anything in this structure.
2379 *
2380 * \return
2381 * \ref cy_en_crypto_status_t
2382 *
2383 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_Decrypt(CRYPTO_Type * base,uint32_t ivSize,uint8_t const * iv,uint32_t aadSize,uint8_t const * aad,uint32_t srcSize,uint8_t * plainTxt,uint8_t const * cipherTxt,uint32_t tagSize,uint8_t const * tag,cy_en_crypto_aesccm_tag_verify_result_t * isValid,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2384 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Decrypt(CRYPTO_Type *base,
2385                                             uint32_t ivSize, uint8_t const * iv,
2386                                             uint32_t aadSize, uint8_t const *aad,
2387                                             uint32_t srcSize, uint8_t *plainTxt, uint8_t const *cipherTxt,
2388                                             uint32_t tagSize, uint8_t const *tag, cy_en_crypto_aesccm_tag_verify_result_t *isValid,
2389                                             cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2390 {
2391     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2392 
2393     if (CY_CRYPTO_V1)
2394     {
2395         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2396         (void)base;
2397         (void)ivSize;
2398         (void)iv;
2399         (void)aadSize;
2400         (void)aad;
2401         (void)srcSize;
2402         (void)cipherTxt;
2403         (void)plainTxt;
2404         (void)tagSize;
2405         (void)tag;
2406         (void)isValid;
2407         (void)aesCcmState;
2408         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2409         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2410     }
2411     else
2412     {
2413         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2414         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Decrypt(base, ivSize, iv, aadSize, aad, srcSize, plainTxt, cipherTxt, tagSize, tag, isValid, aesCcmState);
2415         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2416     }
2417 
2418     return tmpResult;
2419 
2420 }
2421 
2422 
2423 /*******************************************************************************
2424 * Function Name: Cy_Crypto_Core_Aes_Ccm_Free
2425 ****************************************************************************//**
2426 *
2427 * Clears AES CCM operation context.
2428 *
2429 * \param base
2430 * The pointer to the CRYPTO instance.
2431 *
2432 * \param aesCcmState
2433 * The pointer to the AES CCM state structure allocated by the user. The user
2434 * must not modify anything in this structure.
2435 *
2436 * \return
2437 * \ref cy_en_crypto_status_t
2438 *
2439 *******************************************************************************/
Cy_Crypto_Core_Aes_Ccm_Free(CRYPTO_Type * base,cy_stc_crypto_aes_ccm_state_t * aesCcmState)2440 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ccm_Free(CRYPTO_Type *base, cy_stc_crypto_aes_ccm_state_t *aesCcmState)
2441 {
2442 
2443     cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2444 
2445     if (CY_CRYPTO_V1)
2446     {
2447         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
2448         (void)base;
2449         (void)aesCcmState;
2450         tmpResult = CY_CRYPTO_NOT_SUPPORTED;
2451         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
2452     }
2453     else
2454     {
2455         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
2456         tmpResult = Cy_Crypto_Core_V2_Aes_Ccm_Free(base, aesCcmState);
2457         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
2458     }
2459 
2460     return tmpResult;
2461 
2462 }
2463 
2464 #endif /*CY_CRYPTO_CFG_CCM_C*/
2465 
2466 /** \} group_crypto_lld_symmetric_functions */
2467 
2468 #endif /* (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_AES_C) */
2469 
2470 #if defined(__cplusplus)
2471 }
2472 #endif
2473 
2474 #endif /* CY_IP_MXCRYPTO */
2475 
2476 #endif /* #if !defined (CY_CRYPTO_CORE_AES_H) */
2477 
2478 
2479 /* [] END OF FILE */
2480