1 /***************************************************************************//**
2 * \file cy_crypto_core_mem.h
3 * \version 2.120
4 *
5 * \brief
6 *  This file provides the headers for the memory management API
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_MEM_H)
30 #define CY_CRYPTO_CORE_MEM_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 #include "cy_crypto_core_mem_v1.h"
43 #include "cy_crypto_core_mem_v2.h"
44 #include "cy_crypto_core_hw.h"
45 
46 typedef void (*cy_crypto_memcpy_func_t)(CRYPTO_Type *base,
47                                void* dst, void const *src, uint16_t size);
48 typedef void (*cy_crypto_memset_func_t)(CRYPTO_Type *base,
49                                void* dst, uint8_t data, uint16_t size);
50 typedef uint32_t (*cy_crypto_memcmp_func_t)(CRYPTO_Type *base,
51                                void const *src0, void const *src1, uint16_t size);
52 typedef void (*cy_crypto_memxor_func_t)(CRYPTO_Type *base, void* dst,
53                                void const *src0, void const *src1, uint16_t size);
54 
55 /**
56 * \addtogroup group_crypto_lld_mem_functions
57 * \{
58 */
59 
60 /*******************************************************************************
61 * Function Name: Cy_Crypto_Core_MemCpy
62 ****************************************************************************//**
63 *
64 * Function MemCpy uses Crypto HW.
65 * Memory structures should not overlap!
66 * There is no alignment restriction.
67 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters dst and src must align and end in 32 byte boundary.
68 *
69 * \param base
70 * The pointer to the CRYPTO instance.
71 *
72 * \param dst
73 * The pointer to the destination of MemCpy.
74 *
75 * \param src
76 * The pointer to the source of MemCpy.
77 *
78 * \param size
79 * The size in bytes of the copy operation.
80 *
81 *******************************************************************************/
Cy_Crypto_Core_MemCpy(CRYPTO_Type * base,void * dst,void const * src,uint16_t size)82 __STATIC_INLINE void Cy_Crypto_Core_MemCpy(CRYPTO_Type *base, void* dst, void const *src, uint16_t size)
83 {
84     if (CY_CRYPTO_V1)
85     {
86         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
87         Cy_Crypto_Core_V1_MemCpy(base, dst, src, size);
88         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
89     }
90     else
91     {
92         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
93         Cy_Crypto_Core_V2_MemCpy(base, dst, src, size);
94         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
95     }
96 }
97 
98 /*******************************************************************************
99 * Function Name: Cy_Crypto_Core_MemSet
100 ****************************************************************************//**
101 *
102 * Function MemSet uses Crypto HW.
103 * There is no alignment restriction.
104 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameter dst must align and end in 32 byte boundary.
105 *
106 * \param base
107 * The pointer to the CRYPTO instance.
108 *
109 * \param dst
110 * The pointer to the destination of MemSet.
111 
112 * \param data
113 * The value to be set.
114 
115 * \param size
116 * The size in bytes of the set operation.
117 *
118 *******************************************************************************/
Cy_Crypto_Core_MemSet(CRYPTO_Type * base,void * dst,uint8_t data,uint16_t size)119 __STATIC_INLINE void Cy_Crypto_Core_MemSet(CRYPTO_Type *base, void* dst, uint8_t data, uint16_t size)
120 {
121     if (CY_CRYPTO_V1)
122     {
123         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
124         Cy_Crypto_Core_V1_MemSet(base, dst, data, size);
125         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
126     }
127     else
128     {
129         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
130         Cy_Crypto_Core_V2_MemSet(base, dst, data, size);
131         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
132     }
133 }
134 
135 /*******************************************************************************
136 * Function Name: Cy_Crypto_Core_MemCmp
137 ****************************************************************************//**
138 *
139 * Function MemCmp uses Crypto HW.
140 * There is no alignment restriction.
141 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters src0 and src1 must align and end in 32 byte boundary.
142 *
143 * \param base
144 * The pointer to the CRYPTO instance.
145 *
146 * \param src0
147 * The pointer to the first source of MemCmp.
148 
149 * \param src1
150 * The pointer to the second source of MemCmp.
151 
152 * \param size
153 * the size in bytes of the compare operation.
154 *
155 * \return
156 * 0 - if Source 1 = Source 2, 1 - if not.
157 *
158 *******************************************************************************/
Cy_Crypto_Core_MemCmp(CRYPTO_Type * base,void const * src0,void const * src1,uint16_t size)159 __STATIC_INLINE uint32_t Cy_Crypto_Core_MemCmp(CRYPTO_Type *base, void const *src0, void const *src1, uint16_t size)
160 {
161     uint32_t tmpResult = 1u;
162     if (CY_CRYPTO_V1)
163     {
164         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
165         tmpResult = Cy_Crypto_Core_V1_MemCmp(base, src0, src1, size);
166         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
167     }
168     else
169     {
170         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
171         tmpResult = Cy_Crypto_Core_V2_MemCmp(base, src0, src1, size);
172         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
173     }
174 
175     return (tmpResult);
176 }
177 
178 /*******************************************************************************
179 * Function Name: Cy_Crypto_Core_MemXor
180 ****************************************************************************//**
181 *
182 * Function MemXor uses Crypto HW.
183 * Memory structures should not overlap!
184 * There is no alignment restriction.
185 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled parameters dst, src0 and src1 must align and end in 32 byte boundary.
186 *
187 * \param base
188 * The pointer to the CRYPTO instance.
189 *
190 * \param dst
191 * The pointer to the destination of MemXor.
192 *
193 * \param src0
194 * The pointer to the first source of MemXor.
195 *
196 * \param src1
197 * The pointer to the second source of MemXor.
198 *
199 * \param size
200 * The size in bytes of the compare operation.
201 *
202 *******************************************************************************/
Cy_Crypto_Core_MemXor(CRYPTO_Type * base,void * dst,void const * src0,void const * src1,uint16_t size)203 __STATIC_INLINE void Cy_Crypto_Core_MemXor(CRYPTO_Type *base, void* dst,
204                                            void const *src0, void const *src1, uint16_t size)
205 {
206     if (CY_CRYPTO_V1)
207     {
208         #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
209         Cy_Crypto_Core_V1_MemXor(base, dst, src0, src1, size);
210         #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
211     }
212     else
213     {
214         #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
215         Cy_Crypto_Core_V2_MemXor(base, dst, src0, src1, size);
216         #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
217     }
218 }
219 
220 /** \} group_crypto_lld_mem_functions */
221 
222 #if defined(__cplusplus)
223 }
224 #endif
225 
226 #endif /* CY_IP_MXCRYPTO */
227 
228 #endif /* #if !defined (CY_CRYPTO_CORE_MEM_H) */
229 
230 
231 /* [] END OF FILE */
232