1 /***************************************************************************//**
2 * \file cy_crypto_core_hmac_v2.h
3 * \version 2.120
4 *
5 * \brief
6 *  This file provides constants and function prototypes
7 *  for the API for the HMAC 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_HMAC_V2_H)
30 #define CY_CRYPTO_CORE_HMAC_V2_H
31 
32 #include "cy_crypto_common.h"
33 
34 #if defined(CY_IP_MXCRYPTO) && defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
35 
36 #if defined(__cplusplus)
37 extern "C" {
38 #endif
39 
40 #if (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_HMAC_C)
41 
42 #include "cy_crypto_core_sha_v2.h"
43 
44 #define CY_CRYPTO_HMAC_IPAD               (0x36u)
45 #define CY_CRYPTO_HMAC_0PAD               (0x5Cu)
46 #define CY_CRYPTO_HMAC_MAX_PAD_SIZE       (128u)
47 #define CY_CRYPTO_HMAC_MAX_M0_KEY_SIZE    (128u)
48 
49 /** \cond INTERNAL */
50 
51 #if (((CY_CPU_CORTEX_M7) && defined (ENABLE_CM7_DATA_CACHE)) || CY_CPU_CORTEX_M55)
52 CY_ALIGN(__SCB_DCACHE_LINE_SIZE)
53 #endif
54 typedef struct
55 {
56     /* Allocates CY_CRYPTO_HMAC_MAX_PAD_SIZE Bytes for the inner padding. */
57     uint8_t ipad[CY_CRYPTO_HMAC_MAX_PAD_SIZE];
58 
59     /* Allocates CY_CRYPTO_HMAC_MAX_PAD_SIZE Bytes for the outer padding. */
60     uint8_t opad[CY_CRYPTO_HMAC_MAX_PAD_SIZE];
61 
62     /* Allocates CY_CRYPTO_SHA_MAX_BLOCK_SIZE Bytes for the HMAC keys. */
63     uint8_t m0Key[CY_CRYPTO_SHA_MAX_BLOCK_SIZE];
64 
65     /* SHA buffers for storing and processing the data */
66     cy_stc_crypto_v2_sha512_buffers_t shaBuffers;
67 } cy_stc_crypto_v2_hmac_buffers_t;
68 
69 /** \endcond */
70 
71 cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac_Init(CRYPTO_Type *base,
72                                                 cy_stc_crypto_hmac_state_t *hmacState,
73                                                 cy_en_crypto_sha_mode_t mode, cy_stc_crypto_v2_hmac_buffers_t *hmacBuffer);
74 
75 cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac_Start(CRYPTO_Type *base,
76                                                 cy_stc_crypto_hmac_state_t *hmacState,
77                                                 uint8_t const *key,
78                                                 uint32_t keyLength);
79 
80 cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac_Update(CRYPTO_Type *base,
81                                                 cy_stc_crypto_hmac_state_t  *hmacState,
82                                                 uint8_t   const *message,
83                                                 uint32_t  messageSize);
84 
85 cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac_Finish(CRYPTO_Type *base,
86                                                 cy_stc_crypto_hmac_state_t *hmacState,
87                                                 uint8_t *hmac);
88 
89 cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac_Free(CRYPTO_Type *base,
90                                                 cy_stc_crypto_hmac_state_t *hmacState);
91 
92 cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac(CRYPTO_Type *base,
93                                           uint8_t *hmac,
94                                           uint8_t  const *message,
95                                           uint32_t messageSize,
96                                           uint8_t  const *key,
97                                           uint32_t keyLength,
98                                           cy_en_crypto_sha_mode_t mode);
99 
100 
101 #endif /* (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_HMAC_C) */
102 
103 #if defined(__cplusplus)
104 }
105 #endif
106 
107 #endif /* defined(CY_IP_MXCRYPTO) && defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
108 
109 #endif /* #if !defined (CY_CRYPTO_CORE_HMAC_V2_H) */
110 
111 
112 /* [] END OF FILE */
113