1 /***************************************************************************//**
2 * \file cy_crypto.h
3 * \version 2.120
4 *
5 * \brief
6 *  This file provides the public interface for the Crypto driver.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright (c) (2020-2022), Cypress Semiconductor Corporation (an Infineon company) or
11 * an affiliate of Cypress Semiconductor Corporation.
12 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 *    http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 *******************************************************************************/
26 
27 /**
28 * \addtogroup group_crypto
29 * \{
30 * \note IP Supported: CRYPTO
31 * \note Device Categories: CAT1A & CAT1C. Please refer <a href="usergroup1.html">Device Catalog</a>.
32 *
33 * The Crypto driver provides a public API to perform cryptographic and hash
34 * operations, as well as generate both true and pseudo random numbers.
35 *
36 * It uses a hardware IP block to accelerate operations.
37 *
38 * The functions and other declarations used in this driver are in cy_crypto.h,
39 * cy_crypto_core.h, and cy_crypto_server.h. You can also include cy_pdl.h
40 * to get access to all functions and declarations in the PDL.
41 *
42 * The driver implements two usage models:
43 * * \ref group_crypto_cli_srv
44 * * \ref group_crypto_lld_api
45 *
46 * Mixing these usage models will result in undefined behaviour.
47 *
48 * The Crypto driver supports these standards: DES, TDES, AES (128, 192, 256 bits), CMAC-AES, SHA,
49 * HMAC, PRNG, TRNG, CRC, RSA, ECP, and ECDSA.
50 * \note ECP and ECDSA are only implemented for the \ref group_crypto_lld_api model.
51 *
52 * \section group_crypto_configuration_considerations Configuration Considerations
53 *
54 * User can enable/disable cryptographic functionality based on the project
55 * requirements. To do so, create a configuration header file to configure cryptographic
56 * functionalities and define a macro CY_CRYPTO_USER_CONFIG_FILE with configuration
57 * header file name and add to project environment. If CY_CRYPTO_USER_CONFIG_FILE macro
58 * is not defined in project environment, firmware will enable all available
59 * cryptographic functionalities.
60 *
61 * Firmware sets up a cryptographic operation by passing in the required data as
62 * parameters in the function calls.
63 *
64 * All Crypto functions require a context. A context is a data
65 * structure that the driver uses for its operations. Firmware declares a
66 * context (allocates memory) but does not write or read the values in that
67 * context. In effect, the context is a scratch pad you provide to the driver.
68 * The driver uses the context to store and manipulate data during cryptographic
69 * operations.
70 *
71 * Several methods require an additional context unique to the particular
72 * cryptographic technique.
73 * The Crypto driver header files declare all the required structures for both
74 * configuration and context.
75 *
76 * Some encryption techniques require additional initialization specific to the
77 * technique. If there is an Init function, you must call it before using any
78 * other function for that technique, and re-initialize after you use a different
79 * encryption technique.
80 *
81 * For example, use \ref Cy_Crypto_Aes_Init to configure an AES encryption
82 * operation with the encryption key, and key length.
83 * Provide pointers to two context structures. You can then call the AES Run functions.
84 * If you use DES after that, you must re-initialize the AES encryption before using
85 * it again.
86 *
87 * \section group_crypto_definitions Definitions
88 *
89 * <table class="doxtable">
90 *   <tr>
91 *     <th>Term</th>
92 *     <th>Definition</th>
93 *   </tr>
94 *
95 *   <tr>
96 *     <td>Plaintext</td>
97 *     <td>An unencrypted message</td>
98 *   </tr>
99 *
100 *   <tr>
101 *     <td>Ciphertext</td>
102 *     <td>An encrypted message</td>
103 *   </tr>
104 *
105 *   <tr>
106 *     <td>Block Cipher</td>
107 *     <td>An encryption function for fixed-size blocks of data.
108 *     This function takes a fixed-size key and a block of plaintext data from
109 *     the message and encrypts it to generate ciphertext. Block ciphers are
110 *     reversible. The function performed on a block of encrypted data will
111 *     decrypt that data.</td>
112 *   </tr>
113 *
114 *   <tr>
115 *     <td>Block Cipher Mode</td>
116 *     <td>A mode of encrypting a message using block ciphers for messages of an
117 *     arbitrary length. The message is padded so that its length is an integer
118 *     multiple of the block size. ECB (Electronic Code Book), CBC (Cipher Block
119 *     Chaining), and CFB (Cipher Feedback) are all modes of using block ciphers
120 *     to create an encrypted message of an arbitrary length.
121 *     </td>
122 *   </tr>
123 *
124 *   <tr>
125 *     <td>Data Encryption Standard (DES)</td>
126 *     <td>The [DES standard]
127 *     (https://csrc.nist.gov/csrc/media/publications/fips/46/3/archive/1999-10-25/documents/fips46-3.pdf)
128 *     specifies a symmetric-key algorithm for encryption of electronic data.
129 *     It uses a 56-bit key. The block size is 64-bits.
130 *     </td>
131 *   </tr>
132 *
133 *   <tr>
134 *     <td>Triple DES (3DES or TDES)</td>
135 *     <td>The [TDES standard]
136 *     (https://csrc.nist.gov/csrc/media/publications/fips/46/3/archive/1999-10-25/documents/fips46-3.pdf)
137 *     specifies a symmetric-key block cipher that applies the Data Encryption
138 *     Standard (DES) cipher algorithm three times to each data block.
139 *     It uses three 56-bit keys. The block size is 64-bits.
140 *     </td>
141 *   </tr>
142 *
143 *   <tr>
144 *     <td>Advanced Encryption Standard (AES)</td>
145 *     <td>The [AES standard] (https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.197.pdf)
146 *     specifies the Rijndael algorithm, a symmetric block
147 *     cipher that can process 128-bit data blocks, using cipher keys with
148 *     128-, 192-, and 256-bit lengths. Rijndael was designed to handle
149 *     additional block sizes and key lengths. However, they are not adopted in
150 *     this standard. AES is also used for message authentication.
151 *     </td>
152 *   </tr>
153 *
154 *   <tr>
155 *     <td>Secure Hash Algorithm (SHA)</td>
156 *     <td>A cryptographic hash function.
157 *     This function takes a message of an arbitrary length and reduces it to a
158 *     fixed-length residue or message digest after performing a series of
159 *     mathematically defined operations that practically guarantee that any
160 *     change in the message will change the hash value. It is used for message
161 *     authentication by transmitting a message with a hash value appended to it
162 *     and recalculating the message hash value using the same algorithm at the
163 *     recipient's end. If the hashes differ, then the message is corrupted.
164 *     For more information see [Secure Hash standard description]
165 *     (https://csrc.nist.gov/csrc/media/publications/fips/180/2/archive/2002-08-01/documents/fips180-2.pdf).
166 *     </td>
167 *   </tr>
168 *
169 *   <tr>
170 *     <td>Message Authentication Code (MAC)</td>
171 *     <td>MACs are used to verify that a received message has not been altered.
172 *     This is done by first computing a MAC value at the sender's end and
173 *     appending it to the transmitted message. When the message is received,
174 *     the MAC is computed again and checked against the MAC value transmitted
175 *     with the message. If they do not match, the message has been altered.
176 *     Either a Hash algorithm (such as SHA) or a block cipher (such as AES) can
177 *     be used to produce the MAC value. Keyed MAC schemes use a Secret Key
178 *     along with the message, thus the Key value must be known to be able to
179 *     compute the MAC value.</td>
180 *   </tr>
181 *
182 *   <tr>
183 *     <td>Cipher-based Message Authentication Code (CMAC)</td>
184 *     <td>A block cipher-based message authentication code algorithm.
185 *     It computes the MAC value using the AES block cipher algorithm.</td>
186 *     For more information see [Recommendation for Block Cipher Modes of Operation]
187 *     (https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-38b.pdf).
188 *   </tr>
189 *
190 *   <tr>
191 *     <td>Hash Message Authentication Code (HMAC)</td>
192 *     <td>A specific type of message authentication code (MAC) that involves a
193 *     cryptographic hash function and a secret cryptographic key.
194 *     It computes the MAC value using a Hash algorithm.
195 *     For more information see [The Keyed-Hash Message Authentication Code standard]
196 *     (https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.198-1.pdf)
197 *     </td>
198 *   </tr>
199 *
200 *   <tr>
201 *     <td>Pseudo Random Number Generator (PRNG)</td>
202 *     <td>A Linear Feedback Shift Registers-based algorithm for generating a
203 *     sequence of numbers starting from a non-zero seed.</td>
204 *   </tr>
205 *
206 *   <tr>
207 *     <td>True Random Number Generator (TRNG)</td>
208 *     <td>A block that generates a number that is statistically random and based
209 *     on some physical random variation. The number cannot be duplicated by
210 *     running the process again.</td>
211 *   </tr>
212 *
213 *   <tr>
214 *     <td>Symmetric Key Cryptography</td>
215 *     <td>Uses a common, known key to encrypt and decrypt messages (a shared
216 *     secret between sender and receiver). An efficient method used for
217 *     encrypting and decrypting messages after the authenticity of the other
218 *     party has been established. DES (now obsolete), 3DES, and AES (currently
219 *     used) are well-known symmetric cryptography methods.</td>
220 *   </tr>
221 *
222 *   <tr>
223 *     <td>Asymmetric Key Cryptography</td>
224 *     <td>Also referred to as Public Key encryption. To receive a message,
225 *     you publish a very large public key (up to 4096 bits currently). The
226 *     public key is described by the pair (n, e) where n is a product of
227 *     two randomly chosen primes p and q. The exponent e is a random integer
228 *     1 < e < Q where Q = (p-1) (q-1). The private key d is uniquely defined
229 *     by the integer 1 < d < Q so that ed congruent with 1 (mod Q ). To send
230 *     a message to the publisher of the public key, you encrypt the message
231 *     with the public key. This message can now be decrypted only with the
232 *     private key. The message is now sent over any channel to the recipient
233 *     who can decrypt it with the private (secret) key. The same process is
234 *     used to send messages to the sender of the original message. The
235 *     asymmetric cryptography relies on the mathematical impracticality
236 *     (usually related to the processing power available at any given time)
237 *     of factoring the keys.
238 *     </td>
239 *   </tr>
240 * </table>
241 *
242 * \section group_crypto_more_information More Information
243 *
244 * RSASSA-PKCS1-v1_5 described here, page 31:
245 * https://www.rfc-editor.org/rfc/pdfrfc/rfc8017.txt.pdf
246 *
247 * See the "Cryptographic Function Block" chapter of the Technical Reference Manual.
248 *
249 * \section group_crypto_changelog Changelog
250 * <table class="doxtable">
251 *   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
252 *   <tr>
253 *     <td rowspan="2">2.120</td>
254 *     <td>
255 *         <ul>
256 *         <li>Added new enums \ref cy_en_eddsa_sig_type_t , updated enums \ref cy_en_crypto_ecc_curve_id_t and ED25519 macros.<br>
257 *         <li>Added new APIs \ref Cy_Crypto_Core_ED25519_Sign, \ref Cy_Crypto_Core_ED25519_PointMultiplication,
258 *             \ref Cy_Crypto_Core_ED25519_Verify, \ref Cy_Crypto_Core_ED25519_MakePublicKey. </td>
259 *         </ul>
260 *     <td>Added EDDSA Hardware acceleration for CAT1A and CAT1C MCUs.</td>
261 *   </tr>
262 *   <tr>
263 *     <td>Updated structures \ref cy_stc_crypto_aes_buffers_t, \ref cy_stc_crypto_aes_state_t, \ref cy_stc_crypto_aes_ccm_buffers_t
264 *            \ref cy_stc_crypto_aes_gcm_buffers_t, \ref cy_stc_crypto_aes_gcm_state_t, \ref cy_stc_crypto_sha_state_t.</td>
265 *     <td>Fixed AES CCM, GCM and SHA algorithm issues with DCache enablement on CAT1C device. </td>
266 *   </tr>
267 *   <tr>
268 *     <td> 2.110</td>
269 *     <td>Fixed data synchronization barrier issue in AES</td>
270 *     <td></td>
271 *   </tr>
272 *   <tr>
273 *     <td> 2.100</td>
274 *     <td>Added SHA3, HKDF, AES multistage support for modes ECB, CBC, CFB CTR added</td>
275 *     <td></td>
276 *   </tr>
277 *   <tr>
278 *     <td> 2.90</td>
279 *     <td>Updated internal APIs and bug fixes.</td>
280 *     <td>Fixed GCM initialization and coverity bugs.</td>
281 *   </tr>
282 *   <tr>
283 *     <td> 2.80</td>
284 *     <td>Added AES GCM support.</td>
285 *     <td>Driver enhancement.</td>
286 *   </tr>
287 *   <tr>
288 *     <td> 2.70</td>
289 *     <td>Added TRNG enhancements to support health monitor check.</td>
290 *     <td>Driver enhancement and new feature addition.</td>
291 *   </tr>
292 *   <tr>
293 *     <td> 2.60</td>
294 *     <td>
295 *         <ul>
296 *         <li>Added support for compile time crypto functionality selection with user defined
297 *             config header. By default, all crypto features supported will be enabled.<br>
298 *         <li>Added new API \ref Cy_Crypto_Core_Rsa_Verify_Ext to support verification of PKCS 1.5
299 *             signatures with CY_CRYPTO_MODE_SHA_NONE, which was unsupported in existing
300 *             \ref Cy_Crypto_Core_Rsa_Verify.</td>
301 *         </ul>
302 *     <td>Driver enhancement and new feature addition.</td>
303 *   </tr>
304 *   <tr>
305 *     <td> 2.50</td>
306 *     <td>Fixed the Cy_Crypto_Core_ECC_VerifyHash() and an internal function behaviour
307 *         to support 0 hash message. Resolved MISRA 2012 standard defects.</td>
308 *     <td>Defect fixing and MISRA 2012 compliance.</td>
309 *   </tr>
310 *   <tr>
311 *     <td>2.40</td>
312 *     <td>
313 *         Resolve MISRA 2012 standard defects.
314 *     </td>
315 *     <td>
316 *         MISRA 2012 compliance.
317 *     </td>
318 *   </tr>
319 *   <tr>
320 *     <td>2.30.4</td>
321 *     <td>
322 *         Updated code snippets for client-server usage model.
323 *     </td>
324 *     <td>
325 *         Documentation enhancement.
326 *     </td>
327 *   </tr>
328 *   <tr>
329 *     <td>2.30.3</td>
330 *     <td>
331 *         Minor documentation updates.
332 *     </td>
333 *     <td>
334 *         Documentation enhancement.
335 *     </td>
336 *   </tr>
337 *   <tr>
338 *     <td>2.30.2</td>
339 *     <td>
340 *         Code formatting cleanup, updated copyright date.
341 *     </td>
342 *     <td>
343 *         PDL project update.
344 *     </td>
345 *   </tr>
346 *   <tr>
347 *     <td>2.30.1</td>
348 *     <td>
349 *         Added a C++ namespace guards.
350 *     </td>
351 *     <td>
352 *         Make a driver code to be compatible with C++.
353 *     </td>
354 *   </tr>
355 *   <tr>
356 *     <td>2.30</td>
357 *     <td>
358 *         <ul>
359 *         <li>Added a multi-instance support for AES and SHA.</li>
360 *         <li>Added a small chunks mode for SHA with any chunk size (from one
361 *             byte).</li>
362 *         <li>Added the operation memory buffer management (set a new address,
363 *             get a size).</li>
364 *         <li>Added a support for ARM Compiler 6.</li>
365 *         </ul>
366 *     </td>
367 *     <td>Integration with mbedOS/mbedTLS, restructured the implementation of
368 *         AES and SHA for the Crypto ALT interface.
369 *     </td>
370 *   </tr>
371 *   <tr>
372 *     <td>2.20</td>
373 *     <td>
374 *         <ul>
375 *         <li>Moved from a pre-compiled library to Open Source under
376 *             Apache 2.0 license.</li>
377 *         <li>Core (server) This API is now available.</li>
378 *         <li>Added ECP and ECDSA support for the NIST P curves:
379 *             SECP192R1, SECP224R1, SECP256R1, SECP384R1, SECP521R1.</li>
380 *         <li>ECP and ECDSA only supported with direct calls to Crypto APIs,
381 *             no client interface functions are present.</li>
382 *         <li>Added Chunk mode for CRC.</li>
383 *         <li>Added Chunk mode for SHA, the chunk size is limited to
384 *             the SHA block size.</li>
385 *         </ul>
386 *     </td>
387 *     <td>ECC support added.<br>
388 *         Integration with mbedOS/mbedTLS, restructured the implementation of
389 *         SHA and CRC for the Crypto ALT interface.
390 *     </td>
391 *   </tr>
392 *   <tr>
393 *     <td>2.11b</td>
394 *     <td>The same as production 2.10; only the newly-added Elliptic Curve point
395 *     multiplication functionality (NIST P256) is pre-production.
396 *     Open source under Apache version 2.0 license.</td>
397 *     <td></td>
398 *   </tr>
399 *   <tr>
400 *     <td>2.11</td>
401 *     <td>Based on pre-production 2.10, except the newly-added Elliptic Curve point
402 *     multiplication functionality (NIST P256).
403 *     Does not incorporate the production level documentation.
404 *     Open source under Apache version 2.0 license.</td>
405 *     <td>ECC support.</td>
406 *   </tr>
407 *   <tr>
408 *     <td>2.10b</td>
409 *     <td>The same as production 2.10. Open source under Apache version 2.0 license.</td>
410 *     <td></td>
411 *   </tr>
412 *   <tr>
413 *     <td rowspan="4">2.10</td>
414 *     <td>Flattened the organization of the driver source code into the single
415 *         source directory and the single include directory.
416 *     </td>
417 *     <td>Driver library directory-structure simplification.</td>
418 *   </tr>
419 *   <tr>
420 *     <td>Removed files with the default driver configuration. \n
421 *     Added API functions to start different server functionality:
422 *         - Cy_Crypto_Server_Start_Base
423 *         - Cy_Crypto_Server_Start_Extra
424 *         - Cy_Crypto_Server_Start_Full
425 *     </td>
426 *     <td></td>
427 *   </tr>
428 *   <tr>
429 *     <td>Added the register access layer. Use register access macros instead
430 *         of direct register access using dereferenced pointers.</td>
431 *     <td>Makes register access device-independent, so that the PDL does
432 *         not need to be recompiled for each supported part number.</td>
433 *   </tr>
434 *   <tr>
435 *     <td>Added precompiled libraries for the IAR toolchain.</td>
436 *     <td>IAR toolchain support in ModusToolbox.</td>
437 *   </tr>
438 *   <tr>
439 *     <td>2.0b</td>
440 *     <td>The same as production 2.0. Open source under Apache version 2.0 license.</td>
441 *     <td></td>
442 *   </tr>
443 *   <tr>
444 *     <td rowspan="2">2.0</td>
445 *     <td>Clarified what parameters must be 4-byte aligned for the functions:
446 *         \ref Cy_Crypto_Aes_Cmac_Run, \ref Cy_Crypto_Sha_Run,
447 *         \ref Cy_Crypto_Hmac_Run, \ref Cy_Crypto_Str_MemCmp,
448 *         \ref Cy_Crypto_Trng_Generate, \ref Cy_Crypto_Des_Run,
449 *         \ref Cy_Crypto_Tdes_Run, \ref Cy_Crypto_Rsa_Proc
450 *     </td>
451 *     <td>Documentation update and clarification.</td>
452 *   </tr>
453 *   <tr>
454 *     <td>
455 *         Changed crypto IP power control.<br>
456 *         Enhanced Vector Unit functionality for RSA crypto algorithm.<br>
457 *         Added support of the single-core devices.
458 *     </td>
459 *     <td>New device support.</td>
460 *   </tr>
461 *   <tr>
462 *     <td>1.0</td>
463 *     <td>Initial version</td>
464 *     <td></td>
465 *   </tr>
466 * </table>
467 *
468 * \defgroup group_crypto_cli_srv Client-Server Model
469 * \{
470 *   \defgroup group_crypto_cli_srv_macros Macros
471 *   \defgroup group_crypto_cli_srv_functions Functions
472 *   \{
473 *     \defgroup group_crypto_cli_functions Client Functions
474 *     \defgroup group_crypto_srv_functions Server Functions
475 *   \}
476 *   \defgroup group_crypto_cli_srv_data_structures Data Structures
477 *   \{
478 *     \defgroup group_crypto_config_structure Common Data Structures
479 *     \defgroup group_crypto_cli_data_structures Client Data Structures
480 *     \defgroup group_crypto_srv_data_structures Server Data Structures
481 *   \}
482 * \}
483 * \defgroup group_crypto_lld_api Direct Crypto Core Access
484 * \defgroup group_crypto_data_structures Common Data Structures
485 * \defgroup group_crypto_enums Common Enumerated Types
486 */
487 
488 /**
489 * \addtogroup group_crypto_cli_srv
490 * \{
491 *   Use the client-server API to isolate the Crypto hardware from non-secure
492 *   application access.
493 *
494 *   The functions and other declarations used in this part of the driver are in
495 *   cy_crypto.h and cy_crypto_server.h. You can also include cy_pdl.h
496 *   to get access to all functions and declarations in the
497 *   PDL.
498 *
499 *   The firmware initializes and starts the Crypto server. The server can run on any
500 *   core and works with the Crypto hardware. The Crypto server is implemented as
501 *   a secure block. It performs all cryptographic operations for the client.
502 *   Access to the server is through the Inter Process Communication (IPC) driver.
503 *   Direct access is not allowed.
504 *
505 *   The Crypto client can run on any core too. The firmware initializes and starts
506 *   the client. The firmware then provides configuration data required for
507 *   the desired cryptographic technique and a request that the server run the
508 *   cryptographic operation.
509 *
510 *   Note that Client-server model is not supported when DCache is enabled.
511 *
512 * This document contains the following topics:
513 *   - \ref group_crypto_architecture
514 *   - \ref group_crypto_configuration_structure
515 *   - \ref group_crypto_server_init
516 *   - \ref group_crypto_client_init
517 *   - \ref group_crypto_common_use_cases
518 *   - \ref group_crypto_rsa_considerations
519 *   - \ref group_crypto_irq_implements
520 *   - \ref group_crypto_definitions
521 *   - \ref group_crypto_more_information
522 *
523 * \section group_crypto_architecture Architectural model
524 * The client-server implementation uses:
525 *   - one IPC channel for data exchange between client and server applications;
526 *   - three interrupts: an IPC notify interrupt, an IPC release interrupt, and
527 *     an interrupt for error handling.
528 *
529 * Firmware initializes and starts the Crypto server. The server can run on
530 * any core and works with the Crypto hardware.
531 * The Crypto server is implemented as a secure block. It performs all
532 * cryptographic operations for the client. Access to the server is through the
533 * Inter Process Communication (IPC) driver. Direct access is not allowed.
534 *
535 * The Crypto client can also run on any core. Firmware initializes and starts
536 * the client. The firmware then provides the configuration data required for the
537 * desired cryptographic technique, and requests that the server run the
538 * cryptographic operation.
539 *
540 * \note
541 * Only one Crypto server and only one Crypto client can be run at the same time
542 * on any core. So, valid configurations are:
543 * - one server instance runs on CM0+ and one client instance on CM4 (and vice versa).
544 * - one server instance and one client instance run on CM0+
545 *   (__** This is not recommended, use Direct Crypto API's to perform Crypto
546 *   operations on a single core__).
547 * - one server instance and one client instance run on CM4
548 *   (__** This is not recommended, use Direct Crypto API's to perform Crypto
549 *   operations on a single core__).
550 *
551 * \image html crypto_architecture.png
552 *
553 * IPC communication between the client and server is completely transparent.
554 * Using IPC for communication provides a simple synchronization mechanism to
555 * handle concurrent requests from different cores.
556 *
557 * \section group_crypto_configuration_structure Configuration Structure
558 *
559 * IPC communication for the Crypto driver is handled transparently. User should
560 * select the IPC channel, and configure the required notify, release, and error
561 * interrupts.
562 *
563 * These initialization routines, \ref Cy_Crypto_Server_Start (server)
564 * and \ref Cy_Crypto_Init (client), use separate instances of the same
565 * cy_stc_crypto_config_t configuration structure. Some fields should be the same,
566 * and some are set specifically by either the server or client. The table lists
567 * each field in the config structure, and which initialization routine sets the
568 * value.
569 *
570 * <table>
571 * <tr><th>Field</th><th>Which</th><th>Description</th><th>Notes</th></tr>
572 * <tr>
573 * <td>\link cy_stc_crypto_config_t::ipcChannel ipcChannel\endlink</td>
574 * <td>Server and Client</td>
575 * <td>IPC channel for communication between client and server</td>
576 * <td>IPC Channel, same for both</td>
577 * </tr>
578 * <tr>
579 * <td>\link cy_stc_crypto_config_t::acquireNotifierChannel acquireNotifierChannel\endlink</td>
580 * <td>Server and Client</td>
581 * <td>IPC interrupt structure used for the new request notifications</td>
582 * <td>Notify interrupt number, for Server side only</td>
583 * </tr>
584 * <tr>
585 * <td>\link cy_stc_crypto_config_t::releaseNotifierChannel releaseNotifierChannel\endlink</td>
586 * <td>Server and Client</td>
587 * <td>IPC interrupt structure used for data ready notifications. Used to call
588 *     userCompleteCallback handler function.</td>
589 * <td>Release interrupt number, for Client side only</td>
590 * </tr>
591 * <tr>
592 * <td>\link cy_stc_crypto_config_t::userCompleteCallback userCompleteCallback\endlink</td>
593 * <td>Client</td>
594 * <td>User-defined callback for the Release interrupt handler; can be NULL</td>
595 * <td>See Implementing Crypto Interrupts</td>
596 * </tr>
597 * <tr>
598 * <td>\link cy_stc_crypto_config_t::releaseNotifierConfig releaseNotifierConfig \endlink</td>
599 * <td>Client</td>
600 * <td>IRQ handler settings for data ready notifications. This interrupt occurs
601 * when server completely processed all input data and released an IPC
602 * communication channel.</td>
603 * <td>configuration for the interrupt</td>
604 * </tr>
605 * <tr>
606 * <td>\link cy_stc_crypto_config_t::userGetDataHandler userGetDataHandler\endlink</td>
607 * <td>Server</td>
608 * <td>User-defined function to override default interrupt handler; NULL = use default</td>
609 * <td>ISR for the Notify interrupt</td>
610 * </tr>
611 * <tr>
612 * <td>\link cy_stc_crypto_config_t::acquireNotifierConfig acquireNotifierConfig\endlink</td>
613 * <td>Server</td>
614 * <td>IRQ handler settings for new request notifications. This interrupt occurs
615 * when client sent a new request for processing.</td>
616 * <td>configuration for the interrupt</td>
617 * </tr>
618 * <tr>
619 * <td>\link cy_stc_crypto_config_t::userErrorHandler userErrorHandler\endlink</td>
620 * <td>Server</td>
621 * <td>User-defined function to override default interrupt handler; NULL = use default</td>
622 * <td>ISR for a server error</td>
623 * </tr>
624 * <tr>
625 * <td>\link cy_stc_crypto_config_t::cryptoErrorIntrConfig cryptoErrorIntrConfig\endlink</td>
626 * <td>Server</td>
627 * <td>IRQ handler settings for hardware error events</td>
628 * <td>configuration for the interrupt</td>
629 * </tr>
630 * </table>
631 *
632 * \section group_crypto_server_init Server Initialization
633 *
634 * Use a \ref Cy_Crypto_Server_Start function.
635 * Provide the configuration parameters (cy_stc_crypto_config_t) and a pointer
636 * to the server context (cy_stc_crypto_server_context_t) that will be used to
637 * store all temporary data.
638 *
639 * \snippet crypto/snippet/main.c snippet_myCryptoServerStart
640 *
641 * Because the two cores operate asynchronously, ensure that server
642 * initialization is complete before initializing the client.
643 * There are several ways to do this:
644 *
645 *   - Use \ref Cy_Crypto_Sync as a blocking call, before initializing the client.
646 *   - Enable the CM4 core (\ref Cy_SysEnableCM4) after
647 *     Crypto Server Start executes successfully.
648 *   - Check the return status from calls to \ref Cy_Crypto_Init or
649 *     \ref Cy_Crypto_Enable to ensure \ref CY_CRYPTO_SUCCESS.
650 *
651 * All crypto operations are asynchronous. To ensure that any crypto operation
652 * is complete and the result is valid, use \ref Cy_Crypto_Sync.
653 * Use the \ref CY_CRYPTO_SYNC_NON_BLOCKING parameter to check status.
654 * Use \ref CY_CRYPTO_SYNC_BLOCKING  to wait for the operation to complete.
655 *
656 * \section group_crypto_client_init Client initialization
657 *
658 * Use \ref Cy_Crypto_Init to initialize the Crypto client with the configuration
659 * parameters (cy_stc_crypto_config_t) and a pointer to the context
660 * (cy_stc_crypto_context_t). Do not fill in the values for the context structure.
661 *
662 * Then call \ref Cy_Crypto_Enable to enable the Crypto hardware IP block.
663 * After this, the Crypto driver is ready to execute crypto functions.
664 * These calls must be made on the client side.
665 * Firmware can implement the client on either core.
666 *
667 * \snippet crypto/snippet/main.c snippet_myCryptoInit
668 *
669 * \section group_crypto_common_use_cases Common Use Cases
670 *
671 * \subsection group_crypto_Use_CRC CRC Calculation
672 *
673 * To calculate CRC of a data image:
674 *   - Use \ref Cy_Crypto_Crc_Init to set parameters for selected CRC mode,
675 *   - Call \ref Cy_Crypto_Crc_Run to calculate CRC for a data image.
676 *
677 * Code example:
678 * \snippet crypto/snippet/main.c snippet_myCryptoCrcUse
679 *
680 * \subsection group_crypto_Use_PRNG Pseudo Random Number Generation
681 *
682 * To generate a pseudo random number:
683 *   - Use \ref Cy_Crypto_Prng_Init to set required parameters,
684 *   - Call \ref Cy_Crypto_Prng_Generate.
685 *
686 * Code example:
687 * \snippet crypto/snippet/main.c snippet_myCryptoPrngUse
688 *
689 * \subsection group_crypto_Use_TRNG True Random Number Generation
690 *
691 * To generate a true random number:
692 *   - Call \ref Cy_Crypto_Trng_Generate with needed parameters.
693 *
694 * Code example:
695 * \snippet crypto/snippet/main.c snippet_myCryptoTrngUse
696 *
697 * \subsection group_crypto_Use_DES DES encryption
698 *
699 * To encrypt a message using the DES algorithm:
700 *   - Place DES key into an array,
701 *   - Call \ref Cy_Crypto_Des_Run with required parameters, including the key
702 *     array
703 *
704 * Code example:
705 * \snippet crypto/snippet/main.c snippet_myCryptoDesUse
706 *
707 * \subsection group_crypto_Use_TDES TDES encryption
708 *
709 * To encrypt a message using the TDES algorithm:
710 *   - Place 3 DES keys into a solid array,
711 *   - Call \ref Cy_Crypto_Tdes_Run with required parameters, including the array
712 *     of keys
713 *
714 * Code example:
715 * \snippet crypto/snippet/main.c snippet_myCryptoTdesUse
716 *
717 * \subsection group_crypto_Use_AES AES encryption
718 *
719 * The Crypto driver provides a four AES encryption algorithms (ECB, CBC, CFB
720 * and CTR) that are used similarly.
721 *
722 * To encrypt a message using AES ECB algorithm (as example):
723 *   - Place AES key into array of appropriate size
724 *   - Use \ref Cy_Crypto_Aes_Init to configure the operation
725 *   - Call \ref Cy_Crypto_Aes_Ecb_Run (\ref Cy_Crypto_Aes_Cbc_Run,
726 *     \ref Cy_Crypto_Aes_Cfb_Run or \ref Cy_Crypto_Aes_Ctr_Run) with appropriate
727 *     parameters to make an operation
728 *
729 * Code example:
730 * \snippet crypto/snippet/main.c snippet_myCryptoAesEcbUse
731 *
732 * \subsection group_crypto_Use_SHA SHA digest calculation
733 *
734 * To calculate a SHA digest of a message:
735 *   - Call \ref Cy_Crypto_Sha_Run with appropriate parameters to make an
736 *     operation
737 *
738 * Code example:
739 * \snippet crypto/snippet/main.c snippet_myCryptoSha256Use
740 *
741 * \subsection group_crypto_Use_CMAC CMAC calculation
742 *
743 * To calculate CMAC of a message:
744 *   - Place AES key into array of appropriate size
745 *   - Use \ref Cy_Crypto_Aes_Init to configure the operation
746 *   - Call \ref Cy_Crypto_Aes_Ecb_Run with appropriate parameters to make an
747 *     operation
748 *
749 * Code example:
750 * \snippet crypto/snippet/main.c snippet_myCryptoCmacUse
751 *
752 * \subsection group_crypto_Use_HMAC HMAC calculation
753 *
754 * To calculate HMAC of a message:
755 *   - Place HMAC key into array of appropriate size
756 *   - Call \ref Cy_Crypto_Hmac_Run with appropriate parameters to make an
757 *     operation
758 *
759 * Code example:
760 * \snippet crypto/snippet/main.c snippet_myCryptoHmacUse
761 *
762 * \subsection group_crypto_Use_RSA_VER RSA signature verification
763 *
764 * To verify the RSA signature of the data image:
765 *   - Fill RSA public key structure by RSA public key data
766 *   - Use \ref Cy_Crypto_Sha_Run to calculate SHA digest of the data image
767 *   - Use \ref Cy_Crypto_Rsa_Proc to decrypt present encrypted signature
768 *   - Use \ref Cy_Crypto_Rsa_Verify to verify the decrypted signature with
769 *     calculated SHA digest
770 *
771 * Code example:
772 * \snippet crypto/snippet/main.c snippet_myCryptoRsaVerUse
773 *
774 * \section group_crypto_rsa_considerations RSA Usage Considerations
775 *
776 * General RSA encryption and decryption is supported.
777 * \ref Cy_Crypto_Rsa_Proc encrypts or decrypts data based on the parameters
778 * passed to the function. If you pass in plain text and a public key, the output
779 * is encrypted (cipher text). If you pass in cipher text and a private key, the
780 * output is decrypted (plain text).
781 *
782 * One parameter for this function call is a structure that defines the key:
783 * cy_stc_crypto_rsa_pub_key_t. The four modulus and exponent fields are
784 * mandatory. They represent the data for either the public or private key as
785 * appropriate.
786 *
787 * \note The <b>modulus</b> and <b>exponent</b> values in the
788 * \ref cy_stc_crypto_rsa_pub_key_t must be in little-endian order.<br>
789 * Use the \ref Cy_Crypto_InvertEndianness function to convert to or from
790 * little-endian order.
791 *
792 * The remaining fields represent three pre-calculated coefficients that can
793 * reduce execution time by up to 5x. The fields are: coefficient for Barrett
794 * reduction, binary inverse of the modulus, and the result of
795 * (2^moduloLength mod modulo). These fields are optional, and can be set to NULL.
796 *
797 * Calculate these coefficients with \ref Cy_Crypto_Rsa_CalcCoefs.
798 * Pass them in the address of the key structure with the modulus and exponent
799 * values for the key. The function returns the coefficients for the key in the
800 * key structure, replacing any previous values.
801 *
802 * The RSA functionality also implements functions to decrypt a signature using
803 * a public key. This signature must follow the RSASSA-PKCS-v1_5 standard.
804 * The signature must contain a SHA digest (hash).
805 * MD2, MD4, and MD5 message digests are not supported.
806 *
807 * An encrypted signature is stored as big-endian data. It must be inverted for
808 * RSA processing. To use the provided signature decryption, firmware must
809 *   -# Calculate the SHA digest of the data to be verified with
810 *      \ref Cy_Crypto_Sha_Run.
811 *   -# Ensure that the RSA signature is in little-endian format.
812 *      Use \ref Cy_Crypto_InvertEndianness.
813 *   -# Decrypt the RSA signature with a public key, by calling
814 *      \ref Cy_Crypto_Rsa_Proc.
815 *   -# Invert the byte order of the output, to return to big-endian format.
816 *      Use \ref Cy_Crypto_InvertEndianness.
817 *   -# Call \ref Cy_Crypto_Rsa_Verify (which requires data in big-endian format).
818 *
819 * \section group_crypto_irq_implements Implementing Crypto Interrupts
820 *
821 * The Crypto driver uses three interrupts:
822 *   - A notify interrupt when data is ready for a cryptographic operation
823 *   - A release interrupt when a cryptographic operation is complete
824 *   - An error interrupt if the server encounters a hardware error
825 *
826 * You can modify default behavior for each interrupt.
827 *
828 * <b>Notify Interrupt:</b> the Crypto server has a default ISR to handle this
829 * interrupt, \ref Cy_Crypto_Server_GetDataHandler. The default ISR clears the
830 * interrupt, retrieves the data from the IPC channel, and dispatches control to
831 * the desired cryptographic operation.
832 *
833 * To use the default handler, set the \link
834 * cy_stc_crypto_config_t::userGetDataHandler userGetDataHandler \endlink field
835 * of the cy_stc_crypto_config_t structure to NULL.
836 *
837 * To override, populate this
838 * field with your ISR. Then call Crypto Server Start function.
839 * Your ISR can perform additional tasks required by your application logic,
840 * but must also call \ref Cy_Crypto_Server_GetDataHandler to dispatch the data
841 * to the correct cryptographic operation.
842 *
843 * \note \ref Cy_Crypto_Server_Process should be performed from this ISR or from
844 * any other task in the multi-task environment.
845 *
846 * \snippet crypto/snippet/main.c snippet_myCryptoServerMyGetDataISR
847 * \snippet crypto/snippet/main.c snippet_myCryptoServerStartMyGetDataISR
848 *
849 * <b>Release Interrupt:</b> The Crypto driver includes a handler for this
850 * interrupt. The interrupt handler clears the interrupt and calls a user-provided
851 * callback routine. You cannot override this interrupt handler.
852 * By default the interrupt is disabled.
853 *
854 * To use default behavior (interrupt disabled), set the \link
855 * cy_stc_crypto_config_t::userCompleteCallback userCompleteCallback \endlink
856 * field of the cy_stc_crypto_config_t structure to NULL.
857 * To enable the interrupt, populate this field with your callback function.
858 * Then call \ref Cy_Crypto_Init. If the callback function is not NULL, the Init
859 * function enables the interrupt, and default behavior calls your routine.
860 *
861 * When performing cryptographic operations, firmware must ensure the operation
862 * is complete before acting on the results. If the release interrupt is disabled,
863 * typically calls to \ref Cy_Crypto_Sync should be blocking. If the interrupt is
864 * enabled, your callback function is called when the operation is complete.
865 * This lets you avoid blocking calls to \ref Cy_Crypto_Sync.
866 *
867 * <b>Error Interrupt:</b> The Crypto server has a default ISR to handle this
868 * interrupt. It clears the interrupt and sets an internal flag that an error
869 * has occurred.
870 *
871 * To use the default handler, set the userErrorHandler field of the
872 * cy_stc_crypto_config_t structure to NULL. To override, populate this field
873 * with your ISR. Then call Crypto Server Start function.
874 *
875 * Your ISR must call \ref Cy_Crypto_Server_ErrorHandler, and can perform any
876 * additional tasks required by your application logic.
877 */
878 /** \} group_crypto_cli_srv */
879 
880 #if !defined (CY_CRYPTO_H)
881 #define CY_CRYPTO_H
882 
883 #include "cy_device.h"
884 
885 #if defined (CY_IP_MXCRYPTO)
886 
887 #include "cy_crypto_common.h"
888 
889 #if defined(__cplusplus)
890 extern "C" {
891 #endif
892 
893 #include <stddef.h>
894 #include <stdbool.h>
895 
896 /** \cond INTERNAL */
897 
898 cy_en_crypto_status_t Cy_Crypto_GetLibraryInfo(cy_en_crypto_lib_info_t *cryptoInfo);
899 
900 /** \endcond */
901 
902 /**
903 * \addtogroup group_crypto_cli_functions
904 * \{
905 */
906 
907 /*******************************************************************************
908 * Function Name: Cy_Crypto_Init
909 ****************************************************************************//**
910 *
911 * This function initializes the Crypto context buffer and
912 * configures the Crypto driver. Must be called at first.
913 *
914 * To start working with Crypto methods after Crypto_Init(),
915 * call Crypto_Enable() to turn-on the Crypto Hardware.
916 *
917 * \param config
918 * The pointer to the Crypto configuration structure.
919 *
920 * \param context
921 * The pointer to the \ref cy_stc_crypto_context_t instance of structure
922 * that stores the Crypto driver common context.
923 *
924 * \return
925 * \ref cy_en_crypto_status_t
926 *
927 * \funcusage
928 * \snippet crypto/snippet/main.c snippet_myCryptoInit
929 *
930 *******************************************************************************/
931 cy_en_crypto_status_t Cy_Crypto_Init(cy_stc_crypto_config_t const *config, cy_stc_crypto_context_t *context);
932 
933 /*******************************************************************************
934 * Function Name: Cy_Crypto_DeInit
935 ****************************************************************************//**
936 *
937 * This function de-initializes the Crypto driver.
938 *
939 * \return
940 * \ref cy_en_crypto_status_t
941 *
942 *******************************************************************************/
943 cy_en_crypto_status_t Cy_Crypto_DeInit(void);
944 
945 /*******************************************************************************
946 * Function Name: Cy_Crypto_Enable
947 ****************************************************************************//**
948 *
949 * This function enables (turns on) the Crypto hardware.
950 *
951 * \return
952 * \ref cy_en_crypto_status_t
953 *
954 *******************************************************************************/
955 cy_en_crypto_status_t Cy_Crypto_Enable(void);
956 
957 /*******************************************************************************
958 * Function Name: Cy_Crypto_Disable
959 ****************************************************************************//**
960 *
961 * This function disables (turns off) the Crypto hardware.
962 *
963 * \return
964 * \ref cy_en_crypto_status_t
965 *
966 *******************************************************************************/
967 cy_en_crypto_status_t Cy_Crypto_Disable(void);
968 
969 /*******************************************************************************
970 * Function Name: Cy_Crypto_Sync
971 ****************************************************************************//**
972 *
973 * This function waits or just checks (depending on the parameter)
974 * for the Crypto operation to complete.
975 *
976 * \param isBlocking
977 * Set whether Crypto_Sync is blocking:
978 * True - is blocking.
979 * False - is not blocking.
980 *
981 * \return
982 * \ref cy_en_crypto_status_t
983 *
984 *******************************************************************************/
985 cy_en_crypto_status_t Cy_Crypto_Sync(bool isBlocking);
986 
987 /*******************************************************************************
988 * Function Name: Cy_Crypto_GetErrorStatus
989 ****************************************************************************//**
990 *
991 * This function returns a cause of a Crypto hardware error.
992 * It is independent of the Crypto previous state.
993 *
994 * \param hwErrorCause
995 * \ref cy_stc_crypto_hw_error_t.
996 *
997 * \return
998 * \ref cy_en_crypto_status_t
999 *
1000 *******************************************************************************/
1001 cy_en_crypto_status_t Cy_Crypto_GetErrorStatus(cy_stc_crypto_hw_error_t *hwErrorCause);
1002 
1003 #if (CPUSS_CRYPTO_PR == 1) && defined(CY_CRYPTO_CFG_PRNG_C)
1004 /*******************************************************************************
1005 * Function Name: Cy_Crypto_Prng_Init
1006 ****************************************************************************//**
1007 *
1008 * This function initializes parameters of the PRNG.
1009 *
1010 * Call to initialize this encryption technique before using any associated
1011 * functions. You must initialize this technique again after using any other
1012 * encryption technique.
1013 * Invoking this function resets the pseudo random sequence.
1014 *
1015 * \param lfsr32InitState
1016 * A non-zero seed value for the first LFSR. User selected.
1017 
1018 * \param lfsr31InitState
1019 * A non-zero seed value for the second LFSR. User selected.
1020 
1021 * \param lfsr29InitState
1022 * A non-zero seed value for the third LFSR. User selected.
1023 *
1024 * \param cfContext
1025 * The pointer to the \ref cy_stc_crypto_context_prng_t structure that stores
1026 * the Crypto function context.
1027 * __Must be 4-byte aligned.__
1028 *
1029 * \return
1030 * \ref cy_en_crypto_status_t
1031 *
1032 * \funcusage
1033 * \snippet crypto/snippet/main.c snippet_myCryptoPrngUse
1034 *
1035 *******************************************************************************/
1036 cy_en_crypto_status_t Cy_Crypto_Prng_Init(uint32_t lfsr32InitState,
1037                                           uint32_t lfsr31InitState,
1038                                           uint32_t lfsr29InitState,
1039                                           cy_stc_crypto_context_prng_t *cfContext);
1040 
1041 /*******************************************************************************
1042 * Function Name: Cy_Crypto_Prng_Generate
1043 ****************************************************************************//**
1044 *
1045 * This function generates 32-bit the Pseudo Random Number.
1046 * It depends on \ref Cy_Crypto_Prng_Init that should be called before.
1047 *
1048 * \param max
1049 * The maximum value of a generated random number.
1050 *
1051 * \param randomNum
1052 * The pointer to a variable to store the generated pseudo random number.
1053 * __Must be 4-byte aligned.__
1054 *
1055 * \param cfContext
1056 * The pointer to the \ref cy_stc_crypto_context_prng_t structure that stores
1057 * the Crypto function context.
1058 * __Must be 4-byte aligned.__
1059 *
1060 * \return
1061 * \ref cy_en_crypto_status_t
1062 *
1063 * \funcusage
1064 * \snippet crypto/snippet/main.c snippet_myCryptoPrngUse
1065 *
1066 *******************************************************************************/
1067 cy_en_crypto_status_t Cy_Crypto_Prng_Generate(uint32_t max,
1068                                               uint32_t *randomNum,
1069                                               cy_stc_crypto_context_prng_t *cfContext);
1070 #endif /* (CPUSS_CRYPTO_PR == 1) && defined(CY_CRYPTO_CFG_PRNG_C) */
1071 
1072 #if (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_AES_C)
1073 /*******************************************************************************
1074 * Function Name: Cy_Crypto_Aes_Init
1075 ****************************************************************************//**
1076 *
1077 * This function initializes the AES operation by setting key and key length.
1078 *
1079 * Call to initialize this encryption technique before using any associated
1080 * functions. You must initialize this technique again after using any other
1081 * encryption technique.
1082 *
1083 * \param key
1084 * The pointer to the encryption/decryption key. __Must be 4-byte aligned.__
1085 *
1086 * \param keyLength
1087 * \ref cy_en_crypto_aes_key_length_t
1088 *
1089 * \param cfContext
1090 * The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all
1091 * internal variables the Crypto driver requires. __Must be 4-byte aligned.__
1092 *
1093 * \return
1094 * \ref cy_en_crypto_status_t
1095 *
1096 * \funcusage
1097 * \snippet crypto/snippet/main.c snippet_myCryptoAesEcbUse
1098 *
1099 *******************************************************************************/
1100 cy_en_crypto_status_t Cy_Crypto_Aes_Init(uint32_t *key,
1101                                          cy_en_crypto_aes_key_length_t keyLength,
1102                                          cy_stc_crypto_context_aes_t *cfContext);
1103 
1104 /*******************************************************************************
1105 * Function Name: Cy_Crypto_Aes_Ecb_Run
1106 ****************************************************************************//**
1107 *
1108 * This function performs AES operation on one 16-byte block
1109 * (see \ref CY_CRYPTO_AES_BLOCK_SIZE).
1110 * The AES key must be set before by invoking Cy_Crypto_Aes_Init().
1111 *
1112 * \param dirMode
1113 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
1114 * (\ref cy_en_crypto_dir_mode_t).
1115 *
1116 * \param srcBlock
1117 * The pointer to a 16-byte source block. __Must be 4-byte aligned.__
1118 *
1119 * \param dstBlock
1120 * The pointer to a 16-byte destination cipher block. __Must be 4-byte aligned.__
1121 *
1122 * \param cfContext
1123 * The pointer to the \ref cy_stc_crypto_context_aes_t instance of structure
1124 * that stores all AES internal variables. __Must be 4-byte aligned.__
1125 *
1126 * \return
1127 * \ref cy_en_crypto_status_t
1128 *
1129 * \funcusage
1130 * \snippet crypto/snippet/main.c snippet_myCryptoAesEcbUse
1131 *
1132 *******************************************************************************/
1133 cy_en_crypto_status_t Cy_Crypto_Aes_Ecb_Run(cy_en_crypto_dir_mode_t dirMode,
1134                                             uint32_t *dstBlock,
1135                                             uint32_t *srcBlock,
1136                                             cy_stc_crypto_context_aes_t *cfContext);
1137 
1138 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC)
1139 /*******************************************************************************
1140 * Function Name: Cy_Crypto_Aes_Cbc_Run
1141 ****************************************************************************//**
1142 *
1143 * This function performs AES operation on a plain text with Cipher Block Chaining (CBC).
1144 * The key must be set before by invoking Cy_Crypto_Aes_Init().
1145 *
1146 * \param dirMode
1147 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
1148 * (\ref cy_en_crypto_dir_mode_t)
1149 *
1150 * \param srcSize
1151 * The size of the source plain text.
1152 *
1153 * \param ivPtr
1154 * The pointer to the initial vector. __Must be 4-byte aligned.__
1155 *
1156 * \param dst
1157 * The pointer to a destination cipher text. __Must be 4-byte aligned.__
1158 *
1159 * \param src
1160 * The pointer to a source plain text. __Must be 4-byte aligned.__
1161 *
1162 * \param cfContext
1163 * The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all
1164 * internal variables the Crypto driver requires.  __Must be 4-byte aligned.__
1165 *
1166 * \return
1167 * \ref cy_en_crypto_status_t
1168 *
1169 *******************************************************************************/
1170 cy_en_crypto_status_t Cy_Crypto_Aes_Cbc_Run(cy_en_crypto_dir_mode_t dirMode,
1171                                             uint32_t srcSize,
1172                                             uint32_t *ivPtr,
1173                                             uint32_t *dst,
1174                                             uint32_t *src,
1175                                             cy_stc_crypto_context_aes_t *cfContext);
1176 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CBC) */
1177 
1178 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB)
1179 /*******************************************************************************
1180 * Function Name: Cy_Crypto_Aes_Cfb_Run
1181 ****************************************************************************//**
1182 *
1183 * This function performs AES operation on a plain text with Cipher Feedback mode
1184 * (CFB). The key must be set before by invoking Cy_Crypto_Aes_Init().
1185 *
1186 * \param dirMode
1187 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
1188 * (\ref cy_en_crypto_dir_mode_t)
1189 *
1190 * \param srcSize
1191 * The size of the source plain text.
1192 *
1193 * \param ivPtr
1194 * The pointer to the initial vector. __Must be 4-byte aligned.__
1195 *
1196 * \param dst
1197 * The pointer to the destination cipher text. __Must be 4-byte aligned.__
1198 *
1199 * \param src
1200 * The pointer to the source plain text. __Must be 4-byte aligned.__
1201 *
1202 * \param cfContext
1203 * The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all
1204 * internal variables the Crypto driver requires. __Must be 4-byte aligned.__
1205 *
1206 * \return
1207 * \ref cy_en_crypto_status_t
1208 *
1209 *******************************************************************************/
1210 cy_en_crypto_status_t Cy_Crypto_Aes_Cfb_Run(cy_en_crypto_dir_mode_t dirMode,
1211                                             uint32_t srcSize,
1212                                             uint32_t *ivPtr,
1213                                             uint32_t *dst,
1214                                             uint32_t *src,
1215                                             cy_stc_crypto_context_aes_t *cfContext);
1216 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CFB) */
1217 
1218 #if defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR)
1219 /*******************************************************************************
1220 * Function Name: Cy_Crypto_Aes_Ctr_Run
1221 ****************************************************************************//**
1222 *
1223 * This function performs AES operation on a plain text with Cipher Block Counter
1224 * mode (CTR).
1225 * NOTE: preparation of the unique nonceCounter for each block is
1226 * the user's responsibility. This function is dependent on
1227 * the key being set before invoking \ref Cy_Crypto_Aes_Init().
1228 *
1229 * \param dirMode
1230 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
1231 * (\ref cy_en_crypto_dir_mode_t)
1232 *
1233 * \param srcSize
1234 * The size of a source plain text.
1235 *
1236 * \param srcOffset
1237 * The size of an offset within the current block stream for resuming within the
1238 * current cipher stream.
1239 *
1240 * \param nonceCounter
1241 * The 128-bit nonce and counter. __Must be 4-byte aligned.__
1242 *
1243 * \param streamBlock
1244 * The saved stream-block for resuming. Is over-written by the function.
1245 * __Must be 4-byte aligned.__
1246 *
1247 * \param dst
1248 * The pointer to the destination cipher text. __Must be 4-byte aligned.__
1249 *
1250 * \param src
1251 * The pointer to the source plain text. __Must be 4-byte aligned.__
1252 *
1253 * \param cfContext
1254 * The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all
1255 * internal variables the Crypto driver requires. __Must be 4-byte aligned.__
1256 *
1257 * \return
1258 * \ref cy_en_crypto_status_t
1259 *
1260 *******************************************************************************/
1261 cy_en_crypto_status_t Cy_Crypto_Aes_Ctr_Run(cy_en_crypto_dir_mode_t dirMode,
1262                                             uint32_t srcSize,
1263                                             uint32_t *srcOffset,
1264                                             uint32_t nonceCounter[CY_CRYPTO_AES_BLOCK_SIZE / 8u],
1265                                             uint32_t streamBlock[CY_CRYPTO_AES_BLOCK_SIZE / 8u],
1266                                             uint32_t *dst,
1267                                             uint32_t *src,
1268                                             cy_stc_crypto_context_aes_t *cfContext);
1269 #endif /* defined(CY_CRYPTO_CFG_CIPHER_MODE_CTR) */
1270 #endif /* (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_AES_C) */
1271 
1272 #if (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_CMAC_C)
1273 /*******************************************************************************
1274 * Function Name: Cy_Crypto_Aes_Cmac_Run
1275 ****************************************************************************//**
1276 *
1277 * This function performs the cipher-block chaining-message authentication-code.
1278 *
1279 * There is no Init function. Provide the required parameters and the pointer to
1280 * the context structure when making this function call.
1281 *
1282 * \param src
1283 * The pointer to the source plain text. __Must be 4-byte aligned.__
1284 *
1285 * \param srcSize
1286 * The size of a source plain text.
1287 *
1288 * \param key
1289 * The pointer to the encryption key. __Must be 4-byte aligned.__
1290 *
1291 * \param keyLength
1292 * \ref cy_en_crypto_aes_key_length_t
1293 *
1294 * \param cmacPtr
1295 * The pointer to the calculated CMAC. __Must be 4-byte aligned.__
1296 *
1297 * \param cfContext
1298 * The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all
1299 * internal variables the Crypto driver requires.
1300 *
1301 * \return
1302 * \ref cy_en_crypto_status_t
1303 *
1304 * \funcusage
1305 * \snippet crypto/snippet/main.c snippet_myCryptoCmacUse
1306 *
1307 *******************************************************************************/
1308 cy_en_crypto_status_t Cy_Crypto_Aes_Cmac_Run(uint32_t *src,
1309                                              uint32_t srcSize,
1310                                              uint32_t *key,
1311                                              cy_en_crypto_aes_key_length_t keyLength,
1312                                              uint32_t *cmacPtr,
1313                                              cy_stc_crypto_context_aes_t *cfContext);
1314 #endif /* (CPUSS_CRYPTO_AES == 1) && defined(CY_CRYPTO_CFG_CMAC_C) */
1315 
1316 #if (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_SHA_C)
1317 /*******************************************************************************
1318 * Function Name: Cy_Crypto_Sha_Run
1319 ****************************************************************************//**
1320 *
1321 * This function performs the SHA Hash function.
1322 * There is no Init function. Provide the required parameters and the pointer
1323 * to the context structure when making this function call.
1324 * It is independent of the previous Crypto state because it already contains
1325 * preparation, calculation, and finalization steps.
1326 *
1327 * \param mode
1328 * \ref cy_en_crypto_sha_mode_t
1329 *
1330 * \param message
1331 * The pointer to a message whose hash value is being computed.
1332 * __Must be 4-byte aligned.__
1333 *
1334 * \param messageSize
1335 * The size of a message.
1336 *
1337 * \param digest
1338 * The pointer to the hash digest. The hash size depends on the selected SHA mode
1339 * (from 20 to 64 bytes).
1340 * __Must be 4-byte aligned.__
1341 *
1342 * \param cfContext
1343 * the pointer to the \ref cy_stc_crypto_context_sha_t structure that stores all
1344 * internal variables for Crypto driver.
1345 *
1346 * \return
1347 * \ref cy_en_crypto_status_t
1348 *
1349 * \funcusage
1350 * \snippet crypto/snippet/main.c snippet_myCryptoSha256Use
1351 *
1352 *******************************************************************************/
1353 cy_en_crypto_status_t Cy_Crypto_Sha_Run(uint32_t *message,
1354                                         uint32_t  messageSize,
1355                                         uint32_t *digest,
1356                                         cy_en_crypto_sha_mode_t mode,
1357                                         cy_stc_crypto_context_sha_t *cfContext);
1358 #endif /* (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_SHA_C) */
1359 
1360 #if (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_HMAC_C)
1361 /*******************************************************************************
1362 * Function Name: Cy_Crypto_Hmac_Run
1363 ****************************************************************************//**
1364 *
1365 * This function performs HMAC calculation.
1366 * There is no Init function. Provide the required parameters and the pointer
1367 * to the context structure when making this function call.
1368 * It is independent of the previous Crypto state because it already contains
1369 * preparation, calculation, and finalization steps.
1370 *
1371 * \param hmac
1372 * The pointer to the calculated HMAC. __Must be 4-byte aligned.__
1373 *
1374 * \param message
1375 * The pointer to a message whose hash value is being computed.
1376 * __Must be 4-byte aligned.__
1377 *
1378 * \param messageSize
1379 * The size of a message.
1380 *
1381 * \param key
1382 * The pointer to the key. __Must be 4-byte aligned.__
1383 *
1384 * \param keyLength
1385 * The length of the key.
1386 *
1387 * \param mode
1388 * \ref cy_en_crypto_sha_mode_t
1389 *
1390 * \param cfContext
1391 * the pointer to the \ref cy_stc_crypto_context_sha_t structure that stores all
1392 * internal variables for the Crypto driver.
1393 *
1394 * \return
1395 * \ref cy_en_crypto_status_t
1396 *
1397 * \funcusage
1398 * \snippet crypto/snippet/main.c snippet_myCryptoHmacUse
1399 *
1400 *******************************************************************************/
1401 cy_en_crypto_status_t Cy_Crypto_Hmac_Run(uint32_t *hmac,
1402                                          uint32_t *message,
1403                                          uint32_t  messageSize,
1404                                          uint32_t *key,
1405                                          uint32_t keyLength,
1406                                          cy_en_crypto_sha_mode_t mode,
1407                                          cy_stc_crypto_context_sha_t *cfContext);
1408 #endif /* (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_HMAC_C) */
1409 
1410 #if (CPUSS_CRYPTO_STR == 1)
1411 /*******************************************************************************
1412 * Function Name: Cy_Crypto_Str_MemCpy
1413 ****************************************************************************//**
1414 *
1415 * This function copies a memory block. It operates on data in the user SRAM and
1416 * doesn't use Crypto internal SRAM.
1417 *
1418 * \note Memory blocks should not overlap.
1419 *
1420 * There is no alignment restriction.
1421 * This function is independent of the previous Crypto state.
1422 *
1423 * \param dst
1424 * The pointer to the destination of MemCpy.
1425 *
1426 * \param src
1427 * The pointer to the source of MemCpy.
1428 *
1429 * \param size
1430 * The size in bytes of the copy operation. Maximum size is 65535 Bytes.
1431 *
1432 * \param cfContext
1433 * The pointer to the \ref cy_stc_crypto_context_str_t structure that stores all
1434 * internal variables for the Crypto driver.
1435 *
1436 * \return
1437 * \ref cy_en_crypto_status_t
1438 *
1439 *******************************************************************************/
1440 cy_en_crypto_status_t Cy_Crypto_Str_MemCpy(void *dst,
1441                                            void const *src,
1442                                            uint16_t size,
1443                                            cy_stc_crypto_context_str_t *cfContext);
1444 
1445 /*******************************************************************************
1446 * Function Name: Cy_Crypto_Str_MemSet
1447 ****************************************************************************//**
1448 *
1449 * This function sets the memory block. It operates on data in the user SRAM and
1450 * doesn't use Crypto internal SRAM.
1451 *
1452 * There is no alignment restriction.
1453 * This function is independent from the previous Crypto state.
1454 *
1455 * \param dst
1456 * The pointer to the destination of MemSet.
1457 *
1458 * \param data
1459 * The value to be set.
1460 *
1461 * \param size
1462 * The size in bytes of the set operation. Maximum size is 65535 Bytes.
1463 *
1464 * \param cfContext
1465 * the pointer to the \ref cy_stc_crypto_context_str_t structure that stores all
1466 * internal variables for the Crypto driver.
1467 *
1468 * \return
1469 * \ref cy_en_crypto_status_t
1470 *
1471 *******************************************************************************/
1472 cy_en_crypto_status_t Cy_Crypto_Str_MemSet(void *dst,
1473                                            uint8_t data,
1474                                            uint16_t size,
1475                                            cy_stc_crypto_context_str_t *cfContext);
1476 
1477 /*******************************************************************************
1478 * Function Name: Cy_Crypto_Str_MemCmp
1479 ****************************************************************************//**
1480 *
1481 * This function compares memory blocks. It operates on data in the user SRAM and
1482 * doesn't use Crypto internal SRAM.
1483 *
1484 * There is no alignment restriction.
1485 * This function is independent from the previous Crypto state.
1486 *
1487 * \param src0
1488 * The pointer to the first source of MemCmp.(__must be 4-byte aligned__)
1489 *
1490 * \param src1
1491 * The pointer to the second source of MemCmp.
1492 *
1493 * \param size
1494 * The size in bytes of the compare operation. Maximum size is 65535 Bytes.
1495 *
1496 * \param resultPtr
1497 * The pointer to the result of compare (__must be 4-byte aligned__):
1498 *     - 0 - if Source 1 equal Source 2
1499 *     - 1 - if Source 1 not equal Source 2
1500 *
1501 * \param cfContext
1502 * the pointer to the \ref cy_stc_crypto_context_str_t structure that stores all
1503 * internal variables for the Crypto driver. __must be 4-byte aligned__
1504 *
1505 * \return
1506 * \ref cy_en_crypto_status_t
1507 *
1508 *******************************************************************************/
1509 cy_en_crypto_status_t Cy_Crypto_Str_MemCmp(void const *src0,
1510                                            void const *src1,
1511                                            uint16_t size,
1512                                            uint32_t *resultPtr,
1513                                            cy_stc_crypto_context_str_t *cfContext);
1514 
1515 /*******************************************************************************
1516 * Function Name: Crypto_Str_MemXor
1517 ****************************************************************************//**
1518 *
1519 * This function calculates the XOR of two memory blocks. It operates on data in
1520 * the user SRAM and doesn't use Crypto internal SRAM.
1521 *
1522 * \note Memory structures should not overlap.
1523 *
1524 * There is no alignment restriction.
1525 * This function is independent from the previous Crypto state.
1526 *
1527 * \param src0
1528 * The pointer to the first source of MemXor.
1529 
1530 * \param src1
1531 * The pointer to the second source of MemXor.
1532 
1533 * \param dst
1534 * The pointer to the destination of MemXor.
1535 *
1536 * \param size
1537 * The size in bytes of the compare operation. Maximum size is 65535 Bytes.
1538 *
1539 * \param cfContext
1540 * the pointer to the \ref cy_stc_crypto_context_str_t structure that stores all
1541 * internal variables for the Crypto driver.
1542 *
1543 * \return
1544 * \ref cy_en_crypto_status_t
1545 *
1546 *******************************************************************************/
1547 cy_en_crypto_status_t Cy_Crypto_Str_MemXor(void const *src0,
1548                                            void const *src1,
1549                                            void *dst,
1550                                            uint16_t size,
1551                                            cy_stc_crypto_context_str_t *cfContext);
1552 #endif /* #if (CPUSS_CRYPTO_STR == 1) */
1553 
1554 #if (CPUSS_CRYPTO_CRC == 1) && defined(CY_CRYPTO_CFG_CRC_C)
1555 /*******************************************************************************
1556 * Function Name: Cy_Crypto_Crc_Init
1557 ****************************************************************************//**
1558 *
1559 * This function performs CRC initialization.
1560 *
1561 * Call to initialize this encryption technique before using any associated
1562 * functions. You must initialize this technique again after using any other
1563 * encryption technique.
1564 *
1565 * Below is the table with known polynomials with different parameters and their
1566 * calculated CRCs from the string <b>"123456789"</b>:
1567 * | Name               | Width | Poly       | Init       | Data Rev | Data XOR | Rem Rev | Rem XOR    | Expected CRC |
1568 * |:-------------------|:-----:|:----------:|:----------:|:--------:|:--------:|:-------:|:----------:|:------------:|
1569 * | CRC-3 / ROHC       |     3 |        0x3 |        0x7 |        1 |        0 |       1 |        0x0 |          0x6 |
1570 * | CRC-4 / ITU        |     4 |        0x3 |        0x0 |        1 |        0 |       1 |        0x0 |          0x7 |
1571 * | CRC-5 / EPC        |     5 |        0x9 |        0x9 |        0 |        0 |       0 |        0x0 |          0x0 |
1572 * | CRC-5 / ITU        |     5 |       0x15 |        0x0 |        1 |        0 |       1 |        0x0 |          0x7 |
1573 * | CRC-5 / USB        |     5 |        0x5 |       0x1F |        1 |        0 |       1 |       0x1F |         0x19 |
1574 * | CRC-6 / CDMA2000-A |     6 |       0x27 |       0x3F |        0 |        0 |       0 |        0x0 |          0xD |
1575 * | CRC-6 / CDMA2000-B |     6 |        0x7 |       0x3F |        0 |        0 |       0 |        0x0 |         0x3B |
1576 * | CRC-6 / DARC       |     6 |       0x19 |        0x0 |        1 |        0 |       1 |        0x0 |         0x26 |
1577 * | CRC-6 / ITU        |     6 |        0x3 |        0x0 |        1 |        0 |       1 |        0x0 |          0x6 |
1578 * | CRC-7              |     7 |        0x9 |        0x0 |        0 |        0 |       0 |        0x0 |         0x75 |
1579 * | CRC-7 / ROHC       |     7 |       0x4F |       0x7F |        1 |        0 |       1 |        0x0 |         0x53 |
1580 * | CRC-8              |     8 |        0x7 |        0x0 |        0 |        0 |       0 |        0x0 |         0xF4 |
1581 * | CRC-8 / CDMA2000   |     8 |       0x9B |       0xFF |        0 |        0 |       0 |        0x0 |         0xDA |
1582 * | CRC-8 / DARC       |     8 |       0x39 |        0x0 |        1 |        0 |       1 |        0x0 |         0x15 |
1583 * | CRC-8 / DVB-S2     |     8 |       0xD5 |        0x0 |        0 |        0 |       0 |        0x0 |         0xBC |
1584 * | CRC-8 / EBU        |     8 |       0x1D |       0xFF |        1 |        0 |       1 |        0x0 |         0x97 |
1585 * | CRC-8 / I-CODE     |     8 |       0x1D |       0xFD |        0 |        0 |       0 |        0x0 |         0x7E |
1586 * | CRC-8 / ITU        |     8 |        0x7 |        0x0 |        0 |        0 |       0 |       0x55 |         0xA1 |
1587 * | CRC-8 / MAXIM      |     8 |       0x31 |        0x0 |        1 |        0 |       1 |        0x0 |         0xA1 |
1588 * | CRC-8 / ROHC       |     8 |        0x7 |       0xFF |        1 |        0 |       1 |        0x0 |         0xD0 |
1589 * | CRC-8 / WCDMA      |     8 |       0x9B |        0x0 |        1 |        0 |       1 |        0x0 |         0x25 |
1590 * | CRC-10             |    10 |      0x233 |        0x0 |        0 |        0 |       0 |        0x0 |        0x199 |
1591 * | CRC-10 / CDMA2000  |    10 |      0x3D9 |      0x3FF |        0 |        0 |       0 |        0x0 |        0x233 |
1592 * | CRC-11             |    11 |      0x385 |       0x1A |        0 |        0 |       0 |        0x0 |        0x5A3 |
1593 * | CRC-12 / 3GPP      |    12 |      0x80F |        0x0 |        0 |        0 |       1 |        0x0 |        0xDAF |
1594 * | CRC-12 / CDMA2000  |    12 |      0xF13 |      0xFFF |        0 |        0 |       0 |        0x0 |        0xD4D |
1595 * | CRC-12 / DECT      |    12 |      0x80F |        0x0 |        0 |        0 |       0 |        0x0 |        0xF5B |
1596 * | CRC-13 / BBC       |    13 |     0x1CF5 |        0x0 |        0 |        0 |       0 |        0x0 |        0x4FA |
1597 * | CRC-14 / DARC      |    14 |      0x805 |        0x0 |        1 |        0 |       1 |        0x0 |        0x82D |
1598 * | CRC-15             |    15 |     0x4599 |        0x0 |        0 |        0 |       0 |        0x0 |        0x59E |
1599 * | CRC-15 / MPT1327   |    15 |     0x6815 |        0x0 |        0 |        0 |       0 |        0x1 |       0x2566 |
1600 * | CRC-24             |    24 |  0x0864CFB | 0x00B704CE |        0 |        0 |       0 |        0x0 |     0x21CF02 |
1601 * | CRC-24 / FLEXRAY-A |    24 |  0x05D6DCB | 0x00FEDCBA |        0 |        0 |       0 |        0x0 |     0x7979BD |
1602 * | CRC-24 / FLEXRAY-B |    24 |  0x05D6DCB | 0x00ABCDEF |        0 |        0 |       0 |        0x0 |     0x1F23B8 |
1603 * | CRC-31 / PHILIPS   |    31 |  0x4C11DB7 | 0x7FFFFFFF |        0 |        0 |       0 | 0x7FFFFFFF |    0xCE9E46C |
1604 * | CRC-16 / ARC       |    16 |     0x8005 |     0x0000 |        1 |        0 |       1 |     0x0000 |       0xBB3D |
1605 * | CRC-16 / AUG-CCITT |    16 |     0x1021 |     0x1D0F |        0 |        0 |       0 |     0x0000 |       0xE5CC |
1606 * | CRC-16 / BUYPASS   |    16 |     0x8005 |     0x0000 |        0 |        0 |       0 |     0x0000 |       0xFEE8 |
1607 * | CRC-16 / CCITT-0   |    16 |     0x1021 |     0xFFFF |        0 |        0 |       0 |     0x0000 |       0x29B1 |
1608 * | CRC-16 / CDMA2000  |    16 |     0xC867 |     0xFFFF |        0 |        0 |       0 |     0x0000 |       0x4C06 |
1609 * | CRC-16 / DDS-110   |    16 |     0x8005 |     0x800D |        0 |        0 |       0 |     0x0000 |       0x9ECF |
1610 * | CRC-16 / DECT-R    |    16 |     0x0589 |     0x0000 |        0 |        0 |       0 |     0x0001 |       0x007E |
1611 * | CRC-16 / DECT-X    |    16 |     0x0589 |     0x0000 |        0 |        0 |       0 |     0x0000 |       0x007F |
1612 * | CRC-16 / DNP       |    16 |     0x3D65 |     0x0000 |        1 |        0 |       1 |     0xFFFF |       0xEA82 |
1613 * | CRC-16 / EN-13757  |    16 |     0x3D65 |     0x0000 |        0 |        0 |       0 |     0xFFFF |       0xC2B7 |
1614 * | CRC-16 / GENIBUS   |    16 |     0x1021 |     0xFFFF |        0 |        0 |       0 |     0xFFFF |       0xD64E |
1615 * | CRC-16 / MAXIM     |    16 |     0x8005 |     0x0000 |        1 |        0 |       1 |     0xFFFF |       0x44C2 |
1616 * | CRC-16 / MCRF4XX   |    16 |     0x1021 |     0xFFFF |        1 |        0 |       1 |     0x0000 |       0x6F91 |
1617 * | CRC-16 / RIELLO    |    16 |     0x1021 |     0xB2AA |        1 |        0 |       1 |     0x0000 |       0x63D0 |
1618 * | CRC-16 / T10-DIF   |    16 |     0x8BB7 |     0x0000 |        0 |        0 |       0 |     0x0000 |       0xD0DB |
1619 * | CRC-16 / TELEDISK  |    16 |     0xA097 |     0x0000 |        0 |        0 |       0 |     0x0000 |       0x0FB3 |
1620 * | CRC-16 / TMS37157  |    16 |     0x1021 |     0x89EC |        1 |        0 |       1 |     0x0000 |       0x26B1 |
1621 * | CRC-16 / USB       |    16 |     0x8005 |     0xFFFF |        1 |        0 |       1 |     0xFFFF |       0xB4C8 |
1622 * | CRC-A              |    16 |     0x1021 |     0xC6C6 |        1 |        0 |       1 |     0x0000 |       0xBF05 |
1623 * | CRC-16 / KERMIT    |    16 |     0x1021 |     0x0000 |        1 |        0 |       1 |     0x0000 |       0x2189 |
1624 * | CRC-16 / MODBUS    |    16 |     0x8005 |     0xFFFF |        1 |        0 |       1 |     0x0000 |       0x4B37 |
1625 * | CRC-16 / X-25      |    16 |     0x1021 |     0xFFFF |        1 |        0 |       1 |     0xFFFF |       0x906E |
1626 * | CRC-16 / XMODEM    |    16 |     0x1021 |     0x0000 |        0 |        0 |       0 |     0x0000 |       0x31C3 |
1627 * | CRC-32             |    32 | 0x04C11DB7 | 0xFFFFFFFF |        1 |        0 |       1 | 0xFFFFFFFF |   0xCBF43926 |
1628 * | CRC-32 / BZIP2     |    32 | 0x04C11DB7 | 0xFFFFFFFF |        0 |        0 |       0 | 0xFFFFFFFF |   0xFC891918 |
1629 * | CRC-32C            |    32 | 0x1EDC6F41 | 0xFFFFFFFF |        1 |        0 |       1 | 0xFFFFFFFF |   0xE3069283 |
1630 * | CRC-32D            |    32 | 0xA833982B | 0xFFFFFFFF |        1 |        0 |       1 | 0xFFFFFFFF |   0x87315576 |
1631 * | CRC-32 / MPEG-2    |    32 | 0x04C11DB7 | 0xFFFFFFFF |        0 |        0 |       0 | 0x00000000 |   0x0376E6E7 |
1632 * | CRC-32 / POSIX     |    32 | 0x04C11DB7 | 0x00000000 |        0 |        0 |       0 | 0xFFFFFFFF |   0x765E7680 |
1633 * | CRC-32Q            |    32 | 0x814141AB | 0x00000000 |        0 |        0 |       0 | 0x00000000 |   0x3010BF7F |
1634 * | CRC-32 / JAMCRC    |    32 | 0x04C11DB7 | 0xFFFFFFFF |        1 |        0 |       1 | 0x00000000 |   0x340BC6D9 |
1635 * | CRC-32 / XFER      |    32 | 0x000000AF | 0x00000000 |        0 |        0 |       0 | 0x00000000 |   0xBD0BE338 |
1636 *
1637 * \param polynomial
1638 * The polynomial (specified using 32 bits) used in the computing CRC.
1639 *
1640 * \param dataReverse
1641 * The order in which data bytes are processed. 0 - MSB first; 1- LSB first.
1642 *
1643 * \param dataXor
1644 * The byte mask for XORing data
1645 *
1646 * \param remReverse
1647 * A remainder reverse: 0 means the remainder is not reversed. 1 means reversed.
1648 *
1649 * \param remXor
1650 * Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
1651 *
1652 * \param cfContext
1653 * The pointer to the \ref cy_stc_crypto_context_crc_t structure that stores
1654 * the Crypto driver context.
1655 *
1656 * \return
1657 * \ref cy_en_crypto_status_t
1658 *
1659 * \note
1660 * The polynomial, initial seed and remainder XOR values are <b>always</b>
1661 * provided as MSB aligned (so actual higher bit should be located in 31s bit of
1662 * the parameter value).<br>
1663 * Calculated CRC value is MSB aligned <b>only when dataReverse is zero</b>.
1664 *
1665 * \funcusage
1666 * \snippet crypto/snippet/main.c snippet_myCryptoCrcUse
1667 *
1668 *******************************************************************************/
1669 cy_en_crypto_status_t Cy_Crypto_Crc_Init(uint32_t polynomial,
1670                                          uint8_t  dataReverse,
1671                                          uint8_t  dataXor,
1672                                          uint8_t  remReverse,
1673                                          uint32_t remXor,
1674                                          cy_stc_crypto_context_crc_t *cfContext);
1675 
1676 /*******************************************************************************
1677 * Function Name: Cy_Crypto_Crc_Run
1678 ****************************************************************************//**
1679 *
1680 * This function performs CRC calculation on a message.
1681 * It depends on \ref Cy_Crypto_Crc_Init(), which should be called before.
1682 *
1683 * \param data
1684 * The pointer to the message whose CRC is being computed.
1685 *
1686 * \param dataSize
1687 * The size of a message in bytes.
1688 *
1689 * \param crc
1690 * The pointer to a computed CRC value. __Must be 4-byte aligned.__
1691 *
1692 * \param lfsrInitState
1693 * The initial state of the LFSR.
1694 *
1695 * \param cfContext
1696 * The pointer to the \ref cy_stc_crypto_context_crc_t structure that stores
1697 * the Crypto driver context.
1698 *
1699 * \return
1700 * \ref cy_en_crypto_status_t
1701 *
1702 * \note
1703 * The polynomial, initial seed and remainder XOR values are <b>always</b>
1704 * provided as MSB aligned (so actual higher bit should be located in 31s bit of
1705 * the parameter value).<br>
1706 * Calculated CRC value is MSB aligned <b>only when dataReverse is zero</b>.
1707 *
1708 * \funcusage
1709 * \snippet crypto/snippet/main.c snippet_myCryptoCrcUse
1710 *
1711 *******************************************************************************/
1712 cy_en_crypto_status_t Cy_Crypto_Crc_Run(void     *data,
1713                                         uint16_t dataSize,
1714                                         uint32_t *crc,
1715                                         uint32_t  lfsrInitState,
1716                                         cy_stc_crypto_context_crc_t *cfContext);
1717 #endif /* (CPUSS_CRYPTO_CRC == 1) && defined(CY_CRYPTO_CFG_CRC_C) */
1718 
1719 #if (CPUSS_CRYPTO_TR == 1) && defined(CY_CRYPTO_CFG_TRNG_C)
1720 /*******************************************************************************
1721 * Function Name: Cy_Crypto_Trng_Generate
1722 ****************************************************************************//**
1723 *
1724 * This function generates a 32-bit True Random Number.
1725 *
1726 * \param GAROPol
1727 * The polynomial for the programmable Galois ring oscillator.
1728 *
1729 * \param FIROPol
1730 * The polynomial for the programmable Fibonacci ring oscillator.
1731 *
1732 * \param max
1733 * The maximum length of a random number, in the range [0, 32] bits.
1734 *
1735 * \param randomNum
1736 * The pointer to a generated true random number. __Must be 4-byte aligned.__
1737 *
1738 * \param cfContext
1739 * The pointer to the \ref cy_stc_crypto_context_trng_t structure that stores
1740 * the Crypto driver context.
1741 *
1742 * \return
1743 * \ref cy_en_crypto_status_t
1744 *
1745 * \funcusage
1746 * \snippet crypto/snippet/main.c snippet_myCryptoTrngUse
1747 *
1748 *******************************************************************************/
1749 cy_en_crypto_status_t Cy_Crypto_Trng_Generate(uint32_t  GAROPol,
1750                                               uint32_t  FIROPol,
1751                                               uint32_t  max,
1752                                               uint32_t *randomNum,
1753                                               cy_stc_crypto_context_trng_t *cfContext);
1754 #endif /* (CPUSS_CRYPTO_TR == 1) && defined(CY_CRYPTO_CFG_TRNG_C) */
1755 
1756 #if (CPUSS_CRYPTO_DES == 1) && defined(CY_CRYPTO_CFG_DES_C)
1757 /*******************************************************************************
1758 * Function Name: Cy_Crypto_Des_Run
1759 ****************************************************************************//**
1760 *
1761 * This function performs DES operation on a Single Block. All addresses must be
1762 * 4-Byte aligned.
1763 * Ciphertext (dstBlock) may overlap with plaintext (srcBlock)
1764 * There is no Init function. Provide the required parameters and the pointer
1765 * to the context structure when making this function call.
1766 *
1767 * \param dirMode
1768 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
1769 * (\ref cy_en_crypto_dir_mode_t)
1770 *
1771 * \param key
1772 * The pointer to the encryption/decryption key. __Must be 4-byte aligned.__
1773 *
1774 * \param srcBlock
1775 * The pointer to a source block. __Must be 4-byte aligned.__
1776 *
1777 * \param dstBlock
1778 * The pointer to a destination cipher block. __Must be 4-byte aligned.__
1779 *
1780 * \param cfContext
1781 * The pointer to the cy_stc_crypto_context_des_t structure that stores
1782 * the Crypto driver context.
1783 *
1784 * \return
1785 * \ref cy_en_crypto_status_t
1786 *
1787 *******************************************************************************/
1788 cy_en_crypto_status_t Cy_Crypto_Des_Run(cy_en_crypto_dir_mode_t dirMode,
1789                                         uint32_t *key,
1790                                         uint32_t *dstBlock,
1791                                         uint32_t *srcBlock,
1792                                         cy_stc_crypto_context_des_t *cfContext);
1793 
1794 /*******************************************************************************
1795 * Function Name: Cy_Crypto_Tdes_Run
1796 ****************************************************************************//**
1797 *
1798 * This function performs the TDES operation on a single block. All addresses
1799 * __Must be 4-byte aligned.__
1800 * Ciphertext (dstBlock) may overlap with plaintext (srcBlock).
1801 * There is no Init function. Provide the required parameters and the pointer
1802 * to the context structure when making this function call.
1803 *
1804 * \param dirMode
1805 * Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
1806 * (\ref cy_en_crypto_dir_mode_t)
1807 *
1808 * \param key
1809 * The pointer to the encryption/decryption key. __Must be 4-byte aligned.__
1810 *
1811 * \param srcBlock
1812 * The pointer to a source block. __Must be 4-byte aligned.__
1813 *
1814 * \param dstBlock
1815 * The pointer to a destination cipher block. __Must be 4-byte aligned.__
1816 *
1817 * \param cfContext
1818 * The pointer to the cy_stc_crypto_context_des_t structure that stores
1819 * the Crypto driver context.
1820 *
1821 * \return
1822 * \ref cy_en_crypto_status_t
1823 *
1824 * \funcusage
1825 * \snippet crypto/snippet/main.c snippet_myCryptoTdesUse
1826 *
1827 *******************************************************************************/
1828 cy_en_crypto_status_t Cy_Crypto_Tdes_Run(cy_en_crypto_dir_mode_t dirMode,
1829                                          uint32_t *key,
1830                                          uint32_t *dstBlock,
1831                                          uint32_t *srcBlock,
1832                                          cy_stc_crypto_context_des_t *cfContext);
1833 #endif /* (CPUSS_CRYPTO_DES == 1) && defined(CY_CRYPTO_CFG_DES_C) */
1834 
1835 #if (CPUSS_CRYPTO_VU == 1) && defined(CY_CRYPTO_CFG_RSA_C)
1836 /*******************************************************************************
1837 * Function Name: Cy_Crypto_GetMemBufAddress
1838 ****************************************************************************//**
1839 *
1840 * This function gets an operation memory buffer location.
1841 *
1842 * \param membufAddress
1843 * The pointer of the operation memory buffer.
1844 *
1845 * \param cfContext
1846 * The pointer to the \ref cy_stc_crypto_context_str_t structure that stores
1847 * the data context.
1848 *
1849 * \return
1850 * \ref cy_en_crypto_status_t
1851 *
1852 *******************************************************************************/
1853 cy_en_crypto_status_t Cy_Crypto_GetMemBufAddress(uint32_t **membufAddress,
1854                                            cy_stc_crypto_context_str_t *cfContext);
1855 
1856 /*******************************************************************************
1857 * Function Name: Cy_Crypto_GetMemBufSize
1858 ****************************************************************************//**
1859 *
1860 * This function gets an operation memory buffer size.
1861 *
1862 * \param membufSize
1863 * The size of the memory buffer (in bytes)
1864 *
1865 * \param cfContext
1866 * The pointer to the \ref cy_stc_crypto_context_str_t structure that stores
1867 * the data context.
1868 *
1869 * \return
1870 * \ref cy_en_crypto_status_t
1871 *
1872 *******************************************************************************/
1873 cy_en_crypto_status_t Cy_Crypto_GetMemBufSize(uint32_t *membufSize,
1874                                            cy_stc_crypto_context_str_t *cfContext);
1875 
1876 /*******************************************************************************
1877 * Function Name: Cy_Crypto_SetMemBufAddress
1878 ****************************************************************************//**
1879 *
1880 * This function sets a new operation memory buffer.
1881 *
1882 * \param newMembufAddress
1883 * The pointer to the new operation memory buffer.
1884 * __Must be 4-byte aligned.__
1885 *
1886 * \param newMembufSize
1887 * The size of the new memory buffer (in bytes)
1888 *
1889 * \param cfContext
1890 * The pointer to the \ref cy_stc_crypto_context_str_t structure that stores
1891 * the data context.
1892 *
1893 * \return
1894 * \ref cy_en_crypto_status_t
1895 *
1896 * \note This function sets the default device specific values
1897 *       when vuMemoryAddr parameter is NULL and vuMemorySize parameter is zero.
1898 *
1899 * \note New memory buffer should be allocated in a memory region that is not
1900 *       protected by a protection scheme for use by Crypto hardware.
1901 *
1902 *******************************************************************************/
1903 cy_en_crypto_status_t Cy_Crypto_SetMemBufAddress(uint32_t const *newMembufAddress,
1904                                            uint32_t newMembufSize,
1905                                            cy_stc_crypto_context_str_t *cfContext);
1906 
1907 /*******************************************************************************
1908 * Function Name: Cy_Crypto_Rsa_Proc
1909 ****************************************************************************//**
1910 *
1911 * This function calculates (m^e mod modulo) where m is Message (Signature), e -
1912 * public exponent using a public key in the next representation, it contains:
1913 * modulo,
1914 * public exponent,
1915 * coefficient for Barrett reduction,
1916 * binary inverse of the modulo, and
1917 * result of (2^moduloLength mod modulo).
1918 *
1919 * Not all fields in a key must be given. Modulo and public exponents are mandatory;
1920 * Barrett coefficient, inverse modulo, and r-bar are optional.
1921 * If they don't exist, their according pointers should be NULL. These coefficients
1922 * could be calculated by \ref Cy_Crypto_Rsa_CalcCoefs.
1923 * Their presence accelerates performance by five times.
1924 * Approximate performance for 1024-bit modulo is 41.6 ms; for 2048-bit modulo is
1925 * 142 ms when using a 25 MHz clock for Crypto HW. These numbers just for reference.
1926 * They depend on many factors (compiler, optimization level, etc.).
1927 *
1928 * Returns the processed value and a success value.
1929 *
1930 * \note <b>Incoming message</b> and <b>result processed message</b> must be in
1931 * little-endian order.<br>
1932 * The <b>modulus</b> and <b>exponent</b> values in the \ref cy_stc_crypto_rsa_pub_key_t
1933 * must also be in little-endian order.<br>
1934 * Use \ref Cy_Crypto_InvertEndianness function to convert to or from
1935 * little-endian order.
1936 *
1937 * \param pubKey
1938 * The pointer to the \ref cy_stc_crypto_rsa_pub_key_t structure that stores
1939 * public key.
1940 *
1941 * \param message
1942 * The pointer to the message to be processed. __Must be 4-byte aligned.__
1943 *
1944 * \param messageSize
1945 * The length of the message to be processed.
1946 *
1947 * \param processedMessage
1948 * The pointer to processed message. __Must be 4-byte aligned.__
1949 *
1950 * \param cfContext
1951 * The pointer to the \ref cy_stc_crypto_context_rsa_t structure that stores
1952 * the RSA context.
1953 *
1954 * \return
1955 * \ref cy_en_crypto_status_t
1956 *
1957 *******************************************************************************/
1958 cy_en_crypto_status_t Cy_Crypto_Rsa_Proc(cy_stc_crypto_rsa_pub_key_t const *pubKey,
1959                                          uint32_t const *message,
1960                                          uint32_t messageSize,
1961                                          uint32_t *processedMessage,
1962                                          cy_stc_crypto_context_rsa_t *cfContext);
1963 
1964 /*******************************************************************************
1965 * Function Name: Cy_Crypto_Rsa_CalcCoefs
1966 ****************************************************************************//**
1967 *
1968 * This function calculates constant coefficients (which is dependent only on modulo
1969 * and independent on message). With this pre-calculated coefficients calculations
1970 * speed-up by five times.
1971 *
1972 * These coefficients are:
1973 *                         coefficient for Barrett reduction,
1974 *                         binary inverse of the modulo,
1975 *                         result of (2^moduloLength mod modulo)
1976 *
1977 * Calculated coefficients will be placed by addresses provided in the
1978 * pubKey structure for according coefficients.
1979 * Function overwrites previous values.
1980 * Approximate performance for 1024-bit modulo is 33.2 ms; for 2048-bit modulo is
1981 * 113 ms when using a 25 MHz clock for Crypto HW. These numbers are just for
1982 * reference.
1983 * They depend on many factors (compiler, optimization level, etc.).
1984 *
1985 * \param pubKey
1986 * The pointer to the \ref cy_stc_crypto_rsa_pub_key_t structure that stores a
1987 * public key.
1988 *
1989 * \param cfContext
1990 * The pointer to the \ref cy_stc_crypto_context_rsa_t structure that stores
1991 * the RSA context.
1992 *
1993 * \return
1994 * \ref cy_en_crypto_status_t
1995 *
1996 *******************************************************************************/
1997 cy_en_crypto_status_t Cy_Crypto_Rsa_CalcCoefs(cy_stc_crypto_rsa_pub_key_t const *pubKey,
1998                                          cy_stc_crypto_context_rsa_t *cfContext);
1999 
2000 #if (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_SHA_C) && defined(CY_CRYPTO_CFG_RSA_VERIFY_ENABLED)
2001 /*******************************************************************************
2002 * Function Name: Cy_Crypto_Rsa_Verify
2003 ****************************************************************************//**
2004 *
2005 * This function does an RSA verification with checks for content, paddings, and
2006 * signature format.
2007 * The SHA digest of the message and decrypted message should be calculated first.
2008 * Supports only PKCS1-v1_5 format. Inside of this format supported padding
2009 * using only SHA. Cases with MD2 and MD5 are not supported.
2010 *
2011 * PKCS1-v1_5 described here, page 31:
2012 * http://www.emc.com/collateral/white-papers/h11300-pkcs-1v2-2-rsa-cryptography-standard-wp.pdf
2013 *
2014 * Returns the verification result \ref cy_en_crypto_rsa_ver_result_t.
2015 *
2016 * \param verResult
2017 * The pointer to the verification result \ref cy_en_crypto_rsa_ver_result_t.
2018 *
2019 * \param digestType
2020 * SHA mode used for hash calculation \ref cy_en_crypto_sha_mode_t.
2021 *
2022 * \param digest
2023 * The pointer to the hash of the message whose signature is to be verified.
2024 * __Must be 4-byte aligned.__
2025 *
2026 * \param decryptedSignature
2027 * The pointer to the decrypted signature to be verified.
2028 * __Must be 4-byte aligned.__
2029 *
2030 * \param decryptedSignatureLength
2031 * The length of the decrypted signature to be verified (in bytes)
2032 *
2033 * \param cfContext
2034 * The pointer to the \ref cy_stc_crypto_context_rsa_ver_t structure that stores
2035 * the RSA context.
2036 *
2037 * \return
2038 * \ref cy_en_crypto_status_t
2039 *
2040 *******************************************************************************/
2041 cy_en_crypto_status_t Cy_Crypto_Rsa_Verify(cy_en_crypto_rsa_ver_result_t *verResult,
2042                                            cy_en_crypto_sha_mode_t digestType,
2043                                            uint32_t const *digest,
2044                                            uint32_t const *decryptedSignature,
2045                                            uint32_t decryptedSignatureLength,
2046                                            cy_stc_crypto_context_rsa_ver_t *cfContext);
2047 #endif /* (CPUSS_CRYPTO_SHA == 1) && defined(CY_CRYPTO_CFG_SHA_C) && defined(CY_CRYPTO_CFG_RSA_VERIFY_ENABLED) */
2048 #endif /* (CPUSS_CRYPTO_VU == 1) && defined(CY_CRYPTO_CFG_RSA_C) */
2049 
2050 #if (CPUSS_CRYPTO_VU == 1) && defined(CY_CRYPTO_CFG_ECDSA_C)
2051 #if defined(CY_CRYPTO_CFG_ECDSA_SIGN_C)
2052 /*******************************************************************************
2053 * Function Name: Cy_Crypto_ECDSA_SignHash
2054 ****************************************************************************//**
2055 *
2056 * Sign a message digest.
2057 *
2058 * \param hash
2059 * The message digest to sign. Provided as is in data buffer.
2060 *
2061 * \param hashlen
2062 * The length of the digest in bytes.
2063 *
2064 * \param sig
2065 * [out] The destination for the signature, 'R' followed by 'S'.
2066 *
2067 * \param key
2068 * Key used for signature generation. See \ref cy_stc_crypto_ecc_key.
2069 *
2070 * \param messageKey
2071 * Message key.
2072 *
2073 * \param cfContext
2074 * The pointer to the \ref cy_stc_crypto_context_ecc_t structure that stores
2075 * the ECC operation context.
2076 *
2077 * \return status code. See \ref cy_en_crypto_status_t.
2078 *
2079 *******************************************************************************/
2080 cy_en_crypto_status_t Cy_Crypto_ECDSA_SignHash(const uint8_t *hash,
2081                                         uint32_t hashlen,
2082                                         uint8_t *sig,
2083                                         const cy_stc_crypto_ecc_key *key,
2084                                         const uint8_t *messageKey,
2085                                         cy_stc_crypto_context_ecc_t *cfContext);
2086 #endif /* defined(CY_CRYPTO_CFG_ECDSA_SIGN_C) */
2087 
2088 #if defined(CY_CRYPTO_CFG_ECDSA_VERIFY_C)
2089 /*******************************************************************************
2090 * Function Name: Cy_Crypto_ECDSA_VerifyHash
2091 ****************************************************************************//**
2092 *
2093 * Verify an ECC signature.
2094 *
2095 * \param sig
2096 * The signature to verify, 'R' followed by 'S'.
2097 *
2098 * \param hash
2099 * The message digest that was signed. Provided as is in data buffer.
2100 *
2101 * \param hashlen
2102 * The length of the digest in bytes.
2103 *
2104 * \param stat
2105 * Result of signature, 1==valid, 0==invalid.
2106 *
2107 * \param key
2108 * The corresponding public ECC key. See \ref cy_stc_crypto_ecc_key.
2109 *
2110 * \param cfContext
2111 * The pointer to the \ref cy_stc_crypto_context_ecc_t structure that stores
2112 * the ECC operation context.
2113 *
2114 * \return status code. See \ref cy_en_crypto_status_t.
2115 *
2116 *******************************************************************************/
2117 cy_en_crypto_status_t Cy_Crypto_ECDSA_VerifyHash(const uint8_t *sig,
2118                                         const uint8_t *hash,
2119                                         uint32_t hashlen,
2120                                         uint8_t *stat,
2121                                         const cy_stc_crypto_ecc_key *key,
2122                                         cy_stc_crypto_context_ecc_t *cfContext);
2123 
2124 #endif /* defined(CY_CRYPTO_CFG_ECDSA_VERIFY_C) */
2125 #endif /* (CPUSS_CRYPTO_VU == 1) && defined(CY_CRYPTO_CFG_ECDSA_C) */
2126 
2127 /*******************************************************************************
2128 * Function Name: Cy_Crypto_InvertEndianness
2129 ****************************************************************************//**
2130 *
2131 * This function reverts byte-array memory block, like:<br>
2132 * inArr[0] <---> inArr[n]<br>
2133 * inArr[1] <---> inArr[n-1]<br>
2134 * inArr[2] <---> inArr[n-2]<br>
2135 * ........................<br>
2136 * inArr[n/2] <---> inArr[n/2-1]<br>
2137 *
2138 * Odd or even byteSize are acceptable.
2139 *
2140 * \param inArrPtr
2141 * The pointer to the memory whose endianness is to be inverted.
2142 *
2143 * \param byteSize
2144 * The length of the memory array whose endianness is to be inverted (in bytes)
2145 *
2146 *******************************************************************************/
2147 void Cy_Crypto_InvertEndianness(void *inArrPtr, uint32_t byteSize);
2148 
2149 /** \cond INTERNAL */
2150 /* For backward compatibility */
2151 #define Cy_Crypto_Rsa_InvertEndianness(p, s) Cy_Crypto_InvertEndianness((p), (s))
2152 /** \endcond */
2153 
2154 /** \} group_crypto_cli_functions */
2155 
2156 #if defined(__cplusplus)
2157 }
2158 #endif
2159 
2160 #endif /* CY_IP_MXCRYPTO */
2161 
2162 #endif /* (CY_CRYPTO_H) */
2163 
2164 /** \} group_crypto */
2165 
2166 
2167 /* [] END OF FILE */
2168