1 /***************************************************************************//**
2 * \file cy_crypto_core_sha_v2.h
3 * \version 2.120
4 *
5 * \brief
6 *  This file provides constants and function prototypes
7 *  for the API for the SHA 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_SHA_V2_H)
30 #define CY_CRYPTO_CORE_SHA_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_SHA_C)
41 
42 /** \cond INTERNAL */
43 
44 #if (CPUSS_CRYPTO_SHA1 == 1) && defined(CY_CRYPTO_CFG_SHA1_ENABLED)
45 typedef struct
46 {
47     /* Allocates CRYPTO_MAX_BLOCK_SIZE Bytes for the block. */
48     uint32_t block[CY_CRYPTO_SHA1_BLOCK_SIZE / 4u];
49 
50     /* Allocates CRYPTO_MAX_HASH_SIZE Bytes for the hash. */
51      uint32_t hash[CY_CRYPTO_SHA1_HASH_SIZE / 4u];
52 
53     #if (CY_CPU_CORTEX_M7) && defined (ENABLE_CM7_DATA_CACHE)
54     uint8_t padding_bytes[12];
55     #endif
56 
57 
58 } cy_stc_crypto_v2_sha1_buffers_t;
59 #endif /* (CPUSS_CRYPTO_SHA1 == 1) && defined(CY_CRYPTO_CFG_SHA1_ENABLED) */
60 
61 #if (CPUSS_CRYPTO_SHA256 == 1) && defined(CY_CRYPTO_CFG_SHA2_256_ENABLED)
62 typedef struct
63 {
64     /* Allocates CRYPTO_MAX_BLOCK_SIZE Bytes for the block. */
65     uint32_t block[CY_CRYPTO_SHA256_BLOCK_SIZE / 4u];
66 
67     /* Allocates CRYPTO_MAX_HASH_SIZE Bytes for the hash. */
68     uint32_t hash[CY_CRYPTO_SHA256_HASH_SIZE / 4u];
69 } cy_stc_crypto_v2_sha256_buffers_t;
70 #endif /* (CPUSS_CRYPTO_SHA256 == 1) && defined(CY_CRYPTO_CFG_SHA2_256_ENABLED) */
71 
72 #if (CPUSS_CRYPTO_SHA512 == 1) && defined(CY_CRYPTO_CFG_SHA2_512_ENABLED)
73 #if (((CY_CPU_CORTEX_M7) && defined (ENABLE_CM7_DATA_CACHE)) || CY_CPU_CORTEX_M55)
74 CY_ALIGN(__SCB_DCACHE_LINE_SIZE)
75 #endif
76 typedef struct
77 {
78     /* Allocates CRYPTO_MAX_BLOCK_SIZE Bytes for the block. */
79     uint32_t block[CY_CRYPTO_SHA512_BLOCK_SIZE / 4u];
80 
81     /* Allocates CRYPTO_MAX_HASH_SIZE Bytes for the hash. */
82     uint32_t hash[CY_CRYPTO_SHA512_HASH_SIZE / 4u];
83 } cy_stc_crypto_v2_sha512_buffers_t;
84 #endif /* (CPUSS_CRYPTO_SHA512 == 1) && defined(CY_CRYPTO_CFG_SHA2_512_ENABLED) */
85 
86 #if (CPUSS_CRYPTO_SHA3 == 1) && defined(CY_CRYPTO_CFG_SHA3_ENABLED)
87 typedef struct
88 {
89     /* Allocates CY_CRYPTO_SHA3_STATE_SIZE for the hash state. */
90     uint8_t hash[CY_CRYPTO_SHA3_STATE_SIZE];
91 
92 } cy_stc_crypto_v2_sha3_buffers_t;
93 #endif /* (CPUSS_CRYPTO_SHA3 == 1) && defined(CY_CRYPTO_CFG_SHA3_ENABLED) */
94 
95 #if (((CY_CPU_CORTEX_M7) && defined (ENABLE_CM7_DATA_CACHE)) || CY_CPU_CORTEX_M55)
96 CY_ALIGN(__SCB_DCACHE_LINE_SIZE)
97 #endif
98 typedef struct
99 {
100     /* Allocates CRYPTO_MAX_BLOCK_SIZE Bytes for the block. */
101     uint32_t block[CY_CRYPTO_SHA_MAX_BLOCK_SIZE / 4u];
102 
103     #if (((CY_CPU_CORTEX_M7) && defined (ENABLE_CM7_DATA_CACHE)) || CY_CPU_CORTEX_M55)
104     CY_ALIGN(__SCB_DCACHE_LINE_SIZE)
105     #endif
106     uint32_t hash[CY_CRYPTO_SHA_MAX_HASH_SIZE / 4u];
107 
108 } cy_stc_crypto_v2_sha_buffers_t;
109 
110 
111 cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Init(CRYPTO_Type *base,
112                                 cy_stc_crypto_sha_state_t *hashState,
113                                 cy_en_crypto_sha_mode_t mode,
114                                 void *shaBuffers);
115 
116 cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Start(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState);
117 
118 cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Update(CRYPTO_Type *base,
119                                 cy_stc_crypto_sha_state_t *hashState,
120                                 uint8_t const *message,
121                                 uint32_t messageSize);
122 
123 cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Finish(CRYPTO_Type *base,
124                                 cy_stc_crypto_sha_state_t *hashState,
125                                 uint8_t *digest);
126 
127 cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Free(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState);
128 
129 cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha(CRYPTO_Type *base,
130                                 uint8_t const *message,
131                                 uint32_t messageSize,
132                                 uint8_t *digest,
133                                 cy_en_crypto_sha_mode_t mode);
134 
135 /** \endcond */
136 
137 
138 #endif /* (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_SHA_C) */
139 
140 #if defined(__cplusplus)
141 }
142 #endif
143 
144 #endif /* defined(CY_IP_MXCRYPTO) && defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
145 
146 #endif /* #if !defined (CY_CRYPTO_CORE_SHA_V2_H) */
147 
148 
149 /* [] END OF FILE */
150