1 /***************************************************************************//**
2 * \file cy_crypto_core_hkdf.h
3 * \version 2.120
4 *
5 * \brief
6 * This file provides constants and function prototypes
7 * for the API for the HKDF method in the Crypto block driver.
8 *
9 ********************************************************************************
10 * \copyright
11 * Copyright (c) (2020-2023), 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_HKDF_H)
30 #define CY_CRYPTO_CORE_HKDF_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_SHA == 1) && defined(CY_CRYPTO_CFG_HKDF_C)
43
44 #include "cy_crypto_core_hkdf_v2.h"
45
46 /**
47 * \addtogroup group_crypto_lld_kdf_functions
48 * \{
49 */
50
51 /*******************************************************************************
52 * Function Name: Cy_Crypto_Core_Hkdf_Extract
53 ****************************************************************************//**
54 *
55 * Performs HKDF Extract calculation.
56 *
57 * \param base
58 * The pointer to the CRYPTO instance.
59 *
60 * \param mode
61 * \ref cy_en_crypto_sha_mode_t
62 *
63 * \param salt
64 * The pointer to salt.
65 *
66 * \param saltLength
67 * The size of a salt.
68 *
69 * \param ikm
70 * The pointer to the Input Key material.
71 *
72 * \param ikmLength
73 * The length of the IKM.
74 *
75 * \param prk
76 * The pointer to store the generated prk.
77 *
78 * \return
79 * \ref cy_en_crypto_status_t
80 *
81 *******************************************************************************/
Cy_Crypto_Core_Hkdf_Extract(CRYPTO_Type * base,cy_en_crypto_sha_mode_t mode,uint8_t const * salt,uint32_t saltLength,uint8_t const * ikm,uint32_t ikmLength,uint8_t * prk)82 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hkdf_Extract(CRYPTO_Type *base, cy_en_crypto_sha_mode_t mode,
83 uint8_t const *salt,
84 uint32_t saltLength,
85 uint8_t const *ikm,
86 uint32_t ikmLength,
87 uint8_t *prk)
88 {
89 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
90
91 if (CY_CRYPTO_V1)
92 {
93 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
94 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
95 (void)base; /* Suppress a compiler warning about unused variables */
96 (void)mode; /* Suppress a compiler warning about unused variables */
97 (void)salt; /* Suppress a compiler warning about unused variables */
98 (void)saltLength; /* Suppress a compiler warning about unused variables */
99 (void)ikm; /* Suppress a compiler warning about unused variables */
100 (void)ikmLength; /* Suppress a compiler warning about unused variables */
101 (void)prk; /* Suppress a compiler warning about unused variables */
102 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
103 }
104 else
105 {
106 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
107 tmpResult = Cy_Crypto_Core_V2_Hkdf_Extract(base, mode, salt, saltLength, ikm, ikmLength, prk);
108 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
109 }
110
111
112 return tmpResult;
113 }
114
115
116
117 /*******************************************************************************
118 * Function Name: Cy_Crypto_Core_Hkdf_Expand
119 ****************************************************************************//**
120 *
121 * Performs HKDF Expand calculation.
122 *
123 * \param base
124 * The pointer to the CRYPTO instance.
125 *
126 * \param mode
127 * \ref cy_en_crypto_sha_mode_t
128 *
129 * \param prk
130 * The pointer to the pseudo random key.
131 *
132 * \param prkLength
133 * The length of the prk.
134 *
135 * \param info
136 * The pointer to info.
137 *
138 * \param infoLength
139 * The length of the info.
140 *
141 * \param okm
142 * The pointer to Output key material.
143 *
144 * \param okmLength
145 * The length of okm to be generated.
146 *
147 * \return
148 * \ref cy_en_crypto_status_t
149 *
150 *******************************************************************************/
Cy_Crypto_Core_Hkdf_Expand(CRYPTO_Type * base,cy_en_crypto_sha_mode_t mode,uint8_t const * prk,uint32_t prkLength,uint8_t const * info,uint32_t infoLength,uint8_t * okm,uint32_t okmLength)151 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hkdf_Expand(CRYPTO_Type *base, cy_en_crypto_sha_mode_t mode,
152 uint8_t const *prk,
153 uint32_t prkLength,
154 uint8_t const *info,
155 uint32_t infoLength,
156 uint8_t *okm,
157 uint32_t okmLength)
158 {
159 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
160
161 if (CY_CRYPTO_V1)
162 {
163 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
164 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
165 (void)base; /* Suppress a compiler warning about unused variables */
166 (void)mode; /* Suppress a compiler warning about unused variables */
167 (void)prk; /* Suppress a compiler warning about unused variables */
168 (void)prkLength; /* Suppress a compiler warning about unused variables */
169 (void)info; /* Suppress a compiler warning about unused variables */
170 (void)infoLength; /* Suppress a compiler warning about unused variables */
171 (void)okm; /* Suppress a compiler warning about unused variables */
172 (void)okmLength; /* Suppress a compiler warning about unused variables */
173 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
174 }
175 else
176 {
177 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
178 tmpResult = Cy_Crypto_Core_V2_Hkdf_Expand(base, mode, prk, prkLength, info, infoLength, okm, okmLength);
179 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
180 }
181
182 return tmpResult;
183 }
184
185 /*******************************************************************************
186 * Function Name: Cy_Crypto_Core_Hkdf
187 ****************************************************************************//**
188 *
189 * Performs HKDF calculation.
190 *
191 * \param base
192 * The pointer to the CRYPTO instance.
193 *
194 * \param mode
195 * \ref cy_en_crypto_sha_mode_t
196 *
197 * \param salt
198 * The pointer to salt.
199 *
200 * \param saltLength
201 * The size of a salt.
202 *
203 * \param ikm
204 * The pointer to the Input Key material.
205 *
206 * \param ikmLength
207 * The length of the IKM.
208 *
209 * \param info
210 * The pointer to info.
211 *
212 * \param infoLength
213 * The length of the info.
214 *
215 * \param okm
216 * The pointer to Output key material.
217 *
218 * \param okmLength
219 * The length of okm to be generated.
220 *
221 * \return
222 * \ref cy_en_crypto_status_t
223 *
224 *******************************************************************************/
Cy_Crypto_Core_Hkdf(CRYPTO_Type * base,cy_en_crypto_sha_mode_t mode,uint8_t const * salt,uint32_t saltLength,uint8_t const * ikm,uint32_t ikmLength,uint8_t const * info,uint32_t infoLength,uint8_t * okm,uint32_t okmLength)225 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hkdf(CRYPTO_Type *base, cy_en_crypto_sha_mode_t mode,
226 uint8_t const *salt,
227 uint32_t saltLength,
228 uint8_t const *ikm,
229 uint32_t ikmLength,
230 uint8_t const *info,
231 uint32_t infoLength,
232 uint8_t *okm,
233 uint32_t okmLength)
234 {
235
236 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
237
238 if (CY_CRYPTO_V1)
239 {
240 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
241 tmpResult = CY_CRYPTO_NOT_SUPPORTED;
242 (void)base; /* Suppress a compiler warning about unused variables */
243 (void)mode; /* Suppress a compiler warning about unused variables */
244 (void)salt; /* Suppress a compiler warning about unused variables */
245 (void)saltLength; /* Suppress a compiler warning about unused variables */
246 (void)ikm; /* Suppress a compiler warning about unused variables */
247 (void)ikmLength; /* Suppress a compiler warning about unused variables */
248 (void)info; /* Suppress a compiler warning about unused variables */
249 (void)infoLength; /* Suppress a compiler warning about unused variables */
250 (void)okm; /* Suppress a compiler warning about unused variables */
251 (void)okmLength; /* Suppress a compiler warning about unused variables */
252 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
253 }
254 else
255 {
256 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
257 tmpResult = Cy_Crypto_Core_V2_Hkdf(base, mode, salt, saltLength, ikm, ikmLength, info, infoLength,
258 okm, okmLength);
259 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
260 }
261
262 return tmpResult;
263
264 }
265
266 /** \} group_crypto_lld_kdf_functions */
267
268 #endif /* (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_HKDF_C) */
269
270 #if defined(__cplusplus)
271 }
272 #endif
273
274 #endif /* CY_IP_MXCRYPTO */
275
276 #endif /* #if !defined (CY_CRYPTO_CORE_HKDF_H) */
277
278
279 /* [] END OF FILE */
280