1 /***************************************************************************//**
2 * \file cy_cryptolite_vu.h
3 * \version 2.30
4 *
5 * \brief
6 * This file provides provides constant and parameters
7 * for the API of the VU in the Cryptolite driver.
8 *
9 ********************************************************************************
10 * Copyright 2020-2021 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25
26 #if !defined (CY_CRYPTOLITE_VU_H)
27 #define CY_CRYPTOLITE_VU_H
28
29 #include "cy_device.h"
30
31 #if defined (CY_IP_MXCRYPTOLITE)
32
33 #include "cy_cryptolite_common.h"
34
35 #if defined(__cplusplus)
36 extern "C" {
37 #endif
38
39 #if (CRYPTOLITE_VU_PRESENT == 1)
40
41 #define VU_BITS_TO_WORDS(b) (((b)+31U) >> 5)
42 #define VU_BITS_TO_BYTES(b) ((4U)*VU_BITS_TO_WORDS(b))
43 #define VU_BYTES_TO_WORDS(b) ((b) >> 2)
44
45 /* Fix: update it for other sizes */
46 #define VU_TEST_EQUAL_LESS_SIZE (521u)
47
48 void Cy_Cryptolite_Vu_lsl (uint8_t* p_z,uint32_t word_size_z,uint8_t* p_a, uint32_t word_size_a,uint32_t bit_sh);
49 void Cy_Cryptolite_Vu_clr (uint8_t* p_z,uint32_t word_size);
50 bool Cy_Cryptolite_Vu_test_zero(CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t *psrc, uint16_t bitsize);
51 bool Cy_Cryptolite_Vu_test_equal(CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t *rsrc0, uint8_t *rsrc1, uint16_t bitsize);
52 bool Cy_Cryptolite_Vu_test_less_than(CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t *rsrc0, uint8_t *rsrc1, uint16_t bitsize);
53 cy_en_cryptolite_status_t Cy_Cryptolite_Vu_RunInstr(CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t *p_struct);
54
55 /*Compares size bytes of src0 to src1*/
Cy_Cryptolite_Vu_memcmp(void const * src0,void const * src1,uint32_t size)56 __STATIC_INLINE uint32_t Cy_Cryptolite_Vu_memcmp (void const *src0, void const *src1, uint32_t size)
57 {
58 uint32_t i,diff;
59 uint8_t *s0,*s1;
60
61 s0 = (uint8_t*)src0;
62 s1 = (uint8_t*)src1;
63 diff = 0;
64
65 for(i=0; i < size; i++)
66 {
67 diff |= (uint32_t)s0[i] ^ (uint32_t)s1[i];
68 }
69
70 if((bool)diff){
71 return 1;
72 }else{
73 return 0;
74 }
75 }
76
77
78 /*Copy the buffer src to dest of size bytes*/
Cy_Cryptolite_Vu_memcpy(void * dest,const void * src,uint32_t size)79 __STATIC_INLINE void Cy_Cryptolite_Vu_memcpy (void *dest, const void *src, uint32_t size)
80 {
81 uint32_t i;
82 uint8_t *dest_P = (uint8_t *)dest;
83 uint8_t *src_P = (uint8_t *)src;
84
85 for(i=0u; i < size; i++)
86 {
87 dest_P[i] = src_P[i];
88 }
89
90 }
91
92 /*Set the buffer dest to data of size bytes*/
Cy_Cryptolite_Vu_memset(void * dest,uint8_t data,uint32_t size)93 __STATIC_INLINE void Cy_Cryptolite_Vu_memset (void *dest, uint8_t data, uint32_t size)
94 {
95 uint32_t i;
96 uint8_t *dest_P = (uint8_t *)dest;
97
98 for(i=0u; i < size; i++)
99 {
100 dest_P[i] = data;
101 }
102
103 }
104
105 /*Tests for input word to be even or Odd*/
Cy_Cryptolite_Vu_test_even(uint8_t * p_a)106 __STATIC_INLINE bool Cy_Cryptolite_Vu_test_even ( uint8_t* p_a)
107 {
108 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 11.3','Intentional pointer type conversion');
109 uint32_t* p_a_uint32 = (uint32_t *) p_a;
110 uint32_t word = *p_a_uint32;
111
112 return ((word & 1U) == 0U);
113 }
114 /*
115 Clears a bit in the specified position in a word
116 bit_pos" must be within "p_a" size.
117 */
Cy_Cryptolite_Vu_clr_bit(uint8_t * p_z,uint32_t bit_pos)118 __STATIC_INLINE void Cy_Cryptolite_Vu_clr_bit ( uint8_t* p_z, uint32_t bit_pos )
119 {
120 uint32_t byte_offset = bit_pos >> 3U;
121 uint32_t bit_offset = bit_pos & 7U;
122
123 p_z[byte_offset] = p_z[byte_offset] & ~(1U << bit_offset);
124 }
125
126 /*
127 sets a bit in the specified position in a word
128 "pos" must be within "p_a" size.
129 */
Cy_Cryptolite_Vu_set_bit(uint8_t * p_z,uint32_t bit_pos)130 __STATIC_INLINE void Cy_Cryptolite_Vu_set_bit (uint8_t* p_z, uint32_t bit_pos )
131 {
132 uint32_t byte_offset = bit_pos >> 3U;
133 uint32_t bit_offset = bit_pos & 7U;
134
135 p_z[byte_offset] = p_z[byte_offset] | (1U << bit_offset);
136 }
137 /*
138 returns a bit from the specified position in a word
139 "pos" must be within "p_a" size.
140 */
Cy_Cryptolite_Vu_get_bit(uint8_t * p_a,uint32_t bit_pos)141 __STATIC_INLINE uint32_t Cy_Cryptolite_Vu_get_bit ( uint8_t* p_a, uint32_t bit_pos )
142 {
143 uint32_t byte_offset = bit_pos >> 3U;
144 uint32_t bit_offset = bit_pos & 7U;
145
146 return ((uint32_t)p_a[byte_offset] >> bit_offset) & 1U;
147 }
148
149 /*wait till IP is idle*/
Cy_Cryptolite_Vu_wait_hw(CRYPTOLITE_Type * base)150 __STATIC_INLINE void Cy_Cryptolite_Vu_wait_hw (CRYPTOLITE_Type *base)
151 {
152 while ((bool)(REG_CRYPTOLITE_STATUS(base) & CRYPTOLITE_STATUS_BUSY_Msk)){};
153 }
154
155
156 /**
157 * \addtogroup group_cryptolite_lld_vu_functions
158 * \{
159 */
160
161 /*******************************************************************************
162 * Function Name: Cy_Cryptolite_Vu_mul_hw
163 ****************************************************************************//**
164 *
165 * Performs long integer multiplication operation.
166 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
167 * \note This API is not available in CYW20829 A0 CAT1B device
168 *
169 * \param base
170 * The pointer to a Cryptolite instance.
171 *
172 * \param p_struct
173 * The pointer to the cy_stc_cryptolite_descr_t.
174 *
175 * \param p_z
176 * The buffer pointer to the store the output.
177 *
178 * \param word_size_z
179 * The size of the p_z buffer in word size.
180 *
181 * \param p_a
182 * The pointer to the first operand buffer.
183 *
184 * \param word_size_a
185 * The size of the p_a buffer in word size.
186
187 * \param p_b
188 * The pointer to the second operand buffer.
189 *
190 * \param word_size_b
191 * The size of the p_b buffer in word size.
192 *
193 * \return status code. See \ref cy_en_cryptolite_status_t.
194 *
195 * \funcusage
196 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_mul_hw
197 *******************************************************************************/
Cy_Cryptolite_Vu_mul_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint8_t * p_b,uint32_t word_size_b)198 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_mul_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t* p_z,
199 uint32_t word_size_z,
200 uint8_t* p_a,
201 uint32_t word_size_a,
202 uint8_t* p_b,
203 uint32_t word_size_b)
204 {
205 p_struct->data0 = (uint32_t) ((uint32_t)0 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
206 p_struct->data1 = (uint32_t) p_a;
207 p_struct->data2 = (uint32_t) p_b;
208 p_struct->data3 = (uint32_t) p_z;
209 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
210 }
211
212 /*******************************************************************************
213 * Function Name: Cy_Cryptolite_Vu_xmul_hw
214 ****************************************************************************//**
215 *
216 * Performs carry less long integer multiplication operation.
217 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
218 * \note This API is not available in CYW20829 A0 CAT1B device
219 *
220 * \param base
221 * The pointer to a Cryptolite instance.
222 *
223 * \param p_struct
224 * The pointer to the cy_stc_cryptolite_descr_t.
225 *
226 * \param p_z
227 * The buffer pointer to the store the output.
228 *
229 * \param word_size_z
230 * The size of the p_z buffer in word size.
231 *
232 * \param p_a
233 * The pointer to the first operand buffer.
234 *
235 * \param word_size_a
236 * The size of the p_a buffer in word size.
237
238 * \param p_b
239 * The pointer to the second operand buffer.
240 *
241 * \param word_size_b
242 * The size of the p_b buffer in word size.
243 *
244 * \return status code. See \ref cy_en_cryptolite_status_t.
245 *
246 * \funcusage
247 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_xmul_hw
248 *******************************************************************************/
Cy_Cryptolite_Vu_xmul_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint8_t * p_b,uint32_t word_size_b)249 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_xmul_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t* p_z,
250 uint32_t word_size_z,
251 uint8_t* p_a,
252 uint32_t word_size_a,
253 uint8_t* p_b,
254 uint32_t word_size_b)
255 {
256 p_struct->data0 = (uint32_t) ((uint32_t)4 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
257 p_struct->data1 = (uint32_t) p_a;
258 p_struct->data2 = (uint32_t) p_b;
259 p_struct->data3 = (uint32_t) p_z;
260 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
261 }
262
263
264
265 /*******************************************************************************
266 * Function Name: Cy_Cryptolite_Vu_add_hw
267 ****************************************************************************//**
268 *
269 * Performs long integer addition operation.
270 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
271 * \note This API is not available in CYW20829 A0 CAT1B device
272 *
273 * \param base
274 * The pointer to a Cryptolite instance.
275 *
276 * \param p_struct
277 * The pointer to the cy_stc_cryptolite_descr_t.
278 *
279 * \param p_z
280 * The buffer pointer to the store the output.
281 *
282 * \param word_size_z
283 * The size of the p_z buffer in word size.
284 *
285 * \param p_a
286 * The pointer to the first operand buffer.
287 *
288 * \param word_size_a
289 * The size of the p_a buffer in word size.
290
291 * \param p_b
292 * The pointer to the second operand buffer.
293 *
294 * \param word_size_b
295 * The size of the p_b buffer in word size.
296 *
297 * \return status code. See \ref cy_en_cryptolite_status_t.
298 *
299 * \funcusage
300 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_add_hw
301 *******************************************************************************/
Cy_Cryptolite_Vu_add_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint8_t * p_b,uint32_t word_size_b)302 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_add_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t *p_struct, uint8_t* p_z,
303 uint32_t word_size_z,
304 uint8_t* p_a,
305 uint32_t word_size_a,
306 uint8_t* p_b,
307 uint32_t word_size_b)
308 {
309 p_struct->data0 = (uint32_t) ((uint32_t)1 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
310 p_struct->data1 = (uint32_t) p_a;
311 p_struct->data2 = (uint32_t) p_b;
312 p_struct->data3 = (uint32_t) p_z;
313 /*run instruction*/
314 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
315 }
316
317
318 /*******************************************************************************
319 * Function Name: Cy_Cryptolite_Vu_sub_hw
320 ****************************************************************************//**
321 *
322 * Performs long integer subtraction operation.
323 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
324 * \note This API is not available in CYW20829 A0 CAT1B device
325 *
326 * \param base
327 * The pointer to a Cryptolite instance.
328 *
329 * \param p_struct
330 * The pointer to the cy_stc_cryptolite_descr_t.
331 *
332 * \param p_z
333 * The buffer pointer to the store the output.
334 *
335 * \param word_size_z
336 * The size of the p_z buffer in word size.
337 *
338 * \param p_a
339 * The pointer to the first operand buffer.
340 *
341 * \param word_size_a
342 * The size of the p_a buffer in word size.
343
344 * \param p_b
345 * The pointer to the second operand buffer.
346 *
347 * \param word_size_b
348 * The size of the p_b buffer in word size.
349 *
350 * \return status code. See \ref cy_en_cryptolite_status_t.
351 *
352 * \funcusage
353 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_sub_hw
354 *******************************************************************************/
Cy_Cryptolite_Vu_sub_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint8_t * p_b,uint32_t word_size_b)355 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_sub_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t *p_struct, uint8_t* p_z,
356 uint32_t word_size_z,
357 uint8_t* p_a,
358 uint32_t word_size_a,
359 uint8_t* p_b,
360 uint32_t word_size_b)
361 {
362 p_struct->data0 = (uint32_t) ((uint32_t)2 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
363 p_struct->data1 = (uint32_t) p_a;
364 p_struct->data2 = (uint32_t) p_b;
365 p_struct->data3 = (uint32_t) p_z;
366 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
367 }
368
369
370
371 /*******************************************************************************
372 * Function Name: Cy_Cryptolite_Vu_mov_hw
373 ****************************************************************************//**
374 *
375 * Performs long integer move operation.
376 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
377 * \note This API is not available in CYW20829 A0 CAT1B device
378 *
379 * \param base
380 * The pointer to a Cryptolite instance.
381 *
382 * \param p_struct
383 * The pointer to the cy_stc_cryptolite_descr_t.
384 *
385 * \param p_z
386 * The buffer pointer to the store the output.
387 *
388 * \param word_size_z
389 * The size of the p_z buffer in word size.
390 *
391 * \param p_a
392 * The pointer to the operand buffer.
393 *
394 * \param word_size_a
395 * The size of the p_a buffer in word size.
396 *
397 * \return status code. See \ref cy_en_cryptolite_status_t.
398 *
399 * \funcusage
400 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_mov_hw
401 *******************************************************************************/
Cy_Cryptolite_Vu_mov_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a)402 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_mov_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t *p_struct, uint8_t* p_z,
403 uint32_t word_size_z,
404 uint8_t* p_a,
405 uint32_t word_size_a)
406 {
407 p_struct->data0 = (uint32_t) (9UL << 28U) | ((word_size_z-1U) << 16U) | (word_size_a-1U);
408 p_struct->data1 = (uint32_t) p_a;
409 p_struct->data3 = (uint32_t) p_z;
410 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
411 }
412
413
414
415
416 /*******************************************************************************
417 * Function Name: Cy_Cryptolite_Vu_lsl1_hw
418 ****************************************************************************//**
419 *
420 * Performs left shifting of long integer by one bit.
421 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
422 * \note This API is not available in CYW20829 A0 CAT1B device
423 *
424 * \param base
425 * The pointer to a Cryptolite instance.
426 *
427 * \param p_struct
428 * The pointer to the cy_stc_cryptolite_descr_t.
429 *
430 * \param p_z
431 * The buffer pointer to the store the output.
432 *
433 * \param word_size_z
434 * The size of the p_z buffer in word size.
435 *
436 * \param p_a
437 * The pointer to the operand buffer.
438 *
439 * \param word_size_a
440 * The size of the p_a buffer in word size.
441 *
442 * \return status code. See \ref cy_en_cryptolite_status_t.
443 *
444 * \funcusage
445 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_lsl1_hw
446 *******************************************************************************/
Cy_Cryptolite_Vu_lsl1_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a)447 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_lsl1_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t* p_z,
448 uint32_t word_size_z,
449 uint8_t* p_a,
450 uint32_t word_size_a)
451 {
452 p_struct->data0 = (uint32_t) ((uint32_t)6 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_a-1U) << 8U)| (word_size_a-1U);
453 p_struct->data1 = (uint32_t) p_a;
454 p_struct->data3 = (uint32_t) p_z;
455
456 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
457
458
459 }
460
461
462
463
464 /*******************************************************************************
465 * Function Name: Cy_Cryptolite_Vu_lsr1_hw
466 ****************************************************************************//**
467 *
468 * Performs right shifting of long integer by one bit.
469 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
470 * \note This API is not available in CYW20829 A0 CAT1B device
471 *
472 * \param base
473 * The pointer to a Cryptolite instance.
474 *
475 * \param p_struct
476 * The pointer to the cy_stc_cryptolite_descr_t.
477 *
478 * \param p_z
479 * The buffer pointer to the store the output.
480 *
481 * \param word_size_z
482 * The size of the p_z buffer in word size.
483 *
484 * \param p_a
485 * The pointer to the operand buffer.
486 *
487 * \param word_size_a
488 * The size of the p_a buffer in word size.
489 *
490 * \return status code. See \ref cy_en_cryptolite_status_t.
491 *
492 * \funcusage
493 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_lsr1_hw
494 *******************************************************************************/
Cy_Cryptolite_Vu_lsr1_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a)495 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_lsr1_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t *p_z,
496 uint32_t word_size_z,
497 uint8_t *p_a,
498 uint32_t word_size_a)
499 {
500 p_struct->data0 = (uint32_t) ((uint32_t)5 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_a-1U) << 8U) | (word_size_a-1U);
501 p_struct->data1 = (uint32_t) p_a;
502 p_struct->data3 = (uint32_t) p_z;
503 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
504 }
505
506
507 /*******************************************************************************
508 * Function Name: Cy_Cryptolite_Vu_lsr_hw
509 ****************************************************************************//**
510 *
511 * Performs right shifting of long integer by shift bits.
512 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
513 * \note This API is not available in CYW20829 A0 CAT1B device
514 *
515 * \param base
516 * The pointer to a Cryptolite instance.
517 *
518 * \param p_struct
519 * The pointer to the cy_stc_cryptolite_descr_t.
520 *
521 * \param p_z
522 * The buffer pointer to the store the output.
523 *
524 * \param word_size_z
525 * The size of the p_z buffer in word size.
526 *
527 * \param p_a
528 * The pointer to the operand buffer.
529 *
530 * \param word_size_a
531 * The size of the p_a buffer in word size.
532 *
533 * \param shift
534 * The number of bits to shift right.
535 *
536 * \return status code. See \ref cy_en_cryptolite_status_t.
537 *
538 * \funcusage
539 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_lsr_hw
540 *******************************************************************************/
Cy_Cryptolite_Vu_lsr_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint32_t shift)541 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_lsr_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t *p_z,
542 uint32_t word_size_z,
543 uint8_t* p_a,
544 uint32_t word_size_a,
545 uint32_t shift)
546 {
547 p_struct->data0 = (uint32_t) ((uint32_t)7 << 28U) | ((word_size_z-1U) << 16U) | (word_size_a-1U);
548 p_struct->data1 = (uint32_t) p_a;
549 p_struct->data2 = shift;
550 p_struct->data3 = (uint32_t) p_z;
551 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
552 }
553
554 /*******************************************************************************
555 * Function Name: Cy_Cryptolite_Vu_xor_hw
556 ****************************************************************************//**
557 *
558 * Performs long integer exclusive-or operation.
559 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
560 * \note This API is not available in CYW20829 A0 CAT1B device
561 *
562 * \param base
563 * The pointer to a Cryptolite instance.
564 *
565 * \param p_struct
566 * The pointer to the cy_stc_cryptolite_descr_t.
567 *
568 * \param p_z
569 * The buffer pointer to the store the output.
570 *
571 * \param word_size_z
572 * The size of the p_z buffer in word size.
573 *
574 * \param p_a
575 * The pointer to the first operand buffer.
576 *
577 * \param word_size_a
578 * The size of the p_a buffer in word size.
579
580 * \param p_b
581 * The pointer to the second operand buffer.
582 *
583 * \param word_size_b
584 * The size of the p_b buffer in word size.
585 *
586 * \return status code. See \ref cy_en_cryptolite_status_t.
587 *
588 * \funcusage
589 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_xor_hw
590 *******************************************************************************/
Cy_Cryptolite_Vu_xor_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint8_t * p_b,uint32_t word_size_b)591 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_xor_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t* p_z,
592 uint32_t word_size_z,
593 uint8_t* p_a,
594 uint32_t word_size_a,
595 uint8_t* p_b,
596 uint32_t word_size_b)
597 {
598 p_struct->data0 = (uint32_t) ((uint32_t)3 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
599 p_struct->data1 = (uint32_t) p_a;
600 p_struct->data2 = (uint32_t) p_b;
601 p_struct->data3 = (uint32_t) p_z;
602 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
603 }
604
605
606
607 /*******************************************************************************
608 * Function Name: Cy_Cryptolite_Vu_cond_sub_hw
609 ****************************************************************************//**
610 *
611 * Performs long integer conditional subtraction operation.
612 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
613 * \note This API is not available in CYW20829 A0 CAT1B device
614 *
615 * \param base
616 * The pointer to a Cryptolite instance.
617 *
618 * \param p_struct
619 * The pointer to the cy_stc_cryptolite_descr_t.
620 *
621 * \param p_z
622 * The buffer pointer to the store the output.
623 *
624 * \param word_size_z
625 * The size of the p_z buffer in word size.
626 *
627 * \param p_a
628 * The pointer to the first operand buffer.
629 *
630 * \param word_size_a
631 * The size of the p_a buffer in word size.
632
633 * \param p_b
634 * The pointer to the second operand buffer.
635 *
636 * \param word_size_b
637 * The size of the p_b buffer in word size.
638 *
639 * \return status code. See \ref cy_en_cryptolite_status_t.
640 *
641 * \funcusage
642 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_VU_cond_sub_hw
643 *******************************************************************************/
Cy_Cryptolite_Vu_cond_sub_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint8_t * p_b,uint32_t word_size_b)644 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_cond_sub_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t *p_z,
645 uint32_t word_size_z,
646 uint8_t *p_a,
647 uint32_t word_size_a,
648 uint8_t *p_b,
649 uint32_t word_size_b)
650 {
651 p_struct->data0 = (uint32_t) (8UL << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
652 p_struct->data1 = (uint32_t) p_a;
653 p_struct->data2 = (uint32_t) p_b;
654 p_struct->data3 = (uint32_t) p_z;
655 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
656 }
657
658 /** \} group_cryptolite_lld_vu_functions */
659
660
661 /*******************************************************************************
662 * Function Name: Cy_Cryptolite_Vu_lsr1_carry_hw
663 ****************************************************************************//**
664 *
665 * Performs right shifting of long integer by shift bits with carry.
666 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
667 * \note This API is not available in CYW20829 A0 CAT1B device
668 *
669 * \param base
670 * The pointer to a Cryptolite instance.
671 *
672 * \param p_struct
673 * The pointer to the cy_stc_cryptolite_descr_t.
674 *
675 * \param p_z
676 * The buffer pointer to the store the output.
677 *
678 * \param word_size_z
679 * The size of the p_z buffer in word size.
680 *
681 * \param p_a
682 * The pointer to the operand buffer.
683 *
684 * \param word_size_a
685 * The size of the p_a buffer in word size.
686 *
687 * \param carry
688 * To set carry value to the bit.
689 *
690 * \param bitsize
691 * The size of the p_z buffer in bits.
692 *
693 * \return status code. See \ref cy_en_cryptolite_status_t.
694 *
695 *******************************************************************************/
Cy_Cryptolite_Vu_lsr1_carry_hw(CRYPTOLITE_Type * base,cy_stc_cryptolite_descr_t * p_struct,uint8_t * p_z,uint32_t word_size_z,uint8_t * p_a,uint32_t word_size_a,uint32_t carry,uint32_t bitsize)696 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Vu_lsr1_carry_hw (CRYPTOLITE_Type *base, cy_stc_cryptolite_descr_t* p_struct, uint8_t *p_z,
697 uint32_t word_size_z,
698 uint8_t *p_a,
699 uint32_t word_size_a,
700 uint32_t carry,
701 uint32_t bitsize)
702 {
703 cy_en_cryptolite_status_t status;
704 p_struct->data0 = (uint32_t) ((uint32_t)5 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_a-1U) << 8U) |(word_size_a-1U);
705 p_struct->data1 = (uint32_t) p_a;
706 p_struct->data2 = (uint32_t) p_a;
707 p_struct->data3 = (uint32_t) p_z;
708
709 status = Cy_Cryptolite_Vu_RunInstr(base, p_struct);
710 Cy_Cryptolite_Vu_wait_hw(base);
711 if(CY_CRYPTOLITE_SUCCESS !=status)
712 {
713 return status;
714 }
715 if((bool)carry)
716 {
717 Cy_Cryptolite_Vu_set_bit(p_z, bitsize-1U);
718 }
719
720 return status;
721 }
722
723
724 #endif /* #if (CPUSS_CRYPTOLITE_VU == 1) */
725
726 #if defined(__cplusplus)
727 }
728 #endif
729
730 #endif /* CY_IP_MXCRYPTOLITE */
731
732 #endif /* #if !defined (CY_CRYPTOLITE_VU_H) */
733
734 /* [] END OF FILE */
735