1 /***************************************************************************//**
2 * \file cy_crypto_core_cmac.h
3 * \version 2.120
4 *
5 * \brief
6 * This file provides constants and function prototypes
7 * for the API for the CMAC method in the Crypto block 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_CMAC_H)
30 #define CY_CRYPTO_CORE_CMAC_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_CMAC_C)
43
44 #include "cy_crypto_core_cmac_v1.h"
45 #include "cy_crypto_core_cmac_v2.h"
46
47 /** \cond INTERNAL */
48
49 typedef cy_en_crypto_status_t (*cy_crypto_cmac_func_t)(CRYPTO_Type *base,
50 uint8_t const *src,
51 uint32_t srcSize,
52 uint8_t const *key,
53 cy_en_crypto_aes_key_length_t keyLength,
54 uint8_t *dst,
55 cy_stc_crypto_aes_state_t *aesState);
56 /** \endcond */
57
58 /**
59 * \addtogroup group_crypto_lld_mac_functions
60 * \{
61 */
62
63 /*******************************************************************************
64 * Function Name: Cy_Crypto_Core_Cmac
65 ****************************************************************************//**
66 *
67 * Calculates the AES Cipher-based Message Authentication Code (CMAC) on the input
68 * message with the provided key.
69 *
70 * \param base
71 * The pointer to the CRYPTO instance.
72 *
73 * \param message
74 * The pointer to the source plain text. Must be 4-byte aligned.
75 *
76 * \param messageSize
77 * The size of the source plain text in bytes.
78 *
79 * \param key
80 * The pointer to the encryption key. Must be 4-byte aligned.
81 *
82 * \param keyLength
83 * \ref cy_en_crypto_aes_key_length_t
84 *
85 * \param cmac
86 * The pointer to the calculated CMAC.
87 *
88 * \param aesState
89 * The pointer to the AES state structure allocated by the user. The user
90 * must not modify anything in this structure.
91 *
92 * \return
93 * \ref cy_en_crypto_status_t
94 *
95 * \funcusage
96 * \snippet crypto/snippet/main.c snippet_myCryptoCoreCmacUse
97 *
98 *******************************************************************************/
Cy_Crypto_Core_Cmac(CRYPTO_Type * base,uint8_t const * message,uint32_t messageSize,uint8_t const * key,cy_en_crypto_aes_key_length_t keyLength,uint8_t * cmac,cy_stc_crypto_aes_state_t * aesState)99 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac(CRYPTO_Type *base,
100 uint8_t const *message,
101 uint32_t messageSize,
102 uint8_t const *key,
103 cy_en_crypto_aes_key_length_t keyLength,
104 uint8_t *cmac,
105 cy_stc_crypto_aes_state_t *aesState)
106 {
107 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
108
109 if (CY_CRYPTO_V1)
110 {
111 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
112 tmpResult = Cy_Crypto_Core_V1_Cmac(base, message, messageSize, key, keyLength, cmac, aesState);
113 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
114 }
115 else
116 {
117 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
118 tmpResult = Cy_Crypto_Core_V2_Cmac(base, message, messageSize, key, keyLength, cmac, aesState);
119 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
120 }
121
122 return tmpResult;
123 }
124
125
126
127 /*******************************************************************************
128 * Function Name: Cy_Crypto_Core_Cmac_Init
129 ****************************************************************************//**
130 *
131 * The function for initialization of CMAC operation.
132 *
133 * \param base
134 * The pointer to the CRYPTO instance.
135 *
136 * \param cmacState
137 * The pointer to the structure which stores the CMAC context.
138 *
139 * \param buffer
140 * The pointer to the cmac buffer.
141 *
142 * \return
143 * \ref cy_en_crypto_status_t
144 *******************************************************************************/
Cy_Crypto_Core_Cmac_Init(CRYPTO_Type * base,void * cmacState,void * buffer)145 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Init(CRYPTO_Type *base, void* cmacState, void *buffer)
146 {
147 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
148
149 if (CY_CRYPTO_V1)
150 {
151 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
152 (void)base;
153 (void)cmacState;
154 (void)buffer;
155 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
156 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
157 }
158 else
159 {
160 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
161 tmpResult = Cy_Crypto_Core_V2_Cmac_Init(base, (cy_stc_crypto_v2_cmac_state_t *)cmacState, (cy_stc_crypto_v2_cmac_buffers_t *)buffer);
162 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
163 }
164
165 return tmpResult;
166 }
167
168
169
170 /*******************************************************************************
171 * Function Name: Cy_Crypto_Core_Cmac_Start
172 ****************************************************************************//**
173 *
174 * Starts CMAC calculation.
175 *
176 * \param base
177 * The pointer to the CRYPTO instance.
178 *
179 * \param cmacState
180 * The pointer to the structure which stores the CMAC context.
181 *
182 * \param aesKey
183 * The pointer to the cmac key.
184 *
185 * \param keyLength
186 * \ref cy_en_crypto_aes_key_length_t
187 *
188 * \return
189 * \ref cy_en_crypto_status_t
190 *******************************************************************************/
Cy_Crypto_Core_Cmac_Start(CRYPTO_Type * base,void * cmacState,uint8_t const * aesKey,cy_en_crypto_aes_key_length_t keyLength)191 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Start(CRYPTO_Type *base, void *cmacState,
192 uint8_t const *aesKey, cy_en_crypto_aes_key_length_t keyLength)
193
194 {
195 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
196
197 if (CY_CRYPTO_V1)
198 {
199 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
200 (void)base;
201 (void)cmacState;
202 (void)aesKey;
203 (void)keyLength;
204
205 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
206 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
207 }
208 else
209 {
210 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
211 tmpResult = Cy_Crypto_Core_V2_Cmac_Start(base, (cy_stc_crypto_v2_cmac_state_t *)cmacState, aesKey, keyLength);
212 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
213 }
214
215 return tmpResult;
216 }
217
218
219
220
221 /*******************************************************************************
222 * Function Name: Cy_Crypto_Core_Cmac_Update
223 ****************************************************************************//**
224 *
225 * Performs cmac update for multi stage operation.
226 *
227 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameter message must align and end in 32 byte boundary.
228 *
229 * \param base
230 * The pointer to the CRYPTO instance.
231 *
232 * \param cmacState
233 * The pointer to the structure which stores the CMAC context.
234 *
235 * \param message
236 * The pointer to the message whose CMAC is being computed.
237 *
238 * \param messageSize
239 * The size of the message whose CMAC is being computed.
240 *
241 * \return
242 * \ref cy_en_crypto_status_t
243 *******************************************************************************/
Cy_Crypto_Core_Cmac_Update(CRYPTO_Type * base,void * cmacState,uint8_t const * message,uint32_t messageSize)244 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Update(CRYPTO_Type *base,
245 void *cmacState,
246 uint8_t const *message,
247 uint32_t messageSize)
248
249 {
250 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
251
252 if (CY_CRYPTO_V1)
253 {
254 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
255 (void)base;
256 (void)cmacState;
257 (void)message;
258 (void)messageSize;
259 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
260 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
261 }
262 else
263 {
264 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
265 tmpResult = Cy_Crypto_Core_V2_Cmac_Update(base, (cy_stc_crypto_v2_cmac_state_t *)cmacState, message, messageSize);
266 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
267 }
268
269 return tmpResult;
270 }
271
272
273
274
275 /*******************************************************************************
276 * Function Name: Cy_Crypto_Core_Cmac_Finish
277 ****************************************************************************//**
278 *
279 * Completes CMAC calculation.
280 *
281 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameter cmac must align and end in 32 byte boundary.
282 *
283 * \param cmacState
284 * The pointer to the structure which stores the CMAC context.
285 *
286 * \param base
287 * The pointer to the CRYPTO instance.
288 *
289 * \param cmac
290 * The pointer to the computed CMAC value.
291 *
292 * \return
293 * \ref cy_en_crypto_status_t
294 *******************************************************************************/
Cy_Crypto_Core_Cmac_Finish(CRYPTO_Type * base,void * cmacState,uint8_t * cmac)295 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Finish(CRYPTO_Type *base, void *cmacState, uint8_t* cmac)
296
297
298 {
299 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
300
301 if (CY_CRYPTO_V1)
302 {
303 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
304 (void)base;
305 (void)cmacState;
306 (void)cmac;
307 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
308 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
309 }
310 else
311 {
312 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
313 tmpResult = Cy_Crypto_Core_V2_Cmac_Finish(base, (cy_stc_crypto_v2_cmac_state_t *)cmacState, cmac);
314 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
315 }
316
317 return tmpResult;
318 }
319
320
321 /*******************************************************************************
322 * Function Name: Cy_Crypto_Core_Cmac_Free
323 ****************************************************************************//**
324 *
325 *
326 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameter cmac must align and end in 32 byte boundary.
327 *
328 * \param base
329 * The pointer to the CRYPTO instance.
330 *
331 * \param cmacState
332 * The pointer to the structure which stores the CMAC context.
333 *
334 * \return
335 * \ref cy_en_crypto_status_t
336 *******************************************************************************/
Cy_Crypto_Core_Cmac_Free(CRYPTO_Type * base,void * cmacState)337 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Free(CRYPTO_Type *base,
338 void *cmacState
339 )
340
341 {
342 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
343
344 if (CY_CRYPTO_V1)
345 {
346 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
347 (void)base;
348 (void)cmacState;
349 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
350 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
351 }
352 else
353 {
354 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
355 tmpResult = Cy_Crypto_Core_V2_Cmac_Free(base, (cy_stc_crypto_v2_cmac_state_t *)cmacState);
356 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
357 }
358
359 return tmpResult;
360 }
361
362
363 /** \} group_crypto_lld_mac_functions */
364
365 #endif /* (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_CMAC_C) */
366
367 #if defined(__cplusplus)
368 }
369 #endif
370
371 #endif /* CY_IP_MXCRYPTO */
372
373 #endif /* #if !defined (CY_CRYPTO_CORE_CMAC_H) */
374
375
376 /* [] END OF FILE */
377