1 /***************************************************************************//**
2 * \file cy_cryptolite_vu.h
3 * \version 2.50
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 *
167 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
168 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
169 *
170 * \param base
171 * The pointer to a Cryptolite instance.
172 *
173 * \param p_struct
174 * The pointer to the cy_stc_cryptolite_descr_t.
175 *
176 * \param p_z
177 * The buffer pointer to the store the output.
178 *
179 * \param word_size_z
180 * The size of the p_z buffer in word size.
181 *
182 * \param p_a
183 * The pointer to the first operand buffer.
184 *
185 * \param word_size_a
186 * The size of the p_a buffer in word size.
187
188 * \param p_b
189 * The pointer to the second operand buffer.
190 *
191 * \param word_size_b
192 * The size of the p_b buffer in word size.
193 *
194 * \return status code. See \ref cy_en_cryptolite_status_t.
195 *
196 * \funcusage
197 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_mul_hw
198 *******************************************************************************/
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)199 __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,
200 uint32_t word_size_z,
201 uint8_t* p_a,
202 uint32_t word_size_a,
203 uint8_t* p_b,
204 uint32_t word_size_b)
205 {
206 p_struct->data0 = (uint32_t) ((uint32_t)0 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
207 p_struct->data1 = (uint32_t) p_a;
208 p_struct->data2 = (uint32_t) p_b;
209 p_struct->data3 = (uint32_t) p_z;
210 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
211 }
212
213 /*******************************************************************************
214 * Function Name: Cy_Cryptolite_Vu_xmul_hw
215 ****************************************************************************//**
216 *
217 * Performs carry less long integer multiplication operation.
218 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
219 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
220 *
221 * \param base
222 * The pointer to a Cryptolite instance.
223 *
224 * \param p_struct
225 * The pointer to the cy_stc_cryptolite_descr_t.
226 *
227 * \param p_z
228 * The buffer pointer to the store the output.
229 *
230 * \param word_size_z
231 * The size of the p_z buffer in word size.
232 *
233 * \param p_a
234 * The pointer to the first operand buffer.
235 *
236 * \param word_size_a
237 * The size of the p_a buffer in word size.
238
239 * \param p_b
240 * The pointer to the second operand buffer.
241 *
242 * \param word_size_b
243 * The size of the p_b buffer in word size.
244 *
245 * \return status code. See \ref cy_en_cryptolite_status_t.
246 *
247 * \funcusage
248 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_xmul_hw
249 *******************************************************************************/
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)250 __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,
251 uint32_t word_size_z,
252 uint8_t* p_a,
253 uint32_t word_size_a,
254 uint8_t* p_b,
255 uint32_t word_size_b)
256 {
257 p_struct->data0 = (uint32_t) ((uint32_t)4 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
258 p_struct->data1 = (uint32_t) p_a;
259 p_struct->data2 = (uint32_t) p_b;
260 p_struct->data3 = (uint32_t) p_z;
261 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
262 }
263
264
265
266 /*******************************************************************************
267 * Function Name: Cy_Cryptolite_Vu_add_hw
268 ****************************************************************************//**
269 *
270 * Performs long integer addition operation.
271 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
272 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
273 *
274 * \param base
275 * The pointer to a Cryptolite instance.
276 *
277 * \param p_struct
278 * The pointer to the cy_stc_cryptolite_descr_t.
279 *
280 * \param p_z
281 * The buffer pointer to the store the output.
282 *
283 * \param word_size_z
284 * The size of the p_z buffer in word size.
285 *
286 * \param p_a
287 * The pointer to the first operand buffer.
288 *
289 * \param word_size_a
290 * The size of the p_a buffer in word size.
291
292 * \param p_b
293 * The pointer to the second operand buffer.
294 *
295 * \param word_size_b
296 * The size of the p_b buffer in word size.
297 *
298 * \return status code. See \ref cy_en_cryptolite_status_t.
299 *
300 * \funcusage
301 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_add_hw
302 *******************************************************************************/
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)303 __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,
304 uint32_t word_size_z,
305 uint8_t* p_a,
306 uint32_t word_size_a,
307 uint8_t* p_b,
308 uint32_t word_size_b)
309 {
310 p_struct->data0 = (uint32_t) ((uint32_t)1 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
311 p_struct->data1 = (uint32_t) p_a;
312 p_struct->data2 = (uint32_t) p_b;
313 p_struct->data3 = (uint32_t) p_z;
314 /*run instruction*/
315 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
316 }
317
318
319 /*******************************************************************************
320 * Function Name: Cy_Cryptolite_Vu_sub_hw
321 ****************************************************************************//**
322 *
323 * Performs long integer subtraction operation.
324 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
325 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
326 *
327 * \param base
328 * The pointer to a Cryptolite instance.
329 *
330 * \param p_struct
331 * The pointer to the cy_stc_cryptolite_descr_t.
332 *
333 * \param p_z
334 * The buffer pointer to the store the output.
335 *
336 * \param word_size_z
337 * The size of the p_z buffer in word size.
338 *
339 * \param p_a
340 * The pointer to the first operand buffer.
341 *
342 * \param word_size_a
343 * The size of the p_a buffer in word size.
344
345 * \param p_b
346 * The pointer to the second operand buffer.
347 *
348 * \param word_size_b
349 * The size of the p_b buffer in word size.
350 *
351 * \return status code. See \ref cy_en_cryptolite_status_t.
352 *
353 * \funcusage
354 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_sub_hw
355 *******************************************************************************/
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)356 __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,
357 uint32_t word_size_z,
358 uint8_t* p_a,
359 uint32_t word_size_a,
360 uint8_t* p_b,
361 uint32_t word_size_b)
362 {
363 p_struct->data0 = (uint32_t) ((uint32_t)2 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
364 p_struct->data1 = (uint32_t) p_a;
365 p_struct->data2 = (uint32_t) p_b;
366 p_struct->data3 = (uint32_t) p_z;
367 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
368 }
369
370
371
372 /*******************************************************************************
373 * Function Name: Cy_Cryptolite_Vu_mov_hw
374 ****************************************************************************//**
375 *
376 * Performs long integer move operation.
377 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
378 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
379 *
380 * \param base
381 * The pointer to a Cryptolite instance.
382 *
383 * \param p_struct
384 * The pointer to the cy_stc_cryptolite_descr_t.
385 *
386 * \param p_z
387 * The buffer pointer to the store the output.
388 *
389 * \param word_size_z
390 * The size of the p_z buffer in word size.
391 *
392 * \param p_a
393 * The pointer to the operand buffer.
394 *
395 * \param word_size_a
396 * The size of the p_a buffer in word size.
397 *
398 * \return status code. See \ref cy_en_cryptolite_status_t.
399 *
400 * \funcusage
401 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_mov_hw
402 *******************************************************************************/
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)403 __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,
404 uint32_t word_size_z,
405 uint8_t* p_a,
406 uint32_t word_size_a)
407 {
408 p_struct->data0 = (uint32_t) (9UL << 28U) | ((word_size_z-1U) << 16U) | (word_size_a-1U);
409 p_struct->data1 = (uint32_t) p_a;
410 p_struct->data3 = (uint32_t) p_z;
411 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
412 }
413
414
415
416
417 /*******************************************************************************
418 * Function Name: Cy_Cryptolite_Vu_lsl1_hw
419 ****************************************************************************//**
420 *
421 * Performs left shifting of long integer by one bit.
422 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
423 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
424 *
425 * \param base
426 * The pointer to a Cryptolite instance.
427 *
428 * \param p_struct
429 * The pointer to the cy_stc_cryptolite_descr_t.
430 *
431 * \param p_z
432 * The buffer pointer to the store the output.
433 *
434 * \param word_size_z
435 * The size of the p_z buffer in word size.
436 *
437 * \param p_a
438 * The pointer to the operand buffer.
439 *
440 * \param word_size_a
441 * The size of the p_a buffer in word size.
442 *
443 * \return status code. See \ref cy_en_cryptolite_status_t.
444 *
445 * \funcusage
446 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_lsl1_hw
447 *******************************************************************************/
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)448 __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,
449 uint32_t word_size_z,
450 uint8_t* p_a,
451 uint32_t word_size_a)
452 {
453 p_struct->data0 = (uint32_t) ((uint32_t)6 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_a-1U) << 8U)| (word_size_a-1U);
454 p_struct->data1 = (uint32_t) p_a;
455 p_struct->data3 = (uint32_t) p_z;
456
457 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
458
459
460 }
461
462
463
464
465 /*******************************************************************************
466 * Function Name: Cy_Cryptolite_Vu_lsr1_hw
467 ****************************************************************************//**
468 *
469 * Performs right shifting of long integer by one bit.
470 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
471 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
472 *
473 * \param base
474 * The pointer to a Cryptolite instance.
475 *
476 * \param p_struct
477 * The pointer to the cy_stc_cryptolite_descr_t.
478 *
479 * \param p_z
480 * The buffer pointer to the store the output.
481 *
482 * \param word_size_z
483 * The size of the p_z buffer in word size.
484 *
485 * \param p_a
486 * The pointer to the operand buffer.
487 *
488 * \param word_size_a
489 * The size of the p_a buffer in word size.
490 *
491 * \return status code. See \ref cy_en_cryptolite_status_t.
492 *
493 * \funcusage
494 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_lsr1_hw
495 *******************************************************************************/
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)496 __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,
497 uint32_t word_size_z,
498 uint8_t *p_a,
499 uint32_t word_size_a)
500 {
501 p_struct->data0 = (uint32_t) ((uint32_t)5 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_a-1U) << 8U) | (word_size_a-1U);
502 p_struct->data1 = (uint32_t) p_a;
503 p_struct->data3 = (uint32_t) p_z;
504 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
505 }
506
507
508 /*******************************************************************************
509 * Function Name: Cy_Cryptolite_Vu_lsr_hw
510 ****************************************************************************//**
511 *
512 * Performs right shifting of long integer by shift bits.
513 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
514 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
515 *
516 * \param base
517 * The pointer to a Cryptolite instance.
518 *
519 * \param p_struct
520 * The pointer to the cy_stc_cryptolite_descr_t.
521 *
522 * \param p_z
523 * The buffer pointer to the store the output.
524 *
525 * \param word_size_z
526 * The size of the p_z buffer in word size.
527 *
528 * \param p_a
529 * The pointer to the operand buffer.
530 *
531 * \param word_size_a
532 * The size of the p_a buffer in word size.
533 *
534 * \param shift
535 * The number of bits to shift right.
536 *
537 * \return status code. See \ref cy_en_cryptolite_status_t.
538 *
539 * \funcusage
540 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_lsr_hw
541 *******************************************************************************/
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)542 __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,
543 uint32_t word_size_z,
544 uint8_t* p_a,
545 uint32_t word_size_a,
546 uint32_t shift)
547 {
548 p_struct->data0 = (uint32_t) ((uint32_t)7 << 28U) | ((word_size_z-1U) << 16U) | (word_size_a-1U);
549 p_struct->data1 = (uint32_t) p_a;
550 p_struct->data2 = shift;
551 p_struct->data3 = (uint32_t) p_z;
552 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
553 }
554
555 /*******************************************************************************
556 * Function Name: Cy_Cryptolite_Vu_xor_hw
557 ****************************************************************************//**
558 *
559 * Performs long integer exclusive-or operation.
560 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
561 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
562 *
563 * \param base
564 * The pointer to a Cryptolite instance.
565 *
566 * \param p_struct
567 * The pointer to the cy_stc_cryptolite_descr_t.
568 *
569 * \param p_z
570 * The buffer pointer to the store the output.
571 *
572 * \param word_size_z
573 * The size of the p_z buffer in word size.
574 *
575 * \param p_a
576 * The pointer to the first operand buffer.
577 *
578 * \param word_size_a
579 * The size of the p_a buffer in word size.
580
581 * \param p_b
582 * The pointer to the second operand buffer.
583 *
584 * \param word_size_b
585 * The size of the p_b buffer in word size.
586 *
587 * \return status code. See \ref cy_en_cryptolite_status_t.
588 *
589 * \funcusage
590 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Vu_xor_hw
591 *******************************************************************************/
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)592 __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,
593 uint32_t word_size_z,
594 uint8_t* p_a,
595 uint32_t word_size_a,
596 uint8_t* p_b,
597 uint32_t word_size_b)
598 {
599 p_struct->data0 = (uint32_t) ((uint32_t)3 << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
600 p_struct->data1 = (uint32_t) p_a;
601 p_struct->data2 = (uint32_t) p_b;
602 p_struct->data3 = (uint32_t) p_z;
603 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
604 }
605
606
607
608 /*******************************************************************************
609 * Function Name: Cy_Cryptolite_Vu_cond_sub_hw
610 ****************************************************************************//**
611 *
612 * Performs long integer conditional subtraction operation.
613 * \note The pointers p_a, p_b & p_z must be 4 byte aligned and end in 4 byte boundary.
614 * \note User should use the function CY_REMAP_ADDRESS_CRYPTOLITE() to get the remapped address and use it for all the VU operations.
615 *
616 * \param base
617 * The pointer to a Cryptolite instance.
618 *
619 * \param p_struct
620 * The pointer to the cy_stc_cryptolite_descr_t.
621 *
622 * \param p_z
623 * The buffer pointer to the store the output.
624 *
625 * \param word_size_z
626 * The size of the p_z buffer in word size.
627 *
628 * \param p_a
629 * The pointer to the first operand buffer.
630 *
631 * \param word_size_a
632 * The size of the p_a buffer in word size.
633
634 * \param p_b
635 * The pointer to the second operand buffer.
636 *
637 * \param word_size_b
638 * The size of the p_b buffer in word size.
639 *
640 * \return status code. See \ref cy_en_cryptolite_status_t.
641 *
642 * \funcusage
643 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_VU_cond_sub_hw
644 *******************************************************************************/
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)645 __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,
646 uint32_t word_size_z,
647 uint8_t *p_a,
648 uint32_t word_size_a,
649 uint8_t *p_b,
650 uint32_t word_size_b)
651 {
652 p_struct->data0 = (uint32_t) (8UL << 28U) | ((word_size_z-1U) << 16U) | ((word_size_b-1U) << 8U) | (word_size_a-1U);
653 p_struct->data1 = (uint32_t) p_a;
654 p_struct->data2 = (uint32_t) p_b;
655 p_struct->data3 = (uint32_t) p_z;
656 return Cy_Cryptolite_Vu_RunInstr(base, p_struct);
657 }
658
659 /** \} group_cryptolite_lld_vu_functions */
660
661
662 /*******************************************************************************
663 * Function Name: Cy_Cryptolite_Vu_lsr1_carry_hw
664 ****************************************************************************//**
665 *
666 * Performs right shifting of long integer by shift bits with carry.
667 * \note The pointers p_a & p_z must be 4 byte aligned and end in 4 byte boundary.
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