PSOC6: update PDL to the latest version

pull/9762/head
Volodymyr Medvid 2019-02-15 14:33:59 +02:00
parent 400fd82972
commit edb944abf0
59 changed files with 3237 additions and 3110 deletions

View File

@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_ble_clk.h
* \version 3.0
* \version 3.10
*
* The header file of the BLE ECO clock driver.
*
@ -70,7 +70,14 @@
* <table class="doxtable">
* <tr><th>Version</th><th>Changes</th><th>Reason of Change</th></tr>
* <tr>
* <td>3.0.0</td>
* <td>3.10</td>
* <td>Updated the Cy_BLE_EcoConfigure() use case, when the voltageReg parameter is CY_BLE_ECO_VOLTAGE_REG_BLESSLDO
* and the Buck core regulator is enabled.</td>
* <td>Defect fixing: Before, when the Cy_BLE_EcoConfigure() function included the BLE LDO regulator option, the function returned CY_BLE_ECO_HARDWARE_ERROR if
* the Buck core regulator had been enabled.</td>
* </tr>
* <tr>
* <td>3.0</td>
* <td>The initial version. \n The functionality of the BLE ECO clock is migrated from the BLE Middleware to the separated driver (ble_clk).</td>
* <td>Independent usage of BLE ECO clock without BLE Middleware.</td>
* </tr>

View File

@ -26,8 +26,7 @@
* \addtogroup group_crypto
* \{
* The Crypto driver provides a public API to perform cryptographic and hash
* operations, as well as generate both true and pseudo random numbers
* (TRNG, PRNG).
* operations, as well as generate both true and pseudo random numbers.
*
* It uses a hardware IP block to accelerate operations.
*
@ -35,9 +34,43 @@
* cy_crypto_core.h, and cy_crypto_server.h. You can also include cy_pdl.h
* (ModusToolbox only) to get access to all functions and declarations in the PDL.
*
* The driver
* supports these standards: DES, TDES, AES (128, 192, 256 bits), CMAC-AES, SHA,
* HMAC, PRNG, TRNG, CRC, and RSA.
* The driver implements two usage models:
* * \ref group_crypto_cli_srv
* * \ref group_crypto_lld_api
*
* Mixing these usage models will result in undefined behaviour.
*
* The Crypto driver supports these standards: DES, TDES, AES (128, 192, 256 bits), CMAC-AES, SHA,
* HMAC, PRNG, TRNG, CRC, RSA, ECP, and ECDSA.
* \note ECP and ECDSA are only implemented for the \ref group_crypto_lld_api model.
*
* \section group_crypto_configuration_considerations Configuration Considerations
*
* Firmware sets up a cryptographic operation by passing in the required data as
* parameters in the function calls.
*
* All Crypto functions require a context. A context is a data
* structure that the driver uses for its operations. Firmware declares a
* context (allocates memory) but does not write or read the values in that
* context. In effect, the context is a scratch pad you provide to the driver.
* The driver uses the context to store and manipulate data during cryptographic
* operations.
*
* Several methods require an additional context unique to the particular
* cryptographic technique.
* The Crypto driver header files declare all the required structures for both
* configuration and context.
*
* Some encryption techniques require additional initialization specific to the
* technique. If there is an Init function, you must call it before using any
* other function for that technique, and re-initialize after you use a different
* encryption technique.
*
* For example, use \ref Cy_Crypto_Aes_Init to configure an AES encryption
* operation with the encryption key, and key length.
* Provide pointers to two context structures. You can then call the AES Run functions.
* If you use DES after that, you must re-initialize the AES encryption before using
* it again.
*
* \section group_crypto_definitions Definitions
*
@ -63,16 +96,16 @@
* This function takes a fixed-size key and a block of plaintext data from
* the message and encrypts it to generate ciphertext. Block ciphers are
* reversible. The function performed on a block of encrypted data will
* decrypt it.</td>
* decrypt that data.</td>
* </tr>
*
* <tr>
* <td>Block Cipher Mode</td>
* <td>A mode of encrypting a message using block ciphers for messages of
* <td>A mode of encrypting a message using block ciphers for messages of an
* arbitrary length. The message is padded so that its length is an integer
* multiple of the block size. ECB (Electronic Code Book), CBC (Cipher Block
* Chaining), and CFB (Cipher Feedback) are all modes of using block ciphers
* to create an encrypted message of arbitrary length.
* to create an encrypted message of an arbitrary length.
* </td>
* </tr>
*
@ -80,8 +113,8 @@
* <td>Data Encryption Standard (DES)</td>
* <td>The [DES standard]
* (https://csrc.nist.gov/csrc/media/publications/fips/46/3/archive/1999-10-25/documents/fips46-3.pdf)
* specifies a symmetric-key algorithm for the encryption of electronic data.
* It uses a 56-bit key and a 64-bit message block size.
* specifies a symmetric-key algorithm for encryption of electronic data.
* It uses a 56-bit key. The block size is 64-bits.
* </td>
* </tr>
*
@ -89,7 +122,7 @@
* <td>Triple DES (3DES or TDES)</td>
* <td>The [TDES standard]
* (https://csrc.nist.gov/csrc/media/publications/fips/46/3/archive/1999-10-25/documents/fips46-3.pdf)
* specifies a symmetric-key block cipher, which applies the Data Encryption
* specifies a symmetric-key block cipher that applies the Data Encryption
* Standard (DES) cipher algorithm three times to each data block.
* It uses three 56-bit keys. The block size is 64-bits.
* </td>
@ -99,17 +132,17 @@
* <td>Advanced Encryption Standard (AES)</td>
* <td>The [AES standard] (https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.197.pdf)
* specifies the Rijndael algorithm, a symmetric block
* cipher that can process data blocks of 128 bits, using cipher keys with
* lengths of 128, 192, and 256 bits. Rijndael was designed to handle
* additional block sizes and key lengths, however they are not adopted in
* cipher that can process 128-bit data blocks, using cipher keys with
* 128-, 192-, and 256-bit lengths. Rijndael was designed to handle
* additional block sizes and key lengths. However, they are not adopted in
* this standard. AES is also used for message authentication.
* </td>
* </tr>
*
* <tr>
* <td>Secure Hash Algorithm (SHA)</td>
* <td>Is a cryptographic hash function.
* This function takes a message of the arbitrary length and reduces it to a
* <td>A cryptographic hash function.
* This function takes a message of an arbitrary length and reduces it to a
* fixed-length residue or message digest after performing a series of
* mathematically defined operations that practically guarantee that any
* change in the message will change the hash value. It is used for message
@ -136,7 +169,7 @@
*
* <tr>
* <td>Cipher-based Message Authentication Code (CMAC)</td>
* <td>This is a block cipher-based message authentication code algorithm.
* <td>A block cipher-based message authentication code algorithm.
* It computes the MAC value using the AES block cipher algorithm.</td>
* For more information see [Recommendation for Block Cipher Modes of Operation]
* (https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-38b.pdf).
@ -144,7 +177,7 @@
*
* <tr>
* <td>Hash Message Authentication Code (HMAC)</td>
* <td>Is a specific type of message authentication code (MAC) involving a
* <td>A specific type of message authentication code (MAC) that involves a
* cryptographic hash function and a secret cryptographic key.
* It computes the MAC value using a Hash algorithm.
* For more information see [The Keyed-Hash Message Authentication Code standard]
@ -154,7 +187,7 @@
*
* <tr>
* <td>Pseudo Random Number Generator (PRNG)</td>
* <td>Is a Linear Feedback Shift Registers-based algorithm for generating a
* <td>A Linear Feedback Shift Registers-based algorithm for generating a
* sequence of numbers starting from a non-zero seed.</td>
* </tr>
*
@ -176,15 +209,15 @@
*
* <tr>
* <td>Asymmetric Key Cryptography</td>
* <td>Also referred to as Public Key encryption. Someone who wishes to
* receive a message, publishes a very large public key (up to 4096 bits
* currently), which is one of two prime factors of a very large number. The
* other prime factor is the private key of the recipient and a secret.
* Someone wishing to send a message to the publisher of the public key
* encrypts the message with the public key. This message can now be
* decrypted only with the private key (the other prime factor held secret by
* <td>Also referred to as Public Key encryption. To receive a message,
* you publish a very large public key (up to 4096 bits currently).
* That key is one of the two prime factors of a very large number. The
* other prime factor is the recipient's private (secret) key.
* To send a message to the publisher of the public key, you
* encrypt the message with the public key. This message can now be
* decrypted only with the private key (the other prime factor held in secret by
* the recipient). The message is now sent over any channel to the recipient
* who can decrypt it with the private, secret, key. The same process is used
* who can decrypt it with the private (secret) key. The same process is used
* to send messages to the sender of the original message. The asymmetric
* cryptography relies on the mathematical impracticality (usually related to
* the processing power available at any given time) of factoring the keys.
@ -192,7 +225,7 @@
* The public key is described by the pair (n, e) where n is a product of two
* randomly chosen primes p and q. The exponent e is a random integer
* 1 < e < Q where Q = (p-1) (q-1). The private key d is uniquely defined
* by the integer 1 < d < Q such that ed congruent to 1 (mod Q ).
* by the integer 1 < d < Q so that ed congruent with 1 (mod Q ).
* </td>
* </tr>
* </table>
@ -202,10 +235,51 @@
* RSASSA-PKCS1-v1_5 described here, page 31:
* http://www.emc.com/collateral/white-papers/h11300-pkcs-1v2-2-rsa-cryptography-standard-wp.pdf
*
* See the Cryptographic Function Block chapter of the Technical Reference Manual.
* See the "Cryptographic Function Block" chapter of the Technical Reference Manual.
*
* \section group_crypto_MISRA MISRA-C Compliance
* This driver does not contains any driver-specific MISRA violations.
* The Crypto driver has the following specific deviations:
*
* <table class="doxtable">
* <tr>
* <th>MISRA Rule</th>
* <th>Rule Class (Required/Advisory)</th>
* <th>Rule Description</th>
* <th>Description of Deviation(s)</th>
* </tr>
* <tr>
* <td>8.8</td>
* <td>A</td>
* <td>An external object or function shall be declared in one and only
* one file.</td>
* <td>The pointer to the operation context memory can not be public
* accessible (can not be defined in the header file) but it should be
* extarnally accessed, because it is used by other Cypress software
* resources.</td>
* </tr>
* <tr>
* <td>11.4</td>
* <td>A</td>
* <td>A cast should not be performed between a pointer to object type and
* a different pointer to object type.</td>
* <td>The pointers to the context memory are void to allow handling of
* different data types for different operations.
* The cast operation is safe because the configuration is verified
* before operation is performed.
* </td>
* </tr>
* <tr>
* <td>16.7</td>
* <td>A</td>
* <td>A pointer parameter in a function prototype should be declared as
* pointer to const if the pointer is not used to modify the addressed
* object.</td>
* <td>The objects pointed to by the base addresses of the CRYPTO are not
* always modified. While a const qualifier can be used in select
* scenarios, it brings little benefit in adding this to the affected
* functions. </td>
* </tr>
* </table>
*
* \section group_crypto_changelog Changelog
* <table class="doxtable">
@ -214,15 +288,16 @@
* <td>2.20</td>
* <td>
* <ul>
* <li>Moved from pre-compiled library to Open Source under
* <li>Moved from a pre-compiled library to Open Source under
* Apache 2.0 license.</li>
* <li>Added ECP and ECDSA support for NIST P curves:
* <li>Core (server) This API is now available.</li>
* <li>Added ECP and ECDSA support for the NIST P curves:
* SECP192R1, SECP224R1, SECP256R1, SECP384R1, SECP521R1.</li>
* <li>ECP and ECDSA only supported with direct calls to Crypto APIs,
* no client interface functions present.</li>
* <li>Added chunk mode for CRC.</li>
* <li>Added chunk mode for SHA, chunk size is limited to
* SHA block size.</li>
* no client interface functions are present.</li>
* <li>Added Chunk mode for CRC.</li>
* <li>Added Chunk mode for SHA, the chunk size is limited to
* the SHA block size.</li>
* </ul>
* </td>
* <td>ECC support added.<br>
@ -232,22 +307,22 @@
* </tr>
* <tr>
* <td>2.11b</td>
* <td>Same as production 2.10; only newly added Elliptic Curve point
* <td>The same as production 2.10; only the newly-added Elliptic Curve point
* multiplication functionality (NIST P256) is pre-production.
* Open source under Apache version 2.0 license.</td>
* <td></td>
* </tr>
* <tr>
* <td>2.11</td>
* <td>Based on pre-production 2.10, except newly added Elliptic Curve point
* <td>Based on pre-production 2.10, except the newly-added Elliptic Curve point
* multiplication functionality (NIST P256).
* Does not incorporate production level documentation.
* Does not incorporate the production level documentation.
* Open source under Apache version 2.0 license.</td>
* <td>ECC support.</td>
* </tr>
* <tr>
* <td>2.10b</td>
* <td>Same as production 2.10. Open source under Apache version 2.0 license.</td>
* <td>The same as production 2.10. Open source under Apache version 2.0 license.</td>
* <td></td>
* </tr>
* <tr>
@ -267,7 +342,7 @@
* <td></td>
* </tr>
* <tr>
* <td>Added register access layer. Use register access macros instead
* <td>Added the register access layer. Use register access macros instead
* of direct register access using dereferenced pointers.</td>
* <td>Makes register access device-independent, so that the PDL does
* not need to be recompiled for each supported part number.</td>
@ -278,7 +353,7 @@
* </tr>
* <tr>
* <td>2.0b</td>
* <td>Same as production 2.0. Open source under Apache version 2.0 license.</td>
* <td>The same as production 2.0. Open source under Apache version 2.0 license.</td>
* <td></td>
* </tr>
* <tr>
@ -289,15 +364,15 @@
* \ref Cy_Crypto_Trng_Generate, \ref Cy_Crypto_Des_Run,
* \ref Cy_Crypto_Tdes_Run, \ref Cy_Crypto_Rsa_Proc
* </td>
* <td>Documentation update and clarification</td>
* <td>Documentation update and clarification.</td>
* </tr>
* <tr>
* <td>
* Changed crypto IP power control<br>
* Enhanced Vector Unit functionality for RSA crypto algorithm<br>
* Added support of the single-core devices
* Changed crypto IP power control.<br>
* Enhanced Vector Unit functionality for RSA crypto algorithm.<br>
* Added support of the single-core devices.
* </td>
* <td>New device support</td>
* <td>New device support.</td>
* </tr>
* <tr>
* <td>1.0</td>
@ -306,29 +381,24 @@
* </tr>
* </table>
*
* \defgroup group_crypto_cli_srv Client-Server API
* \defgroup group_crypto_cli_srv Client-Server Model
* \{
* \defgroup group_crypto_client Client
* \defgroup group_crypto_cli_srv_macros Macros
* \defgroup group_crypto_cli_srv_functions Functions
* \{
* Client part of the Crypto.
* \defgroup group_crypto_macros Macros
* \defgroup group_crypto_cli_functions Functions
* \defgroup group_crypto_cli_data_structures Data Structures
* \defgroup group_crypto_enums Enumerated Types
* \defgroup group_crypto_cli_functions Client Functions
* \defgroup group_crypto_srv_functions Server Functions
* \}
* \defgroup group_crypto_server Server
* \defgroup group_crypto_cli_srv_data_structures Data Structures
* \{
* Server part of the Crypto.
* \defgroup group_crypto_srv_functions Functions
* \defgroup group_crypto_srv_data_structures Data Structures
* \}
* \defgroup group_crypto_config_structure Configuration Structure
* \{
* Crypto initialization configuration.
* \note Should be the same for Crypto Server and Crypto Client initializations.
* \defgroup group_crypto_config_structure Common Data Structures
* \defgroup group_crypto_cli_data_structures Client Data Structures
* \defgroup group_crypto_srv_data_structures Server Data Structures
* \}
* \}
* \defgroup group_crypto_lld_api Low-Level API
* \defgroup group_crypto_lld_api Direct Crypto Core Access
* \defgroup group_crypto_data_structures Common Data Structures
* \defgroup group_crypto_enums Common Enumerated Types
*/
/**
@ -342,20 +412,19 @@
* (ModusToolbox only) to get access to all functions and declarations in the
* PDL.
*
* Firmware initializes and starts the Crypto server. The server can run on any
* The firmware initializes and starts the Crypto server. The server can run on any
* core and works with the Crypto hardware. The Crypto server is implemented as
* a secure block. It performs all cryptographic operations for the client.
* Access to the server is through the Inter Process Communication (IPC) driver.
* Direct access is not allowed.
*
* The Crypto client can run on any core too. Firmware initializes and starts
* the client. The firmware then provides the configuration data required for
* the desired cryptographic technique, and requests that the server run the
* The Crypto client can run on any core too. The firmware initializes and starts
* the client. The firmware then provides configuration data required for
* the desired cryptographic technique and a request that the server run the
* cryptographic operation.
*
* This document contains the following topics:
* - \ref group_crypto_architecture
* - \ref group_crypto_configuration_considerations
* - \ref group_crypto_configuration_structure
* - \ref group_crypto_server_init
* - \ref group_crypto_client_init
@ -396,23 +465,6 @@
* Using IPC for communication provides a simple synchronization mechanism to
* handle concurrent requests from different cores.
*
* \section group_crypto_configuration_considerations Configuration Considerations
*
* Firmware sets up a cryptographic operation by passing in required data as
* parameters in function calls.
*
* All Crypto functions require a context. A context is a data
* structure that the driver uses for its operations. Firmware declares the
* context (allocates memory) but does not write or read the values in the
* context. In effect the context is a scratch pad you provide to the driver.
* The driver uses the context to store and manipulate data during cryptographic
* operations.
*
* Several methods require an additional context unique to the particular
* cryptographic technique.
* The Crypto driver header files declare all the required structures for both
* configuration and context.
*
* \section group_crypto_configuration_structure Configuration Structure
*
* IPC communication for the Crypto driver is handled transparently. User should
@ -527,17 +579,6 @@
*
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoInit
*
* Some encryption techniques require additional initialization specific to the
* technique. If there is an Init function, you must call it before using any
* other function for that technique, and reinitialize after you use a different
* encryption technique.
*
* For example, use \ref Cy_Crypto_Aes_Init to configure an AES encryption
* operation with the encryption key, and key length.
* Provide pointers to two context structures. You can then call AES Run functions.
* If later on you use DES, you must re-initialize AES encryption before using
* it again.
*
* \section group_crypto_common_use_cases Common Use Cases
*
* \subsection group_crypto_Use_CRC CRC Calculation
@ -667,9 +708,9 @@
* (2^moduloLength mod modulo). These fields are optional, and can be set to NULL.
*
* Calculate these coefficients with \ref Cy_Crypto_Rsa_CalcCoefs.
* Pass in the address of the key structure with the modulus and exponent values
* for the key. The function returns the coefficients for the key in the key
* structure, replacing any previous values.
* Pass them in the address of the key structure with the modulus and exponent
* values for the key. The function returns the coefficients for the key in the
* key structure, replacing any previous values.
*
* The RSA functionality also implements functions to decrypt a signature using
* a public key. This signature must follow the RSASSA-PKCS-v1_5 standard.
@ -786,7 +827,7 @@ cy_en_crypto_status_t Cy_Crypto_GetLibraryInfo(cy_en_crypto_lib_info_t *cryptoIn
* that stores the Crypto driver common context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoInit
@ -801,7 +842,7 @@ cy_en_crypto_status_t Cy_Crypto_Init(cy_stc_crypto_config_t const *config, cy_st
* This function de-initializes the Crypto driver.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_DeInit(void);
@ -813,7 +854,7 @@ cy_en_crypto_status_t Cy_Crypto_DeInit(void);
* This function enables (turns on) the Crypto hardware.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Enable(void);
@ -825,7 +866,7 @@ cy_en_crypto_status_t Cy_Crypto_Enable(void);
* This function disables (turns off) the Crypto hardware.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Disable(void);
@ -843,7 +884,7 @@ cy_en_crypto_status_t Cy_Crypto_Disable(void);
* False - is not blocking.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Sync(bool isBlocking);
@ -859,7 +900,7 @@ cy_en_crypto_status_t Cy_Crypto_Sync(bool isBlocking);
* \ref cy_stc_crypto_hw_error_t.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_GetErrorStatus(cy_stc_crypto_hw_error_t *hwErrorCause);
@ -890,7 +931,7 @@ cy_en_crypto_status_t Cy_Crypto_GetErrorStatus(cy_stc_crypto_hw_error_t *hwError
* the Crypto function context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoPrngUse
@ -920,7 +961,7 @@ cy_en_crypto_status_t Cy_Crypto_Prng_Init(uint32_t lfsr32InitState,
* the Crypto function context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoPrngUse
@ -953,7 +994,7 @@ cy_en_crypto_status_t Cy_Crypto_Prng_Generate(uint32_t max,
* internal variables the Crypto driver requires.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoAesEcbUse
@ -986,7 +1027,7 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Init(uint32_t *key,
* that stores all AES internal variables.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoAesEcbUse
@ -1025,7 +1066,7 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Ecb_Run(cy_en_crypto_dir_mode_t dirMode,
* internal variables the Crypto driver requires.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Aes_Cbc_Run(cy_en_crypto_dir_mode_t dirMode,
@ -1053,17 +1094,17 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Cbc_Run(cy_en_crypto_dir_mode_t dirMode,
* The pointer to the initial vector. __Must be 4-byte aligned.__
*
* \param dst
* The pointer to a destination cipher text. __Must be 4-byte aligned.__
* The pointer to the destination cipher text. __Must be 4-byte aligned.__
*
* \param src
* The pointer to a source plain text. __Must be 4-byte aligned.__
* The pointer to the source plain text. __Must be 4-byte aligned.__
*
* \param cfContext
* The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all
* internal variables the Crypto driver requires.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Aes_Cfb_Run(cy_en_crypto_dir_mode_t dirMode,
@ -1102,17 +1143,17 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Cfb_Run(cy_en_crypto_dir_mode_t dirMode,
* __Must be 4-byte aligned.__
*
* \param dst
* The pointer to a destination cipher text. __Must be 4-byte aligned.__
* The pointer to the destination cipher text. __Must be 4-byte aligned.__
*
* \param src
* The pointer to a source plain text. __Must be 4-byte aligned.__
* The pointer to the source plain text. __Must be 4-byte aligned.__
*
* \param cfContext
* The pointer to the \ref cy_stc_crypto_context_aes_t structure that stores all
* internal variables the Crypto driver requires.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Aes_Ctr_Run(cy_en_crypto_dir_mode_t dirMode,
@ -1134,7 +1175,7 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Ctr_Run(cy_en_crypto_dir_mode_t dirMode,
* the context structure when making this function call.
*
* \param src
* The pointer to a source plain text. __Must be 4-byte aligned.__
* The pointer to the source plain text. __Must be 4-byte aligned.__
*
* \param srcSize
* The size of a source plain text.
@ -1153,7 +1194,7 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Ctr_Run(cy_en_crypto_dir_mode_t dirMode,
* internal variables the Crypto driver requires.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoCmacUse
@ -1189,7 +1230,7 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Cmac_Run(uint32_t *src,
* The size of a message.
*
* \param digest
* The pointer to the hash digest. Hash size depends to selected SHA mode
* The pointer to the hash digest. The hash size depends on the selected SHA mode
* (from 20 to 64 bytes, see \ref CY_CRYPTO_SHA_MAX_DIGEST_SIZE).
* __Must be 4-byte aligned.__
*
@ -1198,7 +1239,7 @@ cy_en_crypto_status_t Cy_Crypto_Aes_Cmac_Run(uint32_t *src,
* internal variables for Crypto driver.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoSha256Use
@ -1246,7 +1287,7 @@ cy_en_crypto_status_t Cy_Crypto_Sha_Run(uint32_t *message,
* internal variables for the Crypto driver.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoHmacUse
@ -1288,7 +1329,7 @@ cy_en_crypto_status_t Cy_Crypto_Hmac_Run(uint32_t *hmac,
* internal variables for the Crypto driver.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Str_MemCpy(void *dst,
@ -1320,7 +1361,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemCpy(void *dst,
* internal variables for the Crypto driver.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Str_MemSet(void *dst,
@ -1357,7 +1398,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemSet(void *dst,
* internal variables for the Crypto driver.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Str_MemCmp(void const *src0,
@ -1395,7 +1436,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemCmp(void const *src0,
* internal variables for the Crypto driver.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Str_MemXor(void const *src0,
@ -1508,7 +1549,7 @@ cy_en_crypto_status_t Cy_Crypto_Str_MemXor(void const *src0,
* the Crypto driver context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t
* \ref cy_en_crypto_status_t
*
* \note
* The polynomial, initial seed and remainder XOR values are <b>always</b>
@ -1551,7 +1592,7 @@ cy_en_crypto_status_t Cy_Crypto_Crc_Init(uint32_t polynomial,
* the Crypto driver context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \note
* The polynomial, initial seed and remainder XOR values are <b>always</b>
@ -1594,7 +1635,7 @@ cy_en_crypto_status_t Cy_Crypto_Crc_Run(void *data,
* the Crypto driver context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoTrngUse
@ -1636,7 +1677,7 @@ cy_en_crypto_status_t Cy_Crypto_Trng_Generate(uint32_t GAROPol,
* the Crypto driver context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Des_Run(cy_en_crypto_dir_mode_t dirMode,
@ -1673,7 +1714,7 @@ cy_en_crypto_status_t Cy_Crypto_Des_Run(cy_en_crypto_dir_mode_t dirMode,
* the Crypto driver context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoTdesUse
@ -1735,7 +1776,7 @@ cy_en_crypto_status_t Cy_Crypto_Tdes_Run(cy_en_crypto_dir_mode_t dirMode,
* the RSA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Rsa_Proc(cy_stc_crypto_rsa_pub_key_t const *pubKey,
@ -1774,7 +1815,7 @@ cy_en_crypto_status_t Cy_Crypto_Rsa_Proc(cy_stc_crypto_rsa_pub_key_t const *pubK
* the RSA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Rsa_CalcCoefs(cy_stc_crypto_rsa_pub_key_t const *pubKey,
@ -1818,7 +1859,7 @@ cy_en_crypto_status_t Cy_Crypto_Rsa_CalcCoefs(cy_stc_crypto_rsa_pub_key_t const
* the RSA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Rsa_Verify(cy_en_crypto_rsa_ver_result_t *verResult,

View File

@ -60,7 +60,7 @@
#define CY_CRYPTO_DRV_VERSION_MINOR 20
/**
* \addtogroup group_crypto_macros
* \addtogroup group_crypto_cli_srv_macros
* \{
*/
@ -70,7 +70,7 @@
/** Defines Crypto_Sync non-blocking execution type parameter */
#define CY_CRYPTO_SYNC_NON_BLOCKING (false)
/** Defines the Crypto DES block size (in bytes) */
/** Defines the Crypto DES block size (in bytes). */
#define CY_CRYPTO_DES_BLOCK_SIZE (8u)
/** Defines the Crypto DES key size (in bytes) */
@ -114,7 +114,7 @@
#define CY_CRYPTO_SHA512_224_DIGEST_SIZE (28u)
/** Hash size for the SHA512_256 mode (in bytes) */
#define CY_CRYPTO_SHA512_256_DIGEST_SIZE (32u)
/** Maximal hash size for the SHA modes (in bytes) */
/** The maximal Hash size for the SHA modes (in bytes). */
#define CY_CRYPTO_SHA_MAX_DIGEST_SIZE (CY_CRYPTO_SHA512_DIGEST_SIZE)
/** Block size for the SHA1 mode (in bytes) */
@ -141,6 +141,9 @@
#define CY_CRYPTO_SHA512_ROUND_MEM_SIZE (640uL)
#define CY_CRYPTO_SHA_MAX_ROUND_MEM_SIZE (CY_CRYPTO_SHA512_ROUND_MEM_SIZE)
/* The width of the Crypto hardware registers values in bits. */
#define CY_CRYPTO_HW_REGS_WIDTH (32UL)
/** \endcond */
#endif /* #if (CPUSS_CRYPTO_SHA == 1) */
@ -161,11 +164,13 @@
/** Crypto Driver PDL ID */
#define CY_CRYPTO_ID CY_PDL_DRV_ID(0x0Cu)
/** \} group_crypto_macros */
/** \} group_crypto_cli_srv_macros */
/**
* \addtogroup group_crypto_config_structure
* \{
The Crypto initialization configuration.
* \note Should be the same for the Crypto Server and Crypto Client initialization.
*/
/** The Crypto user callback function type.
@ -231,14 +236,19 @@ typedef struct
/** \} group_crypto_config_structure */
/**
* \addtogroup group_crypto_cli_data_structures
* \addtogroup group_crypto_data_structures
* \{
*/
#if (CPUSS_CRYPTO_VU == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*
* The driver uses this structure to store and manipulate the RSA public key and
* additional coefficients to accelerate RSA calculation.
*
@ -253,10 +263,10 @@ typedef struct
* \ref cy_stc_crypto_rsa_pub_key_t must also be in little-endian order.<br>
* Use \ref Cy_Crypto_Rsa_InvertEndianness function to convert to or from
* little-endian order.
*
*/
typedef struct
{
/** \cond INTERNAL */
/** The pointer to the modulus part of public key. */
uint8_t *moduloPtr;
/** The modulus length, in bits, maximum supported size is 2048Bit */
@ -278,10 +288,18 @@ typedef struct
/** The pointer to the (2^moduloLength mod modulo). Memory for it should
be allocated by user with size moduloLength */
uint8_t *rBarPtr;
/** \endcond */
} cy_stc_crypto_rsa_pub_key_t;
#endif /* #if (CPUSS_CRYPTO_VU == 1) */
/** \} group_crypto_data_structures */
/**
* \addtogroup group_crypto_cli_data_structures
* \{
*/
/** Structure for storing a description of a Crypto hardware error */
typedef struct
{
@ -484,17 +502,25 @@ typedef enum
/** \endcond */
/**
* \addtogroup group_crypto_cli_data_structures
* \addtogroup group_crypto_data_structures
* \{
*/
#if (CPUSS_CRYPTO_AES == 1)
/** Structure for storing the AES state */
/** The structure for storing the AES state.
* All fields for this structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** Pointer to AES key */
uint8_t *key;
/** Pointer to AES inversed key */
/** Pointer to AES inverse key */
uint8_t *invKey;
/** AES key length */
cy_en_crypto_aes_key_length_t keyLength;
@ -502,10 +528,39 @@ typedef struct
uint32_t *buffers;
/** AES processed block index (for CMAC, SHA operations) */
uint32_t blockIdx;
/** \endcond */
} cy_stc_crypto_aes_state_t;
#endif /* #if (CPUSS_CRYPTO_AES == 1) */
/** \} group_crypto_cli_data_structures */
#if (CPUSS_CRYPTO_SHA == 1)
/** The structure for storing the SHA state.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
uint32_t mode;
uint8_t *block;
uint32_t blockSize;
uint8_t *hash;
uint32_t hashSize;
uint8_t *roundMem;
uint32_t roundMemSize;
uint32_t messageSize;
uint32_t digestSize;
uint32_t blockIdx;
uint8_t const *initialHash;
/** \endcond */
} cy_stc_crypto_sha_state_t;
#endif /* (CPUSS_CRYPTO_SHA == 1) */
/** \} group_crypto_data_structures */
/*************************************************************
* Structures used for communication between Client and Server
@ -516,14 +571,16 @@ typedef struct
* \{
*/
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the server
* context.
/** The structure for storing the crypto server context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** IPC communication channel number */
uint32_t ipcChannel;
/** IPC acquire interrupt channel number */
@ -540,6 +597,7 @@ typedef struct
bool isHwErrorOccured;
/** Hardware processing errors */
cy_stc_crypto_hw_error_t hwErrorStatus;
/** \endcond */
} cy_stc_crypto_server_context_t;
/** \} group_crypto_srv_data_structures */
@ -549,14 +607,16 @@ typedef struct
* \{
*/
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the global
* context.
/** The structure for storing the crypto client context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** Operation instruction code */
cy_en_crypto_comm_instr_t instr;
/** Response from executed crypto function */
@ -575,18 +635,21 @@ typedef struct
cy_stc_sysint_t releaseNotifierConfig;
/** Pointer to the crypto function specific context data */
void *xdata;
/** \endcond */
} cy_stc_crypto_context_t;
#if (CPUSS_CRYPTO_DES == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the DES operational
* context.
/** The structure for storing the DES context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** Operation direction (Encrypt / Decrypt) */
cy_en_crypto_dir_mode_t dirMode;
/** Pointer to key data */
@ -595,18 +658,21 @@ typedef struct
uint32_t *dst;
/** Pointer to data source block */
uint32_t *src;
/** \endcond */
} cy_stc_crypto_context_des_t;
#endif /* #if (CPUSS_CRYPTO_DES == 1) */
#if (CPUSS_CRYPTO_AES == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the AES operational
* context.
/** The structure for storing the AES context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** AES state data */
cy_stc_crypto_aes_state_t aesState;
/** Operation direction (Encrypt / Decrypt) */
@ -627,38 +693,22 @@ typedef struct
uint32_t *dst;
/** Pointer to data source block */
uint32_t *src;
/** \endcond */
} cy_stc_crypto_context_aes_t;
#endif /* #if (CPUSS_CRYPTO_AES == 1) */
#if (CPUSS_CRYPTO_SHA == 1)
/** \cond INTERNAL */
/* The structure for storing the SHA context */
typedef struct
{
uint32_t mode;
uint8_t *block;
uint32_t blockSize;
uint8_t *hash;
uint32_t hashSize;
uint8_t *roundMem;
uint32_t roundMemSize;
uint32_t messageSize;
uint32_t digestSize;
uint32_t blockIdx;
uint8_t const *initialHash;
} cy_stc_crypto_sha_state_t;
/** \endcond */
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the SHA operational
* context.
/** The structure for storing the SHA context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** Pointer to data source block */
uint32_t *message;
/** Operation data size */
@ -671,35 +721,41 @@ typedef struct
uint32_t *key;
/** Key data length (for HMAC only) */
uint32_t keyLength;
/** \endcond */
} cy_stc_crypto_context_sha_t;
#endif /* #if (CPUSS_CRYPTO_SHA == 1) */
#if (CPUSS_CRYPTO_PR == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the PRNG operational
* context.
/** The structure for storing the PRNG context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
uint32_t lfsr32InitState; /**< lfsr32 initialization data */
uint32_t lfsr31InitState; /**< lfsr31 initialization data */
uint32_t lfsr29InitState; /**< lfsr29 initialization data */
uint32_t max; /**< Maximum of the generated value */
uint32_t *prngNum; /**< Pointer to generated value */
/** \endcond */
} cy_stc_crypto_context_prng_t;
#endif /* #if (CPUSS_CRYPTO_PR == 1) */
#if (CPUSS_CRYPTO_TR == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the TRNG operational
* context.
/** The structure for storing the TRNG context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/**
The polynomial for the programmable Galois ring oscillator (TR_GARO_CTL).
The polynomial is represented WITHOUT the high order bit (this bit is
@ -721,35 +777,41 @@ typedef struct
uint32_t max;
/** Pointer to generated value */
uint32_t *trngNum;
/** \endcond */
} cy_stc_crypto_context_trng_t;
#endif /* #if (CPUSS_CRYPTO_TR == 1) */
#if (CPUSS_CRYPTO_STR == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the STR operational
* context.
/** The structure for storing the string context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
void const *src0; /**< Pointer to 1-st string source */
void const *src1; /**< Pointer to 2-nd string source */
void *dst; /**< Pointer to string destination */
uint32_t dataSize; /**< Operation data size */
uint32_t data; /**< Operation data value (for memory setting) */
/** \endcond */
} cy_stc_crypto_context_str_t;
#endif /* #if (CPUSS_CRYPTO_STR == 1) */
#if (CPUSS_CRYPTO_CRC == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the CRC operational
* context.
/** The structure for storing the CRC context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
void* data; /**< Pointer to data source block */
uint32_t dataSize; /**< Operation data size */
uint32_t *crc; /**< Pointer to CRC destination variable */
@ -759,20 +821,23 @@ typedef struct
uint32_t dataXor; /**< Input data XOR flag */
uint32_t remReverse; /**< Output data reverse flag */
uint32_t remXor; /**< Output data XOR flag */
/** \endcond */
} cy_stc_crypto_context_crc_t;
#endif /* #if (CPUSS_CRYPTO_CRC == 1) */
#if (CPUSS_CRYPTO_VU == 1)
#if (CPUSS_CRYPTO_SHA == 1)
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the RSA verifying
* context.
/** The structure for storing the RSA verification context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in the function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** Pointer to verification result /ref cy_en_crypto_rsa_ver_result_t */
cy_en_crypto_rsa_ver_result_t *verResult;
/** SHA digest type, used with SHA calculation of the message */
@ -783,17 +848,20 @@ typedef struct
uint32_t const *decryptedSignature;
/** Length of the decrypted RSA signature */
uint32_t decryptedSignatureLength;
/** \endcond */
} cy_stc_crypto_context_rsa_ver_t;
#endif /* #if (CPUSS_CRYPTO_SHA == 1) */
/**
* Firmware allocates memory and provides a pointer to this structure in
* function calls. Firmware does not write or read values in this structure.
* The driver uses this structure to store and manipulate the RSA operational
* context.
/** The structure for storing the RSA context.
* All fields for the context structure are internal. Firmware never reads or
* writes these values. Firmware allocates the structure and provides the
* address of the structure to the driver in function calls. Firmware must
* ensure that the defined instance of this structure remains in scope
* while the drive is in use.
*/
typedef struct
{
/** \cond INTERNAL */
/** Pointer to key data */
cy_stc_crypto_rsa_pub_key_t const *key;
/** Pointer to data source block */
@ -802,6 +870,7 @@ typedef struct
uint32_t messageSize;
/** Pointer to data destination block */
uint32_t *result;
/** \endcond */
} cy_stc_crypto_context_rsa_t;
#endif /* #if (CPUSS_CRYPTO_VU == 1) */

View File

@ -36,10 +36,43 @@
* provides the configuration data required for the desired cryptographic
* technique.
*
* \defgroup group_crypto_llc_macros Macros
* \defgroup group_crypto_llc_functions Functions
* \defgroup group_crypto_llc_data_structures Data Structures
* \defgroup group_crypto_llc_enums Enumerated Types
* \defgroup group_crypto_lld_hw Control and Status
* \{
* \defgroup group_crypto_lld_hw_functions Functions
* \}
* \defgroup group_crypto_lld_symmetric Symmetric Key Algorithms (AES, DES, TDES)
* \{
* \defgroup group_crypto_lld_symmetric_functions Functions
* \}
* \defgroup group_crypto_lld_asymmetric Asymmetric Key Algorithms (RSA, ECP, ECDSA)
* \{
* \defgroup group_crypto_lld_asymmetric_functions Functions
* \defgroup group_crypto_lld_asymmetric_enums Enumerated Types
* \}
* \defgroup group_crypto_lld_sha Hash Operations (SHA)
* \{
* \defgroup group_crypto_lld_sha_functions Functions
* \}
* \defgroup group_crypto_lld_mac Message Authentication Code (CMAC, HMAC)
* \{
* \defgroup group_crypto_lld_mac_functions Functions
* \}
* \defgroup group_crypto_lld_crc Cyclic Redundancy Code (CRC)
* \{
* \defgroup group_crypto_lld_crc_functions Functions
* \}
* \defgroup group_crypto_lld_rng Random Number Generation (TRNG, PRNG)
* \{
* \defgroup group_crypto_lld_rng_functions Functions
* \}
* \defgroup group_crypto_lld_vu Vector Unit (VU)
* \{
* \defgroup group_crypto_lld_vu_functions Functions
* \}
* \defgroup group_crypto_lld_mem Memory Streaming Functions
* \{
* \defgroup group_crypto_lld_mem_functions Functions
* \}
* \} */
#if !defined(CY_CRYPTO_CORE_H)

View File

@ -72,15 +72,19 @@ typedef cy_en_crypto_status_t (*cy_crypto_aes_ctr_func_t)(CRYPTO_Type *base,
uint8_t const *src,
cy_stc_crypto_aes_state_t *aesState);
/**
* \addtogroup group_crypto_lld_symmetric_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Aes_Init
****************************************************************************//**
*
* Sets Aes mode and prepare inversed key.
* Initializes AES mode of operation and prepares an inverse key.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param key
* The pointer to the encryption/decryption key.
@ -89,10 +93,11 @@ typedef cy_en_crypto_status_t (*cy_crypto_aes_ctr_func_t)(CRYPTO_Type *base,
* \ref cy_en_crypto_aes_key_length_t
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Init(CRYPTO_Type *base,
@ -100,44 +105,45 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Init(CRYPTO_Type *base,
cy_en_crypto_aes_key_length_t keyLength,
cy_stc_crypto_aes_state_t *aesState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Aes_Init(base, key, keyLength, aesState);
tmpResult = Cy_Crypto_Core_V1_Aes_Init(base, key, keyLength, aesState);
}
else
{
myResult = Cy_Crypto_Core_V2_Aes_Init(base, key, keyLength, aesState);
tmpResult = Cy_Crypto_Core_V2_Aes_Init(base, key, keyLength, aesState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Aes_Ecb
****************************************************************************//**
*
* Performs AES operation on one Block.
* Performs the AES operation on a single block.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
* (\ref cy_en_crypto_dir_mode_t).
*
* \param dst
* The pointer to a destination cipher block.
* The pointer to the destination cipher block.
*
* \param src
* The pointer to a source block.
* The pointer to the source block.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ecb(CRYPTO_Type *base,
@ -146,28 +152,29 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ecb(CRYPTO_Type *base,
uint8_t const *src,
cy_stc_crypto_aes_state_t *aesState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Aes_Ecb(base, dirMode, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V1_Aes_Ecb(base, dirMode, dst, src, aesState);
}
else
{
myResult = Cy_Crypto_Core_V2_Aes_Ecb(base, dirMode, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V2_Aes_Ecb(base, dirMode, dst, src, aesState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Aes_Cbc
****************************************************************************//**
*
* Performs AES operation on a plain text with Cipher Block Chaining (CBC).
* Performs the AES-CBC operation defined in the dirMode parameter on a plain text
* defined in the src parameter.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -180,16 +187,17 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ecb(CRYPTO_Type *base,
* The pointer to the initial vector.
*
* \param dst
* The pointer to a destination cipher text.
* The pointer to the destination cipher text.
*
* \param src
* The pointer to a source plain text.
* The pointer to the source plain text.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc(CRYPTO_Type *base,
@ -200,28 +208,29 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc(CRYPTO_Type *base,
uint8_t const *src,
cy_stc_crypto_aes_state_t *aesState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Aes_Cbc(base, dirMode, srcSize, ivPtr, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V1_Aes_Cbc(base, dirMode, srcSize, ivPtr, dst, src, aesState);
}
else
{
myResult = Cy_Crypto_Core_V2_Aes_Cbc(base, dirMode, srcSize, ivPtr, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V2_Aes_Cbc(base, dirMode, srcSize, ivPtr, dst, src, aesState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Aes_Cfb
********************************************************************************
****************************************************************************//**
*
* Performs AES operation on a plain text with the Cipher Feedback Block method (CFB).
* Performs the AES-CFB operation defined in the dirMode parameter on a plain text
* defined in the SRC parameter.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -234,16 +243,17 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cbc(CRYPTO_Type *base,
* The pointer to the initial vector.
*
* \param dst
* The pointer to a destination cipher text.
* The pointer to the destination cipher text.
*
* \param src
* The pointer to a source plain text.
* The pointer to the source plain text.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb(CRYPTO_Type *base,
@ -254,31 +264,31 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb(CRYPTO_Type *base,
uint8_t const *src,
cy_stc_crypto_aes_state_t *aesState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Aes_Cfb(base, dirMode, srcSize, ivPtr, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V1_Aes_Cfb(base, dirMode, srcSize, ivPtr, dst, src, aesState);
}
else
{
myResult = Cy_Crypto_Core_V2_Aes_Cfb(base, dirMode, srcSize, ivPtr, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V2_Aes_Cfb(base, dirMode, srcSize, ivPtr, dst, src, aesState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Aes_Ctr
********************************************************************************
****************************************************************************//**
*
* Performs AES operation on a plain text using the counter method (CTR).
* Performs the AES-CTR operation on a plain text defined in the src parameter.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcSize
* The size of a source plain text.
* The size of the source plain text.
*
* \param srcOffset
* The size of an offset within the current block stream for resuming within the
@ -291,16 +301,17 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Cfb(CRYPTO_Type *base,
* The saved stream-block for resuming. Is over-written by the function.
*
* \param dst
* The pointer to a destination cipher text.
* The pointer to the destination cipher text.
*
* \param src
* The pointer to a source plain text. Must be 4-Byte aligned.
* The pointer to the source plain text. Must be 4-Byte aligned.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ctr(CRYPTO_Type *base,
@ -312,20 +323,22 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Aes_Ctr(CRYPTO_Type *base,
uint8_t const *src,
cy_stc_crypto_aes_state_t *aesState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Aes_Ctr(base, srcSize, srcOffset, ivPtr, streamBlock, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V1_Aes_Ctr(base, srcSize, srcOffset, ivPtr, streamBlock, dst, src, aesState);
}
else
{
myResult = Cy_Crypto_Core_V2_Aes_Ctr(base, srcSize, srcOffset, ivPtr, streamBlock, dst, src, aesState);
tmpResult = Cy_Crypto_Core_V2_Aes_Ctr(base, srcSize, srcOffset, ivPtr, streamBlock, dst, src, aesState);
}
return myResult;
return tmpResult;
}
/** \} group_crypto_lld_symmetric_functions */
#endif /* #if (CPUSS_CRYPTO_AES == 1) */
#endif /* CY_IP_MXCRYPTO */

View File

@ -47,21 +47,26 @@ typedef cy_en_crypto_status_t (*cy_crypto_cmac_func_t)(CRYPTO_Type *base,
cy_stc_crypto_aes_state_t *aesState);
/** \endcond */
/**
* \addtogroup group_crypto_lld_mac_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Cmac
****************************************************************************//**
*
* Performs CMAC(Cipher-based Message Authentication Code) operation
* on a message to produce message authentication code using AES.
* Calculates the AES Cipher-based Message Authentication Code (CMAC) on the input
* message with the provided key.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param message
* The pointer to a source plain text. Must be 4-byte aligned.
* The pointer to the source plain text. Must be 4-byte aligned.
*
* \param messageSize
* The size of a source plain text.
* The size of the source plain text in bytes.
*
* \param key
* The pointer to the encryption key. Must be 4-byte aligned.
@ -73,10 +78,11 @@ typedef cy_en_crypto_status_t (*cy_crypto_cmac_func_t)(CRYPTO_Type *base,
* The pointer to the calculated CMAC.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac(CRYPTO_Type *base,
@ -87,20 +93,22 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac(CRYPTO_Type *base,
uint8_t *cmac,
cy_stc_crypto_aes_state_t *aesState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Cmac(base, message, messageSize, key, keyLength, cmac, aesState);
tmpResult = Cy_Crypto_Core_V1_Cmac(base, message, messageSize, key, keyLength, cmac, aesState);
}
else
{
myResult = Cy_Crypto_Core_V2_Cmac(base, message, messageSize, key, keyLength, cmac, aesState);
tmpResult = Cy_Crypto_Core_V2_Cmac(base, message, messageSize, key, keyLength, cmac, aesState);
}
return myResult;
return tmpResult;
}
/** \} group_crypto_lld_mac_functions */
#endif /* (CPUSS_CRYPTO_AES == 1) */
#endif /* CY_IP_MXCRYPTO */

View File

@ -49,14 +49,19 @@ typedef cy_en_crypto_status_t (*cy_crypto_crc_func_t)(CRYPTO_Type *base,
uint32_t dataSize,
uint32_t lfsrInitState);
/**
* \addtogroup group_crypto_lld_crc_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Crc_Init
****************************************************************************//**
*
* Initializes CRC calculation.
* Initializes the CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param polynomial
* The polynomial (specified using 32 bits) used in the computing CRC.
@ -65,16 +70,16 @@ typedef cy_en_crypto_status_t (*cy_crypto_crc_func_t)(CRYPTO_Type *base,
* The order in which data bytes are processed. 0 - MSB first; 1- LSB first.
*
* \param dataXor
* The byte mask for XORing data
* The byte mask for XORing data.
*
* \param remReverse
* A remainder reverse: 0 means the remainder is not reversed. 1 means reversed.
*
* \param remXor
* Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
* Specifies the mask with which the LFSR32 register is XORed to produce a remainder.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_Init(CRYPTO_Type *base,
@ -84,28 +89,28 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_Init(CRYPTO_Type *base,
uint32_t remReverse,
uint32_t remXor)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Crc_Init(base, polynomial, dataReverse, dataXor, remReverse, remXor);
tmpResult = Cy_Crypto_Core_V1_Crc_Init(base, polynomial, dataReverse, dataXor, remReverse, remXor);
}
else
{
myResult = Cy_Crypto_Core_V2_Crc_Init(base, polynomial, dataReverse, dataXor, remReverse, remXor);
tmpResult = Cy_Crypto_Core_V2_Crc_Init(base, polynomial, dataReverse, dataXor, remReverse, remXor);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Crc
****************************************************************************//**
*
* Performs CRC calculation on a message.
* Performs the CRC calculation on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param crc
* The pointer to a computed CRC value. Must be 4-byte aligned.
@ -120,7 +125,7 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_Init(CRYPTO_Type *base,
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc(CRYPTO_Type *base,
@ -129,28 +134,28 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc(CRYPTO_Type *base,
uint32_t dataSize,
uint32_t lfsrInitState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Crc(base, crc, data, dataSize, lfsrInitState);
tmpResult = Cy_Crypto_Core_V1_Crc(base, crc, data, dataSize, lfsrInitState);
}
else
{
myResult = Cy_Crypto_Core_V2_Crc(base, crc, data, dataSize, lfsrInitState);
tmpResult = Cy_Crypto_Core_V2_Crc(base, crc, data, dataSize, lfsrInitState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Crc_CalcInit
****************************************************************************//**
*
* Initializes CRC calculation.
* Initializes the CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -168,13 +173,13 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc(CRYPTO_Type *base,
* A remainder reverse: 0 means the remainder is not reversed. 1 means reversed.
*
* \param remXor
* Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
* Specifies the mask with which the LFSR32 register is XORed to produce a remainder.
*
* \param lfsrInitState
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcInit(CRYPTO_Type *base,
@ -186,30 +191,30 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcInit(CRYPTO_Type *b
uint32_t remXor,
uint32_t lfsrInitState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Crc_CalcInit(base, width, polynomial, dataReverse, dataXor,
tmpResult = Cy_Crypto_Core_V1_Crc_CalcInit(base, width, polynomial, dataReverse, dataXor,
remReverse, remXor, lfsrInitState);
}
else
{
myResult = Cy_Crypto_Core_V2_Crc_CalcInit(base, width, polynomial, dataReverse, dataXor,
tmpResult = Cy_Crypto_Core_V2_Crc_CalcInit(base, width, polynomial, dataReverse, dataXor,
remReverse, remXor, lfsrInitState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Crc_CalcStart
****************************************************************************//**
*
* Prepares CRC calculation by setting an initial seeds value.
* Prepares the CRC calculation by setting an initial seed value.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -218,34 +223,34 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcInit(CRYPTO_Type *b
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcStart(CRYPTO_Type *base,
uint32_t width, uint32_t lfsrInitState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Crc_CalcStart(base, width, lfsrInitState);
tmpResult = Cy_Crypto_Core_V1_Crc_CalcStart(base, width, lfsrInitState);
}
else
{
myResult = Cy_Crypto_Core_V2_Crc_CalcStart(base, width, lfsrInitState);
tmpResult = Cy_Crypto_Core_V2_Crc_CalcStart(base, width, lfsrInitState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Crc_CalcPartial
****************************************************************************//**
*
* Performs CRC calculation of a message part.
* Performs the CRC calculation of a message part.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param data
* The pointer to the message whose CRC is being computed.
@ -254,34 +259,34 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcStart(CRYPTO_Type *
* The size of a message in bytes.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcPartial(CRYPTO_Type *base,
void const *data, uint32_t dataSize)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Crc_CalcPartial(base, data, dataSize);
tmpResult = Cy_Crypto_Core_V1_Crc_CalcPartial(base, data, dataSize);
}
else
{
myResult = Cy_Crypto_Core_V2_Crc_CalcPartial(base, data, dataSize);
tmpResult = Cy_Crypto_Core_V2_Crc_CalcPartial(base, data, dataSize);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Crc_CalcFinish
****************************************************************************//**
*
* Finalizes CRC calculation.
* Finalizes the CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -290,33 +295,33 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcPartial(CRYPTO_Type
* The pointer to a computed CRC value. Must be 4-byte aligned.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcFinish(CRYPTO_Type *base, uint32_t width, uint32_t *crc)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Crc_CalcFinish(base, width, crc);
tmpResult = Cy_Crypto_Core_V1_Crc_CalcFinish(base, width, crc);
}
else
{
myResult = Cy_Crypto_Core_V2_Crc_CalcFinish(base, width, crc);
tmpResult = Cy_Crypto_Core_V2_Crc_CalcFinish(base, width, crc);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Crc_Calc
****************************************************************************//**
*
* Performs CRC calculation on a message.
* Performs the CRC calculation on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -331,27 +336,29 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_CalcFinish(CRYPTO_Type
* The size of a message in bytes.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Crc_Calc(CRYPTO_Type *base,
uint32_t width, uint32_t *crc,
void const *data, uint32_t dataSize)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Crc_Calc(base, width, crc, data, dataSize);
tmpResult = Cy_Crypto_Core_V1_Crc_Calc(base, width, crc, data, dataSize);
}
else
{
myResult = Cy_Crypto_Core_V2_Crc_Calc(base, width, crc, data, dataSize);
tmpResult = Cy_Crypto_Core_V2_Crc_Calc(base, width, crc, data, dataSize);
}
return myResult;
return tmpResult;
}
/** \} group_crypto_lld_crc_functions */
#endif /* #if (CPUSS_CRYPTO_CRC == 1) */
#endif /* CY_IP_MXCRYPTO */

View File

@ -48,7 +48,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc(CRYPTO_Type *base,
uint32_t dataSize,
uint32_t lfsrInitState);
/* New Partial calculation interface */
/* The new partial calculation interface. */
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcInit(CRYPTO_Type *base,
uint32_t width,
uint32_t polynomial,

View File

@ -48,7 +48,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc(CRYPTO_Type *base,
uint32_t dataSize,
uint32_t lfsrInitState);
/* New Partial calculation interface */
/* The new partial calculation interface. */
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcInit(CRYPTO_Type *base,
uint32_t width,
uint32_t polynomial,

View File

@ -42,16 +42,21 @@ typedef cy_en_crypto_status_t (*cy_crypto_des_func_t)(CRYPTO_Type *base,
uint8_t *dst,
uint8_t const *src);
/**
* \addtogroup group_crypto_lld_symmetric_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Des
****************************************************************************//**
*
* Performs DES operation on a Single Block. All addresses must be 4-Byte aligned.
* Ciphertext (dstBlock) may overlap with plaintext (srcBlock)
* Performs the DES operation on a single block. All addresses must be 4-byte aligned.
* Ciphertext (dst) may overlap with plaintext (src).
* This function is independent from the previous Crypto state.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -61,13 +66,13 @@ typedef cy_en_crypto_status_t (*cy_crypto_des_func_t)(CRYPTO_Type *base,
* The pointer to the encryption/decryption key.
*
* \param dst
* The pointer to a destination cipher block.
* The pointer to the destination cipher block.
*
* \param src
* The pointer to a source block.
* The pointer to the source block.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Des(CRYPTO_Type *base,
@ -76,30 +81,30 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Des(CRYPTO_Type *base,
uint8_t *dst,
uint8_t const *src)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Des(base, dirMode, key, dst, src);
tmpResult = Cy_Crypto_Core_V1_Des(base, dirMode, key, dst, src);
}
else
{
myResult = Cy_Crypto_Core_V2_Des(base, dirMode, key, dst, src);
tmpResult = Cy_Crypto_Core_V2_Des(base, dirMode, key, dst, src);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Tdes
****************************************************************************//**
*
* Performs TDES operation on a Single Block. All addresses must be 4-Byte aligned.
* Ciphertext (dstBlock) may overlap with plaintext (srcBlock)
* Performs the TDES operation on a single block. All addresses must be 4-byte aligned.
* Ciphertext (dst) may overlap with plaintext (src).
* This function is independent from the previous Crypto state.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -109,13 +114,13 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Des(CRYPTO_Type *base,
* The pointer to the encryption/decryption keys.
*
* \param dst
* The pointer to a destination cipher block.
* The pointer to the destination cipher block.
*
* \param src
* The pointer to a source data block.
* The pointer to the source data block.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Tdes(CRYPTO_Type *base,
@ -124,20 +129,22 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Tdes(CRYPTO_Type *base,
uint8_t *dst,
uint8_t const *src)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Tdes(base, dirMode, key, dst, src);
tmpResult = Cy_Crypto_Core_V1_Tdes(base, dirMode, key, dst, src);
}
else
{
myResult = Cy_Crypto_Core_V2_Tdes(base, dirMode, key, dst, src);
tmpResult = Cy_Crypto_Core_V2_Tdes(base, dirMode, key, dst, src);
}
return myResult;
return tmpResult;
}
/** \} group_crypto_lld_symmetric_functions */
#endif /* #if (CPUSS_CRYPTO_DES == 1) */
#endif /* CY_IP_MXCRYPTO */

View File

@ -34,6 +34,12 @@
#if (CPUSS_CRYPTO_VU == 1)
/**
* \addtogroup group_crypto_lld_asymmetric_enums
* \{
*/
/** List of supported elliptic curve IDs */
typedef enum {
CY_CRYPTO_ECC_ECP_NONE = 0,
CY_CRYPTO_ECC_ECP_SECP192R1,
@ -45,6 +51,8 @@ typedef enum {
CY_CRYPTO_ECC_ECP_CURVES_CNT
} cy_en_crypto_ecc_curve_id_t;
/** \} group_crypto_lld_asymmetric_enums */
typedef enum cy_en_red_mul_algs {
CY_CRYPTO_NIST_P_CURVE_SPECIFIC_RED_ALG = 0,
CY_CRYPTO_NIST_P_SHIFT_MUL_RED_ALG,
@ -60,7 +68,7 @@ typedef struct {
uint32_t size;
/** name of curve */
const char *name;
const char_t *name;
/** ECC calculation default algorithm */
cy_en_crypto_ecc_red_mul_algs_t algo;
@ -118,7 +126,14 @@ typedef struct {
} cy_stc_crypto_ecc_key;
typedef int (*cy_func_get_random_data_t)(void *, unsigned char *, size_t);
/**
* \addtogroup group_crypto_lld_asymmetric_functions
* \{
*/
/** Pointer to a random number supplier function */
typedef int (*cy_func_get_random_data_t)(void *rndInfo, uint8_t *rndData, size_t rndSize);
cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakeKeyPair(CRYPTO_Type *base,
cy_en_crypto_ecc_curve_id_t curveID,
cy_stc_crypto_ecc_key *key,
@ -127,22 +142,24 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base,
const uint8_t *hash,
uint32_t hashlen,
uint8_t *sig,
cy_stc_crypto_ecc_key *key,
uint8_t *messageKey);
const cy_stc_crypto_ecc_key *key,
const uint8_t *messageKey);
cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
const uint8_t *sig,
const uint8_t *hash,
uint32_t hashlen,
uint8_t *status,
cy_stc_crypto_ecc_key *key);
uint8_t *stat,
const cy_stc_crypto_ecc_key *key);
cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePrivateKey(CRYPTO_Type *base,
cy_en_crypto_ecc_curve_id_t curveID, uint8_t *key,
cy_func_get_random_data_t GetRandomDataFunc, void *randomDataInfo);
cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePublicKey(CRYPTO_Type *base,
cy_en_crypto_ecc_curve_id_t curveID,
uint8_t *privateKey,
const uint8_t *privateKey,
cy_stc_crypto_ecc_key *publicKey);
/** \} group_crypto_lld_asymmetric_functions */
/** Calculates the actual size in bytes of the bits value */
#define CY_CRYPTO_BYTE_SIZE_OF_BITS(x) (uint32_t)(((x) + 7u) >> 3u)
@ -166,11 +183,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePublicKey(CRYPTO_Type *base,
#define CY_CRYPTO_ECC_MAX_BYTE_SIZE (CY_CRYPTO_ECC_P521_BYTE_SIZE)
/* "Global" vector unit registers. */
#define VR_D 10
#define VR_S_X 11
#define VR_S_Y 12
#define VR_BARRETT 13
#define VR_P 14 /* polynomial */
#define VR_D 10u
#define VR_S_X 11u
#define VR_S_Y 12u
#define VR_BARRETT 13u
#define VR_P 14u /* polynomial */
#endif /* #if (CPUSS_CRYPTO_VU == 1) */

View File

@ -33,38 +33,39 @@
#if (CPUSS_CRYPTO_VU == 1)
void Cy_Crypto_Core_EC_NistP_SetMode(int bitsize);
void Cy_Crypto_Core_EC_NistP_SetMode(uint32_t bitsize);
void Cy_Crypto_Core_EC_NistP_SetRedAlg(cy_en_crypto_ecc_red_mul_algs_t alg);
void Cy_Crypto_Core_EC_NistP_PointMul(CRYPTO_Type *base, int p_x, int p_y, int p_d, int p_order, int bitsize);
/**
* \addtogroup group_crypto_lld_asymmetric_functions
* \{
*/
cy_en_crypto_status_t Cy_Crypto_Core_EC_NistP_PointMultiplication(CRYPTO_Type *base,
cy_en_crypto_ecc_curve_id_t curveID,
uint8_t* ecpGX,
uint8_t* ecpGY,
uint8_t* ecpD,
const uint8_t *ecpGX,
const uint8_t *ecpGY,
const uint8_t *ecpD,
uint8_t *ecpQX,
uint8_t *ecpQY);
void Cy_Crypto_Core_EC_MulMod( CRYPTO_Type *base,
int z,
int a,
int b,
int size);
void Cy_Crypto_Core_EC_DivMod( CRYPTO_Type *base,
int z,
int a,
int b,
int size);
void Cy_Crypto_Core_EC_SquareMod( CRYPTO_Type *base,
int z,
int a,
int size);
void Cy_Crypto_Core_EC_Bar_MulRed(CRYPTO_Type *base,
int z,
int x,
int size
);
void Cy_Crypto_Core_EC_AddMod( CRYPTO_Type *base, int z, int a, int b);
void Cy_Crypto_Core_EC_SubMod( CRYPTO_Type *base, int z, int a, int b);
void Cy_Crypto_Core_EC_HalfMod( CRYPTO_Type *base, int z, int a);
/** \} group_crypto_lld_asymmetric_functions */
void Cy_Crypto_Core_EC_MulMod( CRYPTO_Type *base, uint32_t z, uint32_t a, uint32_t b, uint32_t size);
void Cy_Crypto_Core_EC_DivMod( CRYPTO_Type *base, uint32_t z, uint32_t a, uint32_t b, uint32_t size);
void Cy_Crypto_Core_EC_SquareMod( CRYPTO_Type *base, uint32_t z, uint32_t a, uint32_t size);
void Cy_Crypto_Core_EC_Bar_MulRed(CRYPTO_Type *base, uint32_t z, uint32_t x, uint32_t size);
void Cy_Crypto_Core_EC_AddMod( CRYPTO_Type *base, uint32_t z, uint32_t a, uint32_t b);
void Cy_Crypto_Core_EC_SubMod( CRYPTO_Type *base, uint32_t z, uint32_t a, uint32_t b);
void Cy_Crypto_Core_EC_HalfMod( CRYPTO_Type *base, uint32_t z, uint32_t a);
void Cy_Crypto_Core_JacobianEcAdd(CRYPTO_Type *base, uint32_t s_x, uint32_t s_y, uint32_t s_z, uint32_t t_x, uint32_t t_y, uint32_t size);
void Cy_Crypto_Core_JacobianEcDouble(CRYPTO_Type *base, uint32_t s_x, uint32_t s_y, uint32_t s_z, uint32_t size);
void Cy_Crypto_Core_JacobianEcScalarMul(CRYPTO_Type *base, uint32_t s_x, uint32_t s_y, uint32_t d, uint32_t size);
void Cy_Crypto_Core_JacobianTransform(CRYPTO_Type *base, uint32_t s_x, uint32_t s_y, uint32_t s_z);
void Cy_Crypto_Core_JacobianInvTransform(CRYPTO_Type *base, uint32_t s_x, uint32_t s_y, uint32_t s_z, uint32_t size);
void Cy_Crypto_Core_EC_NistP_PointMul(CRYPTO_Type *base, uint32_t p_x, uint32_t p_y, uint32_t p_d, uint32_t p_order, uint32_t bitsize);
#endif /* #if (CPUSS_CRYPTO_VU == 1) */

View File

@ -44,23 +44,28 @@ typedef cy_en_crypto_status_t (*cy_crypto_hmac_func_t)(CRYPTO_Type *base,
uint32_t keyLength,
cy_en_crypto_sha_mode_t mode);
/**
* \addtogroup group_crypto_lld_mac_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Hmac
****************************************************************************//**
*
* Performs HMAC calculation.
* Performs the HMAC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hmac
* The pointer to the calculated HMAC. Must be 4-byte aligned.
*
* \param message
* The pointer to a message whose hash value is being computed.
* The pointer to the message whose hash value is being computed.
*
* \param messageSize
* The size of a message.
* The size of the message.
*
* \param key
* The pointer to the key.
@ -72,7 +77,7 @@ typedef cy_en_crypto_status_t (*cy_crypto_hmac_func_t)(CRYPTO_Type *base,
* \ref cy_en_crypto_sha_mode_t
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac(CRYPTO_Type *base,
@ -83,20 +88,22 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac(CRYPTO_Type *base,
uint32_t keyLength,
cy_en_crypto_sha_mode_t mode)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Hmac(base, hmac, message, messageSize, key, keyLength, mode);
tmpResult = Cy_Crypto_Core_V1_Hmac(base, hmac, message, messageSize, key, keyLength, mode);
}
else
{
myResult = Cy_Crypto_Core_V2_Hmac(base, hmac, message, messageSize, key, keyLength, mode);
tmpResult = Cy_Crypto_Core_V2_Hmac(base, hmac, message, messageSize, key, keyLength, mode);
}
return myResult;
return tmpResult;
}
/** \} group_crypto_lld_mac_functions */
#endif /* #if (CPUSS_CRYPTO_SHA == 1) */
#endif /* CY_IP_MXCRYPTO */

View File

@ -108,9 +108,9 @@
#define REG_CRYPTO_DEV_KEY_CTL0(base) (((CRYPTO_V2_Type*)(base))->DEV_KEY_CTL0)
#define REG_CRYPTO_DEV_KEY_CTL1(base) (((CRYPTO_V2_Type*)(base))->DEV_KEY_CTL1)
/* CRYPTO internal memory buffer size IN BYTES */
/* The CRYPTO internal-memory buffer-size in bytes. */
#define CY_CRYPTO_MEM_BUFF_SIZE ((cy_device->cryptoMemSize) * 4u)
/* CRYPTO internal memory buffer size IN 32 bit WORDS */
/* The CRYPTO internal-memory buffer-size in 32-bit words. */
#define CY_CRYPTO_MEM_BUFF_SIZE_U32 (cy_device->cryptoMemSize)
/* Device Crypto IP descriptor type */
@ -220,6 +220,11 @@ typedef enum
/** \endcond */
/**
* \addtogroup group_crypto_lld_hw_functions
* \{
*/
void Cy_Crypto_Core_HwInit(void);
cy_en_crypto_status_t Cy_Crypto_Core_Enable(CRYPTO_Type *base);
@ -239,10 +244,10 @@ void Cy_Crypto_Core_InvertEndianness(void *inArrPtr, uint32_t byteSize);
* The function checks whether the Crypto hardware is enabled.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \return
* Crypto status \ref cy_en_crypto_status_t.
* Crypto status \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE bool Cy_Crypto_Core_IsEnabled(CRYPTO_Type *base)
@ -265,7 +270,7 @@ __STATIC_INLINE bool Cy_Crypto_Core_IsEnabled(CRYPTO_Type *base)
* - from 0 to 16 for MXCRYPTO_ver2 IP block
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
__STATIC_INLINE uint8_t Cy_Crypto_Core_GetFIFODepth(CRYPTO_Type *base)
@ -281,7 +286,7 @@ __STATIC_INLINE uint8_t Cy_Crypto_Core_GetFIFODepth(CRYPTO_Type *base)
* The value of this field ranges from 0 to 8
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
__STATIC_INLINE uint8_t Cy_Crypto_Core_GetFIFOUsed(CRYPTO_Type *base)
@ -299,7 +304,7 @@ __STATIC_INLINE uint8_t Cy_Crypto_Core_GetFIFOUsed(CRYPTO_Type *base)
* By default EVENT_LEVEL = 0;
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
__STATIC_INLINE void Cy_Crypto_Core_WaitForFifoAvailable(CRYPTO_Type *base)
@ -316,7 +321,7 @@ __STATIC_INLINE void Cy_Crypto_Core_WaitForFifoAvailable(CRYPTO_Type *base)
* Waits until all instruction in FIFO will be completed
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
__STATIC_INLINE void Cy_Crypto_Core_WaitForReady(CRYPTO_Type *base)
@ -333,7 +338,7 @@ __STATIC_INLINE void Cy_Crypto_Core_WaitForReady(CRYPTO_Type *base)
* Masks / unmasks multiple interrupt sources.
*
* \param base
* Pointer to Crypto instance address
* The pointer to the CRYPTO instance.
*
* \param interrupts
* Mask bits. See definitions above.
@ -351,7 +356,7 @@ __STATIC_INLINE void Cy_Crypto_Core_SetInterruptMask(CRYPTO_Type *base, uint32_t
* Reports mask / unmask multiple interrupt sources.
*
* \param base
* Pointer to Crypto instance address
* The pointer to the CRYPTO instance.
*
* \return
* Mask bits. See definitions above.
@ -369,7 +374,7 @@ __STATIC_INLINE uint32_t Cy_Crypto_Core_GetInterruptMask(CRYPTO_Type const *base
* Reports states of multiple enabled interrupt sources.
*
* \param base
* Pointer to Crypto instance address
* The pointer to the CRYPTO instance.
*
* \return
* Source bits. See definitions above.
@ -387,7 +392,7 @@ __STATIC_INLINE uint32_t Cy_Crypto_Core_GetInterruptStatusMasked(CRYPTO_Type con
* Reports states of multiple interrupt sources.
*
* \param base
* Pointer to Crypto instance address
* The pointer to the CRYPTO instance.
*
* \return
* Source bits. See definitions above.
@ -405,7 +410,7 @@ __STATIC_INLINE uint32_t Cy_Crypto_Core_GetInterruptStatus(CRYPTO_Type *base)
* Sets one of more interrupt sources
*
* \param base
* Pointer to Crypto instance address
* The pointer to the CRYPTO instance.
*
* \param interrupts
* Source bit(s)
@ -423,7 +428,7 @@ __STATIC_INLINE void Cy_Crypto_Core_SetInterrupt(CRYPTO_Type *base, uint32_t in
* Clears multiple interrupt sources.
*
* \param base
* Pointer to Crypto instance address
* The pointer to the CRYPTO instance.
*
* \param interrupts
* Source bit(s). See definitions above.
@ -435,6 +440,7 @@ __STATIC_INLINE void Cy_Crypto_Core_ClearInterrupt(CRYPTO_Type *base, uint32_t
(void) REG_CRYPTO_INTR(base);
}
/** \} group_crypto_lld_hw_functions */
#endif /* CY_IP_MXCRYPTO */

View File

@ -151,8 +151,8 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_FFStart(CRYPTO_Type *base,
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (CY_CRYPTO_V2_FF_START_OPC << CY_CRYPTO_OPCODE_POS)
| (ff_idx << CY_CRYPTO_RSRC0_SHIFT);
REG_CRYPTO_INSTR_FF_WR(base) = ((uint32_t)CY_CRYPTO_V2_FF_START_OPC << CY_CRYPTO_OPCODE_POS) |
(ff_idx << CY_CRYPTO_RSRC0_SHIFT);
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t) p_mem;
REG_CRYPTO_INSTR_FF_WR(base) = size;
}
@ -168,8 +168,8 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_FFContinue(CRYPTO_Type *base,
/* Wait for previous loading has been completed. */
(CY_CRYPTO_V2_RB_FF_LOAD0 == ff_idx) ? Cy_Crypto_Core_V2_FFLoad0Sync(base) : Cy_Crypto_Core_V2_FFLoad1Sync(base);
REG_CRYPTO_INSTR_FF_WR(base) = (CY_CRYPTO_V2_FF_CONTINUE_OPC << CY_CRYPTO_OPCODE_POS)
| (ff_idx << CY_CRYPTO_RSRC0_SHIFT);
REG_CRYPTO_INSTR_FF_WR(base) = ((uint32_t)CY_CRYPTO_V2_FF_CONTINUE_OPC << CY_CRYPTO_OPCODE_POS) |
(ff_idx << CY_CRYPTO_RSRC0_SHIFT);
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t) p_mem;
REG_CRYPTO_INSTR_FF_WR(base) = size;
}
@ -181,7 +181,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_FFStop(CRYPTO_Type *base, uint32_t ff_idx
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_FF_STOP_OPC << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_FF_STOP_OPC << CY_CRYPTO_OPCODE_POS) |
(ff_idx << CY_CRYPTO_RSRC0_SHIFT));
}
@ -193,7 +193,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_BlockMov(CRYPTO_Type *base,
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_BLOCK_MOV_OPC << CY_CRYPTO_OPCODE_POS)
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_BLOCK_MOV_OPC << CY_CRYPTO_OPCODE_POS)
| (size << CY_CRYPTO_RSRC16_SHIFT)
| (dst_idx << CY_CRYPTO_RSRC12_SHIFT)
| (src_idx << CY_CRYPTO_RSRC0_SHIFT));
@ -207,8 +207,8 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_BlockMov_Reflect(CRYPTO_Type *base,
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_BLOCK_MOV_OPC << CY_CRYPTO_OPCODE_POS)
| (1u << CY_CRYPTO_RSRC23_SHIFT)
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_BLOCK_MOV_OPC << CY_CRYPTO_OPCODE_POS)
| (1UL << CY_CRYPTO_RSRC23_SHIFT)
| (size << CY_CRYPTO_RSRC16_SHIFT)
| (dst_idx << CY_CRYPTO_RSRC12_SHIFT)
| (src_idx << CY_CRYPTO_RSRC0_SHIFT));
@ -222,7 +222,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_BlockSet(CRYPTO_Type *base,
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_BLOCK_SET_OPC << CY_CRYPTO_OPCODE_POS)
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_BLOCK_SET_OPC << CY_CRYPTO_OPCODE_POS)
| (size << CY_CRYPTO_RSRC16_SHIFT)
| (dst_idx << CY_CRYPTO_RSRC12_SHIFT)
| ((uint32_t)(data) << CY_CRYPTO_RSRC0_SHIFT));
@ -236,7 +236,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_BlockCmp(CRYPTO_Type *base,
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_BLOCK_CMP_OPC << CY_CRYPTO_OPCODE_POS)
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_BLOCK_CMP_OPC << CY_CRYPTO_OPCODE_POS)
| (size << CY_CRYPTO_RSRC16_SHIFT)
| (src1_idx << CY_CRYPTO_RSRC4_SHIFT)
| (src0_idx << CY_CRYPTO_RSRC0_SHIFT));
@ -250,7 +250,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_BlockXor(CRYPTO_Type *base,
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_BLOCK_XOR_OPC << CY_CRYPTO_OPCODE_POS)
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_BLOCK_XOR_OPC << CY_CRYPTO_OPCODE_POS)
| (size << CY_CRYPTO_RSRC16_SHIFT)
| (dst_idx << CY_CRYPTO_RSRC12_SHIFT)
| (src1_idx << CY_CRYPTO_RSRC4_SHIFT)
@ -264,7 +264,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_BlockGcm(CRYPTO_Type *base)
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(CY_CRYPTO_V2_BLOCK_GCM_OPC << CY_CRYPTO_OPCODE_POS);
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((uint32_t)CY_CRYPTO_V2_BLOCK_GCM_OPC << CY_CRYPTO_OPCODE_POS);
}
__STATIC_INLINE void Cy_Crypto_Core_V2_Run(CRYPTO_Type *base, uint32_t opc)
@ -284,7 +284,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_RBClear(CRYPTO_Type *base)
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(CY_CRYPTO_V2_RB_CLEAR_OPC << CY_CRYPTO_OPCODE_POS);
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((uint32_t)CY_CRYPTO_V2_RB_CLEAR_OPC << CY_CRYPTO_OPCODE_POS);
}
__STATIC_INLINE void Cy_Crypto_Core_V2_RBSwap(CRYPTO_Type *base)
@ -294,7 +294,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_RBSwap(CRYPTO_Type *base)
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(CY_CRYPTO_V2_RB_SWAP_OPC << CY_CRYPTO_OPCODE_POS);
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((uint32_t)CY_CRYPTO_V2_RB_SWAP_OPC << CY_CRYPTO_OPCODE_POS);
}
__STATIC_INLINE void Cy_Crypto_Core_V2_RBXor(CRYPTO_Type *base, uint32_t offset, uint32_t size)
@ -304,7 +304,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_RBXor(CRYPTO_Type *base, uint32_t offset,
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_RB_XOR_OPC << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_RB_XOR_OPC << CY_CRYPTO_OPCODE_POS) |
(offset << CY_CRYPTO_RSRC8_SHIFT) |
(size << CY_CRYPTO_RSRC0_SHIFT));
}
@ -316,7 +316,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_RBStore(CRYPTO_Type *base, uint32_t offse
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_RB_STORE_OPC << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_RB_STORE_OPC << CY_CRYPTO_OPCODE_POS) |
(offset << CY_CRYPTO_RSRC8_SHIFT) |
(size << CY_CRYPTO_RSRC0_SHIFT));}
@ -327,7 +327,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_RBSetByte(CRYPTO_Type *base, uint32_t off
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((CY_CRYPTO_V2_RB_BYTE_SET_OPC << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(((uint32_t)CY_CRYPTO_V2_RB_BYTE_SET_OPC << CY_CRYPTO_OPCODE_POS) |
(offset << CY_CRYPTO_RSRC8_SHIFT) |
((uint32_t)(byte) << CY_CRYPTO_RSRC0_SHIFT));
}
@ -339,7 +339,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_RunAes(CRYPTO_Type *base)
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(CY_CRYPTO_V2_AES_OPC << CY_CRYPTO_OPCODE_POS);
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((uint32_t)CY_CRYPTO_V2_AES_OPC << CY_CRYPTO_OPCODE_POS);
}
__STATIC_INLINE void Cy_Crypto_Core_V2_RunAesInv(CRYPTO_Type *base)
@ -349,7 +349,7 @@ __STATIC_INLINE void Cy_Crypto_Core_V2_RunAesInv(CRYPTO_Type *base)
{
}
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)(CY_CRYPTO_V2_AES_INV_OPC << CY_CRYPTO_OPCODE_POS);
REG_CRYPTO_INSTR_FF_WR(base) = (uint32_t)((uint32_t)CY_CRYPTO_V2_AES_INV_OPC << CY_CRYPTO_OPCODE_POS);
}
__STATIC_INLINE void Cy_Crypto_Core_V2_RunChacha(CRYPTO_Type *base, uint8_t roundNum)

View File

@ -191,8 +191,8 @@
#define CY_CRYPTO_VU2_INV_BIT_IMM_OPC (0x2Eu)
__STATIC_INLINE void CY_CRYPTO_VU_SAVE_REG (CRYPTO_Type *base, uint32_t rsrc, uint32_t *ddata);
__STATIC_INLINE void CY_CRYPTO_VU_RESTORE_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t ddata);
__STATIC_INLINE void CY_CRYPTO_VU_SAVE_REG (CRYPTO_Type *base, uint32_t rsrc, uint32_t *data);
__STATIC_INLINE void CY_CRYPTO_VU_RESTORE_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t data);
__STATIC_INLINE void CY_CRYPTO_VU_SET_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t data, uint32_t size);
@ -200,7 +200,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_MOV_REG_TO_STATUS (CRYPTO_Type *base, uin
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_MOV_REG_TO_STATUS_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
(uint32_t)rsrc);
((uint32_t)rsrc));
}
__STATIC_INLINE void CY_CRYPTO_VU_MOV_REG_TO_STATUS (CRYPTO_Type *base, uint32_t rsrc)
@ -222,18 +222,19 @@ __STATIC_INLINE void CY_CRYPTO_VU_MOV_STATUS_TO_REG (CRYPTO_Type *base, uint32_t
__STATIC_INLINE void CY_CRYPTO_VU_COND_MOV_IMM_TO_STATUS (CRYPTO_Type *base, uint32_t cc, uint32_t imm4)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******* V1 *********/
int tmp_reg = CY_CRYPTO_VU_HW_REG14;
uint32_t tmp_data;
uint32_t tmpReg = CY_CRYPTO_VU_HW_REG14;
uint32_t tmpData;
CY_CRYPTO_VU_SAVE_REG(base, tmp_reg, &tmp_data);
CY_CRYPTO_VU_SAVE_REG(base, tmpReg, &tmpData);
CY_CRYPTO_VU_SET_REG(base, tmp_reg, imm4, 4);
CY_CRYPTO_VU_COND_MOV_REG_TO_STATUS(base, cc, tmp_reg);
/* Load 4 bit immediate value */
CY_CRYPTO_VU_SET_REG(base, tmpReg, imm4, 4u);
CY_CRYPTO_VU_COND_MOV_REG_TO_STATUS(base, cc, tmpReg);
CY_CRYPTO_VU_RESTORE_REG(base, tmp_reg, tmp_data);
CY_CRYPTO_VU_RESTORE_REG(base, tmpReg, tmpData);
}
else
{
@ -255,8 +256,8 @@ __STATIC_INLINE void CY_CRYPTO_VU_SET_REG (CRYPTO_Type *base, uint32_t rdst, uin
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_SET_REG_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)rdst << CY_CRYPTO_RSRC26_SHIFT) |
((uint32_t)data << ((cy_device->cryptoVersion == 1) ? CY_CRYPTO_RSRC12_SHIFT : CY_CRYPTO_RSRC13_SHIFT)) |
(((uint32_t)size - 1) << CY_CRYPTO_RSRC0_SHIFT));
((uint32_t)data << ((CY_CRYPTO_HW_V1) ? CY_CRYPTO_RSRC12_SHIFT : CY_CRYPTO_RSRC13_SHIFT)) |
(((uint32_t)size - 1u) << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_COND_LD_REG (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc)
@ -317,7 +318,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_ADD_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_ADD_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -331,7 +332,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_SUB_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_SUB_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -345,7 +346,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_OR_REG (CRYPTO_Type *base, uint32_t cc, u
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_OR_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -359,7 +360,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_AND_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_AND_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -373,7 +374,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_XOR_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_XOR_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -387,7 +388,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_NOR_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_NOR_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -401,7 +402,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_NAND_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_NAND_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -415,7 +416,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_MIN_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_MIN_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -429,7 +430,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_MAX_REG (CRYPTO_Type *base, uint32_t cc,
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_MAX_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -464,8 +465,8 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_ALLOC_MEM (CRYPTO_Type *base, uint32_t cc
REG_CRYPTO_INSTR_FF_WR(base) =
(((uint32_t)CY_CRYPTO_VU_ALLOC_MEM_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << ((cy_device->cryptoVersion == 1) ? CY_CRYPTO_RSRC12_SHIFT : CY_CRYPTO_RSRC16_SHIFT)) |
(((uint32_t)size - 1) << CY_CRYPTO_RSRC0_SHIFT));
((uint32_t)rdst << ((CY_CRYPTO_HW_V1) ? CY_CRYPTO_RSRC12_SHIFT : CY_CRYPTO_RSRC16_SHIFT)) |
(((uint32_t)size - 1u) << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_ALLOC_MEM (CRYPTO_Type *base, uint32_t rdst, uint32_t size)
@ -477,7 +478,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_FREE_MEM (CRYPTO_Type *base, uint32_t cc,
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_FREE_MEM_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
(uint32_t)reg_mask);
((uint32_t)reg_mask));
}
__STATIC_INLINE void CY_CRYPTO_VU_FREE_MEM (CRYPTO_Type *base, uint32_t reg_mask)
@ -491,7 +492,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_LSL (CRYPTO_Type *base, uint32_t cc, uint
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_LSL (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -501,7 +502,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_LSL (CRYPTO_Type *base, uint32_t rdst, uint32_
__STATIC_INLINE void CY_CRYPTO_VU_COND_LSL1 (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******* V1 *********/
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_LSL1_OPC << CY_CRYPTO_OPCODE_POS) |
@ -527,7 +528,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_LSL1 (CRYPTO_Type *base, uint32_t rdst, uint32
__STATIC_INLINE void CY_CRYPTO_VU_COND_LSL1_WITH_CARRY (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******* V1 *********/
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_LSL1_WITH_CARRY_OPC << CY_CRYPTO_OPCODE_POS) |
@ -553,11 +554,11 @@ __STATIC_INLINE void CY_CRYPTO_VU_LSL1_WITH_CARRY (CRYPTO_Type *base, uint32_t r
__STATIC_INLINE void CY_CRYPTO_VU_COND_LSR (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((cy_device->cryptoVersion == 1) ? CY_CRYPTO_VU1_LSR_OPC : CY_CRYPTO_VU2_LSR_OPC) << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((CY_CRYPTO_HW_V1) ? CY_CRYPTO_VU1_LSR_OPC : CY_CRYPTO_VU2_LSR_OPC) << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_LSR (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -567,7 +568,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_LSR (CRYPTO_Type *base, uint32_t rdst, uint32_
__STATIC_INLINE void CY_CRYPTO_VU_COND_LSR1 (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******* V1 *********/
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)(CY_CRYPTO_VU1_LSR1_OPC) << CY_CRYPTO_OPCODE_POS) |
@ -593,7 +594,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_LSR1 (CRYPTO_Type *base, uint32_t rdst, uint32
__STATIC_INLINE void CY_CRYPTO_VU_COND_LSR1_WITH_CARRY (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******* V1 *********/
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)(CY_CRYPTO_VU1_LSR1_WITH_CARRY_OPC) << CY_CRYPTO_OPCODE_POS) |
@ -619,11 +620,11 @@ __STATIC_INLINE void CY_CRYPTO_VU_LSR1_WITH_CARRY (CRYPTO_Type *base, uint32_t r
__STATIC_INLINE void CY_CRYPTO_VU_COND_CLSAME (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((cy_device->cryptoVersion == 1) ? CY_CRYPTO_VU1_CLSAME_OPC : CY_CRYPTO_VU2_CLSAME_OPC) << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((CY_CRYPTO_HW_V1) ? CY_CRYPTO_VU1_CLSAME_OPC : CY_CRYPTO_VU2_CLSAME_OPC) << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_CLSAME (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -633,11 +634,11 @@ __STATIC_INLINE void CY_CRYPTO_VU_CLSAME (CRYPTO_Type *base, uint32_t rdst, uint
__STATIC_INLINE void CY_CRYPTO_VU_COND_CTSAME (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((cy_device->cryptoVersion == 1) ? CY_CRYPTO_VU1_CTSAME_OPC : CY_CRYPTO_VU2_CTSAME_OPC) << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((CY_CRYPTO_HW_V1) ? CY_CRYPTO_VU1_CTSAME_OPC : CY_CRYPTO_VU2_CTSAME_OPC) << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_CTSAME (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -647,10 +648,10 @@ __STATIC_INLINE void CY_CRYPTO_VU_CTSAME (CRYPTO_Type *base, uint32_t rdst, uint
__STATIC_INLINE void CY_CRYPTO_VU_COND_SET_BIT (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc)
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((cy_device->cryptoVersion == 1) ? CY_CRYPTO_VU1_SET_BIT_OPC : CY_CRYPTO_VU2_SET_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((CY_CRYPTO_HW_V1) ? CY_CRYPTO_VU1_SET_BIT_OPC : CY_CRYPTO_VU2_SET_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
(uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_SET_BIT (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc)
@ -660,10 +661,10 @@ __STATIC_INLINE void CY_CRYPTO_VU_SET_BIT (CRYPTO_Type *base, uint32_t rdst, uin
__STATIC_INLINE void CY_CRYPTO_VU_COND_CLR_BIT (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc)
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((cy_device->cryptoVersion == 1) ? CY_CRYPTO_VU1_CLR_BIT_OPC : CY_CRYPTO_VU2_CLR_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((CY_CRYPTO_HW_V1) ? CY_CRYPTO_VU1_CLR_BIT_OPC : CY_CRYPTO_VU2_CLR_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
(uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_CLR_BIT (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc)
@ -673,10 +674,10 @@ __STATIC_INLINE void CY_CRYPTO_VU_CLR_BIT (CRYPTO_Type *base, uint32_t rdst, uin
__STATIC_INLINE void CY_CRYPTO_VU_COND_INV_BIT (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc)
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((cy_device->cryptoVersion == 1) ? CY_CRYPTO_VU1_INV_BIT_OPC : CY_CRYPTO_VU2_INV_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((CY_CRYPTO_HW_V1) ? CY_CRYPTO_VU1_INV_BIT_OPC : CY_CRYPTO_VU2_INV_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
(uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_INV_BIT (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc)
@ -686,11 +687,11 @@ __STATIC_INLINE void CY_CRYPTO_VU_INV_BIT (CRYPTO_Type *base, uint32_t rdst, uin
__STATIC_INLINE void CY_CRYPTO_VU_COND_GET_BIT (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((cy_device->cryptoVersion == 1) ? CY_CRYPTO_VU1_GET_BIT_OPC : CY_CRYPTO_VU2_GET_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)((CY_CRYPTO_HW_V1) ? CY_CRYPTO_VU1_GET_BIT_OPC : CY_CRYPTO_VU2_GET_BIT_OPC) << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_GET_BIT (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -701,17 +702,18 @@ __STATIC_INLINE void CY_CRYPTO_VU_GET_BIT (CRYPTO_Type *base, uint32_t rdst, uin
/******************************************************************************/
__STATIC_INLINE void CY_CRYPTO_VU_COND_SET_BIT_IMM (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t imm13)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******** V1 ********/
int tmp_reg = (rdst != CY_CRYPTO_VU_HW_REG14) ? CY_CRYPTO_VU_HW_REG14 : CY_CRYPTO_VU_HW_REG13;
uint32_t tmp_data;
CY_CRYPTO_VU_SAVE_REG(base, tmp_reg, &tmp_data);
uint32_t tmpReg = (rdst != CY_CRYPTO_VU_HW_REG14) ? CY_CRYPTO_VU_HW_REG14 : CY_CRYPTO_VU_HW_REG13;
uint32_t tmpData;
CY_CRYPTO_VU_SAVE_REG(base, tmpReg, &tmpData);
CY_CRYPTO_VU_SET_REG(base, tmp_reg, imm13, 13);
CY_CRYPTO_VU_COND_SET_BIT(base, cc, rdst, tmp_reg);
/* Load 13 bit immediate value */
CY_CRYPTO_VU_SET_REG(base, tmpReg, imm13, 13u);
CY_CRYPTO_VU_COND_SET_BIT(base, cc, rdst, tmpReg);
CY_CRYPTO_VU_RESTORE_REG(base, tmp_reg, tmp_data);
CY_CRYPTO_VU_RESTORE_REG(base, tmpReg, tmpData);
}
else
{
@ -719,7 +721,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_SET_BIT_IMM (CRYPTO_Type *base, uint32_t
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU2_SET_BIT_IMM_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC16_SHIFT) |
(uint32_t)imm13 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)imm13 << CY_CRYPTO_RSRC0_SHIFT));
}
}
@ -730,17 +732,18 @@ __STATIC_INLINE void CY_CRYPTO_VU_SET_BIT_IMM (CRYPTO_Type *base, uint32_t rdst,
__STATIC_INLINE void CY_CRYPTO_VU_COND_CLR_BIT_IMM (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t imm13)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******** V1 ********/
int tmp_reg = (rdst != CY_CRYPTO_VU_HW_REG14) ? CY_CRYPTO_VU_HW_REG14 : CY_CRYPTO_VU_HW_REG13;
uint32_t tmp_data;
CY_CRYPTO_VU_SAVE_REG(base, tmp_reg, &tmp_data);
uint32_t tmpReg = (rdst != CY_CRYPTO_VU_HW_REG14) ? CY_CRYPTO_VU_HW_REG14 : CY_CRYPTO_VU_HW_REG13;
uint32_t tmpData;
CY_CRYPTO_VU_SAVE_REG(base, tmpReg, &tmpData);
CY_CRYPTO_VU_SET_REG(base, tmp_reg, imm13, 13);
CY_CRYPTO_VU_COND_CLR_BIT(base, cc, rdst, tmp_reg);
/* Load 13 bit immediate value */
CY_CRYPTO_VU_SET_REG(base, tmpReg, imm13, 13u);
CY_CRYPTO_VU_COND_CLR_BIT(base, cc, rdst, tmpReg);
CY_CRYPTO_VU_RESTORE_REG(base, tmp_reg, tmp_data);
CY_CRYPTO_VU_RESTORE_REG(base, tmpReg, tmpData);
}
else
{
@ -748,7 +751,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_CLR_BIT_IMM (CRYPTO_Type *base, uint32_t
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU2_CLR_BIT_IMM_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC16_SHIFT) |
(uint32_t)imm13 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)imm13 << CY_CRYPTO_RSRC0_SHIFT));
}
}
@ -759,17 +762,18 @@ __STATIC_INLINE void CY_CRYPTO_VU_CLR_BIT_IMM (CRYPTO_Type *base, uint32_t rdst,
__STATIC_INLINE void CY_CRYPTO_VU_COND_INV_BIT_IMM (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t imm13)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/******** V1 ********/
int tmp_reg = (rdst != CY_CRYPTO_VU_HW_REG14) ? CY_CRYPTO_VU_HW_REG14 : CY_CRYPTO_VU_HW_REG13;
uint32_t tmp_data;
CY_CRYPTO_VU_SAVE_REG(base, tmp_reg, &tmp_data);
uint32_t tmpReg = (rdst != CY_CRYPTO_VU_HW_REG14) ? CY_CRYPTO_VU_HW_REG14 : CY_CRYPTO_VU_HW_REG13;
uint32_t tmpData;
CY_CRYPTO_VU_SAVE_REG(base, tmpReg, &tmpData);
CY_CRYPTO_VU_SET_REG(base, tmp_reg, imm13, 13);
CY_CRYPTO_VU_COND_INV_BIT(base, cc, rdst, tmp_reg);
/* Load 13 bit immediate value */
CY_CRYPTO_VU_SET_REG(base, tmpReg, imm13, 13u);
CY_CRYPTO_VU_COND_INV_BIT(base, cc, rdst, tmpReg);
CY_CRYPTO_VU_RESTORE_REG(base, tmp_reg, tmp_data);
CY_CRYPTO_VU_RESTORE_REG(base, tmpReg, tmpData);
}
else
{
@ -777,7 +781,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_INV_BIT_IMM (CRYPTO_Type *base, uint32_t
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU2_INV_BIT_IMM_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC16_SHIFT) |
(uint32_t)imm13 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)imm13 << CY_CRYPTO_RSRC0_SHIFT));
}
}
@ -791,7 +795,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_TST (CRYPTO_Type *base, uint32_t cc, uint
{
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_TST_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
(uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_TST (CRYPTO_Type *base, uint32_t rsrc)
@ -804,7 +808,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_MOV (CRYPTO_Type *base, uint32_t cc, uint
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_MOV_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
(uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_MOV (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc)
@ -817,7 +821,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_XSQUARE (CRYPTO_Type *base, uint32_t cc,
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_XSQUARE_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
(uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_XSQUARE (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc)
@ -831,7 +835,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_XMUL (CRYPTO_Type *base, uint32_t cc, uin
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_XMUL (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -846,7 +850,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_UMUL (CRYPTO_Type *base, uint32_t cc, uin
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_UMUL (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -856,7 +860,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_UMUL (CRYPTO_Type *base, uint32_t rdst, uint32
__STATIC_INLINE void CY_CRYPTO_VU_COND_USQUARE (CRYPTO_Type *base, uint32_t cc, uint32_t rdst, uint32_t rsrc)
{
if (cy_device->cryptoVersion == 1)
if (CY_CRYPTO_HW_V1)
{
/***** V1 *******/
CY_CRYPTO_VU_COND_UMUL(base, cc, rdst, rsrc, rsrc);
@ -867,7 +871,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_USQUARE (CRYPTO_Type *base, uint32_t cc,
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU2_USQUARE_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
(uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc << CY_CRYPTO_RSRC0_SHIFT));
}
}
@ -906,7 +910,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_ADD (CRYPTO_Type *base, uint32_t cc, uint
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_ADD (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -920,7 +924,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_SUB (CRYPTO_Type *base, uint32_t cc, uint
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_SUB (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -934,7 +938,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_OR (CRYPTO_Type *base, uint32_t cc, uint3
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_OR (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -948,7 +952,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_AND (CRYPTO_Type *base, uint32_t cc, uint
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_AND (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -962,7 +966,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_XOR (CRYPTO_Type *base, uint32_t cc, uint
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_XOR (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -976,7 +980,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_NOR (CRYPTO_Type *base, uint32_t cc, uint
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_NOR (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -990,7 +994,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_NAND (CRYPTO_Type *base, uint32_t cc, uin
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rdst << CY_CRYPTO_RSRC12_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_NAND (CRYPTO_Type *base, uint32_t rdst, uint32_t rsrc1, uint32_t rsrc0)
@ -1003,7 +1007,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_CMP_SUB (CRYPTO_Type *base, uint32_t cc,
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_CMP_SUB_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_CMP_SUB (CRYPTO_Type *base, uint32_t rsrc1, uint32_t rsrc0)
@ -1016,7 +1020,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_COND_CMP_DEGREE (CRYPTO_Type *base, uint32_t c
REG_CRYPTO_INSTR_FF_WR(base) = (((uint32_t)CY_CRYPTO_VU_CMP_DEGREE_OPC << CY_CRYPTO_OPCODE_POS) |
((uint32_t)cc << CY_CRYPTO_RSRC20_SHIFT) |
((uint32_t)rsrc1 << CY_CRYPTO_RSRC4_SHIFT) |
(uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT);
((uint32_t)rsrc0 << CY_CRYPTO_RSRC0_SHIFT));
}
__STATIC_INLINE void CY_CRYPTO_VU_CMP_DEGREE (CRYPTO_Type *base, uint32_t rsrc1, uint32_t rsrc0)
@ -1031,7 +1035,7 @@ __STATIC_INLINE void CY_CRYPTO_VU_SAVE_REG (CRYPTO_Type *base, uint32_t rsrc, ui
__STATIC_INLINE void CY_CRYPTO_VU_RESTORE_REG (CRYPTO_Type *base, uint32_t rdst, uint32_t data)
{
CY_CRYPTO_VU_SET_REG(base, rdst, CY_CRYPTO_VU_GET_REG_DATA(data), CY_CRYPTO_VU_GET_REG_SIZE(data) + 1);
CY_CRYPTO_VU_SET_REG(base, rdst, CY_CRYPTO_VU_GET_REG_DATA(data), CY_CRYPTO_VU_GET_REG_SIZE(data) + 1u);
}

View File

@ -44,6 +44,11 @@ typedef uint32_t (*cy_crypto_memcmp_func_t)(CRYPTO_Type *base,
typedef void (*cy_crypto_memxor_func_t)(CRYPTO_Type *base, void* dst,
void const *src0, void const *src1, uint16_t size);
/**
* \addtogroup group_crypto_lld_mem_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_MemCpy
****************************************************************************//**
@ -53,7 +58,7 @@ typedef void (*cy_crypto_memxor_func_t)(CRYPTO_Type *base, void* dst,
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dst
* The pointer to the destination of MemCpy.
@ -67,7 +72,7 @@ typedef void (*cy_crypto_memxor_func_t)(CRYPTO_Type *base, void* dst,
*******************************************************************************/
__STATIC_INLINE void Cy_Crypto_Core_MemCpy(CRYPTO_Type *base, void* dst, void const *src, uint16_t size)
{
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
Cy_Crypto_Core_V1_MemCpy(base, dst, src, size);
}
@ -85,7 +90,7 @@ __STATIC_INLINE void Cy_Crypto_Core_MemCpy(CRYPTO_Type *base, void* dst, void co
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dst
* The pointer to the destination of MemSet.
@ -99,7 +104,7 @@ __STATIC_INLINE void Cy_Crypto_Core_MemCpy(CRYPTO_Type *base, void* dst, void co
*******************************************************************************/
__STATIC_INLINE void Cy_Crypto_Core_MemSet(CRYPTO_Type *base, void* dst, uint8_t data, uint16_t size)
{
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
Cy_Crypto_Core_V1_MemSet(base, dst, data, size);
}
@ -117,7 +122,7 @@ __STATIC_INLINE void Cy_Crypto_Core_MemSet(CRYPTO_Type *base, void* dst, uint8_t
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param src0
* The pointer to the first source of MemCmp.
@ -134,17 +139,17 @@ __STATIC_INLINE void Cy_Crypto_Core_MemSet(CRYPTO_Type *base, void* dst, uint8_t
*******************************************************************************/
__STATIC_INLINE uint32_t Cy_Crypto_Core_MemCmp(CRYPTO_Type *base, void const *src0, void const *src1, uint16_t size)
{
uint32_t result;
if (cy_device->cryptoVersion == 1u)
uint32_t tmpResult;
if (CY_CRYPTO_HW_V1)
{
result = Cy_Crypto_Core_V1_MemCmp(base, src0, src1, size);
tmpResult = Cy_Crypto_Core_V1_MemCmp(base, src0, src1, size);
}
else
{
result = Cy_Crypto_Core_V2_MemCmp(base, src0, src1, size);
tmpResult = Cy_Crypto_Core_V2_MemCmp(base, src0, src1, size);
}
return (result);
return (tmpResult);
}
/*******************************************************************************
@ -156,7 +161,7 @@ __STATIC_INLINE uint32_t Cy_Crypto_Core_MemCmp(CRYPTO_Type *base, void const *sr
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dst
* The pointer to the destination of MemXor.
@ -174,7 +179,7 @@ __STATIC_INLINE uint32_t Cy_Crypto_Core_MemCmp(CRYPTO_Type *base, void const *sr
__STATIC_INLINE void Cy_Crypto_Core_MemXor(CRYPTO_Type *base, void* dst,
void const *src0, void const *src1, uint16_t size)
{
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
Cy_Crypto_Core_V1_MemXor(base, dst, src0, src1, size);
}
@ -184,6 +189,7 @@ __STATIC_INLINE void Cy_Crypto_Core_MemXor(CRYPTO_Type *base, void* dst,
}
}
/** \} group_crypto_lld_mem_functions */
#endif /* CY_IP_MXCRYPTO */

View File

@ -45,6 +45,11 @@ typedef cy_en_crypto_status_t (*cy_crypto_prng_func_t)(CRYPTO_Type *base,
uint32_t max,
uint32_t *randomNum);
/**
* \addtogroup group_crypto_lld_rng_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Prng_Init
****************************************************************************//**
@ -53,7 +58,7 @@ typedef cy_en_crypto_status_t (*cy_crypto_prng_func_t)(CRYPTO_Type *base,
* Invoking this function causes a restart of the pseudo-random sequence.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param lfsr32InitState
* A non-zero seed value for the first LFSR.
@ -65,7 +70,7 @@ typedef cy_en_crypto_status_t (*cy_crypto_prng_func_t)(CRYPTO_Type *base,
* A non-zero seed value for the third LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng_Init(CRYPTO_Type *base,
@ -73,18 +78,18 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng_Init(CRYPTO_Type *base
uint32_t lfsr31InitState,
uint32_t lfsr29InitState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Prng_Init(base, lfsr32InitState, lfsr31InitState, lfsr29InitState);
tmpResult = Cy_Crypto_Core_V1_Prng_Init(base, lfsr32InitState, lfsr31InitState, lfsr29InitState);
}
else
{
myResult = Cy_Crypto_Core_V2_Prng_Init(base, lfsr32InitState, lfsr31InitState, lfsr29InitState);
tmpResult = Cy_Crypto_Core_V2_Prng_Init(base, lfsr32InitState, lfsr31InitState, lfsr29InitState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
@ -94,7 +99,7 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng_Init(CRYPTO_Type *base
* Generates a Pseudo Random Number.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param max
* The maximum value of a random number.
@ -103,27 +108,29 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng_Init(CRYPTO_Type *base
* The pointer to a variable to store the generated pseudo random number.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng(CRYPTO_Type *base,
uint32_t max,
uint32_t *randomNum)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Prng(base, max, randomNum);
tmpResult = Cy_Crypto_Core_V1_Prng(base, max, randomNum);
}
else
{
myResult = Cy_Crypto_Core_V2_Prng(base, max, randomNum);
tmpResult = Cy_Crypto_Core_V2_Prng(base, max, randomNum);
}
return myResult;
return tmpResult;
}
/** \} group_crypto_lld_rng_functions */
#endif /* #if (CPUSS_CRYPTO_PR == 1) */
#endif /* CY_IP_MXCRYPTO */

View File

@ -42,6 +42,11 @@ typedef cy_en_crypto_status_t (*cy_crypto_sha_func_t)(CRYPTO_Type *base,
uint8_t *digest,
cy_en_crypto_sha_mode_t mode);
/**
* \addtogroup group_crypto_lld_sha_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Sha
****************************************************************************//**
@ -49,22 +54,22 @@ typedef cy_en_crypto_status_t (*cy_crypto_sha_func_t)(CRYPTO_Type *base,
* Performs the SHA Hash function.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param mode
* \ref cy_en_crypto_sha_mode_t
*
* \param message
* The pointer to a message whose hash value is being computed.
* The pointer to the message whose hash value is being computed.
*
* \param messageSize
* The size of a message.
* The size of the message.
*
* \param digest
* The pointer to the hash digest.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha(CRYPTO_Type *base,
@ -73,41 +78,41 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha(CRYPTO_Type *base,
uint8_t *digest,
cy_en_crypto_sha_mode_t mode)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Sha(base, message, messageSize, digest, mode);
tmpResult = Cy_Crypto_Core_V1_Sha(base, message, messageSize, digest, mode);
}
else
{
myResult = Cy_Crypto_Core_V2_Sha(base, message, messageSize, digest, mode);
tmpResult = Cy_Crypto_Core_V2_Sha(base, message, messageSize, digest, mode);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Sha_Init
****************************************************************************//**
*
* The function to initialize SHA operation.
* The function to initialize the SHA operation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param shaHashState
* The pointer to a Hash State.
* The pointer to a Hash state.
*
* \param mode
* One of these: CY_CRYPTO_SHA256, CY_CRYPTO_SHA1, CY_CRYPTO_SHA256_224,
* CY_CRYPTO_SHA512, CY_CRYPTO_SHA384, CY_CRYPTO_SHA512_224, CY_CRYPTO_SHA512_256
*
* \param shaBuffers
* The pointer to memory buffers storage
* The pointer to the memory buffers storage.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Init(CRYPTO_Type *base,
@ -115,50 +120,50 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Init(CRYPTO_Type *base,
cy_en_crypto_sha_mode_t mode,
void *shaBuffers)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Sha_Init(base, shaHashState, mode, shaBuffers);
tmpResult = Cy_Crypto_Core_V1_Sha_Init(base, shaHashState, mode, shaBuffers);
}
else
{
myResult = Cy_Crypto_Core_V2_Sha_Init(base, shaHashState, mode, shaBuffers);
tmpResult = Cy_Crypto_Core_V2_Sha_Init(base, shaHashState, mode, shaBuffers);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Sha_Start
****************************************************************************//**
*
* Initializes the initial hash vector.
* Initializes the initial Hash vector.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Start(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Sha_Start(base, hashState);
tmpResult = Cy_Crypto_Core_V1_Sha_Start(base, hashState);
}
else
{
myResult = Cy_Crypto_Core_V2_Sha_Start(base, hashState);
tmpResult = Cy_Crypto_Core_V2_Sha_Start(base, hashState);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
@ -168,7 +173,7 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Start(CRYPTO_Type *base
* Performs the SHA calculation on one message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
@ -180,12 +185,12 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Start(CRYPTO_Type *base
* The size of the message whose Hash is being computed.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \note
* This function can be called several times only with message lengths dividable
* by block size. Only the last call to the function can process a message with
* the not dividable size.
* by the block size. Only the last call to the function can process a message with
* a not-dividable size.
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Update(CRYPTO_Type *base,
@ -193,55 +198,55 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Update(CRYPTO_Type *bas
uint8_t const *message,
uint32_t messageSize)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Sha_Update(base, hashState, message, messageSize);
tmpResult = Cy_Crypto_Core_V1_Sha_Update(base, hashState, message, messageSize);
}
else
{
myResult = Cy_Crypto_Core_V2_Sha_Update(base, hashState, message, messageSize);
tmpResult = Cy_Crypto_Core_V2_Sha_Update(base, hashState, message, messageSize);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_V1_Sha_Finish
****************************************************************************//**
*
* Completes SHA calculation.
* Completes the SHA calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
*
* \param digest
* The pointer to the calculated hash digest.
* The pointer to the calculated Hash digest.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Finish(CRYPTO_Type *base,
cy_stc_crypto_sha_state_t *hashState,
uint8_t *digest)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Sha_Finish(base, hashState, digest);
tmpResult = Cy_Crypto_Core_V1_Sha_Finish(base, hashState, digest);
}
else
{
myResult = Cy_Crypto_Core_V2_Sha_Finish(base, hashState, digest);
tmpResult = Cy_Crypto_Core_V2_Sha_Finish(base, hashState, digest);
}
return myResult;
return tmpResult;
}
/*******************************************************************************
@ -251,31 +256,32 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Finish(CRYPTO_Type *bas
* Clears the used memory buffers.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Free(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
{
cy_en_crypto_status_t myResult;
cy_en_crypto_status_t tmpResult;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
myResult = Cy_Crypto_Core_V1_Sha_Free(base, hashState);
tmpResult = Cy_Crypto_Core_V1_Sha_Free(base, hashState);
}
else
{
myResult = Cy_Crypto_Core_V2_Sha_Free(base, hashState);
tmpResult = Cy_Crypto_Core_V2_Sha_Free(base, hashState);
}
return myResult;
return tmpResult;
}
/** \} group_crypto_lld_sha_functions */
#endif /* #if (CPUSS_CRYPTO_SHA == 1) */

View File

@ -38,37 +38,37 @@
typedef struct
{
/* Allocate CRYPTO_MAX_BLOCK_SIZE Bytes for block */
/* Allocates CRYPTO_MAX_BLOCK_SIZE Bytes for the block. */
uint32_t block[CY_CRYPTO_SHA1_BLOCK_SIZE / 4u];
/* Allocate CRYPTO_MAX_HASH_SIZE Bytes for hash */
/* Allocates CRYPTO_MAX_HASH_SIZE Bytes for the hash. */
uint32_t hash[CY_CRYPTO_SHA1_HASH_SIZE / 4u];
/* Allocate CRYPTO_MAX_ROUND_MEM_SIZE Bytes for roundMem */
/* Allocates CRYPTO_MAX_ROUND_MEM_SIZE Bytes for roundMem. */
uint32_t roundMem[CY_CRYPTO_SHA1_ROUND_MEM_SIZE / 4u];
} cy_stc_crypto_v1_sha1_buffers_t;
typedef struct
{
/* Allocate CRYPTO_MAX_BLOCK_SIZE Bytes for block */
/* Allocates CRYPTO_MAX_BLOCK_SIZE Bytes for the block. */
uint32_t block[CY_CRYPTO_SHA256_BLOCK_SIZE / 4u];
/* Allocate CRYPTO_MAX_HASH_SIZE Bytes for hash */
/* Allocates CRYPTO_MAX_HASH_SIZE Bytes for the hash. */
uint32_t hash[CY_CRYPTO_SHA256_HASH_SIZE / 4u];
/* Allocate CRYPTO_MAX_ROUND_MEM_SIZE Bytes for roundMem */
/* Allocates CRYPTO_MAX_ROUND_MEM_SIZE Bytes for roundMem. */
uint32_t roundMem[CY_CRYPTO_SHA256_ROUND_MEM_SIZE / 4u];
} cy_stc_crypto_v1_sha256_buffers_t;
typedef struct
{
/* Allocate CRYPTO_MAX_BLOCK_SIZE Bytes for block */
/* Allocates CRYPTO_MAX_BLOCK_SIZE Bytes for the block. */
uint32_t block[CY_CRYPTO_SHA512_BLOCK_SIZE / 4u];
/* Allocate CRYPTO_MAX_HASH_SIZE Bytes for hash */
/* Allocates CRYPTO_MAX_HASH_SIZE Bytes for the hash. */
uint32_t hash[CY_CRYPTO_SHA512_HASH_SIZE / 4u];
/* Allocate CRYPTO_MAX_ROUND_MEM_SIZE Bytes for roundMem */
/* Allocates CRYPTO_MAX_ROUND_MEM_SIZE Bytes for roundMem. */
uint32_t roundMem[CY_CRYPTO_SHA512_ROUND_MEM_SIZE / 4u];
} cy_stc_crypto_v1_sha512_buffers_t;

View File

@ -38,7 +38,7 @@
/** \cond INTERNAL */
cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Init(CRYPTO_Type *base,
cy_stc_crypto_sha_state_t *shaHashState,
cy_stc_crypto_sha_state_t *hashState,
cy_en_crypto_sha_mode_t mode,
void *shaBuffers);

View File

@ -42,15 +42,19 @@ typedef cy_en_crypto_status_t (*cy_crypto_trng_func_t)(CRYPTO_Type *base,
uint32_t max,
uint32_t *randomNum);
/**
* \addtogroup group_crypto_lld_rng_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Trng
****************************************************************************//**
*
* Generates a True Random Number and returns it in the
* cfContext->trngNumPtr.
* Generates a True Random Number.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param GAROPol
* The polynomial for the programmable Galois ring oscillator.
@ -59,13 +63,13 @@ typedef cy_en_crypto_status_t (*cy_crypto_trng_func_t)(CRYPTO_Type *base,
* The polynomial for the programmable Fibonacci ring oscillator.
*
* \param max
* The maximum length of a random number, in the range [0, 32] bits.
* The maximum length of a random number, in the range of [0, 32] bits.
*
* \param randomNum
* The pointer to a generated true random number. Must be 4-byte aligned.
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Trng(CRYPTO_Type *base,
@ -74,18 +78,19 @@ __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Trng(CRYPTO_Type *base,
uint32_t max,
uint32_t *randomNum)
{
cy_en_crypto_status_t result;
if (cy_device->cryptoVersion == 1u)
cy_en_crypto_status_t tmpResult;
if (CY_CRYPTO_HW_V1)
{
result = Cy_Crypto_Core_V1_Trng(base, GAROPol, FIROPol, max, randomNum);
tmpResult = Cy_Crypto_Core_V1_Trng(base, GAROPol, FIROPol, max, randomNum);
}
else
{
result = Cy_Crypto_Core_V2_Trng(base, GAROPol, FIROPol, max, randomNum);
tmpResult = Cy_Crypto_Core_V2_Trng(base, GAROPol, FIROPol, max, randomNum);
}
return (result);
return (tmpResult);
}
/** \} group_crypto_lld_rng_functions */
#endif /* #if (CPUSS_CRYPTO_TR == 1) */

View File

@ -182,11 +182,11 @@
#define CY_CRYPTO_V1_TR_CUTOFF_COUNT8 (1UL)
/**
Cut-off count (legal range is [1, 65535]).
"0": Illegal.
"1": 1 occurrence.
...
"65535": 65535 occurrences.
* Cut-off count (legal range is [1, 65535]).
* "0": Illegal.
* "1": 1 occurrence.
* ...
* "65535": 65535 occurrences.
*/
#define CY_CRYPTO_V1_TR_CUTOFF_COUNT16 (1UL)
@ -196,9 +196,9 @@ Cut-off count (legal range is [1, 65535]).
* ...
* "65535": 65536 bits.
*/
#define CY_CRYPTO_V1_TR_WINDOW_SIZE (1uL)
#define CY_CRYPTO_V1_TR_WINDOW_SIZE (1UL)
/** the composed value for the TR_CTL0 register */
/** The composed value for the TR_CTL0 register */
#define CY_CRYPTO_V1_TR_CTL0_VAL (_VAL2FLD(CRYPTO_TR_CTL0_SAMPLE_CLOCK_DIV, CY_CRYPTO_V1_TR_SAMPLE_CLOCK_DIV) | \
_VAL2FLD(CRYPTO_TR_CTL0_RED_CLOCK_DIV, CY_CRYPTO_V1_TR_RED_CLOCK_DIV) | \
_VAL2FLD(CRYPTO_TR_CTL0_INIT_DELAY, CY_CRYPTO_V1_TR_INIT_DELAY) | \

View File

@ -182,11 +182,11 @@
#define CY_CRYPTO_V2_TR_CUTOFF_COUNT8 (1UL)
/**
Cut-off count (legal range is [1, 65535]).
"0": Illegal.
"1": 1 occurrence.
...
"65535": 65535 occurrences.
* Cut-off count (legal range is [1, 65535]).
* "0": Illegal.
* "1": 1 occurrence.
* ...
* "65535": 65535 occurrences.
*/
#define CY_CRYPTO_V2_TR_CUTOFF_COUNT16 (1UL)
@ -196,9 +196,9 @@ Cut-off count (legal range is [1, 65535]).
* ...
* "65535": 65536 bits.
*/
#define CY_CRYPTO_V2_TR_WINDOW_SIZE (1uL)
#define CY_CRYPTO_V2_TR_WINDOW_SIZE (1UL)
/** the composed value for the TR_CTL0 register */
/** The composed value for the TR_CTL0 register */
#define CY_CRYPTO_V2_TR_CTL0_VAL (_VAL2FLD(CRYPTO_TR_CTL0_SAMPLE_CLOCK_DIV, CY_CRYPTO_V2_TR_SAMPLE_CLOCK_DIV) | \
_VAL2FLD(CRYPTO_TR_CTL0_RED_CLOCK_DIV, CY_CRYPTO_V2_TR_RED_CLOCK_DIV) | \
_VAL2FLD(CRYPTO_TR_CTL0_INIT_DELAY, CY_CRYPTO_V2_TR_INIT_DELAY) | \

View File

@ -46,7 +46,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Trng(CRYPTO_Type *base,
#endif /* CY_IP_MXCRYPTO */
#endif /* #if !defined(CY_CRYPTO_CORE_TRNG_H) */
#endif /* #if !defined(CY_CRYPTO_CORE_TRNG_V1_H) */
/* [] END OF FILE */

View File

@ -41,17 +41,22 @@
#define CY_CRYPTO_VU_DATA_FLD_MASK (0x00003fffuL)
#define CY_CRYPTO_VU_DATA_FLD_POS (16u)
/**
* \addtogroup group_crypto_lld_vu_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Cleanup
****************************************************************************//**
*
* Cleanup the the CRYPTO block.
* Cleans up the Crypto block.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_Cleanup(CRYPTO_Type *base);
@ -60,10 +65,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_Cleanup(CRYPTO_Type *base);
* Function Name: Cy_Crypto_Core_Vu_SetMemValue
****************************************************************************//**
*
* Sets the value in the crypto memory allocated by destination VU register.
* Sets the value in the Crypto memory allocated by the destination VU register.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dstReg
* The destination vector unit register.
@ -84,7 +89,7 @@ void Cy_Crypto_Core_Vu_SetMemValue(CRYPTO_Type *base, uint32_t dstReg, uint8_t c
* Gets the value located in the crypto memory and pointed by source VU register.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dst
* The pointer to the destination value.
@ -102,10 +107,10 @@ void Cy_Crypto_Core_Vu_GetMemValue(CRYPTO_Type *base, uint8_t *dst, uint32_t src
* Function Name: Cy_Crypto_Core_Vu_IsRegZero
****************************************************************************//**
*
* Returns TRUE if srcReg contains 0. FALSE otherwise.
* Returns TRUE if srcReg contains 0. FALSE - otherwise.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -120,10 +125,10 @@ bool Cy_Crypto_Core_Vu_IsRegZero(CRYPTO_Type *base, uint32_t srcReg);
* Function Name: Cy_Crypto_Core_Vu_IsRegEqual
****************************************************************************//**
*
* Returns TRUE if srcReg0 contains the same value as srcReg1. FALSE otherwise.
* Returns TRUE if srcReg0 contains the same value as srcReg1. FALSE - otherwise.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg0
* The source 0 vector unit register.
@ -142,10 +147,10 @@ bool Cy_Crypto_Core_Vu_IsRegEqual(CRYPTO_Type *base, uint32_t srcReg0, uint32_t
****************************************************************************//**
*
* Returns TRUE if srcReg0 contains the value less than value of srcReg1.
* FALSE otherwise.
* FALSE - otherwise.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg0
* The source 0 vector unit register.
@ -163,10 +168,10 @@ bool Cy_Crypto_Core_Vu_IsRegLess(CRYPTO_Type *base, uint32_t srcReg0, uint32_t s
* Function Name: Cy_Crypto_Core_Vu_RegRead
****************************************************************************//**
*
* Returns the data pointed in given register
* Returns the data pointed in a given register.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -185,7 +190,7 @@ __STATIC_INLINE uint32_t Cy_Crypto_Core_Vu_RegRead(CRYPTO_Type *base, uint32_t s
* it is lower 12Bit of the 32Bit word
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -204,7 +209,7 @@ __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegSizeRead(CRYPTO_Type *base, uint32
* It is lower 12Bit of the 32Bit word
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -223,7 +228,7 @@ __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegBitSizeRead(CRYPTO_Type *base, uin
* It is lower 12Bit of the 32Bit word
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -242,7 +247,7 @@ __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegByteSizeRead(CRYPTO_Type *base, ui
* It is lower 12Bit of the 32Bit word
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -261,7 +266,7 @@ __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegWordSizeRead(CRYPTO_Type *base, ui
* it is upper 16Bit of the 32Bir word. Pointer is in words (uint32_t).
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -269,7 +274,7 @@ __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegWordSizeRead(CRYPTO_Type *base, ui
*******************************************************************************/
__STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegDataPtrRead(CRYPTO_Type *base, uint32_t srcReg)
{
return ((uint16_t)(_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) >> CY_CRYPTO_VU_DATA_FLD_POS)
return (uint16_t)((_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) >> CY_CRYPTO_VU_DATA_FLD_POS)
& CY_CRYPTO_VU_DATA_FLD_MASK);
}
@ -280,7 +285,7 @@ __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegDataPtrRead(CRYPTO_Type *base, uin
* Returns the memory address of the data pointed in given register.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcReg
* The source vector unit register.
@ -288,7 +293,7 @@ __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegDataPtrRead(CRYPTO_Type *base, uin
*******************************************************************************/
__STATIC_INLINE uint32_t * Cy_Crypto_Core_Vu_RegMemPointer(CRYPTO_Type *base, uint32_t srcReg)
{
return (uint32_t *)((uint32_t)REG_CRYPTO_MEM_BUFF(base) + 4u * (uint32_t)Cy_Crypto_Core_Vu_RegDataPtrRead(base, srcReg));
return (uint32_t *)((uint32_t)REG_CRYPTO_MEM_BUFF(base) + (4u * (uint32_t)Cy_Crypto_Core_Vu_RegDataPtrRead(base, srcReg)));
}
/*******************************************************************************
@ -298,13 +303,13 @@ __STATIC_INLINE uint32_t * Cy_Crypto_Core_Vu_RegMemPointer(CRYPTO_Type *base, ui
* Waits until VU instruction will be completed
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
__STATIC_INLINE void Cy_Crypto_Core_Vu_WaitForComplete(CRYPTO_Type *base)
{
/* Wait until the VU instruction is complete */
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
while (0uL != _FLD2VAL(CRYPTO_STATUS_VU_BUSY, REG_CRYPTO_STATUS(base)))
{
@ -322,19 +327,20 @@ __STATIC_INLINE void Cy_Crypto_Core_Vu_WaitForComplete(CRYPTO_Type *base)
* Function Name: Cy_Crypto_Core_Vu_StatusRead
****************************************************************************//**
*
* Returns value of the VU status register
* Returns the value of the VU status register.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
__STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_StatusRead(CRYPTO_Type *base)
__STATIC_INLINE uint32_t Cy_Crypto_Core_Vu_StatusRead(CRYPTO_Type *base)
{
Cy_Crypto_Core_Vu_WaitForComplete(base);
return((uint16_t)REG_CRYPTO_VU_STATUS(base));
return((uint32_t)REG_CRYPTO_VU_STATUS(base));
}
/** \} group_crypto_lld_vu_functions */
#endif /* #if (CPUSS_CRYPTO_VU == 1) */

View File

@ -63,7 +63,7 @@ extern "C" {
* the Crypto server context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \funcusage
* \snippet crypto/2.10/snippet/main.c snippet_myCryptoServerStartBase
@ -94,7 +94,7 @@ cy_en_crypto_status_t Cy_Crypto_Server_Start_Base(cy_stc_crypto_config_t const *
* the Crypto server context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* Refer to \ref Cy_Crypto_Server_Start_Base for the function usage example.
*
@ -124,7 +124,7 @@ cy_en_crypto_status_t Cy_Crypto_Server_Start_Extra(cy_stc_crypto_config_t const
* the Crypto server context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* Refer to \ref Cy_Crypto_Server_Start_Base for the function usage example.
*
@ -142,7 +142,7 @@ cy_en_crypto_status_t Cy_Crypto_Server_Start_Full(cy_stc_crypto_config_t const *
* This function available for Server side only.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Server_Stop(void);

View File

@ -189,6 +189,8 @@ void Cy_PDL_Init(const cy_stc_device_t * device);
* Register Access Helper Macros
*******************************************************************************/
#define CY_CRYPTO_HW_V1 (1U == cy_device->cryptoVersion) /* true if the mxcrypto version is 1 */
#define CY_SRSS_NUM_CLKPATH ((uint32_t)(cy_device->srssNumClkpath))
#define CY_SRSS_NUM_PLL ((uint32_t)(cy_device->srssNumPll))
#define CY_SRSS_NUM_HFROOT ((uint32_t)(cy_device->srssNumHfroot))

View File

@ -36,6 +36,7 @@
#include "cy_ctb.h"
#include "cy_ctdac.h"
#include "cy_dma.h"
#include "cy_dmac.h"
#include "cy_efuse.h"
#include "cy_flash.h"
#include "cy_gpio.h"
@ -55,8 +56,10 @@
#include "cy_scb_i2c.h"
#include "cy_scb_spi.h"
#include "cy_scb_uart.h"
#include "cy_sd_host.h"
#include "cy_smartio.h"
#include "cy_smif.h"
#include "cy_smif_memslot.h"
#include "cy_sysanalog.h"
#include "cy_sysclk.h"
#include "cy_sysint.h"

View File

@ -112,6 +112,7 @@
* <td>Updated the following functions implementation: \ref Cy_SysClk_EcoEnable, \ref Cy_SysClk_EcoGetStatus, \ref Cy_SysClk_FllGetConfiguration \n
* and \ref Cy_SysClk_DeepSleepCallback. \n
* The \ref Cy_SysClk_DeepSleepCallback now implements all four SysPm callback modes \ref cy_en_syspm_callback_mode_t. \n
* The actions that were done in \ref CY_SYSPM_CHECK_READY case are moved to \ref CY_SYSPM_BEFORE_TRANSITION. \n
* So the \ref cy_stc_syspm_callback_t::skipMode must be set to 0UL.</td>
* <td>Defect fixing.</td>
* </tr>

View File

@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_ble_clk.c
* \version 3.0
* \version 3.10
*
* \brief
* This driver provides the source code for API BLE ECO clock.
@ -138,8 +138,8 @@ static cy_en_ble_eco_status_t Cy_BLE_HAL_MxdRadioEnableClocks(cy_en_ble_eco_freq
/* Range for inputs parameters */
#define CY_BLE_ECO_XTAL_SRART_UP_TIME_MAX ((uint8_t) (4593.75 / 31.25))
#define CY_BLE_ECO_XTAL_SRART_UP_TIME_MIN ((uint8_t) (400 / 31.25))
#define CY_BLE_ECO_XTAL_START_UP_TIME_MAX ((uint8_t) (4593.75 / 31.25))
#define CY_BLE_ECO_XTAL_START_UP_TIME_MIN ((uint8_t) (400 / 31.25))
#define CY_BLE_ECO_CLOAD_MIN ((uint8_t) ((7.5 - 7.5)/0.075))
#define CY_BLE_ECO_CLOAD_MAX ((uint8_t) ((26.325 - 7.5)/0.075))
@ -220,7 +220,7 @@ cy_en_ble_eco_status_t Cy_BLE_EcoConfigure(cy_en_ble_eco_freq_t freq, cy_en_ble_
uint32_t temp = 0UL;
if( (freq > CY_BLE_BLESS_ECO_FREQ_32MHZ) || (sysClkDiv > CY_BLE_SYS_ECO_CLK_DIV_8) ||
(xtalStartUpTime > CY_BLE_ECO_XTAL_SRART_UP_TIME_MAX) || (xtalStartUpTime < CY_BLE_ECO_XTAL_SRART_UP_TIME_MIN) ||
(xtalStartUpTime > CY_BLE_ECO_XTAL_START_UP_TIME_MAX) || (xtalStartUpTime < CY_BLE_ECO_XTAL_START_UP_TIME_MIN) ||
(cLoad > CY_BLE_ECO_CLOAD_MAX))
{
status = CY_BLE_ECO_BAD_PARAM;
@ -355,7 +355,7 @@ cy_en_ble_eco_status_t Cy_BLE_EcoConfigure(cy_en_ble_eco_freq_t freq, cy_en_ble_
/* Clear the BLERD_ACTIVE_INTR */
BLE_BLESS_INTR_STAT |= BLE_BLESS_INTR_STAT_BLERD_ACTIVE_INTR_Msk;
if(!Cy_SysPm_SimoBuckOutputIsEnabled(CY_SYSPM_BUCK_VRF))
if((!Cy_SysPm_SimoBuckOutputIsEnabled(CY_SYSPM_BUCK_VRF)) || (voltageReg == CY_BLE_ECO_VOLTAGE_REG_BLESSLDO))
{
temp |= BLE_BLESS_MT_CFG_ACT_LDO_NOT_BUCK_Msk;
}

View File

@ -171,7 +171,7 @@ cy_en_crypto_status_t Cy_Crypto_Sync(bool isBlocking)
* This function is internal and should not to be called directly by user software.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
static cy_en_crypto_status_t Cy_Crypto_Client_Send(void)
@ -309,7 +309,7 @@ cy_en_crypto_status_t Cy_Crypto_Enable(void)
* The pointer to a variable to store gathered crypto library information.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_GetLibraryInfo(cy_en_crypto_lib_info_t *cryptoInfo)

View File

@ -44,10 +44,11 @@ static void Cy_Crypto_Core_V1_Aes_InvKey(CRYPTO_Type *base, cy_stc_crypto_aes_st
* Performs the AES block cipher.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \param dirMode
* One of CRYPTO_ENCRYPT or CRYPTO_DECRYPT.
@ -90,10 +91,11 @@ void Cy_Crypto_Core_V1_Aes_ProcessBlock(CRYPTO_Type *base,
* All addresses must be 4-Byte aligned!
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \param dstBlock
* The pointer to the memory structure with the XOR results.
@ -136,10 +138,11 @@ void Cy_Crypto_Core_V1_Aes_Xor(CRYPTO_Type *base,
* Calculates an inverse block cipher key from the block cipher key.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
*******************************************************************************/
static void Cy_Crypto_Core_V1_Aes_InvKey(CRYPTO_Type *base, cy_stc_crypto_aes_state_t const *aesState)
@ -162,10 +165,10 @@ static void Cy_Crypto_Core_V1_Aes_InvKey(CRYPTO_Type *base, cy_stc_crypto_aes_st
* Function Name: Cy_Crypto_Core_V1_Aes_Init
****************************************************************************//**
*
* Sets Aes mode and prepare inversed key.
* Sets AES mode and prepares an inverse key.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param key
* The pointer to the encryption/decryption key.
@ -174,10 +177,11 @@ static void Cy_Crypto_Core_V1_Aes_InvKey(CRYPTO_Type *base, cy_stc_crypto_aes_st
* \ref cy_en_crypto_aes_key_length_t
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Init(CRYPTO_Type *base,
@ -212,10 +216,10 @@ void Cy_Crypto_Core_V1_Aes_Free(CRYPTO_Type *base)
* Function Name: Cy_Crypto_Core_V1_Aes_Ecb
****************************************************************************//**
*
* Performs AES operation on one Block.
* Performs an AES operation on one block.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -228,10 +232,11 @@ void Cy_Crypto_Core_V1_Aes_Free(CRYPTO_Type *base)
* The pointer to a source block.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Ecb(CRYPTO_Type *base,
@ -258,7 +263,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Ecb(CRYPTO_Type *base,
* Performs AES operation on a plain text with Cipher Block Chaining (CBC).
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -277,10 +282,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Ecb(CRYPTO_Type *base,
* The pointer to a source plain text.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cbc(CRYPTO_Type *base,
@ -298,17 +304,17 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cbc(CRYPTO_Type *base,
uint32_t *srcBuff = (uint32_t*)(&aesBuffers->block0);
uint32_t *dstBuff = (uint32_t*)(&aesBuffers->block1);
cy_en_crypto_status_t myResult = CY_CRYPTO_SIZE_NOT_X16;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SIZE_NOT_X16;
/* Check whether the data size is multiple of CY_CRYPTO_AES_BLOCK_SIZE */
if (0uL == (uint32_t)(size & (CY_CRYPTO_AES_BLOCK_SIZE - 1u)))
if (0UL == (uint32_t)(size & (CY_CRYPTO_AES_BLOCK_SIZE - 1U)))
{
/* Copy the Initialization Vector to the local buffer because it changes during calculation */
Cy_Crypto_Core_V1_MemCpy(base, tempBuff, ivPtr, CY_CRYPTO_AES_BLOCK_SIZE);
if (CY_CRYPTO_DECRYPT == dirMode)
{
while (size > 0uL)
while (size != 0UL)
{
/* source message block */
Cy_Crypto_Core_V1_MemCpy(base, srcBuff, src, CY_CRYPTO_AES_BLOCK_SIZE);
@ -329,7 +335,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cbc(CRYPTO_Type *base,
}
else
{
while (size > 0uL)
while (size != 0UL)
{
/* source message block */
Cy_Crypto_Core_V1_MemCpy(base, srcBuff, src, CY_CRYPTO_AES_BLOCK_SIZE);
@ -349,10 +355,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cbc(CRYPTO_Type *base,
}
}
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -362,7 +368,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cbc(CRYPTO_Type *base,
* Performs AES operation on a plain text with the Cipher Feedback Block method (CFB).
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -381,10 +387,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cbc(CRYPTO_Type *base,
* The pointer to a source plain text.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user must
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cfb(CRYPTO_Type *base,
@ -396,7 +403,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cfb(CRYPTO_Type *base,
cy_stc_crypto_aes_state_t *aesState)
{
uint32_t size = srcSize;
cy_en_crypto_status_t myResult = CY_CRYPTO_SIZE_NOT_X16;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SIZE_NOT_X16;
cy_stc_crypto_aes_buffers_t *aesBuffers = (cy_stc_crypto_aes_buffers_t*)aesState->buffers;
@ -406,17 +413,17 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cfb(CRYPTO_Type *base,
uint32_t *encBuff = dstBuff; /* Default operation is ENCRYPT */
/* Check whether the data size is multiple of CY_CRYPTO_AES_BLOCK_SIZE */
if (0uL == (size & (CY_CRYPTO_AES_BLOCK_SIZE - 1u)))
if (0UL == (size & (CY_CRYPTO_AES_BLOCK_SIZE - 1U)))
{
if (CY_CRYPTO_DECRYPT == dirMode)
{
encBuff = srcBuff;
}
/* Copy the Initialization Vector to local encode buffer */
/* Copies the Initialization Vector to the local encode buffer. */
Cy_Crypto_Core_V1_MemCpy(base, encBuff, ivPtr, CY_CRYPTO_AES_BLOCK_SIZE);
while (size > 0uL)
while (size != 0UL)
{
/* In this mode, (CFB) is always an encryption! */
Cy_Crypto_Core_V1_Aes_ProcessBlock(base, aesState, CY_CRYPTO_ENCRYPT, dstBuff, encBuff);
@ -435,20 +442,20 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cfb(CRYPTO_Type *base,
size -= CY_CRYPTO_AES_BLOCK_SIZE;
}
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_V1_Aes_Ctr
********************************************************************************
*
* Performs AES operation on a plain text using the counter method (CTR).
* Performs an AES operation on a plain text using the counter method (CTR).
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcSize
* The size of a source plain text.
@ -458,7 +465,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cfb(CRYPTO_Type *base,
* current cipher stream.
*
* \param ivPtr
* The 128-bit nonce and counter.
* The 128-bit initial vector and counter.
*
* \param streamBlock
* The saved stream-block for resuming. Is over-written by the function.
@ -470,13 +477,14 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Cfb(CRYPTO_Type *base,
* The pointer to a source plain text. Must be 4-Byte aligned.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user must
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
#define CY_CRYPTO_AES_CTR_CNT_POS (0x02u)
#define CY_CRYPTO_AES_CTR_CNT_POS (0x02U)
cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Ctr(CRYPTO_Type *base,
uint32_t srcSize,
uint32_t *srcOffset,
@ -491,28 +499,28 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Ctr(CRYPTO_Type *base,
uint64_t counter;
cy_stc_crypto_aes_buffers_t *aesBuffers = (cy_stc_crypto_aes_buffers_t*)aesState->buffers;
uint32_t *nonceCounter = (uint32_t*)(&aesBuffers->iv);
uint32_t *blockCounter = (uint32_t*)(&aesBuffers->iv);
uint32_t *srcBuff = (uint32_t*)(&aesBuffers->block0);
uint32_t *dstBuff = (uint32_t*)(&aesBuffers->block1);
uint32_t *streamBuff = (uint32_t*)(&aesBuffers->block2);
Cy_Crypto_Core_V1_MemCpy(base, nonceCounter, ivPtr, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V1_MemCpy(base, blockCounter, ivPtr, CY_CRYPTO_AES_BLOCK_SIZE);
counter = CY_SWAP_ENDIAN64(*(uint64_t*)(nonceCounter + CY_CRYPTO_AES_CTR_CNT_POS));
counter = CY_SWAP_ENDIAN64(*(uint64_t*)(blockCounter + CY_CRYPTO_AES_CTR_CNT_POS));
cnt = (uint32_t)(srcSize / CY_CRYPTO_AES_BLOCK_SIZE);
for (i = 0uL; i < cnt; i++)
for (i = 0UL; i < cnt; i++)
{
/* source message block */
Cy_Crypto_Core_V1_MemCpy(base, srcBuff, src, CY_CRYPTO_AES_BLOCK_SIZE);
/* In this mode, (CTR) is always an encryption! */
Cy_Crypto_Core_V1_Aes_ProcessBlock(base, aesState, CY_CRYPTO_ENCRYPT, streamBuff, nonceCounter);
Cy_Crypto_Core_V1_Aes_ProcessBlock(base, aesState, CY_CRYPTO_ENCRYPT, streamBuff, blockCounter);
/* Increment the nonce counter, at least 64Bits (from 128) is the counter part */
/* Increment the block counter, at least 64Bits (from 128) is the counter part */
counter++;
*(uint64_t*)(nonceCounter + CY_CRYPTO_AES_CTR_CNT_POS) = CY_SWAP_ENDIAN64(counter);
*(uint64_t*)(blockCounter + CY_CRYPTO_AES_CTR_CNT_POS) = CY_SWAP_ENDIAN64(counter);
Cy_Crypto_Core_V1_Aes_Xor(base, aesState, dstBuff, srcBuff, streamBuff);
@ -523,7 +531,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Aes_Ctr(CRYPTO_Type *base,
dst += CY_CRYPTO_AES_BLOCK_SIZE;
}
Cy_Crypto_Core_V1_MemCpy(base, ivPtr, nonceCounter, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V1_MemCpy(base, ivPtr, blockCounter, CY_CRYPTO_AES_BLOCK_SIZE);
/* Save the reminder of the last non-complete block */
*srcOffset = (uint32_t)(srcSize % CY_CRYPTO_AES_BLOCK_SIZE);

View File

@ -45,10 +45,11 @@
* Calculates an inverse block cipher key from the block cipher key.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
*******************************************************************************/
void Cy_Crypto_Core_V2_Aes_LoadEncKey(CRYPTO_Type *base,
@ -77,10 +78,11 @@ void Cy_Crypto_Core_V2_Aes_LoadEncKey(CRYPTO_Type *base,
* Calculates an inverse block cipher key from the block cipher key.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
*******************************************************************************/
void Cy_Crypto_Core_V2_Aes_LoadDecKey(CRYPTO_Type *base,
@ -109,10 +111,10 @@ void Cy_Crypto_Core_V2_Aes_LoadDecKey(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V2_Aes_Init
****************************************************************************//**
*
* Sets Aes mode and prepare inversed key.
* Sets AES mode and prepares inverse key.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param key
* The pointer to the encryption/decryption key.
@ -121,10 +123,11 @@ void Cy_Crypto_Core_V2_Aes_LoadDecKey(CRYPTO_Type *base,
* \ref cy_en_crypto_aes_key_length_t
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Init(CRYPTO_Type *base,
@ -150,10 +153,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Init(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V2_Aes_Ecb
****************************************************************************//**
*
* Performs AES operation on one Block.
* Performs an AES operation on one block.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -166,10 +169,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Init(CRYPTO_Type *base,
* The pointer to a source block.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ecb(CRYPTO_Type *base,
@ -202,7 +206,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ecb(CRYPTO_Type *base,
* Performs AES operation on a plain text with Cipher Block Chaining (CBC).
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -221,10 +225,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ecb(CRYPTO_Type *base,
* The pointer to a source plain text. Must be 4-Byte aligned.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base,
@ -236,10 +241,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base,
cy_stc_crypto_aes_state_t *aesState)
{
uint32_t size = srcSize;
cy_en_crypto_status_t myResult = CY_CRYPTO_SIZE_NOT_X16;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SIZE_NOT_X16;
/* Check whether the data size is multiple of CY_CRYPTO_AES_BLOCK_SIZE */
if (0uL == (uint32_t)(srcSize & (uint32_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1u)))
if (0UL == (uint32_t)(srcSize & (uint32_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1U)))
{
(CY_CRYPTO_ENCRYPT == dirMode) ? \
@ -254,7 +259,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base,
{
Cy_Crypto_Core_V2_BlockMov(base, CY_CRYPTO_V2_RB_BLOCK1, CY_CRYPTO_V2_RB_FF_LOAD1, CY_CRYPTO_AES_BLOCK_SIZE);
while (size != 0u)
while (size != 0U)
{
Cy_Crypto_Core_V2_BlockXor(base, CY_CRYPTO_V2_RB_BLOCK0, CY_CRYPTO_V2_RB_FF_LOAD0,
CY_CRYPTO_V2_RB_BLOCK1, CY_CRYPTO_AES_BLOCK_SIZE);
@ -268,7 +273,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base,
{
Cy_Crypto_Core_V2_BlockMov(base, CY_CRYPTO_V2_RB_BLOCK2, CY_CRYPTO_V2_RB_FF_LOAD1, CY_CRYPTO_AES_BLOCK_SIZE);
while (size != 0u)
while (size != 0U)
{
Cy_Crypto_Core_V2_BlockMov(base, CY_CRYPTO_V2_RB_BLOCK0, CY_CRYPTO_V2_RB_FF_LOAD0, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V2_RunAesInv(base);
@ -280,12 +285,12 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base,
}
}
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
Cy_Crypto_Core_WaitForReady(base);
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -295,7 +300,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base,
* Performs AES operation on a plain text with the Cipher Feedback Block method (CFB).
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -314,10 +319,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cbc(CRYPTO_Type *base,
* The pointer to a source plain text. Must be 4-Byte aligned.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base,
@ -330,10 +336,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base,
{
uint32_t size = srcSize;
cy_en_crypto_status_t myResult = CY_CRYPTO_SIZE_NOT_X16;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SIZE_NOT_X16;
/* Check whether the data size is multiple of CY_CRYPTO_AES_BLOCK_SIZE */
if (0uL == (uint32_t)(size & (uint32_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1u)))
if (0UL == (uint32_t)(size & (uint32_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1U)))
{
Cy_Crypto_Core_V2_Aes_LoadEncKey(base, aesState);
@ -345,7 +351,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base,
if (CY_CRYPTO_ENCRYPT == dirMode)
{
while (size != 0u)
while (size != 0U)
{
Cy_Crypto_Core_V2_RunAes(base);
Cy_Crypto_Core_V2_BlockXor(base, CY_CRYPTO_V2_RB_BLOCK0, CY_CRYPTO_V2_RB_FF_LOAD0,
@ -357,7 +363,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base,
}
else
{
while (size != 0u)
while (size != 0U)
{
Cy_Crypto_Core_V2_RunAes(base);
Cy_Crypto_Core_V2_BlockMov(base, CY_CRYPTO_V2_RB_BLOCK0, CY_CRYPTO_V2_RB_FF_LOAD0, CY_CRYPTO_AES_BLOCK_SIZE);
@ -368,12 +374,12 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base,
}
}
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
Cy_Crypto_Core_WaitForReady(base);
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -383,7 +389,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base,
* Performs AES operation on a plain text using the counter method (CTR).
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param srcSize
* The size of a source plain text.
@ -405,13 +411,14 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Cfb(CRYPTO_Type *base,
* The pointer to a source plain text. Must be 4-Byte aligned.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
#define CY_CRYPTO_AES_CTR_CNT_POS (2u)
#define CY_CRYPTO_AES_CTR_CNT_POS (2U)
cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr(CRYPTO_Type *base,
uint32_t srcSize,
uint32_t *srcOffset,
@ -421,28 +428,28 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr(CRYPTO_Type *base,
uint8_t const *src,
cy_stc_crypto_aes_state_t *aesState)
{
uint32_t nonceCounter[4];
uint32_t blockCounter[4];
uint64_t counter;
uint32_t cnt;
uint32_t i;
nonceCounter[ 0] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[ 3], ivPtr[ 2], ivPtr[ 1], ivPtr[0]);
nonceCounter[ 1] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[ 7], ivPtr[ 6], ivPtr[ 5], ivPtr[4]);
nonceCounter[ 2] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[11], ivPtr[10], ivPtr[ 9], ivPtr[8]);
nonceCounter[ 3] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[15], ivPtr[14], ivPtr[13], ivPtr[12]);
blockCounter[ 0] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[ 3], ivPtr[ 2], ivPtr[ 1], ivPtr[0]);
blockCounter[ 1] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[ 7], ivPtr[ 6], ivPtr[ 5], ivPtr[4]);
blockCounter[ 2] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[11], ivPtr[10], ivPtr[ 9], ivPtr[8]);
blockCounter[ 3] = (uint32_t) CY_CRYPTO_MERGE_BYTES(ivPtr[15], ivPtr[14], ivPtr[13], ivPtr[12]);
counter = CY_SWAP_ENDIAN64(*(uint64_t*)(nonceCounter + CY_CRYPTO_AES_CTR_CNT_POS));
counter = CY_SWAP_ENDIAN64(*(uint64_t*)(blockCounter + CY_CRYPTO_AES_CTR_CNT_POS));
Cy_Crypto_Core_V2_Aes_LoadEncKey(base, aesState);
Cy_Crypto_Core_V2_FFContinue(base, CY_CRYPTO_V2_RB_FF_LOAD1, (const uint8_t *) &nonceCounter, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V2_FFContinue(base, CY_CRYPTO_V2_RB_FF_LOAD1, (const uint8_t *) &blockCounter, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V2_BlockMov (base, CY_CRYPTO_V2_RB_BLOCK0, CY_CRYPTO_V2_RB_FF_LOAD1, CY_CRYPTO_AES_BLOCK_SIZE);
/* CTR counter is placed into last 4 bytes of the Nonce block */
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 4u, (uint8_t)((counter >> 24u) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 3u, (uint8_t)((counter >> 16u) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 2u, (uint8_t)((counter >> 8u) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 1u, (uint8_t)((counter) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 4U, (uint8_t)((counter >> 24U) & 0xffU));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 3U, (uint8_t)((counter >> 16U) & 0xffU));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 2U, (uint8_t)((counter >> 8U) & 0xffU));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 1U, (uint8_t)((counter) & 0xffU));
Cy_Crypto_Core_V2_RunAes(base);
@ -457,19 +464,19 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Aes_Ctr(CRYPTO_Type *base,
/* Increment the nonce counter */
counter++;
*(uint64_t*)(nonceCounter + CY_CRYPTO_AES_CTR_CNT_POS) = CY_SWAP_ENDIAN64(counter);
*(uint64_t*)(blockCounter + CY_CRYPTO_AES_CTR_CNT_POS) = CY_SWAP_ENDIAN64(counter);
/* CTR counter is placed into last 4 bytes of the Nonce block */
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 4u, (uint8_t)((counter >> 24u) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 3u, (uint8_t)((counter >> 16u) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 2u, (uint8_t)((counter >> 8u) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 1u, (uint8_t)((counter) & 0xffu));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 4U, (uint8_t)((counter >> 24u) & 0xffU));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 3U, (uint8_t)((counter >> 16u) & 0xffU));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 2U, (uint8_t)((counter >> 8u) & 0xffU));
Cy_Crypto_Core_V2_RBSetByte(base, CY_CRYPTO_AES_BLOCK_SIZE - 1U, (uint8_t)((counter) & 0xffU));
Cy_Crypto_Core_V2_RBXor (base, CY_CRYPTO_AES_BLOCK_SIZE, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V2_RBStore(base, CY_CRYPTO_AES_BLOCK_SIZE, CY_CRYPTO_AES_BLOCK_SIZE);
}
Cy_Crypto_Core_V2_MemCpy(base, ivPtr, nonceCounter, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V2_MemCpy(base, ivPtr, blockCounter, CY_CRYPTO_AES_BLOCK_SIZE);
/* Save the reminder of the last non-complete block */
*srcOffset = (uint32_t)(srcSize % CY_CRYPTO_AES_BLOCK_SIZE);

View File

@ -56,20 +56,20 @@ static void Cy_Crypto_Core_V1_Cmac_CalcSubKey(uint8_t *srcDstPtr)
{
int32_t i;
uint32_t c;
uint32_t msb = 0uL;
uint32_t msb = 0UL;
for (i = (int32_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1); i >= 0; i--)
for (i = (int32_t)((int32_t)CY_CRYPTO_AES_BLOCK_SIZE - 1); i >= 0; i--)
{
c = (uint32_t)srcDstPtr[i];
c = (c << 1u) | msb;
c = (c << 1U) | msb;
srcDstPtr[i] = (uint8_t) c;
msb = (c >> 8u) & 1uL;
msb = (c >> 8U) & 1UL;
}
if (0uL != msb)
if (0UL != msb)
{
/* Just one byte is valuable, the rest are zeros */
srcDstPtr[(uint8_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1u)] ^= CY_CRYPTO_CMAC_RB;
srcDstPtr[(uint8_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1U)] ^= CY_CRYPTO_CMAC_RB;
}
}
@ -110,13 +110,13 @@ void Cy_Crypto_Core_V1_Cmac_Init(cy_stc_crypto_v1_cmac_state_t* cmacState,
* Starts CMAC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* The pointer to the structure which stores the AES context.
*
* \param cmacState
* the pointer to the structure which stores the CMAC context.
* The pointer to the structure which stores the CMAC context.
*
*******************************************************************************/
void Cy_Crypto_Core_V1_Cmac_Start(CRYPTO_Type *base,
@ -127,7 +127,7 @@ void Cy_Crypto_Core_V1_Cmac_Start(CRYPTO_Type *base,
uint32_t *tempTmp = cmacState->temp;
/* Calculate the K1 sub-key */
Cy_Crypto_Core_V1_MemSet(base, (void*)tempTmp, 0u, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V1_MemSet(base, (void*)tempTmp, 0U, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V1_Aes_ProcessBlock(base, aesState, CY_CRYPTO_ENCRYPT, kTmp, tempTmp);
@ -141,7 +141,7 @@ void Cy_Crypto_Core_V1_Cmac_Start(CRYPTO_Type *base,
* Calculates CMAC on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* The pointer to the structure which stores the AES context.
@ -166,7 +166,7 @@ void Cy_Crypto_Core_V1_Cmac_Update(CRYPTO_Type *base,
uint32_t *tempBuff = cmacState->temp;
/* Clear the argument for XOR for the first block */
Cy_Crypto_Core_V1_MemSet(base, (void* )tempBuff, 0x00u, CY_CRYPTO_AES_BLOCK_SIZE);
Cy_Crypto_Core_V1_MemSet(base, (void* )tempBuff, 0x00U, CY_CRYPTO_AES_BLOCK_SIZE);
/* Process all blocks except last */
while (messageSize > CY_CRYPTO_AES_BLOCK_SIZE)
@ -197,7 +197,7 @@ void Cy_Crypto_Core_V1_Cmac_Update(CRYPTO_Type *base,
* Completes CMAC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param aesState
* the pointer to the structure which stores the AES context.
@ -226,11 +226,11 @@ void Cy_Crypto_Core_V1_Cmac_Finish(CRYPTO_Type *base,
Cy_Crypto_Core_V1_Cmac_CalcSubKey((uint8_t* )kPtrTmp);
/* Appended '1' bit to the end of message, followed by '0' */
*((uint8_t* )blockBuff + blockIdxTmp) = 0x80u;
*((uint8_t* )blockBuff + blockIdxTmp) = 0x80U;
/* Write zeros into the rest of the message */
copySize = CY_CRYPTO_AES_BLOCK_SIZE - 1u - blockIdxTmp;
Cy_Crypto_Core_V1_MemSet(base, ((uint8_t* )blockBuff + blockIdxTmp + 1), 0x00u, (uint16_t)copySize);
Cy_Crypto_Core_V1_MemSet(base, ((uint8_t* )blockBuff + blockIdxTmp + 1), 0x00U, (uint16_t)copySize);
}
Cy_Crypto_Core_V1_Aes_Xor(base, aesState, blockBuff, blockBuff, tempBuff);
@ -250,7 +250,7 @@ void Cy_Crypto_Core_V1_Cmac_Finish(CRYPTO_Type *base,
* on a message to produce message authentication code using AES.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param message
* The pointer to a source plain text. Must be 4-byte aligned.
@ -268,10 +268,11 @@ void Cy_Crypto_Core_V1_Cmac_Finish(CRYPTO_Type *base,
* The pointer to the calculated CMAC.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Cmac(CRYPTO_Type *base,

View File

@ -66,20 +66,20 @@ static void Cy_Crypto_Core_V2_Cmac_CalcSubKey(uint8_t *srcDstPtr)
{
int32_t i;
uint32_t c;
uint32_t msb = 0uL;
uint32_t msb = 0UL;
for (i = (int32_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1); i >= 0; i--)
for (i = (int32_t)((int32_t)CY_CRYPTO_AES_BLOCK_SIZE - 1); i >= 0; i--)
{
c = (uint32_t)srcDstPtr[i];
c = (c << 1u) | msb;
c = (c << 1U) | msb;
srcDstPtr[i] = (uint8_t) c;
msb = (c >> 8u) & 1uL;
msb = (c >> 8U) & 1UL;
}
if (0uL != msb)
if (0UL != msb)
{
/* Just one byte is valuable, the rest are zeros */
srcDstPtr[(uint8_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1u)] ^= CY_CRYPTO_CMAC_RB;
srcDstPtr[(uint8_t)(CY_CRYPTO_AES_BLOCK_SIZE - 1U)] ^= CY_CRYPTO_CMAC_RB;
}
}
@ -105,7 +105,7 @@ void Cy_Crypto_Core_V2_Cmac_Init(cy_stc_crypto_v2_cmac_state_t* cmacState, uint8
* Starts CMAC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param cmacState
* the pointer to the structure which stores the CMAC context.
@ -114,7 +114,7 @@ void Cy_Crypto_Core_V2_Cmac_Init(cy_stc_crypto_v2_cmac_state_t* cmacState, uint8
void Cy_Crypto_Core_V2_Cmac_Start(CRYPTO_Type *base,
cy_stc_crypto_v2_cmac_state_t *cmacState)
{
cmacState->block_idx = 0u;
cmacState->block_idx = 0U;
/* Calculate the K1 sub-key */
Cy_Crypto_Core_V2_BlockXor(base, CY_CRYPTO_V2_RB_BLOCK0, CY_CRYPTO_V2_RB_BLOCK0,
@ -137,7 +137,7 @@ void Cy_Crypto_Core_V2_Cmac_Start(CRYPTO_Type *base,
* Calculates CMAC on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param cmacState
* The pointer to the structure which stores the CMAC context.
@ -177,7 +177,7 @@ void Cy_Crypto_Core_V2_Cmac_Update(CRYPTO_Type *base,
* Completes CMAC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param cmacState
* The pointer to the structure which stores the CMAC context.
@ -226,7 +226,7 @@ void Cy_Crypto_Core_V2_Cmac_Finish(CRYPTO_Type *base,
* on a message to produce message authentication code using AES.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param message
* The pointer to a source plain text. Must be 4-byte aligned.
@ -244,10 +244,11 @@ void Cy_Crypto_Core_V2_Cmac_Finish(CRYPTO_Type *base,
* The pointer to the calculated CMAC.
*
* \param aesState
* The pointer to the aesState structure which stores the AES context.
* The pointer to the AES state structure allocated by the user. The user
* must not modify anything in this structure.
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Cmac(CRYPTO_Type *base,
@ -259,7 +260,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Cmac(CRYPTO_Type *base,
cy_stc_crypto_aes_state_t *aesState)
{
/* Allocate space for the structure which stores the CMAC context */
cy_stc_crypto_v2_cmac_buffers_t cmacBuffersData;
cy_stc_crypto_v2_cmac_buffers_t cmacBuffersData = { 0 };
cy_stc_crypto_v2_cmac_buffers_t *cmacBuffers = &cmacBuffersData;
uint8_t *myK = cmacBuffers->k;

View File

@ -41,7 +41,7 @@
* Initializes CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param polynomial
* The polynomial (specified using 32 bits) used in the computing CRC.
@ -59,7 +59,7 @@
* Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_Init(CRYPTO_Type *base,
@ -99,7 +99,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_Init(CRYPTO_Type *base,
* Performs CRC calculation on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param crc
* The pointer to a computed CRC value. Must be 4-byte aligned.
@ -114,7 +114,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_Init(CRYPTO_Type *base,
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc(CRYPTO_Type *base,
@ -148,10 +148,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V1_Crc_CalcInit
****************************************************************************//**
*
* Initializes CRC calculation.
* Initializes the CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -163,19 +163,19 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc(CRYPTO_Type *base,
* The order in which data bytes are processed. 0 - MSB first; 1- LSB first.
*
* \param dataXor
* The byte mask for XORing data
* The byte mask for XORing data.
*
* \param remReverse
* A remainder reverse: 0 means the remainder is not reversed. 1 means reversed.
* A remainder reverse: 0 means the remainder is not reversed. 1 means it is reversed.
*
* \param remXor
* Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
* Specifies the mask with which the LFSR32 register is XORed to produce a remainder.
*
* \param lfsrInitState
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcInit(CRYPTO_Type *base,
@ -187,30 +187,33 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcInit(CRYPTO_Type *base,
uint32_t remXor,
uint32_t lfsrInitState)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
/* Specifies the bit order in which a data Byte is processed
/* Specifies the bit order in which a data byte is processed
* (reversal is performed after XORing):
* '0': Most significant bit (bit 1) first.
* '1': Least significant bit (bit 0) first. */
REG_CRYPTO_CRC_CTL(base) = (uint32_t)( (_VAL2FLD(CRYPTO_CRC_CTL_DATA_REVERSE, dataReverse)) |
(_VAL2FLD(CRYPTO_CRC_CTL_REM_REVERSE, remReverse)) );
/* Specifies a byte mask with which each data byte is XORed.
/* Specifies the byte mask with which each data byte is XORed.
* The XOR is performed before data reversal. */
REG_CRYPTO_CRC_DATA_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_CRC_DATA_CTL_DATA_XOR, dataXor));
/* CRC polynomial. The polynomial is represented WITHOUT the high order bit
/* The CRC polynomial. The polynomial is represented WITHOUT the high-order bit
* (this bit is always assumed '1').
* CRC_POLYNOMIAL << (32 - CRC_BITLEN) */
REG_CRYPTO_CRC_POL_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_CRC_POL_CTL_POLYNOMIAL, polynomial << (32u - width)));
REG_CRYPTO_CRC_POL_CTL(base) =
(uint32_t)(_VAL2FLD(CRYPTO_CRC_POL_CTL_POLYNOMIAL, polynomial << (CY_CRYPTO_HW_REGS_WIDTH - width)));
/*Specifies a mask with which the CRC_LFSR_CTL.LFSR32 register is XORed to produce a remainder.
/*Specifies the mask with which the CRC_LFSR_CTL.LFSR32 register is XORed to produce a remainder.
* The XOR is performed before remainder reversal. */
REG_CRYPTO_CRC_REM_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_CRC_REM_CTL_REM_XOR, remXor << (32u - width)));
REG_CRYPTO_CRC_REM_CTL(base) =
(uint32_t)(_VAL2FLD(CRYPTO_CRC_REM_CTL_REM_XOR, remXor << (CY_CRYPTO_HW_REGS_WIDTH - width)));
/* A state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement CRC. */
REG_CRYPTO_CRC_LFSR_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_CRC_LFSR_CTL_LFSR32, lfsrInitState << (32u - width)));
/* The state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement the CRC. */
REG_CRYPTO_CRC_LFSR_CTL(base) =
(uint32_t)(_VAL2FLD(CRYPTO_CRC_LFSR_CTL_LFSR32, lfsrInitState << (CY_CRYPTO_HW_REGS_WIDTH - width)));
return (CY_CRYPTO_SUCCESS);
}
@ -219,10 +222,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcInit(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V1_Crc_CalcStart
****************************************************************************//**
*
* Prepare CRC calculation by setting an initial seeds value.
* Prepares the CRC calculation by setting an initial seed value.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -231,15 +234,16 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcInit(CRYPTO_Type *base,
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcStart(CRYPTO_Type *base, uint32_t width, uint32_t lfsrInitState)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
/* A state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement CRC. */
REG_CRYPTO_CRC_LFSR_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_CRC_LFSR_CTL_LFSR32, lfsrInitState << (32u - width)));
/* The state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement the CRC. */
REG_CRYPTO_CRC_LFSR_CTL(base) =
(uint32_t)(_VAL2FLD(CRYPTO_CRC_LFSR_CTL_LFSR32, lfsrInitState << (CY_CRYPTO_HW_REGS_WIDTH - width)));
return (CY_CRYPTO_SUCCESS);
}
@ -248,10 +252,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcStart(CRYPTO_Type *base, uint32_
* Function Name: Cy_Crypto_Core_V1_Crc_CalcPartial
****************************************************************************//**
*
* Performs CRC calculation of a message part.
* Performs the CRC calculation of a message part.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param data
* The pointer to the message whose CRC is being computed.
@ -260,19 +264,19 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcStart(CRYPTO_Type *base, uint32_
* The size of a message in bytes.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcPartial(CRYPTO_Type *base,
void const *data, uint32_t dataSize)
{
/* Fill the FIFO with the instruction parameters */
/* Fills the FIFO with the instruction parameters. */
Cy_Crypto_SetReg2Instr(base, (uint32_t)data, dataSize );
/* Issue the CRC instruction */
/* Issues the CRC instruction. */
Cy_Crypto_Run2ParamInstr(base, CY_CRYPTO_V1_CRC_OPC, CY_CRYPTO_RSRC0_SHIFT, CY_CRYPTO_RSRC4_SHIFT);
/* Wait until CRC instruction is complete */
/* Waits until the CRC instruction is complete. */
while(0uL != _FLD2VAL(CRYPTO_STATUS_CRC_BUSY, REG_CRYPTO_STATUS(base)))
{
}
@ -284,10 +288,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcPartial(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V1_Crc_CalcFinish
****************************************************************************//**
*
* Finalizes CRC calculation.
* Finalizes the CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -296,22 +300,22 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcPartial(CRYPTO_Type *base,
* The pointer to a computed CRC value. Must be 4-byte aligned.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcFinish(CRYPTO_Type *base, uint32_t width, uint32_t *crc)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
uint32_t calculatedCrc;
/* Copy the result from the CRC_REM_RESULT register */
/* Copies the result from the CRC_REM_RESULT register. */
calculatedCrc = (uint32_t)_FLD2VAL(CRYPTO_CRC_REM_RESULT_REM, REG_CRYPTO_CRC_REM_RESULT(base));
/* Note: Calculated CRC value is MSB aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
/* NOTE The calculated CRC value is MSB-aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
if (_FLD2VAL(CRYPTO_CRC_CTL_REM_REVERSE, REG_CRYPTO_CRC_CTL(base)) == 0u)
{
calculatedCrc = calculatedCrc >> (32u - width);
calculatedCrc = calculatedCrc >> (CY_CRYPTO_HW_REGS_WIDTH - width);
}
*crc = calculatedCrc;
@ -323,10 +327,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcFinish(CRYPTO_Type *base, uint32
* Function Name: Cy_Crypto_Core_V1_Crc_Calc
****************************************************************************//**
*
* Performs CRC calculation on a message.
* Performs the CRC calculation on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -341,7 +345,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_CalcFinish(CRYPTO_Type *base, uint32
* The size of a message in bytes.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_Calc(CRYPTO_Type *base,
@ -350,28 +354,28 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Crc_Calc(CRYPTO_Type *base,
void const *data,
uint32_t dataSize)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
uint32_t calculatedCrc;
/* Fill the FIFO with the instruction parameters */
/* Fills the FIFO with the instruction parameters. */
Cy_Crypto_SetReg2Instr(base, (uint32_t)data, dataSize );
/* Issue the CRC instruction */
/* Issues the CRC instruction. */
Cy_Crypto_Run2ParamInstr(base, CY_CRYPTO_V1_CRC_OPC, CY_CRYPTO_RSRC0_SHIFT, CY_CRYPTO_RSRC4_SHIFT);
/* Wait until CRC instruction is complete */
/* Waits until the CRC instruction is complete. */
while(0uL != _FLD2VAL(CRYPTO_STATUS_CRC_BUSY, REG_CRYPTO_STATUS(base)))
{
}
/* Copy the result from the CRC_REM_RESULT register */
/* Copies the result from the CRC_REM_RESULT register. */
calculatedCrc = (uint32_t)_FLD2VAL(CRYPTO_CRC_REM_RESULT_REM, REG_CRYPTO_CRC_REM_RESULT(base));
/* Note: Calculated CRC value is MSB aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
/* NOTE The calculated CRC value is MSB-aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
if (_FLD2VAL(CRYPTO_CRC_CTL_REM_REVERSE, REG_CRYPTO_CRC_CTL(base)) == 0u)
{
calculatedCrc = calculatedCrc >> (32u - width);
calculatedCrc = calculatedCrc >> (CY_CRYPTO_HW_REGS_WIDTH - width);
}
*crc = calculatedCrc;

View File

@ -42,7 +42,7 @@
* Initializes CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param polynomial
* The polynomial (specified using 32 bits) used in the computing CRC.
@ -60,7 +60,7 @@
* Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_Init(CRYPTO_Type *base,
@ -100,7 +100,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_Init(CRYPTO_Type *base,
* Performs CRC calculation on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param crc
* The pointer to a computed CRC value. Must be 4-byte aligned.
@ -115,7 +115,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_Init(CRYPTO_Type *base,
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc(CRYPTO_Type *base,
@ -146,10 +146,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V2_Crc_CalcInit
****************************************************************************//**
*
* Initializes CRC calculation.
* Initializes the CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -161,19 +161,19 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc(CRYPTO_Type *base,
* The order in which data bytes are processed. 0 - MSB first; 1- LSB first.
*
* \param dataXor
* The byte mask for XORing data
* The byte mask for XORing data.
*
* \param remReverse
* A remainder reverse: 0 means the remainder is not reversed. 1 means reversed.
* The remainder reverse: 0 means the remainder is not reversed; 1 means it is reversed.
*
* \param remXor
* Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
* Specifies the mask with which the LFSR32 register is XORed to produce a remainder.
*
* \param lfsrInitState
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcInit(CRYPTO_Type *base,
@ -185,29 +185,32 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcInit(CRYPTO_Type *base,
uint32_t remXor,
uint32_t lfsrInitState)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
/* Specifies the bit order in which a data Byte is processed
/* Specifies the bit order in which a data byte is processed
* (reversal is performed after XORing):
* '0': Most significant bit (bit 1) first.
* '1': Least significant bit (bit 0) first. */
REG_CRYPTO_CRC_CTL(base) = (uint32_t)( (_VAL2FLD(CRYPTO_V2_CRC_CTL_DATA_REVERSE, dataReverse)) |
(_VAL2FLD(CRYPTO_V2_CRC_CTL_REM_REVERSE, remReverse)) );
/* Specifies a byte mask with which each data byte is XORed.
/* Specifies the byte mask with which each data byte is XORed.
* The XOR is performed before data reversal. */
REG_CRYPTO_CRC_DATA_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_V2_CRC_DATA_CTL_DATA_XOR, dataXor));
/* CRC polynomial. The polynomial is represented WITHOUT the high order bit
/* The CRC polynomial. The polynomial is represented WITHOUT the high-order bit
* (this bit is always assumed '1'). */
REG_CRYPTO_CRC_POL_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_V2_CRC_POL_CTL_POLYNOMIAL, polynomial << (32u - width)));
REG_CRYPTO_CRC_POL_CTL(base) =
(uint32_t)(_VAL2FLD(CRYPTO_V2_CRC_POL_CTL_POLYNOMIAL, polynomial << (CY_CRYPTO_HW_REGS_WIDTH - width)));
/*Specifies a mask with which the CRC_LFSR_CTL.LFSR32 register is XORed to produce a remainder.
/*Specifies the mask with which the CRC_LFSR_CTL.LFSR32 register is XORed to produce a remainder.
* The XOR is performed before remainder reversal. */
REG_CRYPTO_CRC_REM_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_V2_CRC_REM_CTL_REM_XOR, remXor << (32u - width)));
REG_CRYPTO_CRC_REM_CTL(base) =
(uint32_t)(_VAL2FLD(CRYPTO_V2_CRC_REM_CTL_REM_XOR, remXor << (CY_CRYPTO_HW_REGS_WIDTH - width)));
/* A state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement CRC. */
REG_CRYPTO_RESULT(base) = (uint32_t)(_VAL2FLD(CRYPTO_V2_RESULT_DATA, lfsrInitState << (32u - width)));
/* The state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement the CRC. */
REG_CRYPTO_RESULT(base) =
(uint32_t)(_VAL2FLD(CRYPTO_V2_RESULT_DATA, lfsrInitState << (CY_CRYPTO_HW_REGS_WIDTH - width)));
return (CY_CRYPTO_SUCCESS);
}
@ -216,10 +219,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcInit(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V2_Crc_CalcStart
****************************************************************************//**
*
* Prepares CRC calculation by setting an initial seeds value.
* Prepares the CRC calculation by setting an initial seed value.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -228,15 +231,15 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcInit(CRYPTO_Type *base,
* The initial state of the LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcStart(CRYPTO_Type *base, uint32_t width, uint32_t lfsrInitState)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
/* A state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement CRC. */
REG_CRYPTO_RESULT(base) = (uint32_t)(_VAL2FLD(CRYPTO_V2_RESULT_DATA, lfsrInitState << (32u - width)));
/* The state of 32-bit Linear Feedback Shift Registers (LFSR) used to implement the CRC. */
REG_CRYPTO_RESULT(base) = (uint32_t)(_VAL2FLD(CRYPTO_V2_RESULT_DATA, lfsrInitState << (CY_CRYPTO_HW_REGS_WIDTH - width)));
return (CY_CRYPTO_SUCCESS);
}
@ -245,10 +248,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcStart(CRYPTO_Type *base, uint32_
* Function Name: Cy_Crypto_Core_V2_Crc_CalcPartial
****************************************************************************//**
*
* Performs CRC calculation of a message part.
* Performs the CRC calculation of a message part.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param data
* The pointer to the message whose CRC is being computed.
@ -257,19 +260,19 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcStart(CRYPTO_Type *base, uint32_
* The size of a message in bytes.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcPartial(CRYPTO_Type *base,
void const *data, uint32_t dataSize)
{
/* Fill the FIFO with the instruction parameters */
/* Fills the FIFO with the instruction parameters. */
Cy_Crypto_Core_V2_FFStart(base, CY_CRYPTO_V2_RB_FF_LOAD0, (uint8_t const *)data, dataSize);
/* Issue the CRC instruction */
/* Issues the CRC instruction. */
Cy_Crypto_Core_V2_Run(base, CY_CRYPTO_V2_CRC_OPC);
/* Wait until CRC instruction is complete */
/* Waits until the CRC instruction is complete. */
Cy_Crypto_Core_V2_Sync(base);
return (CY_CRYPTO_SUCCESS);
@ -279,10 +282,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcPartial(CRYPTO_Type *base,
* Function Name: Cy_Crypto_Core_V2_Crc_CalcFinish
****************************************************************************//**
*
* Finalizes CRC calculation.
* Finalizes the CRC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -291,22 +294,22 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcPartial(CRYPTO_Type *base,
* The pointer to a computed CRC value. Must be 4-byte aligned.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcFinish(CRYPTO_Type *base, uint32_t width, uint32_t *crc)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
uint32_t calculatedCrc;
/* Copy the result from the CRC_REM_RESULT register */
/* Copies the result from the CRC_REM_RESULT register. */
calculatedCrc = (uint32_t)_FLD2VAL(CRYPTO_V2_CRC_REM_RESULT_REM, REG_CRYPTO_CRC_REM_RESULT(base));
/* Note: Calculated CRC value is MSB aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
if (_FLD2VAL(CRYPTO_V2_CRC_CTL_REM_REVERSE, REG_CRYPTO_CRC_CTL(base)) == 0u)
/* NOTE The calculated CRC value is MSB-aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
if (_FLD2VAL(CRYPTO_V2_CRC_CTL_REM_REVERSE, REG_CRYPTO_CRC_CTL(base)) == 0U)
{
calculatedCrc = calculatedCrc >> (32u - width);
calculatedCrc = calculatedCrc >> (CY_CRYPTO_HW_REGS_WIDTH - width);
}
*crc = calculatedCrc;
@ -318,10 +321,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcFinish(CRYPTO_Type *base, uint32
* Function Name: Cy_Crypto_Core_V2_Crc_Calc
****************************************************************************//**
*
* Performs CRC calculation on a message.
* Performs the CRC calculation on a message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param width
* The CRC width in bits.
@ -336,7 +339,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_CalcFinish(CRYPTO_Type *base, uint32
* The size of a message in bytes.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_Calc(CRYPTO_Type *base,
@ -345,26 +348,26 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Crc_Calc(CRYPTO_Type *base,
void const *data,
uint32_t dataSize)
{
CY_ASSERT_L1((width >= 1) && (width <=32u));
CY_ASSERT_L1((width >= 1U) && (width <= CY_CRYPTO_HW_REGS_WIDTH));
uint32_t calculatedCrc;
/* Fill the FIFO with the instruction parameters */
/* Fills the FIFO with the instruction parameters. */
Cy_Crypto_Core_V2_FFStart(base, CY_CRYPTO_V2_RB_FF_LOAD0, (uint8_t const *)data, dataSize);
/* Issue the CRC instruction */
/* Issues the CRC instruction. */
Cy_Crypto_Core_V2_Run(base, CY_CRYPTO_V2_CRC_OPC);
/* Wait until CRC instruction is complete */
/* Waits until the CRC instruction is complete. */
Cy_Crypto_Core_V2_Sync(base);
/* Copy the result from the CRC_REM_RESULT register */
/* Copies the result from the CRC_REM_RESULT register. */
calculatedCrc = (uint32_t)_FLD2VAL(CRYPTO_V2_CRC_REM_RESULT_REM, REG_CRYPTO_CRC_REM_RESULT(base));
/* Note: Calculated CRC value is MSB aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
if (_FLD2VAL(CRYPTO_V2_CRC_CTL_REM_REVERSE, REG_CRYPTO_CRC_CTL(base)) == 0u)
/* NOTE The calculated CRC value is MSB-aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */
if (_FLD2VAL(CRYPTO_V2_CRC_CTL_REM_REVERSE, REG_CRYPTO_CRC_CTL(base)) == 0U)
{
calculatedCrc = calculatedCrc >> (32u - width);
calculatedCrc = calculatedCrc >> (CY_CRYPTO_HW_REGS_WIDTH - width);
}
*crc = calculatedCrc;

View File

@ -91,7 +91,7 @@ static void Cy_Crypto_Core_V1_Des_ProcessBlock(CRYPTO_Type *base,
* srcBlock could overlap dstBlock.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* One of CRYPTO_ENCRYPT or CRYPTO_DECRYPT.
@ -145,7 +145,7 @@ static void Cy_Crypto_Core_V1_Des_ProcessBlock(CRYPTO_Type *base,
* This function is independent from the previous Crypto state.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -161,7 +161,7 @@ static void Cy_Crypto_Core_V1_Des_ProcessBlock(CRYPTO_Type *base,
* The pointer to a source block.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Des(CRYPTO_Type *base,
@ -176,12 +176,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Des(CRYPTO_Type *base,
cy_stc_crypto_des_buffers_t *desBuffers = (cy_stc_crypto_des_buffers_t *)REG_CRYPTO_MEM_BUFF(base);
/* Check weak keys */
for (i = 0u; i < CY_CRYPTO_DES_WEAK_KEY_COUNT; i++)
for (i = 0U; (i < CY_CRYPTO_DES_WEAK_KEY_COUNT) && (CY_CRYPTO_SUCCESS == status); i++)
{
if (memcmp(key, (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0)
if (Cy_Crypto_Core_V1_MemCmp(base, key, (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0U)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
}
}
@ -205,7 +204,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Des(CRYPTO_Type *base,
* This function is independent from the previous Crypto state.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -221,7 +220,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Des(CRYPTO_Type *base,
* The pointer to a source data block.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Tdes(CRYPTO_Type *base,
@ -236,30 +235,18 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Tdes(CRYPTO_Type *base,
cy_stc_crypto_des_buffers_t *desBuffers = (cy_stc_crypto_des_buffers_t *)REG_CRYPTO_MEM_BUFF(base);
/* Check weak keys */
for (i = 0u; i < CY_CRYPTO_DES_WEAK_KEY_COUNT; i++)
for (i = 0U; (i < CY_CRYPTO_DES_WEAK_KEY_COUNT) && (CY_CRYPTO_SUCCESS == status); i++)
{
if (memcmp(key, (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0)
for (uint32_t keynum=0U; (keynum < (CY_CRYPTO_TDES_KEY_SIZE / CY_CRYPTO_DES_KEY_SIZE)) && (CY_CRYPTO_SUCCESS == status); keynum++)
{
if (Cy_Crypto_Core_V1_MemCmp(base, &(key[keynum * CY_CRYPTO_DES_KEY_BYTE_LENGTH]), (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0U)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
}
if (memcmp(&(key[CY_CRYPTO_DES_KEY_BYTE_LENGTH]),
(uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
}
if (memcmp(&(key[2u * CY_CRYPTO_DES_KEY_BYTE_LENGTH]),
(uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
}
}
Cy_Crypto_Core_V1_MemCpy(base, desBuffers->key, key, CY_CRYPTO_DES_KEY_BYTE_LENGTH * 3u);
Cy_Crypto_Core_V1_MemCpy(base, desBuffers->key, key, CY_CRYPTO_DES_KEY_BYTE_LENGTH * 3U);
Cy_Crypto_Core_V1_MemCpy(base, desBuffers->block0, src, CY_CRYPTO_DES_KEY_BYTE_LENGTH);
Cy_Crypto_Core_V1_Des_ProcessBlock(base, CY_CRYPTO_DES_MODE_TRIPLE, dirMode,

View File

@ -36,8 +36,8 @@
#if (CPUSS_CRYPTO_DES == 1)
#define CY_CRYPTO_DES_WEAK_KEY_COUNT (16u)
#define CY_CRYPTO_DES_KEY_BYTE_LENGTH (8u)
#define CY_CRYPTO_DES_WEAK_KEY_COUNT (16U)
#define CY_CRYPTO_DES_KEY_BYTE_LENGTH (8U)
typedef enum
{
@ -78,7 +78,7 @@ static uint8_t const cy_desWeakKeys[CY_CRYPTO_DES_WEAK_KEY_COUNT][CY_CRYPTO_DES_
* This function is independent from the previous Crypto state.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -94,7 +94,7 @@ static uint8_t const cy_desWeakKeys[CY_CRYPTO_DES_WEAK_KEY_COUNT][CY_CRYPTO_DES_
* The pointer to a source data block.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Des(CRYPTO_Type *base,
@ -107,9 +107,9 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Des(CRYPTO_Type *base,
cy_en_crypto_status_t status = CY_CRYPTO_SUCCESS;
/* Check weak keys */
for (i = 0u; i < CY_CRYPTO_DES_WEAK_KEY_COUNT; i++)
for (i = 0U; i < CY_CRYPTO_DES_WEAK_KEY_COUNT; i++)
{
if (Cy_Crypto_Core_V2_MemCmp(base, key, (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0u)
if (Cy_Crypto_Core_V2_MemCmp(base, key, (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0U)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
@ -139,7 +139,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Des(CRYPTO_Type *base,
* This function is independent from the previous Crypto state.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dirMode
* Can be \ref CY_CRYPTO_ENCRYPT or \ref CY_CRYPTO_DECRYPT
@ -155,7 +155,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Des(CRYPTO_Type *base,
* The pointer to a source data block.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Tdes(CRYPTO_Type *base,
@ -168,32 +168,20 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Tdes(CRYPTO_Type *base,
cy_en_crypto_status_t status = CY_CRYPTO_SUCCESS;
/* Check weak keys */
for (i = 0u; i < CY_CRYPTO_DES_WEAK_KEY_COUNT; i++)
for (i = 0U; (i < CY_CRYPTO_DES_WEAK_KEY_COUNT) && (CY_CRYPTO_SUCCESS == status); i++)
{
if (Cy_Crypto_Core_V2_MemCmp(base, key, (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0u)
for (uint32_t keynum=0U; (keynum < (CY_CRYPTO_TDES_KEY_SIZE / CY_CRYPTO_DES_KEY_SIZE)) && (CY_CRYPTO_SUCCESS == status); keynum++)
{
if (Cy_Crypto_Core_V2_MemCmp(base, &(key[keynum * CY_CRYPTO_DES_KEY_BYTE_LENGTH]), (uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0U)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
}
if (Cy_Crypto_Core_V2_MemCmp(base, &(key[CY_CRYPTO_DES_KEY_BYTE_LENGTH]),
(uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0u)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
}
if (Cy_Crypto_Core_V2_MemCmp(base, &(key[2u * CY_CRYPTO_DES_KEY_BYTE_LENGTH]),
(uint8_t const *)cy_desWeakKeys[i], CY_CRYPTO_DES_KEY_BYTE_LENGTH) == 0u)
{
status = CY_CRYPTO_DES_WEAK_KEY;
break;
}
}
/* Load keys */
Cy_Crypto_Core_V2_FFContinue(base, CY_CRYPTO_V2_RB_FF_LOAD0, key, CY_CRYPTO_DES_KEY_BYTE_LENGTH * 3u);
Cy_Crypto_Core_V2_BlockMov (base, CY_CRYPTO_V2_RB_KEY0, CY_CRYPTO_V2_RB_FF_LOAD0, CY_CRYPTO_DES_KEY_BYTE_LENGTH * 2u);
Cy_Crypto_Core_V2_FFContinue(base, CY_CRYPTO_V2_RB_FF_LOAD0, key, CY_CRYPTO_DES_KEY_BYTE_LENGTH * 3U);
Cy_Crypto_Core_V2_BlockMov (base, CY_CRYPTO_V2_RB_KEY0, CY_CRYPTO_V2_RB_FF_LOAD0, CY_CRYPTO_DES_KEY_BYTE_LENGTH * 2U);
Cy_Crypto_Core_V2_BlockMov (base, CY_CRYPTO_V2_RB_KEY1, CY_CRYPTO_V2_RB_FF_LOAD0, CY_CRYPTO_DES_KEY_BYTE_LENGTH);
Cy_Crypto_Core_V2_FFContinue(base, CY_CRYPTO_V2_RB_FF_LOAD0, src, CY_CRYPTO_DES_KEY_BYTE_LENGTH);

View File

@ -27,343 +27,332 @@
#include "cy_crypto_core_ecc.h"
#include "cy_syslib.h"
const cy_stc_crypto_ecc_dp_type eccDomainParams[];
/*******************************************************************************
* Function Name: Cy_Crypto_Core_ECC_GetCurveParams
****************************************************************************//**
*
* .
* Get curve domain parameters if this curve is supported.
*
* \param curveID
* See \ref cy_en_crypto_ecc_curve_id_t.
*
* \return status code. See \ref cy_stc_crypto_ecc_dp_type.
* \return
* Pointer to curve domain parameters. See \ref cy_stc_crypto_ecc_dp_type.
*
*******************************************************************************/
cy_stc_crypto_ecc_dp_type *Cy_Crypto_Core_ECC_GetCurveParams(cy_en_crypto_ecc_curve_id_t curveId)
{
cy_stc_crypto_ecc_dp_type *result = NULL;
if ((curveId > CY_CRYPTO_ECC_ECP_NONE) && (curveId < CY_CRYPTO_ECC_ECP_CURVES_CNT))
{
result = (cy_stc_crypto_ecc_dp_type *)&eccDomainParams[curveId];
}
return result;
}
/* P192 CURVE PARAMETERS */
CY_ALIGN(4) const uint8_t eccP192Polynomial[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP192Polynomial[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xfeu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
};
CY_ALIGN(4) const uint8_t eccP192PolyBarrett[CY_CRYPTO_ECC_P192_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP192PolyBarrett[CY_CRYPTO_ECC_P192_BYTE_SIZE + 1u] =
{ /* pre-calculated */
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01
0x01u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u
};
CY_ALIGN(4) const uint8_t eccP192Order[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP192Order[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
{
0x31, 0x28, 0xD2, 0xB4, 0xB1, 0xC9, 0x6B, 0x14,
0x36, 0xF8, 0xDE, 0x99, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
0x31u, 0x28u, 0xD2u, 0xB4u, 0xB1u, 0xC9u, 0x6Bu, 0x14u,
0x36u, 0xF8u, 0xDEu, 0x99u, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu
};
/* barrett_o: "1000000000000000000000000662107c9eb94364e4b2dd7cf" */
CY_ALIGN(4) const uint8_t eccP192OrderBarrett[CY_CRYPTO_ECC_P192_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP192OrderBarrett[CY_CRYPTO_ECC_P192_BYTE_SIZE + 1u] =
{ /* pre-calculated */
0xcf, 0xd7, 0x2d, 0x4b, 0x4e, 0x36, 0x94, 0xeb,
0xc9, 0x07, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01
0xcfu, 0xd7u, 0x2du, 0x4bu, 0x4eu, 0x36u, 0x94u, 0xebu,
0xc9u, 0x07u, 0x21u, 0x66u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u
};
/* base point x: "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012" */
CY_ALIGN(4) const uint8_t eccP192BasePointX[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP192BasePointX[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
{
0x12, 0x10, 0xff, 0x82, 0xfd, 0x0a, 0xff, 0xf4,
0x00, 0x88, 0xa1, 0x43, 0xeb, 0x20, 0xbf, 0x7c,
0xf6, 0x90, 0x30, 0xb0, 0x0e, 0xa8, 0x8d, 0x18
0x12u, 0x10u, 0xffu, 0x82u, 0xfdu, 0x0au, 0xffu, 0xf4u,
0x00u, 0x88u, 0xa1u, 0x43u, 0xebu, 0x20u, 0xbfu, 0x7cu,
0xf6u, 0x90u, 0x30u, 0xb0u, 0x0eu, 0xa8u, 0x8du, 0x18u
};
/* base point y: "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811" */
CY_ALIGN(4) const uint8_t eccP192BasePointY[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP192BasePointY[CY_CRYPTO_ECC_P192_BYTE_SIZE] =
{
0x11, 0x48, 0x79, 0x1e, 0xa1, 0x77, 0xf9, 0x73,
0xd5, 0xcd, 0x24, 0x6b, 0xed, 0x11, 0x10, 0x63,
0x78, 0xda, 0xc8, 0xff, 0x95, 0x2b, 0x19, 0x07
0x11u, 0x48u, 0x79u, 0x1eu, 0xa1u, 0x77u, 0xf9u, 0x73u,
0xd5u, 0xcdu, 0x24u, 0x6bu, 0xedu, 0x11u, 0x10u, 0x63u,
0x78u, 0xdau, 0xc8u, 0xffu, 0x95u, 0x2bu, 0x19u, 0x07u
};
/* P224 CURVE PARAMETERS */
CY_ALIGN(4) const uint8_t eccP224Polynomial[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP224Polynomial[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff
0x01u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu
};
CY_ALIGN(4) const uint8_t eccP224PolyBarrett[CY_CRYPTO_ECC_P224_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP224PolyBarrett[CY_CRYPTO_ECC_P224_BYTE_SIZE + 1u] =
{ /* pre-calculated */
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x01u
};
CY_ALIGN(4) const uint8_t eccP224Order[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP224Order[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
{
0x3D, 0x2A, 0x5C, 0x5C, 0x45, 0x29, 0xDD, 0x13,
0x3E, 0xF0, 0xB8, 0xE0, 0xA2, 0x16, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF
0x3Du, 0x2Au, 0x5Cu, 0x5Cu, 0x45u, 0x29u, 0xDDu, 0x13u,
0x3Eu, 0xF0u, 0xB8u, 0xE0u, 0xA2u, 0x16u, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu
};
/* barrett_o: "10000000000000000000000000000e95d1f470fc1ec22d6baa3a3d5c3" */
CY_ALIGN(4) const uint8_t eccP224OrderBarrett[CY_CRYPTO_ECC_P224_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP224OrderBarrett[CY_CRYPTO_ECC_P224_BYTE_SIZE + 1u] =
{ /* pre-calculated */
0xc3, 0xd5, 0xa3, 0xa3, 0xba, 0xd6, 0x22, 0xec,
0xc1, 0x0f, 0x47, 0x1f, 0x5d, 0xe9, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01
0xc3u, 0xd5u, 0xa3u, 0xa3u, 0xbau, 0xd6u, 0x22u, 0xecu,
0xc1u, 0x0fu, 0x47u, 0x1fu, 0x5du, 0xe9u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x01u
};
/* Gx - base point x: "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21" */
CY_ALIGN(4) const uint8_t eccP224BasePointX[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP224BasePointX[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
{
0x21, 0x1d, 0x5c, 0x11, 0xd6, 0x80, 0x32, 0x34,
0x22, 0x11, 0xc2, 0x56, 0xd3, 0xc1, 0x03, 0x4a,
0xb9, 0x90, 0x13, 0x32, 0x7f, 0xbf, 0xb4, 0x6b,
0xbd, 0x0c, 0x0e, 0xb7
0x21u, 0x1du, 0x5cu, 0x11u, 0xd6u, 0x80u, 0x32u, 0x34u,
0x22u, 0x11u, 0xc2u, 0x56u, 0xd3u, 0xc1u, 0x03u, 0x4au,
0xb9u, 0x90u, 0x13u, 0x32u, 0x7fu, 0xbfu, 0xb4u, 0x6bu,
0xbdu, 0x0cu, 0x0eu, 0xb7u
};
/* Gy - base point y: "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34" */
CY_ALIGN(4) const uint8_t eccP224BasePointY[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP224BasePointY[CY_CRYPTO_ECC_P224_BYTE_SIZE] =
{
0x34, 0x7e, 0x00, 0x85, 0x99, 0x81, 0xd5, 0x44,
0x64, 0x47, 0x07, 0x5a, 0xa0, 0x75, 0x43, 0xcd,
0xe6, 0xdf, 0x22, 0x4c, 0xfb, 0x23, 0xf7, 0xb5,
0x88, 0x63, 0x37, 0xbd
0x34u, 0x7eu, 0x00u, 0x85u, 0x99u, 0x81u, 0xd5u, 0x44u,
0x64u, 0x47u, 0x07u, 0x5au, 0xa0u, 0x75u, 0x43u, 0xcdu,
0xe6u, 0xdfu, 0x22u, 0x4cu, 0xfbu, 0x23u, 0xf7u, 0xb5u,
0x88u, 0x63u, 0x37u, 0xbdu
};
/* P256 CURVE PARAMETERS */
/* prime: "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF" */
CY_ALIGN(4) const uint8_t eccP256Polynomial[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP256Polynomial[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u, 0x00u, 0x00u, 0x00u, 0xffu, 0xffu, 0xffu, 0xffu
};
/* barrett_p: "100000000fffffffffffffffefffffffefffffffeffffffff0000000000000003" */
CY_ALIGN(4) const uint8_t eccP256PolyBarrett[CY_CRYPTO_ECC_P256_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP256PolyBarrett[CY_CRYPTO_ECC_P256_BYTE_SIZE + 1u] =
{ /* pre-calculated! */
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff,
0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x01
0x03u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0xffu, 0xffu, 0xffu, 0xffu, 0xfeu, 0xffu, 0xffu, 0xffu,
0xfeu, 0xffu, 0xffu, 0xffu, 0xfeu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u
};
/* order: "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551" */
CY_ALIGN(4) const uint8_t eccP256Order[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP256Order[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
{
0x51, 0x25, 0x63, 0xfc, 0xc2, 0xca, 0xb9, 0xf3,
0x84, 0x9e, 0x17, 0xa7, 0xad, 0xfa, 0xe6, 0xbc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
0x51u, 0x25u, 0x63u, 0xfcu, 0xc2u, 0xcau, 0xb9u, 0xf3u,
0x84u, 0x9eu, 0x17u, 0xa7u, 0xadu, 0xfau, 0xe6u, 0xbcu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0x00u, 0x00u, 0x00u, 0x00u, 0xffu, 0xffu, 0xffu, 0xffu
};
/* barrett_o: 100000000fffffffffffffffeffffffff43190552df1a6c21012ffd85eedf9bfe" */
CY_ALIGN(4) const uint8_t eccP256OrderBarrett[CY_CRYPTO_ECC_P256_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP256OrderBarrett[CY_CRYPTO_ECC_P256_BYTE_SIZE + 1u] =
{ /* pre-calculated */
0xfe, 0x9b, 0xdf, 0xee, 0x85, 0xfd, 0x2f, 0x01,
0x21, 0x6c, 0x1a, 0xdf, 0x52, 0x05, 0x19, 0x43,
0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x01
0xfeu, 0x9bu, 0xdfu, 0xeeu, 0x85u, 0xfdu, 0x2fu, 0x01u,
0x21u, 0x6cu, 0x1au, 0xdfu, 0x52u, 0x05u, 0x19u, 0x43u,
0xffu, 0xffu, 0xffu, 0xffu, 0xfeu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u
};
/* base point x: "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296" */
CY_ALIGN(4) const uint8_t eccP256BasePointX[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP256BasePointX[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
{
0x96, 0xc2, 0x98, 0xd8, 0x45, 0x39, 0xa1, 0xf4,
0xa0, 0x33, 0xeb, 0x2d, 0x81, 0x7d, 0x03, 0x77,
0xf2, 0x40, 0xa4, 0x63, 0xe5, 0xe6, 0xbc, 0xf8,
0x47, 0x42, 0x2c, 0xe1, 0xf2, 0xd1, 0x17, 0x6b
0x96u, 0xc2u, 0x98u, 0xd8u, 0x45u, 0x39u, 0xa1u, 0xf4u,
0xa0u, 0x33u, 0xebu, 0x2du, 0x81u, 0x7du, 0x03u, 0x77u,
0xf2u, 0x40u, 0xa4u, 0x63u, 0xe5u, 0xe6u, 0xbcu, 0xf8u,
0x47u, 0x42u, 0x2cu, 0xe1u, 0xf2u, 0xd1u, 0x17u, 0x6bu
};
/* base point y: "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5" */
CY_ALIGN(4) const uint8_t eccP256BasePointY[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP256BasePointY[CY_CRYPTO_ECC_P256_BYTE_SIZE] =
{
0xf5, 0x51, 0xbf, 0x37, 0x68, 0x40, 0xb6, 0xcb,
0xce, 0x5e, 0x31, 0x6b, 0x57, 0x33, 0xce, 0x2b,
0x16, 0x9e, 0x0f, 0x7c, 0x4a, 0xeb, 0xe7, 0x8e,
0x9b, 0x7f, 0x1a, 0xfe, 0xe2, 0x42, 0xe3, 0x4f,
0xf5u, 0x51u, 0xbfu, 0x37u, 0x68u, 0x40u, 0xb6u, 0xcbu,
0xceu, 0x5eu, 0x31u, 0x6bu, 0x57u, 0x33u, 0xceu, 0x2bu,
0x16u, 0x9eu, 0x0fu, 0x7cu, 0x4au, 0xebu, 0xe7u, 0x8eu,
0x9bu, 0x7fu, 0x1au, 0xfeu, 0xe2u, 0x42u, 0xe3u, 0x4fu,
};
/* prime: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF" */
CY_ALIGN(4) const uint8_t eccP384Polynomial[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP384Polynomial[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
{
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xffu, 0xffu, 0xffu, 0xffu, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0xffu, 0xffu, 0xffu, 0xffu,
0xfeu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu
};
/* barrett_p: "1000000000000000000000000000000000000000000000000000000000000000100000000ffffffffffffffff00000001" */
CY_ALIGN(4) const uint8_t eccP384PolyBarrett[CY_CRYPTO_ECC_P384_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP384PolyBarrett[CY_CRYPTO_ECC_P384_BYTE_SIZE + 1u] =
{ /* pre-calculated */
0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01
0x01u, 0x00u, 0x00u, 0x00u, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u
};
/* order: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973" */
CY_ALIGN(4) const uint8_t eccP384Order[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP384Order[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
{
0x73, 0x29, 0xC5, 0xCC, 0x6A, 0x19, 0xEC, 0xEC,
0x7A, 0xA7, 0xB0, 0x48, 0xB2, 0x0D, 0x1A, 0x58,
0xDF, 0x2D, 0x37, 0xF4, 0x81, 0x4D, 0x63, 0xC7,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
0x73u, 0x29u, 0xC5u, 0xCCu, 0x6Au, 0x19u, 0xECu, 0xECu,
0x7Au, 0xA7u, 0xB0u, 0x48u, 0xB2u, 0x0Du, 0x1Au, 0x58u,
0xDFu, 0x2Du, 0x37u, 0xF4u, 0x81u, 0x4Du, 0x63u, 0xC7u,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu
};
/* barrett_o: "1000000000000000000000000000000000000000000000000389cb27e0bc8d220a7e5f24db74f58851313e695333ad68d" */
CY_ALIGN(4) const uint8_t eccP384OrderBarrett[CY_CRYPTO_ECC_P384_BYTE_SIZE + 1u] =
CY_ALIGN(4) static const uint8_t eccP384OrderBarrett[CY_CRYPTO_ECC_P384_BYTE_SIZE + 1u] =
{ /* pre-calculated */
0x8d, 0xd6, 0x3a, 0x33, 0x95, 0xe6, 0x13, 0x13,
0x85, 0x58, 0x4f, 0xb7, 0x4d, 0xf2, 0xe5, 0xa7,
0x20, 0xd2, 0xc8, 0x0b, 0x7e, 0xb2, 0x9c, 0x38,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01
0x8du, 0xd6u, 0x3au, 0x33u, 0x95u, 0xe6u, 0x13u, 0x13u,
0x85u, 0x58u, 0x4fu, 0xb7u, 0x4du, 0xf2u, 0xe5u, 0xa7u,
0x20u, 0xd2u, 0xc8u, 0x0bu, 0x7eu, 0xb2u, 0x9cu, 0x38u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x01u
};
/* base point x: "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7" */
CY_ALIGN(4) const uint8_t eccP384BasePointX[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP384BasePointX[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
{
0xb7, 0x0a, 0x76, 0x72, 0x38, 0x5e, 0x54, 0x3a,
0x6c, 0x29, 0x55, 0xbf, 0x5d, 0xf2, 0x02, 0x55,
0x38, 0x2a, 0x54, 0x82, 0xe0, 0x41, 0xf7, 0x59,
0x98, 0x9b, 0xa7, 0x8b, 0x62, 0x3b, 0x1d, 0x6e,
0x74, 0xad, 0x20, 0xf3, 0x1e, 0xc7, 0xb1, 0x8e,
0x37, 0x05, 0x8b, 0xbe, 0x22, 0xca, 0x87, 0xaa
0xb7u, 0x0au, 0x76u, 0x72u, 0x38u, 0x5eu, 0x54u, 0x3au,
0x6cu, 0x29u, 0x55u, 0xbfu, 0x5du, 0xf2u, 0x02u, 0x55u,
0x38u, 0x2au, 0x54u, 0x82u, 0xe0u, 0x41u, 0xf7u, 0x59u,
0x98u, 0x9bu, 0xa7u, 0x8bu, 0x62u, 0x3bu, 0x1du, 0x6eu,
0x74u, 0xadu, 0x20u, 0xf3u, 0x1eu, 0xc7u, 0xb1u, 0x8eu,
0x37u, 0x05u, 0x8bu, 0xbeu, 0x22u, 0xcau, 0x87u, 0xaau
};
/* base point y: "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F" */
CY_ALIGN(4) const uint8_t eccP384BasePointY[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP384BasePointY[CY_CRYPTO_ECC_P384_BYTE_SIZE] =
{
0x5f, 0x0e, 0xea, 0x90, 0x7c, 0x1d, 0x43, 0x7a,
0x9d, 0x81, 0x7e, 0x1d, 0xce, 0xb1, 0x60, 0x0a,
0xc0, 0xb8, 0xf0, 0xb5, 0x13, 0x31, 0xda, 0xe9,
0x7c, 0x14, 0x9a, 0x28, 0xbd, 0x1d, 0xf4, 0xf8,
0x29, 0xdc, 0x92, 0x92, 0xbf, 0x98, 0x9e, 0x5d,
0x6f, 0x2c, 0x26, 0x96, 0x4a, 0xde, 0x17, 0x36
0x5fu, 0x0eu, 0xeau, 0x90u, 0x7cu, 0x1du, 0x43u, 0x7au,
0x9du, 0x81u, 0x7eu, 0x1du, 0xceu, 0xb1u, 0x60u, 0x0au,
0xc0u, 0xb8u, 0xf0u, 0xb5u, 0x13u, 0x31u, 0xdau, 0xe9u,
0x7cu, 0x14u, 0x9au, 0x28u, 0xbdu, 0x1du, 0xf4u, 0xf8u,
0x29u, 0xdcu, 0x92u, 0x92u, 0xbfu, 0x98u, 0x9eu, 0x5du,
0x6fu, 0x2cu, 0x26u, 0x96u, 0x4au, 0xdeu, 0x17u, 0x36u
};
CY_ALIGN(4) const uint8_t eccP521Polynomial[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP521Polynomial[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x01
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0x01u
};
CY_ALIGN(4) const uint8_t eccP521PolyBarrett[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP521PolyBarrett[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
{ /* pre-calculated */
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02
0x01u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x02u
};
CY_ALIGN(4) const uint8_t eccP521Order[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP521Order[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
{
0x09, 0x64, 0x38, 0x91, 0x1E, 0xB7, 0x6F, 0xBB,
0xAE, 0x47, 0x9C, 0x89, 0xB8, 0xC9, 0xB5, 0x3B,
0xD0, 0xA5, 0x09, 0xF7, 0x48, 0x01, 0xCC, 0x7F,
0x6B, 0x96, 0x2F, 0xBF, 0x83, 0x87, 0x86, 0x51,
0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x01
0x09u, 0x64u, 0x38u, 0x91u, 0x1Eu, 0xB7u, 0x6Fu, 0xBBu,
0xAEu, 0x47u, 0x9Cu, 0x89u, 0xB8u, 0xC9u, 0xB5u, 0x3Bu,
0xD0u, 0xA5u, 0x09u, 0xF7u, 0x48u, 0x01u, 0xCCu, 0x7Fu,
0x6Bu, 0x96u, 0x2Fu, 0xBFu, 0x83u, 0x87u, 0x86u, 0x51u,
0xFAu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu, 0xffu,
0xffu, 0x01u
};
/* barrett_o: "2000000000000000000000000000000000000000000000000000000000000000005ae79787c40d069948033feb708f65a2fc44a36477663b851449048e16ec79bf7" */
CY_ALIGN(4) const uint8_t eccP521OrderBarrett[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP521OrderBarrett[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
{ /* pre-calculated */
0xf7, 0x9b, 0xc7, 0x6e, 0xe1, 0x48, 0x90, 0x44,
0x51, 0xb8, 0x63, 0x76, 0x47, 0x36, 0x4a, 0xc4,
0x2f, 0x5a, 0xf6, 0x08, 0xb7, 0xfe, 0x33, 0x80,
0x94, 0x69, 0xd0, 0x40, 0x7c, 0x78, 0x79, 0xae,
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02
0xf7u, 0x9bu, 0xc7u, 0x6eu, 0xe1u, 0x48u, 0x90u, 0x44u,
0x51u, 0xb8u, 0x63u, 0x76u, 0x47u, 0x36u, 0x4au, 0xc4u,
0x2fu, 0x5au, 0xf6u, 0x08u, 0xb7u, 0xfeu, 0x33u, 0x80u,
0x94u, 0x69u, 0xd0u, 0x40u, 0x7cu, 0x78u, 0x79u, 0xaeu,
0x05u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u,
0x00u, 0x02u
};
/* base point x: "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66" */
CY_ALIGN(4) const uint8_t eccP521BasePointX[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP521BasePointX[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
{
0x66, 0xbd, 0xe5, 0xc2, 0x31, 0x7e, 0x7e, 0xf9,
0x9b, 0x42, 0x6a, 0x85, 0xc1, 0xb3, 0x48, 0x33,
0xde, 0xa8, 0xff, 0xa2, 0x27, 0xc1, 0x1d, 0xfe,
0x28, 0x59, 0xe7, 0xef, 0x77, 0x5e, 0x4b, 0xa1,
0xba, 0x3d, 0x4d, 0x6b, 0x60, 0xaf, 0x28, 0xf8,
0x21, 0xb5, 0x3f, 0x05, 0x39, 0x81, 0x64, 0x9c,
0x42, 0xb4, 0x95, 0x23, 0x66, 0xcb, 0x3e, 0x9e,
0xcd, 0xe9, 0x04, 0x04, 0xb7, 0x06, 0x8e, 0x85,
0xc6, 0x00
0x66u, 0xbdu, 0xe5u, 0xc2u, 0x31u, 0x7eu, 0x7eu, 0xf9u,
0x9bu, 0x42u, 0x6au, 0x85u, 0xc1u, 0xb3u, 0x48u, 0x33u,
0xdeu, 0xa8u, 0xffu, 0xa2u, 0x27u, 0xc1u, 0x1du, 0xfeu,
0x28u, 0x59u, 0xe7u, 0xefu, 0x77u, 0x5eu, 0x4bu, 0xa1u,
0xbau, 0x3du, 0x4du, 0x6bu, 0x60u, 0xafu, 0x28u, 0xf8u,
0x21u, 0xb5u, 0x3fu, 0x05u, 0x39u, 0x81u, 0x64u, 0x9cu,
0x42u, 0xb4u, 0x95u, 0x23u, 0x66u, 0xcbu, 0x3eu, 0x9eu,
0xcdu, 0xe9u, 0x04u, 0x04u, 0xb7u, 0x06u, 0x8eu, 0x85u,
0xc6u, 0x00u
};
/* base point y: "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650" */
CY_ALIGN(4) const uint8_t eccP521BasePointY[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
CY_ALIGN(4) static const uint8_t eccP521BasePointY[CY_CRYPTO_ECC_P521_BYTE_SIZE] =
{
0x50, 0x66, 0xd1, 0x9f, 0x76, 0x94, 0xbe, 0x88,
0x40, 0xc2, 0x72, 0xa2, 0x86, 0x70, 0x3c, 0x35,
0x61, 0x07, 0xad, 0x3f, 0x01, 0xb9, 0x50, 0xc5,
0x40, 0x26, 0xf4, 0x5e, 0x99, 0x72, 0xee, 0x97,
0x2c, 0x66, 0x3e, 0x27, 0x17, 0xbd, 0xaf, 0x17,
0x68, 0x44, 0x9b, 0x57, 0x49, 0x44, 0xf5, 0x98,
0xd9, 0x1b, 0x7d, 0x2c, 0xb4, 0x5f, 0x8a, 0x5c,
0x04, 0xc0, 0x3b, 0x9a, 0x78, 0x6a, 0x29, 0x39,
0x18, 0x01
0x50u, 0x66u, 0xd1u, 0x9fu, 0x76u, 0x94u, 0xbeu, 0x88u,
0x40u, 0xc2u, 0x72u, 0xa2u, 0x86u, 0x70u, 0x3cu, 0x35u,
0x61u, 0x07u, 0xadu, 0x3fu, 0x01u, 0xb9u, 0x50u, 0xc5u,
0x40u, 0x26u, 0xf4u, 0x5eu, 0x99u, 0x72u, 0xeeu, 0x97u,
0x2cu, 0x66u, 0x3eu, 0x27u, 0x17u, 0xbdu, 0xafu, 0x17u,
0x68u, 0x44u, 0x9bu, 0x57u, 0x49u, 0x44u, 0xf5u, 0x98u,
0xd9u, 0x1bu, 0x7du, 0x2cu, 0xb4u, 0x5fu, 0x8au, 0x5cu,
0x04u, 0xc0u, 0x3bu, 0x9au, 0x78u, 0x6au, 0x29u, 0x39u,
0x18u, 0x01u
};
const cy_stc_crypto_ecc_dp_type eccDomainParams[] =
static const cy_stc_crypto_ecc_dp_type eccDomainParams[] =
{
{
CY_CRYPTO_ECC_ECP_NONE,
0,
0u,
NULL,
CY_CRYPTO_NIST_P_CURVE_SPECIFIC_RED_ALG,
NULL,
@ -467,5 +456,15 @@ const cy_stc_crypto_ecc_dp_type eccDomainParams[] =
}
};
cy_stc_crypto_ecc_dp_type *tmpResult = NULL;
if ((curveId > CY_CRYPTO_ECC_ECP_NONE) && (curveId < CY_CRYPTO_ECC_ECP_CURVES_CNT))
{
tmpResult = (cy_stc_crypto_ecc_dp_type *)&eccDomainParams[curveId];
}
return tmpResult;
}
/* [] END OF FILE */

View File

@ -31,16 +31,6 @@
#include <stdbool.h>
#define ECC_ECDSA_DEBUG 0
#if ECC_ECDSA_DEBUG
#include "cy_crypto_core_my_support.h"
#ifndef Tb_PrintStr
#include <stdio.h>
#define Tb_PrintStr(s) printf("%s\n", s)
#endif
#endif
/*******************************************************************************
* Function Name: Cy_Crypto_Core_ECC_SignHash
@ -70,22 +60,22 @@
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8_t *hash, uint32_t hashlen, uint8_t *sig,
cy_stc_crypto_ecc_key *key, uint8_t *messageKey)
const cy_stc_crypto_ecc_key *key, const uint8_t *messageKey)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
cy_stc_crypto_ecc_key ephKey;
uint8_t myKGX[CY_CRYPTO_ECC_MAX_BYTE_SIZE];
uint8_t myKGY[CY_CRYPTO_ECC_MAX_BYTE_SIZE];
const cy_stc_crypto_ecc_dp_type *eccDp;
uint32_t mallocMask = 0;
uint32_t mallocMask = 0U;
uint32_t bitsize;
/* NULL parameters checking */
if ((hash != NULL) && (sig != NULL) && (key != NULL) && (messageKey != NULL))
{
myResult = CY_CRYPTO_NOT_SUPPORTED;
tmpResult = CY_CRYPTO_NOT_SUPPORTED;
eccDp = Cy_Crypto_Core_ECC_GetCurveParams(key->curveID);
@ -93,44 +83,27 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
{
bitsize = eccDp->size;
#if ECC_ECDSA_DEBUG
Tb_PrintStr("\necc_sign_hash() for ");
Tb_PrintStr(eccDp->name);
Tb_PrintStr("\n");
#endif /* ECC_ECDSA_DEBUG */
/* make ephemeral key pair */
ephKey.pubkey.x = myKGX;
ephKey.pubkey.y = myKGY;
myResult = Cy_Crypto_Core_ECC_MakePublicKey(base, key->curveID, messageKey, &ephKey);
tmpResult = Cy_Crypto_Core_ECC_MakePublicKey(base, key->curveID, messageKey, &ephKey);
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = CY_CRYPTO_BAD_PARAMS;
tmpResult = CY_CRYPTO_BAD_PARAMS;
int dividend = 0; /* for whatever reason Crypto_EC_DivMod only works if dividend is in register 0 */
int p_temp = 8;
int p_r = 9;
int p_s = 10;
int p_d = 11;
#if ECC_ECDSA_DEBUG
Tb_PrintStr("%10s: \t", "hash");
Crypto_PrintNumber((uint8_t *)hash, hashlen);
Tb_PrintStr("%10s: \t", "k");
Crypto_PrintNumber(messageKey, CY_CRYPTO_BYTE_SIZE_OF_BITS(bitsize));
Tb_PrintStr("%10s: \t", "x1");
Crypto_PrintNumber((uint8_t *)ephKey.pubkey.x, CY_CRYPTO_BYTE_SIZE_OF_BITS(bitsize));
#endif /* ECC_ECDSA_DEBUG */
uint32_t dividend = 0U; /* for whatever reason Crypto_EC_DivMod only works if dividend is in register 0 */
uint32_t p_temp = 8U;
uint32_t p_r = 9U;
uint32_t p_s = 10U;
uint32_t p_d = 11U;
/* load values needed for reduction modulo order of the base point */
CY_CRYPTO_VU_ALLOC_MEM (base, VR_P, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_P, (uint8_t *)eccDp->order, bitsize);
CY_CRYPTO_VU_ALLOC_MEM (base, VR_BARRETT, bitsize + 1);
CY_CRYPTO_VU_ALLOC_MEM (base, VR_BARRETT, bitsize + 1U);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, (uint8_t *)eccDp->barrett_o, bitsize);
CY_CRYPTO_VU_ALLOC_MEM (base, p_r, bitsize);
@ -140,7 +113,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
if (!Cy_Crypto_Core_Vu_IsRegZero(base, p_r))
{
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
CY_CRYPTO_VU_ALLOC_MEM (base, p_d, bitsize);
CY_CRYPTO_VU_ALLOC_MEM (base, p_s, bitsize);
@ -162,15 +135,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
/* r = x1 mod n */
Cy_Crypto_Core_Vu_GetMemValue (base, sig, p_r, bitsize);
#if ECC_ECDSA_DEBUG
Tb_PrintStr("x1 after reduction modulo order: ");
Crypto_RegMemNumberPrint(p_r);
#endif /* ECC_ECDSA_DEBUG */
if (Cy_Crypto_Core_Vu_IsRegZero(base, p_r))
{
/* R is zero!!! */
myResult = CY_CRYPTO_HW_ERROR;
tmpResult = CY_CRYPTO_HW_ERROR;
}
}
else
@ -180,14 +148,14 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
Cy_Crypto_Core_MemCpy(base, sig, ephKey.pubkey.x, (uint16_t)CY_CRYPTO_BYTE_SIZE_OF_BITS(bitsize));
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* find s = (e + d*r)/k */
/* load signing private key */
Cy_Crypto_Core_Vu_SetMemValue (base, p_d, (uint8_t *)key->k, bitsize);
/* use barrett reduction algorithm for operations modulo n (order of the base point) */
/* use Barrett reduction algorithm for operations modulo n (order of the base point) */
Cy_Crypto_Core_EC_NistP_SetRedAlg(CY_CRYPTO_NIST_P_BARRETT_RED_ALG);
/* d*r mod n */
@ -202,7 +170,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
}
else
{
Cy_Crypto_Core_Vu_SetMemValue (base, p_d, (uint8_t *)hash, hashlen * 8);
Cy_Crypto_Core_Vu_SetMemValue (base, p_d, (uint8_t *)hash, hashlen * 8U);
}
Cy_Crypto_Core_Vu_SetMemValue (base, p_r, messageKey, bitsize);
@ -226,14 +194,8 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
}
else
{
myResult = CY_CRYPTO_HW_ERROR;
tmpResult = CY_CRYPTO_HW_ERROR;
}
#if ECC_ECDSA_DEBUG
Crypto_PrintRegister(p_r, "k");
Crypto_PrintRegister(p_s, "(e+d*r)/k");
#endif /* ECC_ECDSA_DEBUG */
}
}
@ -243,7 +205,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
}
}
return (myResult);
return (tmpResult);
}
@ -276,47 +238,40 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base, const uint8
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
const uint8_t *sig, const uint8_t *hash, uint32_t hashlen,
uint8_t *stat, cy_stc_crypto_ecc_key *key)
uint8_t *stat, const cy_stc_crypto_ecc_key *key)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
const cy_stc_crypto_ecc_dp_type *eccDp;
uint32_t bitsize;
uint32_t mallocMask = 0;
uint32_t mallocMask = 0U;
/* NULL parameters checking */
if ((sig != NULL) && (hash != NULL) && (stat != NULL) && (key != NULL))
{
myResult = CY_CRYPTO_NOT_SUPPORTED;
tmpResult = CY_CRYPTO_NOT_SUPPORTED;
eccDp = Cy_Crypto_Core_ECC_GetCurveParams(key->curveID);
if (eccDp != NULL)
{
#if ECC_ECDSA_DEBUG
Tb_PrintStr("\necc_verify_hash() for ");
Tb_PrintStr((char *)eccDp->name);
Tb_PrintStr("\n");
#endif /* ECC_ECDSA_DEBUG */
bitsize = eccDp->size;
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
int dividend = 0; /* for whatever reason Crypto_EC_DivMod only works if dividend is in register 0 */
int p_r = 4;
int p_s = 5;
int p_u1 = 6;
int p_u2 = 7;
int p_o = 8;
int p_gx = 9;
int p_gy = 10;
int p_qx = 11;
int p_qy = 12;
uint32_t dividend = 0u; /* for whatever reason Crypto_EC_DivMod only works if dividend is in register 0 */
uint32_t p_r = 4U;
uint32_t p_s = 5U;
uint32_t p_u1 = 6U;
uint32_t p_u2 = 7U;
uint32_t p_o = 8U;
uint32_t p_gx = 9U;
uint32_t p_gy = 10U;
uint32_t p_qx = 11U;
uint32_t p_qy = 12U;
/* use barrett reduction algorithm for operations modulo n (order of the base point) */
/* use Barrett reduction algorithm for operations modulo n (order of the base point) */
Cy_Crypto_Core_EC_NistP_SetRedAlg(CY_CRYPTO_NIST_P_BARRETT_RED_ALG);
Cy_Crypto_Core_EC_NistP_SetMode(bitsize);
@ -325,8 +280,8 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
CY_CRYPTO_VU_ALLOC_MEM (base, VR_P, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_P, (uint8_t *)eccDp->order, bitsize);
CY_CRYPTO_VU_ALLOC_MEM (base, VR_BARRETT, bitsize + 1);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, (uint8_t *)eccDp->barrett_o, bitsize + 1);
CY_CRYPTO_VU_ALLOC_MEM (base, VR_BARRETT, bitsize + 1U);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, (uint8_t *)eccDp->barrett_o, bitsize + 1U);
/*******************************************************************************/
/* check that R and S are within the valid range, i.e. 0 < R < n and 0 < S < n */
@ -342,25 +297,25 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
if (Cy_Crypto_Core_Vu_IsRegZero(base, p_r))
{
/* R is zero!!! */
myResult = CY_CRYPTO_BAD_PARAMS;
tmpResult = CY_CRYPTO_BAD_PARAMS;
}
if (!Cy_Crypto_Core_Vu_IsRegLess(base, p_r, VR_P))
{
/* R is not less than n!!! */
myResult = CY_CRYPTO_BAD_PARAMS;
tmpResult = CY_CRYPTO_BAD_PARAMS;
}
if (Cy_Crypto_Core_Vu_IsRegZero(base, p_s))
{
/* S is zero!!! */
myResult = CY_CRYPTO_BAD_PARAMS;
tmpResult = CY_CRYPTO_BAD_PARAMS;
}
if (!Cy_Crypto_Core_Vu_IsRegLess(base, p_s, VR_P))
{
/* S is not less than n!!! */
myResult = CY_CRYPTO_BAD_PARAMS;
tmpResult = CY_CRYPTO_BAD_PARAMS;
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
CY_CRYPTO_VU_ALLOC_MEM (base, dividend, bitsize);
CY_CRYPTO_VU_ALLOC_MEM (base, p_o, bitsize);
@ -386,41 +341,25 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
}
else
{
Cy_Crypto_Core_Vu_SetMemValue (base, p_u1, (uint8_t *)hash, hashlen * 8);
Cy_Crypto_Core_Vu_SetMemValue (base, p_u1, (uint8_t *)hash, hashlen * 8U);
}
#if ECC_ECDSA_DEBUG
Crypto_PrintRegister(p_u1, "hash");
Crypto_PrintRegister(p_r, "R");
Crypto_PrintRegister(p_s, "S");
Tb_PrintStr("\n");
#endif /* ECC_ECDSA_DEBUG */
/* w = s^-1 mod n */
CY_CRYPTO_VU_SET_TO_ONE(base, dividend);
Cy_Crypto_Core_EC_DivMod(base, p_s, dividend, p_s, bitsize);
#if ECC_ECDSA_DEBUG
Crypto_PrintRegister(p_s, "w");
#endif /* ECC_ECDSA_DEBUG */
/* u1 = e*w mod n */
Cy_Crypto_Core_EC_MulMod(base, p_u1, p_u1, p_s, bitsize);
/* u2 = r*w mod n */
Cy_Crypto_Core_EC_MulMod(base, p_u2, p_r, p_s, bitsize);
#if ECC_ECDSA_DEBUG
Crypto_PrintRegister(p_u1, "u1");
Crypto_PrintRegister(p_u2, "u2");
#endif /* ECC_ECDSA_DEBUG */
/* Initialize point multiplication */
Cy_Crypto_Core_EC_NistP_SetRedAlg(eccDp->algo);
/* load prime, order and barrett coefficient */
/* load prime, order and Barrett coefficient */
Cy_Crypto_Core_Vu_SetMemValue (base, VR_P, (uint8_t *)eccDp->prime, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, p_o, (uint8_t *)eccDp->order, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, (uint8_t *)eccDp->barrett_p, bitsize + 1);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, (uint8_t *)eccDp->barrett_p, bitsize + 1U);
/* load base Point G */
Cy_Crypto_Core_Vu_SetMemValue (base, p_gx, (uint8_t *)eccDp->Gx, bitsize);
@ -439,40 +378,22 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
/* u2 * Qa */
Cy_Crypto_Core_EC_NistP_PointMul(base, p_qx, p_qy, p_u2, p_o, bitsize);
#if ECC_ECDSA_DEBUG
Tb_PrintStr("u1 * G: \n");
Crypto_PrintRegister(p_gx, " u1*G(x)");
Crypto_PrintRegister(p_gy, " u1*G(y)");
Tb_PrintStr("u2 * Q: \n");
Crypto_PrintRegister(p_qx, " u2*Q(x)");
Crypto_PrintRegister(p_qy, " u2*Q(x)");
#endif /* ECC_ECDSA_DEBUG */
/* P = u1 * G + u2 * Qa. Only Px is needed */
Cy_Crypto_Core_EC_SubMod(base, dividend, p_qy, p_gy); /* (y2-y1) */
Cy_Crypto_Core_EC_SubMod(base, p_s, p_qx, p_gx); /* (x2-x1) */
Cy_Crypto_Core_EC_DivMod(base, p_s, dividend, p_s, bitsize); /* s = (y2-y1)/(x2-x1) */
#if ECC_ECDSA_DEBUG
Tb_PrintStr("Point addition: \n");
Crypto_PrintRegister(p_s, "s");
#endif /* ECC_ECDSA_DEBUG */
Cy_Crypto_Core_EC_SquareMod (base, p_s, p_s, bitsize); /* s^2 */
Cy_Crypto_Core_EC_SubMod (base, p_s, p_s, p_gx); /* s^2 - x1 */
Cy_Crypto_Core_EC_SubMod (base, p_s, p_s, p_qx); /* s^2 - x1 - x2 which is Px mod n */
#if ECC_ECDSA_DEBUG
Crypto_PrintRegister(p_s, "px");
#endif /* ECC_ECDSA_DEBUG */
if (Cy_Crypto_Core_Vu_IsRegEqual(base, p_s, p_r))
{
*stat = 1;
*stat = 1u;
}
else
{
*stat = 0;
*stat = 0u;
}
}
@ -481,7 +402,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
}
}
return (myResult);
return (tmpResult);
}

View File

@ -29,11 +29,8 @@
#include "cy_crypto_core_vu.h"
#include "cy_crypto_core_trng.h"
#define CY_ECC_CONFIG_TR_GARO_CTL 0x6C740B8Du
#define CY_ECC_CONFIG_TR_FIRO_CTL 0x52D246E1u
/* print some debug information. enabling this will render meaningless all time measurements */
#define ECC_KEY_GEN_DEBUG 0
#define CY_ECC_CONFIG_TR_GARO_CTL 0x6C740B8DuL
#define CY_ECC_CONFIG_TR_FIRO_CTL 0x52D246E1uL
/*******************************************************************************
@ -65,45 +62,38 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakeKeyPair(CRYPTO_Type *base,
cy_func_get_random_data_t GetRandomDataFunc,
void *randomDataInfo)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
cy_stc_crypto_ecc_dp_type *eccDp = Cy_Crypto_Core_ECC_GetCurveParams(curveID);
if (eccDp == NULL || key == NULL)
if ((eccDp != NULL) && (key != NULL))
{
/* NULL parameter detected in Cy_Crypto_Core_ECC_MakeKeyPair()!!! */
return CY_CRYPTO_NOT_SUPPORTED;
}
tmpResult = CY_CRYPTO_SUCCESS;
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("\necc_make_key() for ");
Tb_PrintStr((int8_t *)eccDp->name);
Tb_PrintStr("\n");
#endif /* ECC_KEY_GEN_DEBUG */
int bitsize = eccDp->size;
uint32_t bitsize = eccDp->size;
/* used VU registers. Same values as in crypto_NIST_P.c */
int p_temp = 8; /* temporal values */
int p_order = 9; /* order of the curve */
int p_d = 10; /* private key */
int p_x = 11; /* x coordinate */
int p_y = 12; /* y coordinate */
uint32_t p_temp = 8u; /* temporal values */
uint32_t p_order = 9u; /* order of the curve */
uint32_t p_d = 10u; /* private key */
uint32_t p_x = 11u; /* x coordinate */
uint32_t p_y = 12u; /* y coordinate */
CY_CRYPTO_VU_ALLOC_MEM(base, VR_P, bitsize);
CY_CRYPTO_VU_ALLOC_MEM(base, p_order, bitsize);
CY_CRYPTO_VU_ALLOC_MEM(base, VR_BARRETT, bitsize + 1);
CY_CRYPTO_VU_ALLOC_MEM(base, VR_BARRETT, bitsize + 1U);
CY_CRYPTO_VU_ALLOC_MEM(base, p_x, bitsize);
CY_CRYPTO_VU_ALLOC_MEM(base, p_y, bitsize);
/***************************************************************
* Apply domain parameters
***************************************************************/
/* load prime and order defining the curve as well as the barrett coefficient. */
/* load prime and order defining the curve as well as the Barrett coefficient. */
/* P and BARRETT_U are "globally" defined in cy_crypto_core_ecc.h */
Cy_Crypto_Core_Vu_SetMemValue (base, VR_P, eccDp->prime, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, p_order, eccDp->order, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, eccDp->barrett_p, bitsize + 1);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, eccDp->barrett_p, bitsize + 1U);
/* Base Point, G = (p_x, p_y) */
Cy_Crypto_Core_Vu_SetMemValue (base, p_x, eccDp->Gx, bitsize);
@ -112,49 +102,48 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakeKeyPair(CRYPTO_Type *base,
Cy_Crypto_Core_EC_NistP_SetMode(bitsize);
Cy_Crypto_Core_EC_NistP_SetRedAlg(eccDp->algo);
/***************************************************************
* generate random string
***************************************************************/
if (GetRandomDataFunc != NULL)
{
GetRandomDataFunc( randomDataInfo, key->k, (bitsize + 7u) >> 3u );
(void)GetRandomDataFunc( randomDataInfo, (uint8_t*)key->k, ((bitsize + 7U) >> 3U) );
}
else
{
for (int i = 0, randomsize = bitsize; randomsize > 0; randomsize-=32, i++)
{
int randombits = CY_CRYPTO_MIN(randomsize, 32);
uint32_t i = 0U;
int32_t randomsize = (int32_t)bitsize;
cy_en_crypto_status_t status = CY_CRYPTO_SUCCESS;
cy_en_crypto_status_t error = Cy_Crypto_Core_Trng(base, CY_ECC_CONFIG_TR_GARO_CTL, CY_ECC_CONFIG_TR_FIRO_CTL,
while ((randomsize > 0) && (CY_CRYPTO_SUCCESS == status))
{
uint32_t randombits = (uint32_t)CY_CRYPTO_MIN(randomsize, 32);
status = Cy_Crypto_Core_Trng(base, CY_ECC_CONFIG_TR_GARO_CTL, CY_ECC_CONFIG_TR_FIRO_CTL,
randombits, &((uint32_t *)key->k)[i]);
randomsize -= 32;
i++;
if (CY_CRYPTO_SUCCESS != error)
if (CY_CRYPTO_SUCCESS != status)
{
return CY_CRYPTO_HW_ERROR;
tmpResult = CY_CRYPTO_HW_ERROR;
}
}
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/***************************************************************
* Load random data into VU
***************************************************************/
CY_CRYPTO_VU_ALLOC_MEM(base, p_d, bitsize);
Cy_Crypto_Core_Vu_SetMemValue(base, p_d, (uint8_t *)key->k, bitsize);
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("random data: ");
Crypto_RegMemNumberPrint(p_d);
Tb_PrintStr("p_order: ");
Crypto_RegMemNumberPrint(p_order);
#endif /*ECC_KEY_GEN_DEBUG */
/* check that the key is smaller than the order of base point */
CY_CRYPTO_VU_CMP_SUB (base, p_d, p_order); /* C = (a >= b) */
uint16_t status = Cy_Crypto_Core_Vu_StatusRead(base);
uint32_t status = Cy_Crypto_Core_Vu_StatusRead(base);
if (status & CY_CRYPTO_VU_STATUS_CARRY_BIT)
if (0u != (status & CY_CRYPTO_VU_STATUS_CARRY_BIT))
{
/* random data >= order, needs reduction */
@ -177,27 +166,14 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakeKeyPair(CRYPTO_Type *base,
Cy_Crypto_Core_Vu_GetMemValue(base, (uint8_t *)key->k, p_d, bitsize);
/* restore previous prime and barrett values */
/* restore previous prime and Barrett values */
CY_CRYPTO_VU_POP_REG(base);
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("random data after reduction modulo order: ");
Crypto_RegMemNumberPrint(p_d);
#endif /* ECC_KEY_GEN_DEBUG */
}
else
{
/* carry is clear, i. e. p_d < p_order */
}
/* make the public key
/*
* Make the public key
* EC scalar multiplication - X,Y-only co-Z arithmetic
*/
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("Doing scalar multiplication\n");
#endif /* ECC_KEY_GEN_DEBUG */
Cy_Crypto_Core_EC_NistP_PointMul(base, p_x, p_y, p_d, p_order, bitsize);
Cy_Crypto_Core_Vu_GetMemValue(base, (uint8_t *)key->pubkey.x, p_x, bitsize);
@ -206,11 +182,15 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakeKeyPair(CRYPTO_Type *base,
key->type = PK_PRIVATE;
key->curveID = curveID;
tmpResult = CY_CRYPTO_SUCCESS;
}
CY_CRYPTO_VU_FREE_MEM(base, CY_CRYPTO_VU_REG_BIT(VR_P) | CY_CRYPTO_VU_REG_BIT(VR_BARRETT) |
CY_CRYPTO_VU_REG_BIT(p_x) | CY_CRYPTO_VU_REG_BIT(p_y) |
CY_CRYPTO_VU_REG_BIT(p_order) | CY_CRYPTO_VU_REG_BIT(p_d));
}
return CY_CRYPTO_SUCCESS;
return (tmpResult);
}
@ -242,58 +222,54 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePrivateKey(CRYPTO_Type *base,
uint8_t *key,
cy_func_get_random_data_t GetRandomDataFunc, void *randomDataInfo)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
const cy_stc_crypto_ecc_dp_type *eccDp = Cy_Crypto_Core_ECC_GetCurveParams(curveID);
if (eccDp == NULL || key == NULL)
if ((eccDp != NULL) && (key != NULL))
{
/* NULL parameter detected in Cy_Crypto_Core_ECC_MakeKey()!!! */
return CY_CRYPTO_NOT_SUPPORTED;
}
tmpResult = CY_CRYPTO_SUCCESS;
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("\necc_make_key() for ");
Tb_PrintStr((int8_t *)eccDp->name);
Tb_PrintStr("\n");
#endif /* ECC_KEY_GEN_DEBUG */
uint32_t bitsize = eccDp->size;
int bitsize = eccDp->size;
int p_temp = 8; /* temporal values */
int p_d = 10; /* private key */
uint32_t p_temp = 8u; /* temporal values */
uint32_t p_d = 10u; /* private key */
/* generate random string */
if (GetRandomDataFunc != NULL)
{
GetRandomDataFunc( randomDataInfo, key, (bitsize + 7u) >> 3u );
(void)GetRandomDataFunc( randomDataInfo, key, ((bitsize + 7U) >> 3U) );
}
else
{
for (int i = 0, randomsize = bitsize; randomsize > 0; randomsize-=32, i++)
{
int randombits = CY_CRYPTO_MIN(randomsize, 32);
uint32_t i = 0U;
int32_t randomsize = (int32_t)bitsize;
cy_en_crypto_status_t status = CY_CRYPTO_SUCCESS;
cy_en_crypto_status_t error = Cy_Crypto_Core_Trng(base, CY_ECC_CONFIG_TR_GARO_CTL, CY_ECC_CONFIG_TR_FIRO_CTL,
while ((randomsize > 0) && (CY_CRYPTO_SUCCESS == status))
{
uint32_t randombits = (uint32_t)CY_CRYPTO_MIN(randomsize, 32);
status = Cy_Crypto_Core_Trng(base, CY_ECC_CONFIG_TR_GARO_CTL, CY_ECC_CONFIG_TR_FIRO_CTL,
randombits, &((uint32_t *)key)[i]);
randomsize -= 32;
i++;
if (CY_CRYPTO_SUCCESS != error)
if (CY_CRYPTO_SUCCESS != status)
{
return CY_CRYPTO_HW_ERROR;
tmpResult = CY_CRYPTO_HW_ERROR;
}
}
}
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("private key: ");
Crypto_PrintNumber((uint8_t *)key, CY_CRYPTO_BYTE_SIZE_OF_BITS(bitsize));
#endif /* ECC_KEY_GEN_DEBUG */
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* load prime and order defining the curve as well as the barrett coefficient. */
/* P and BARRETT_U are "globally" defined in cy_crypto_core_ecc.h */
CY_CRYPTO_VU_ALLOC_MEM(base, VR_P, bitsize);
CY_CRYPTO_VU_ALLOC_MEM(base, VR_BARRETT, bitsize + 1);
CY_CRYPTO_VU_ALLOC_MEM(base, VR_BARRETT, bitsize + 1u);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_P, eccDp->order, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, eccDp->barrett_o, bitsize + 1);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, eccDp->barrett_o, bitsize + 1u);
/* Load random data into VU */
CY_CRYPTO_VU_ALLOC_MEM(base, p_d, bitsize);
@ -302,22 +278,15 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePrivateKey(CRYPTO_Type *base,
CY_CRYPTO_VU_ALLOC_MEM(base, p_temp, bitsize);
CY_CRYPTO_VU_MOV(base, p_temp, p_d);
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("random data: ");
Crypto_RegMemNumberPrint(p_d);
Tb_PrintStr("p_order: ");
Crypto_RegMemNumberPrint(VR_P);
#endif /* ECC_KEY_GEN_DEBUG */
/* check that the key is smaller than the order of base point */
CY_CRYPTO_VU_CMP_SUB (base, p_d, VR_P); /* C = (a >= b) */
uint16_t status = Cy_Crypto_Core_Vu_StatusRead(base);
uint32_t status = Cy_Crypto_Core_Vu_StatusRead(base);
if (status & CY_CRYPTO_VU_STATUS_CARRY_BIT)
if (0u != (status & CY_CRYPTO_VU_STATUS_CARRY_BIT))
{
/* private key (random data) >= order, needs reduction */
/* use barrett reduction algorithm for operations modulo n (order of the base point) */
/* use Barrett reduction algorithm for operations modulo n (order of the base point) */
Cy_Crypto_Core_EC_NistP_SetRedAlg(eccDp->algo);
Cy_Crypto_Core_EC_NistP_SetMode(bitsize);
@ -325,22 +294,16 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePrivateKey(CRYPTO_Type *base,
Cy_Crypto_Core_EC_Bar_MulRed(base, p_d, p_temp, bitsize);
Cy_Crypto_Core_Vu_GetMemValue(base, (uint8_t *)key, p_d, bitsize);
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("private key after reduction modulo order: ");
Crypto_RegMemNumberPrint(p_d);
#endif /* ECC_KEY_GEN_DEBUG */
}
else
{
/* carry is clear, i. e. p_d < p_order */
}
CY_CRYPTO_VU_FREE_MEM(base, CY_CRYPTO_VU_REG_BIT(VR_P) | CY_CRYPTO_VU_REG_BIT(VR_BARRETT) |
CY_CRYPTO_VU_REG_BIT(p_d) | CY_CRYPTO_VU_REG_BIT(p_temp));
return CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
}
return (tmpResult);
}
@ -367,36 +330,28 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePrivateKey(CRYPTO_Type *base,
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePublicKey(CRYPTO_Type *base,
cy_en_crypto_ecc_curve_id_t curveID,
uint8_t *privateKey,
const uint8_t *privateKey,
cy_stc_crypto_ecc_key *publicKey)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
cy_stc_crypto_ecc_dp_type *eccDp = Cy_Crypto_Core_ECC_GetCurveParams(curveID);
if (eccDp == NULL || privateKey == NULL || publicKey == NULL)
if ((eccDp != NULL) && (privateKey != NULL) && (publicKey != NULL))
{
/* NULL parameter detected in Cy_Crypto_Core_ECC_MakeKey()!!! */
return CY_CRYPTO_NOT_SUPPORTED;
}
uint32_t bitsize = eccDp->size;
#if ECC_KEY_GEN_DEBUG
Tb_PrintStr("\necc_make public key() for ");
Tb_PrintStr((int8_t *)eccDp->name);
Tb_PrintStr("\n");
#endif /* ECC_KEY_GEN_DEBUG */
int bitsize = eccDp->size;
int p_order = 9; /* order of the curve */
int p_d = 10; /* private key */
int p_x = 11; /* x coordinate */
int p_y = 12; /* y coordinate */
uint32_t p_order = 9u; /* order of the curve */
uint32_t p_d = 10u; /* private key */
uint32_t p_x = 11u; /* x coordinate */
uint32_t p_y = 12u; /* y coordinate */
/* make the public key
* EC scalar multiplication - X,Y-only co-Z arithmetic
*/
CY_CRYPTO_VU_ALLOC_MEM(base, VR_P, bitsize);
CY_CRYPTO_VU_ALLOC_MEM(base, p_order, bitsize);
CY_CRYPTO_VU_ALLOC_MEM(base, VR_BARRETT, bitsize + 1);
CY_CRYPTO_VU_ALLOC_MEM(base, VR_BARRETT, bitsize + 1u);
CY_CRYPTO_VU_ALLOC_MEM(base, p_x, bitsize);
CY_CRYPTO_VU_ALLOC_MEM(base, p_y, bitsize);
@ -407,7 +362,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePublicKey(CRYPTO_Type *base,
/* P and BARRETT_U are "globally" defined in cy_crypto_core_ecc.h */
Cy_Crypto_Core_Vu_SetMemValue (base, VR_P, eccDp->prime, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, p_order, eccDp->order, bitsize);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, eccDp->barrett_p, bitsize + 1);
Cy_Crypto_Core_Vu_SetMemValue (base, VR_BARRETT, eccDp->barrett_p, bitsize + 1u);
/*Base Point, G = (p_x, p_y) */
Cy_Crypto_Core_Vu_SetMemValue (base, p_x, eccDp->Gx, bitsize);
@ -431,7 +386,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePublicKey(CRYPTO_Type *base,
CY_CRYPTO_VU_FREE_MEM(base, CY_CRYPTO_VU_REG_BIT(VR_P) | CY_CRYPTO_VU_REG_BIT(p_order) | CY_CRYPTO_VU_REG_BIT(VR_BARRETT) |
CY_CRYPTO_VU_REG_BIT(p_x) | CY_CRYPTO_VU_REG_BIT(p_y) | CY_CRYPTO_VU_REG_BIT(p_d));
return CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
return (tmpResult);
}

View File

@ -65,7 +65,7 @@ static void Cy_Crypto_Core_V1_Hmac_Init(cy_stc_crypto_v1_hmac_state_t *hmacState
uint8_t *opad,
uint8_t *m0Key);
static void Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
static cy_en_crypto_status_t Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
cy_stc_crypto_v1_hmac_state_t *hmacState,
cy_stc_crypto_sha_state_t *hashState,
uint8_t const *key,
@ -118,7 +118,7 @@ static void Cy_Crypto_Core_V1_Hmac_Init(cy_stc_crypto_v1_hmac_state_t *hmacState
* Starts HMAC (Hash-based Message Authentication Code) calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hmacState
* The pointer to the hmacState structure which stores internal variables
@ -144,7 +144,7 @@ static void Cy_Crypto_Core_V1_Hmac_Init(cy_stc_crypto_v1_hmac_state_t *hmacState
* The pointer to the calculated HMAC.
*
*******************************************************************************/
static void Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
static cy_en_crypto_status_t Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
cy_stc_crypto_v1_hmac_state_t *hmacState,
cy_stc_crypto_sha_state_t *hashState,
uint8_t const *key,
@ -153,6 +153,8 @@ static void Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
uint32_t messageSize,
uint8_t *hmac)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
uint32_t i = 0uL;
uint8_t *ipadPtrTmp = (uint8_t*)hmacState->ipad;
uint8_t *opadPtrTmp = (uint8_t*)hmacState->opad;
@ -162,14 +164,23 @@ static void Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
if (keyLength > hashState->blockSize)
{
/* The key is larger than the block size. Do a hash on the key. */
Cy_Crypto_Core_V1_Sha_Start (base, hashState);
Cy_Crypto_Core_V1_Sha_Update (base, hashState, key, keyLength);
Cy_Crypto_Core_V1_Sha_Finish (base, hashState, (uint8_t*)m0KeyPtrTmp/*, keyLength*/);
tmpResult = Cy_Crypto_Core_V1_Sha_Start(base, hashState);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V1_Sha_Update(base, hashState, key, keyLength);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V1_Sha_Finish(base, hashState, (uint8_t*)m0KeyPtrTmp);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* Append zeros */
Cy_Crypto_Core_V1_MemSet(base, (m0KeyPtrTmp + hashState->digestSize), 0x00u,
(uint16_t)(hashState->blockSize - hashState->digestSize));
}
}
else if (keyLength < hashState->blockSize)
{
/* If the key is shorter than the block, append zeros */
@ -181,6 +192,8 @@ static void Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
Cy_Crypto_Core_V1_MemCpy(base, m0KeyPtrTmp, key, (uint16_t)keyLength);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* Steps 4 and 7 according to FIPS 198-1 */
while (i < hashState->blockSize)
{
@ -190,22 +203,48 @@ static void Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
}
/* Step 6 according to FIPS 198-1 */
Cy_Crypto_Core_V1_Sha_Start (base, hashState);
Cy_Crypto_Core_V1_Sha_Update(base, hashState, ipadPtrTmp, hashState->blockSize);
tmpResult = Cy_Crypto_Core_V1_Sha_Start(base, hashState);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V1_Sha_Update(base, hashState, ipadPtrTmp, hashState->blockSize);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* Append a message */
Cy_Crypto_Core_V1_Sha_Update (base, hashState, message, messageSize);
Cy_Crypto_Core_V1_Sha_Finish (base, hashState, ipadPtrTmp);
tmpResult = Cy_Crypto_Core_V1_Sha_Update (base, hashState, message, messageSize);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V1_Sha_Finish (base, hashState, ipadPtrTmp);
}
/* Here is the ready part of HASH: Hash((Key^ipad)||text) */
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* Steps 8, 9 according to FIPS 198-1 */
Cy_Crypto_Core_V1_Sha_Start (base, hashState);
Cy_Crypto_Core_V1_Sha_Update(base, hashState, opadPtrTmp, hashState->blockSize);
tmpResult = Cy_Crypto_Core_V1_Sha_Start(base, hashState);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V1_Sha_Update(base, hashState, opadPtrTmp, hashState->blockSize);
}
/* Append HASH from Step 6 */
Cy_Crypto_Core_V1_Sha_Update (base, hashState, (uint8_t*)ipadPtrTmp, hashState->digestSize);
Cy_Crypto_Core_V1_Sha_Finish (base, hashState, hmac);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V1_Sha_Update(base, hashState, (uint8_t*)ipadPtrTmp, hashState->digestSize);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V1_Sha_Finish(base, hashState, hmac);
}
}
}
return (tmpResult);
}
/*******************************************************************************
@ -215,7 +254,7 @@ static void Cy_Crypto_Core_V1_Hmac_Calculate(CRYPTO_Type *base,
* Clears the used memory buffers.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hmacState
* The pointer to the HMAC context.
@ -236,7 +275,7 @@ static void Cy_Crypto_Core_V1_Hmac_Free(CRYPTO_Type *base, cy_stc_crypto_v1_hmac
* Performs HMAC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hmac
* The pointer to the calculated HMAC. Must be 4-byte aligned.
@ -257,7 +296,7 @@ static void Cy_Crypto_Core_V1_Hmac_Free(CRYPTO_Type *base, cy_stc_crypto_v1_hmac
* \ref cy_en_crypto_sha_mode_t
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Hmac(CRYPTO_Type *base,
@ -268,25 +307,30 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Hmac(CRYPTO_Type *base,
uint32_t keyLength,
cy_en_crypto_sha_mode_t mode)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
/* Allocating internal variables into the CRYPTO SRAM Buffer */
cy_stc_crypto_hmac_buffers_t *hmacBuffers = (cy_stc_crypto_hmac_buffers_t *)(REG_CRYPTO_MEM_BUFF(base));
cy_stc_crypto_v1_hmac_state_t *hmacStateTmp = &hmacBuffers->hmacState;
cy_stc_crypto_sha_state_t hashState;
cy_stc_crypto_sha_state_t hashStateLoc = { 0 };
uint8_t *ipadTmp = (uint8_t*)(&hmacBuffers->ipad);
uint8_t *opadTmp = (uint8_t*)(&hmacBuffers->opad);
uint8_t *m0KeyTmp = (uint8_t*)(&hmacBuffers->m0Key);
Cy_Crypto_Core_V1_Sha_Init (base, &hashState, mode, &hmacBuffers->shaBuffers);
tmpResult = Cy_Crypto_Core_V1_Sha_Init(base, &hashStateLoc, mode, &hmacBuffers->shaBuffers);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
Cy_Crypto_Core_V1_Hmac_Init(hmacStateTmp, ipadTmp, opadTmp, m0KeyTmp);
Cy_Crypto_Core_V1_Hmac_Calculate (base, hmacStateTmp, &hashState, key, keyLength, message, messageSize, hmac);
tmpResult = Cy_Crypto_Core_V1_Hmac_Calculate (base, hmacStateTmp, &hashStateLoc, key, keyLength, message, messageSize, hmac);
Cy_Crypto_Core_V1_Hmac_Free(base, hmacStateTmp);
}
Cy_Crypto_Core_V1_Sha_Free (base, &hashState);
(void)Cy_Crypto_Core_V1_Sha_Free(base, &hashStateLoc);
return (CY_CRYPTO_SUCCESS);
return (tmpResult);
}

View File

@ -64,7 +64,7 @@ static void Cy_Crypto_Core_V2_Hmac_Init(cy_stc_crypto_v2_hmac_state_t *hmacState
uint8_t *ipad,
uint8_t *opad,
uint8_t *m0Key);
static void Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
static cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
cy_stc_crypto_v2_hmac_state_t *hmacState,
cy_stc_crypto_sha_state_t *hashState,
uint8_t const *key,
@ -116,7 +116,7 @@ static void Cy_Crypto_Core_V2_Hmac_Init(cy_stc_crypto_v2_hmac_state_t *hmacState
* Starts HMAC (Hash-based Message Authentication Code) calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hmacState
* The pointer to the hmacState structure which stores internal variables
@ -142,7 +142,7 @@ static void Cy_Crypto_Core_V2_Hmac_Init(cy_stc_crypto_v2_hmac_state_t *hmacState
* The pointer to the calculated HMAC.
*
*******************************************************************************/
static void Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
static cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
cy_stc_crypto_v2_hmac_state_t *hmacState,
cy_stc_crypto_sha_state_t *hashState,
uint8_t const *key,
@ -151,6 +151,8 @@ static void Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
uint32_t messageSize,
uint8_t *hmac)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
uint32_t i = 0uL;
uint32_t blockSizeTmp = hashState->blockSize;
uint32_t digestSizeTmp = hashState->digestSize;
@ -164,9 +166,16 @@ static void Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
if (keyLength > blockSizeTmp)
{
/* The key is larger than the block size. Do a hash on the key. */
Cy_Crypto_Core_V2_Sha_Start (base, hashState);
Cy_Crypto_Core_V2_Sha_Update (base, hashState, key, keyLength);
Cy_Crypto_Core_V2_Sha_Finish (base, hashState, m0KeyPtrTmp);
tmpResult = Cy_Crypto_Core_V2_Sha_Start (base, hashState);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V2_Sha_Update (base, hashState, key, keyLength);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V2_Sha_Finish (base, hashState, m0KeyPtrTmp);
}
/* Append zeros */
Cy_Crypto_Core_V2_MemSet(base, (m0KeyPtrTmp + digestSizeTmp), 0x00u, (uint16_t)(blockSizeTmp - digestSizeTmp));
@ -182,6 +191,8 @@ static void Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
Cy_Crypto_Core_V2_MemCpy(base, m0KeyPtrTmp, key, (uint16_t)keyLength);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* Steps 4 and 7 according to FIPS 198-1 */
while (i < blockSizeTmp)
{
@ -191,22 +202,48 @@ static void Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
}
/* Step 6 according to FIPS 198-1 */
Cy_Crypto_Core_V2_Sha_Start (base, hashState);
Cy_Crypto_Core_V2_Sha_Update(base, hashState, ipadPtrTmp, blockSizeTmp);
tmpResult = Cy_Crypto_Core_V2_Sha_Start (base, hashState);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V2_Sha_Update(base, hashState, ipadPtrTmp, blockSizeTmp);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* Append a message */
Cy_Crypto_Core_V2_Sha_Update(base, hashState, message, messageSize);
Cy_Crypto_Core_V2_Sha_Finish(base, hashState, ipadPtrTmp);
tmpResult = Cy_Crypto_Core_V2_Sha_Update(base, hashState, message, messageSize);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V2_Sha_Finish(base, hashState, ipadPtrTmp);
}
/* Here is the ready part of HASH: Hash((Key^ipad)||text) */
if (CY_CRYPTO_SUCCESS == tmpResult)
{
/* Steps 8, 9 according to FIPS 198-1 */
Cy_Crypto_Core_V2_Sha_Start(base, hashState);
Cy_Crypto_Core_V2_Sha_Update(base, hashState, opadPtrTmp, blockSizeTmp);
tmpResult = Cy_Crypto_Core_V2_Sha_Start(base, hashState);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V2_Sha_Update(base, hashState, opadPtrTmp, blockSizeTmp);
}
/* Append HASH from Step 6 */
Cy_Crypto_Core_V2_Sha_Update(base, hashState, ipadPtrTmp, digestSizeTmp);
Cy_Crypto_Core_V2_Sha_Finish(base, hashState, hmac);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V2_Sha_Update(base, hashState, ipadPtrTmp, digestSizeTmp);
}
if (CY_CRYPTO_SUCCESS == tmpResult)
{
tmpResult = Cy_Crypto_Core_V2_Sha_Finish(base, hashState, hmac);
}
}
}
return (tmpResult);
}
/*******************************************************************************
@ -216,7 +253,7 @@ static void Cy_Crypto_Core_V2_Hmac_Calculate(CRYPTO_Type *base,
* Clears the used memory buffers.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hmacState
* The pointer to the HMAC context.
@ -235,7 +272,7 @@ static void Cy_Crypto_Core_V2_Hmac_Free(CRYPTO_Type *base, cy_stc_crypto_v2_hmac
* Performs HMAC calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hmac
* The pointer to the calculated HMAC. Must be 4-byte aligned.
@ -256,7 +293,7 @@ static void Cy_Crypto_Core_V2_Hmac_Free(CRYPTO_Type *base, cy_stc_crypto_v2_hmac
* \ref cy_en_crypto_sha_mode_t
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac(CRYPTO_Type *base,
@ -267,27 +304,32 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Hmac(CRYPTO_Type *base,
uint32_t keyLength,
cy_en_crypto_sha_mode_t mode)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
/* Allocating internal variables into the CRYPTO SRAM Buffer */
cy_stc_crypto_v2_hmac_buffers_t hmacBuffersData;
cy_stc_crypto_v2_hmac_buffers_t hmacBuffersData = { 0 };
cy_stc_crypto_v2_hmac_buffers_t *hmacBuffers = &hmacBuffersData;
cy_stc_crypto_v2_hmac_state_t *hmacStateTmp = &hmacBuffers->hmacState;
cy_stc_crypto_sha_state_t hashState;
cy_stc_crypto_sha_state_t hashStateLoc = { 0 };
uint8_t *ipadTmp = (uint8_t*)&hmacBuffers->ipad;
uint8_t *opadTmp = (uint8_t*)&hmacBuffers->opad;
uint8_t *m0KeyTmp = (uint8_t*)&hmacBuffers->m0Key;
/* No any buffers needed for Crypto_ver2 IP block */
Cy_Crypto_Core_V2_Sha_Init (base, &hashState, mode, NULL);
tmpResult = Cy_Crypto_Core_V2_Sha_Init(base, &hashStateLoc, mode, NULL);
if (CY_CRYPTO_SUCCESS == tmpResult)
{
Cy_Crypto_Core_V2_Hmac_Init(hmacStateTmp, ipadTmp, opadTmp, m0KeyTmp);
Cy_Crypto_Core_V2_Hmac_Calculate (base, hmacStateTmp, &hashState, key, keyLength, message, messageSize, hmac);
tmpResult = Cy_Crypto_Core_V2_Hmac_Calculate(base, hmacStateTmp, &hashStateLoc, key, keyLength, message, messageSize, hmac);
Cy_Crypto_Core_V2_Hmac_Free(base, hmacStateTmp);
}
Cy_Crypto_Core_V2_Sha_Free (base, &hashState);
(void)Cy_Crypto_Core_V2_Sha_Free(base, &hashStateLoc);
return (CY_CRYPTO_SUCCESS);
return (tmpResult);
}

View File

@ -104,6 +104,12 @@ const cy_stc_cryptoIP_t cy_cryptoIpBlockCfgPSoC6_02 =
#define CY_CRYPTO_PWR_MODE_RETAINED (2UL)
#define CY_CRYPTO_PWR_MODE_ENABLED (3UL)
/**
* \addtogroup group_crypto_lld_hw_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_ClearVuRegisters
****************************************************************************//**
@ -111,7 +117,7 @@ const cy_stc_cryptoIP_t cy_cryptoIpBlockCfgPSoC6_02 =
* The function to initialize the Crypto VU registers.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
void Cy_Crypto_Core_ClearVuRegisters(CRYPTO_Type *base)
@ -140,8 +146,6 @@ void Cy_Crypto_Core_ClearVuRegisters(CRYPTO_Type *base)
*
* The function to initialize the Crypto hardware.
*
* This function is internal and should not to be called directly by user software
*
*******************************************************************************/
void Cy_Crypto_Core_HwInit(void)
{
@ -155,17 +159,17 @@ void Cy_Crypto_Core_HwInit(void)
* The function to enable the Crypto hardware.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \return
* Crypto status \ref cy_en_crypto_status_t.
* Crypto status \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_Enable(CRYPTO_Type *base)
{
Cy_Crypto_Core_HwInit();
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
/* Enable Crypto HW */
REG_CRYPTO_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_CTL_PWR_MODE, CY_CRYPTO_PWR_MODE_ENABLED) |
@ -232,7 +236,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_Enable(CRYPTO_Type *base)
* The pointer to a variable to store gathered crypto library information.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_GetLibInfo(cy_en_crypto_lib_info_t *libInfo)
@ -249,15 +253,15 @@ cy_en_crypto_status_t Cy_Crypto_Core_GetLibInfo(cy_en_crypto_lib_info_t *libInfo
* Disables the operation of the CRYPTO block.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_Disable(CRYPTO_Type *base)
{
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
/* Disable Crypto HW */
REG_CRYPTO_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_CTL_PWR_MODE, CY_CRYPTO_PWR_MODE_OFF) |
@ -322,6 +326,7 @@ void Cy_Crypto_Core_InvertEndianness(void *inArrPtr, uint32_t byteSize)
}
}
/** \} group_crypto_lld_hw_functions */
#endif /* CY_IP_MXCRYPTO */

View File

@ -39,7 +39,7 @@
* Writes one 32-Bit data word into Crypto FIFO.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param data0
* The address of data to be placed into Crypto FIFO
@ -66,7 +66,7 @@ void Cy_Crypto_SetReg1Instr(CRYPTO_Type *base, uint32_t data0)
* Writes two 32-Bit data words into Crypto FIFO.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param data0
* The address of data to be placed into Crypto FIFO
@ -99,7 +99,7 @@ void Cy_Crypto_SetReg2Instr(CRYPTO_Type *base, uint32_t data0, uint32_t data1)
* Writes three 32-Bit data words into Crypto FIFO.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param data0
* The address of data to be placed into Crypto FIFO
@ -138,7 +138,7 @@ void Cy_Crypto_SetReg3Instr(CRYPTO_Type *base, uint32_t data0, uint32_t data1, u
* Writes four 32-Bit data words into Crypto FIFO.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param data0
* The address of data to be placed into Crypto FIFO
@ -183,7 +183,7 @@ void Cy_Crypto_SetReg4Instr(CRYPTO_Type *base, uint32_t data0, uint32_t data1, u
* Run the Crypto instruction without parameters.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param instr
* The Opcode of the called instruction.
@ -207,7 +207,7 @@ void Cy_Crypto_Run0ParamInstr(CRYPTO_Type *base, uint8_t instr)
* The parameter must be placed into register 0
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param instr
* The Opcode of the called instruction.
@ -236,7 +236,7 @@ void Cy_Crypto_Run1ParamInstr(CRYPTO_Type *base, uint8_t instr, uint32_t rdst0Sh
* the first parameter must be placed into register 1.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param instr
* The Opcode of the called instruction.
@ -273,7 +273,7 @@ void Cy_Crypto_Run2ParamInstr(CRYPTO_Type *base,
* the second parameter must be placed into register 2.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param instr
* The Opcode of the called instruction.
@ -316,7 +316,7 @@ void Cy_Crypto_Run3ParamInstr(CRYPTO_Type *base,
* the third parameter must be placed into register 3.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param instr
* The Opcode of the called instruction.

View File

@ -44,7 +44,7 @@
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param src
* The pointer to the source of MemCpy.
@ -85,7 +85,7 @@ void Cy_Crypto_Core_V1_MemCpy(CRYPTO_Type *base, void* dst, void const *src, uin
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dst
* The pointer to the destination of MemSet.
@ -125,7 +125,7 @@ void Cy_Crypto_Core_V1_MemSet(CRYPTO_Type *base, void* dst, uint8_t data, uint16
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param src0
* The pointer to the first source of MemCmp.
@ -171,7 +171,7 @@ uint32_t Cy_Crypto_Core_V1_MemCmp(CRYPTO_Type *base, void const *src0, void cons
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param src0
* The pointer to the first source of MemXor.

View File

@ -42,7 +42,7 @@
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param src
* The pointer to the source of MemCpy.
@ -81,7 +81,7 @@ void Cy_Crypto_Core_V2_MemCpy(CRYPTO_Type *base, void* dst, void const *src, uin
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param dst
* The pointer to the destination of MemSet.
@ -119,7 +119,7 @@ void Cy_Crypto_Core_V2_MemSet(CRYPTO_Type *base, void* dst, uint8_t data, uint16
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param src0
* The pointer to the first source of MemCmp.
@ -166,7 +166,7 @@ uint32_t Cy_Crypto_Core_V2_MemCmp(CRYPTO_Type *base, void const *src0, void cons
* There is no alignment restriction.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param src0
* The pointer to the first source of MemXor.

View File

@ -43,7 +43,7 @@
* Invoking this function causes a restart of the pseudo-random sequence.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param lfsr32InitState
* A non-zero seed value for the first LFSR.
@ -55,7 +55,7 @@
* A non-zero seed value for the third LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Prng_Init(CRYPTO_Type *base,
@ -79,7 +79,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Prng_Init(CRYPTO_Type *base,
* Generates a Pseudo Random Number.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param max
* The maximum value of a random number.
@ -88,7 +88,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Prng_Init(CRYPTO_Type *base,
* The pointer to a variable to store the generated pseudo random number.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Prng(CRYPTO_Type *base,

View File

@ -43,7 +43,7 @@
* Invoking this function causes a restart of the pseudo-random sequence.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param lfsr32InitState
* A non-zero seed value for the first LFSR.
@ -55,7 +55,7 @@
* A non-zero seed value for the third LFSR.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Prng_Init(CRYPTO_Type *base,
@ -79,7 +79,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Prng_Init(CRYPTO_Type *base,
* Generates a Pseudo Random Number.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param max
* The maximum value of a random number.
@ -88,7 +88,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Prng_Init(CRYPTO_Type *base,
* The pointer to a variable to store the generated pseudo random number.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Prng(CRYPTO_Type *base,

View File

@ -57,6 +57,55 @@ static void Cy_Crypto_Core_Rsa_expModByMont(CRYPTO_Type *base,
#endif /* #if (CPUSS_CRYPTO_VU == 1) */
/**
* \addtogroup group_crypto_lld_asymmetric_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Rsa_Verify
****************************************************************************//**
*
* RSA verification with checks for content, paddings and signature format.
* SHA digest of the message and decrypted message should be calculated before.
* Supports only PKCS1-v1_5 format, inside of this format supported padding
* using only SHA, cases with MD2 and MD5 are not supported.
* PKCS1-v1_5 described here, page 31:
* http://www.emc.com/collateral/white-papers/h11300-pkcs-1v2-2-rsa-cryptography-standard-wp.pdf
*
* Returns the verification result \ref cy_en_crypto_rsa_ver_result_t.
*
* \param base
* The pointer to the CRYPTO instance.
*
* \param verResult
* The pointer to the verification result \ref cy_en_crypto_rsa_ver_result_t.
*
* \param digestType
* SHA mode used for hash calculation \ref cy_en_crypto_sha_mode_t.
*
* \param digest
* The pointer to the hash of the message whose signature is to be verified.
*
* \param decryptedSignature
* The pointer to the decrypted signature to be verified.
*
* \param decryptedSignatureLength
* The length of the decrypted signature to be verified (in bytes)
*
* \return
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
cy_en_crypto_rsa_ver_result_t *verResult,
cy_en_crypto_sha_mode_t digestType,
uint8_t const *digest,
uint8_t const *decryptedSignature,
uint32_t decryptedSignatureLength)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
/* Encodings for hash functions */
#if (CPUSS_CRYPTO_SHA1 == 1)
@ -113,53 +162,9 @@ static const uint8_t sha512_256EncStr[CY_CRYPTO_SHA256_512_PADDING_SIZE] =
};
#endif /* #if (CPUSS_CRYPTO_SHA512 == 1) */
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Rsa_Verify
****************************************************************************//**
*
* RSA verification with checks for content, paddings and signature format.
* SHA digest of the message and decrypted message should be calculated before.
* Supports only PKCS1-v1_5 format, inside of this format supported padding
* using only SHA, cases with MD2 and MD5 are not supported.
* PKCS1-v1_5 described here, page 31:
* http://www.emc.com/collateral/white-papers/h11300-pkcs-1v2-2-rsa-cryptography-standard-wp.pdf
*
* Returns the verification result \ref cy_en_crypto_rsa_ver_result_t.
*
* \param base
* The pointer to the CRYPTO instance address.
*
* \param verResult
* The pointer to the verification result \ref cy_en_crypto_rsa_ver_result_t.
*
* \param digestType
* SHA mode used for hash calculation \ref cy_en_crypto_sha_mode_t.
*
* \param digest
* The pointer to the hash of the message whose signature is to be verified.
*
* \param decryptedSignature
* The pointer to the decrypted signature to be verified.
*
* \param decryptedSignatureLength
* The length of the decrypted signature to be verified (in bytes)
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
cy_en_crypto_rsa_ver_result_t *verResult,
cy_en_crypto_sha_mode_t digestType,
uint8_t const *digest,
uint8_t const *decryptedSignature,
uint32_t decryptedSignatureLength)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_SUCCESS;
uint8_t const *encodingArr = NULL;
uint32_t encodingArrSize = 0u;
uint32_t digestSize = 0u;
uint32_t locDigestSize = 0u;
uint32_t i;
uint32_t psLength;
uint32_t cmpRes = 0u;
@ -172,7 +177,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
case CY_CRYPTO_MODE_SHA1:
encodingArr = sha1EncStr;
encodingArrSize = sizeof(sha1EncStr);
digestSize = CY_CRYPTO_SHA1_DIGEST_SIZE;
locDigestSize = CY_CRYPTO_SHA1_DIGEST_SIZE;
break;
#endif /* #if (CPUSS_CRYPTO_SHA1 == 1) */
@ -180,13 +185,13 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
case CY_CRYPTO_MODE_SHA224:
encodingArr = sha224EncStr;
encodingArrSize = sizeof(sha224EncStr);
digestSize = CY_CRYPTO_SHA224_DIGEST_SIZE;
locDigestSize = CY_CRYPTO_SHA224_DIGEST_SIZE;
break;
case CY_CRYPTO_MODE_SHA256:
encodingArr = sha256EncStr;
encodingArrSize = sizeof(sha256EncStr);
digestSize = CY_CRYPTO_SHA256_DIGEST_SIZE;
locDigestSize = CY_CRYPTO_SHA256_DIGEST_SIZE;
break;
#endif /* #if (CPUSS_CRYPTO_SHA256 == 1) */
@ -194,25 +199,25 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
case CY_CRYPTO_MODE_SHA384:
encodingArr = sha384EncStr;
encodingArrSize = sizeof(sha384EncStr);
digestSize = CY_CRYPTO_SHA384_DIGEST_SIZE;
locDigestSize = CY_CRYPTO_SHA384_DIGEST_SIZE;
break;
case CY_CRYPTO_MODE_SHA512:
encodingArr = sha512EncStr;
encodingArrSize = sizeof(sha512EncStr);
digestSize = CY_CRYPTO_SHA512_DIGEST_SIZE;
locDigestSize = CY_CRYPTO_SHA512_DIGEST_SIZE;
break;
case CY_CRYPTO_MODE_SHA512_224:
encodingArr = sha512_224EncStr;
encodingArrSize = sizeof(sha512_224EncStr);
digestSize = CY_CRYPTO_SHA512_224_DIGEST_SIZE;
locDigestSize = CY_CRYPTO_SHA512_224_DIGEST_SIZE;
break;
case CY_CRYPTO_MODE_SHA512_256:
encodingArr = sha512_256EncStr;
encodingArrSize = sizeof(sha512_256EncStr);
digestSize = CY_CRYPTO_SHA512_256_DIGEST_SIZE;
locDigestSize = CY_CRYPTO_SHA512_256_DIGEST_SIZE;
break;
#endif /* #if (CPUSS_CRYPTO_SHA512 == 1) */
@ -224,12 +229,12 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
*verResult = CY_CRYPTO_RSA_VERIFY_FAIL;
/* Check size of decrypted message */
if (decryptedSignatureLength < (encodingArrSize + digestSize + 11u))
if (decryptedSignatureLength < (encodingArrSize + locDigestSize + 11u))
{
cmpRes = 1u; /* further checking is not needed */
}
psLength = decryptedSignatureLength - digestSize - encodingArrSize - 3u;
psLength = decryptedSignatureLength - locDigestSize - encodingArrSize - 3u;
/* Check whether the begin of message is 0x00, 0x01 and after PS string (before T string) is 0x00 byte.*/
if ( (0u != cmpRes) ||
@ -265,8 +270,8 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
if (0u == cmpRes)
{
cmpRes = Cy_Crypto_Core_MemCmp(base, digest,
(decryptedSignature + (decryptedSignatureLength - digestSize)),
(uint16_t)digestSize);
(decryptedSignature + (decryptedSignatureLength - locDigestSize)),
(uint16_t)locDigestSize);
}
if (0u == cmpRes )
@ -274,9 +279,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
*verResult = CY_CRYPTO_RSA_VERIFY_SUCCESS;
}
return (myResult);
return (tmpResult);
}
/** \} group_crypto_lld_asymmetric_functions */
#if (CPUSS_CRYPTO_VU == 1)
@ -297,7 +303,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
* where R = 1 << size.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param modDerReg
* Register index for Montgomery coefficient value.
@ -306,17 +312,17 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Verify(CRYPTO_Type *base,
* Register index for modulo value.
*
* \param size
* Size of modulo, in Bits.
* Modulo size in bits.
*
*******************************************************************************/
static void Cy_Crypto_Core_Rsa_MontCoeff(CRYPTO_Type *base, uint32_t modDerReg, uint32_t modReg, uint32_t size)
{
uint32_t myMod = 9u;
uint32_t tmp = 10u;
uint32_t a = 11u;
uint32_t b = 12u;
uint32_t u = 13u;
uint32_t v = 14u;
uint32_t ra = 11u;
uint32_t rb = 12u;
uint32_t ru = 13u;
uint32_t rv = 14u;
uint32_t status;
uint32_t aZero;
@ -324,27 +330,27 @@ static void Cy_Crypto_Core_Rsa_MontCoeff(CRYPTO_Type *base, uint32_t modDerReg,
CY_CRYPTO_VU_PUSH_REG (base);
CY_CRYPTO_VU_LD_REG (base, v, modDerReg);
CY_CRYPTO_VU_LD_REG (base, rv, modDerReg);
CY_CRYPTO_VU_LD_REG (base, myMod, modReg);
CY_CRYPTO_VU_ALLOC_MEM (base, a, size);
CY_CRYPTO_VU_ALLOC_MEM (base, b, size);
CY_CRYPTO_VU_ALLOC_MEM (base, u, size);
CY_CRYPTO_VU_ALLOC_MEM (base, ra, size);
CY_CRYPTO_VU_ALLOC_MEM (base, rb, size);
CY_CRYPTO_VU_ALLOC_MEM (base, ru, size);
CY_CRYPTO_VU_SET_TO_ONE (base, u);
CY_CRYPTO_VU_SET_TO_ZERO (base, v);
CY_CRYPTO_VU_SET_TO_ONE (base, ru);
CY_CRYPTO_VU_SET_TO_ZERO (base, rv);
CY_CRYPTO_VU_SET_TO_ZERO (base, a);
CY_CRYPTO_VU_SET_TO_ZERO (base, ra);
CY_CRYPTO_VU_SET_REG (base, tmp, (size - 1u), 1u);
CY_CRYPTO_VU_SET_BIT (base, a, tmp);
CY_CRYPTO_VU_MOV (base, b, myMod);
CY_CRYPTO_VU_SET_BIT (base, ra, tmp);
CY_CRYPTO_VU_MOV (base, rb, myMod);
while (1)
{
Cy_Crypto_Core_WaitForReady(base);
CY_CRYPTO_VU_TST(base, a);
CY_CRYPTO_VU_TST(base, ra);
status = Cy_Crypto_Core_Vu_StatusRead(base);
aZero = status & CY_CRYPTO_VU_STATUS_ZERO_BIT;
@ -354,27 +360,27 @@ static void Cy_Crypto_Core_Rsa_MontCoeff(CRYPTO_Type *base, uint32_t modDerReg,
break;
}
CY_CRYPTO_VU_LSR1(base, a, a);
CY_CRYPTO_VU_LSR1(base, ra, ra);
CY_CRYPTO_VU_TST(base, u);
CY_CRYPTO_VU_TST(base, ru);
status = Cy_Crypto_Core_Vu_StatusRead(base);
uEven = status & CY_CRYPTO_VU_STATUS_EVEN_BIT;
if (uEven != 0u)
{
CY_CRYPTO_VU_LSR1(base, u, u);
CY_CRYPTO_VU_LSR1(base, v, v);
CY_CRYPTO_VU_LSR1(base, ru, ru);
CY_CRYPTO_VU_LSR1(base, rv, rv);
}
else
{
CY_CRYPTO_VU_ADD(base, u, u, b);
CY_CRYPTO_VU_LSR1_WITH_CARRY(base, u, u);
CY_CRYPTO_VU_LSR1(base, v, v);
CY_CRYPTO_VU_SET_BIT(base, v, tmp);
CY_CRYPTO_VU_ADD(base, ru, ru, rb);
CY_CRYPTO_VU_LSR1_WITH_CARRY(base, ru, ru);
CY_CRYPTO_VU_LSR1(base, rv, rv);
CY_CRYPTO_VU_SET_BIT(base, rv, tmp);
}
}
CY_CRYPTO_VU_FREE_MEM(base, CY_CRYPTO_VU_REG_BIT(a) | CY_CRYPTO_VU_REG_BIT(b) | CY_CRYPTO_VU_REG_BIT(u));
CY_CRYPTO_VU_FREE_MEM(base, CY_CRYPTO_VU_REG_BIT(ra) | CY_CRYPTO_VU_REG_BIT(rb) | CY_CRYPTO_VU_REG_BIT(ru));
CY_CRYPTO_VU_POP_REG(base);
}
@ -392,7 +398,7 @@ static void Cy_Crypto_Core_Rsa_MontCoeff(CRYPTO_Type *base, uint32_t modDerReg,
* barrett = (1 << (2 * size)) / mod NO!!! leading '1' Barrett bit.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param barrettUReg
* Register index for Barrett reduction value.
@ -400,8 +406,8 @@ static void Cy_Crypto_Core_Rsa_MontCoeff(CRYPTO_Type *base, uint32_t modDerReg,
* \param modReg
* Register index for modulo value.
*
* \param
* Size modulo size in Bits.
* \param size
* The modulo size in bits.
*
*******************************************************************************/
static void Cy_Crypto_Core_Rsa_BarrettGetU(CRYPTO_Type *base, uint32_t barrettUReg, uint32_t modReg, uint32_t size)
@ -447,7 +453,7 @@ static void Cy_Crypto_Core_Rsa_BarrettGetU(CRYPTO_Type *base, uint32_t barrettUR
* z = (a << size) % mod
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param z
* Register index for Montgomery representation value.
@ -521,7 +527,7 @@ static void Cy_Crypto_Core_Rsa_MontTransform(CRYPTO_Type *base, uint32_t z, uint
* u = IF (u >= mod) u = u - mod
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param z
* Register index for product value.
@ -561,7 +567,7 @@ static void Cy_Crypto_Core_Rsa_MontMul(CRYPTO_Type *base,
CY_CRYPTO_VU_UMUL (base, tDouble, a, b);
/* Only lower 32 bits are needed */
/* Only the lower 32 bits are needed. */
CY_CRYPTO_VU_UMUL (base, t, tDouble, montModDer);
/* Clear the MSB bit (cut to size length) */
@ -605,7 +611,7 @@ static void Cy_Crypto_Core_Rsa_MontMul(CRYPTO_Type *base,
* calculation. Suitable for cases with short e.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param y
* Register index for calculated value.
@ -619,8 +625,17 @@ static void Cy_Crypto_Core_Rsa_MontMul(CRYPTO_Type *base,
* \param n
* Register index for modulo value.
*
* \param barretCoef
* Barrett coefficient.
*
* \param inverseModulo
* Binary inverse of the modulo.
*
* \param rBar
* Values of (2^moduloLength mod modulo).
*
* \param size
* modulo size, in Bits
* The modulo size in bits.
*
*******************************************************************************/
static void Cy_Crypto_Core_Rsa_expModByMont(CRYPTO_Type *base,
@ -720,6 +735,11 @@ static void Cy_Crypto_Core_Rsa_expModByMont(CRYPTO_Type *base,
CY_CRYPTO_VU_POP_REG(base);
}
/**
* \addtogroup group_crypto_lld_asymmetric_functions
* \{
*/
/*******************************************************************************
* Function Name: Cy_Crypto_Core_Rsa_Proc
****************************************************************************//**
@ -730,7 +750,7 @@ static void Cy_Crypto_Core_Rsa_expModByMont(CRYPTO_Type *base,
* https://en.wikipedia.org/wiki/RSA_%28cryptosystem%29
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param key
* The pointer to the \ref cy_stc_crypto_rsa_pub_key_t structure that stores
@ -746,7 +766,7 @@ static void Cy_Crypto_Core_Rsa_expModByMont(CRYPTO_Type *base,
* The pointer to processed message.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Proc(CRYPTO_Type *base,
@ -755,7 +775,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Proc(CRYPTO_Type *base,
uint32_t messageSize,
uint8_t *processedMessage)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_SUCCESS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
uint8_t *expPtr = key->pubExpPtr;
uint32_t expBitLength = key->pubExpLength;
@ -834,7 +854,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Proc(CRYPTO_Type *base,
Cy_Crypto_Core_Vu_WaitForComplete(base);
/* Copy the myResult to output buffer */
/* Copy the tmpResult to output buffer */
Cy_Crypto_Core_Vu_GetMemValue(base, (uint8_t*)processedMessage, yReg, nBitLength);
CY_CRYPTO_VU_FREE_MEM(base, CY_CRYPTO_VU_REG_BIT(yReg) | CY_CRYPTO_VU_REG_BIT(xReg) |
@ -842,7 +862,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Proc(CRYPTO_Type *base,
CY_CRYPTO_VU_REG_BIT(inverseModuloReg) |
CY_CRYPTO_VU_REG_BIT(barrettReg) | CY_CRYPTO_VU_REG_BIT(rBarReg));
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -856,20 +876,20 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Proc(CRYPTO_Type *base,
* result of (2^moduloLength mod modulo)
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param key
* The pointer to the \ref cy_stc_crypto_rsa_pub_key_t structure that stores a
* public key.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Coef(CRYPTO_Type *base,
cy_stc_crypto_rsa_pub_key_t const *key)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_SUCCESS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
uint8_t *nPtr = key->moduloPtr;
uint32_t nBitLength = key->moduloLength;
@ -916,9 +936,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_Rsa_Coef(CRYPTO_Type *base,
CY_CRYPTO_VU_FREE_MEM(base, CY_CRYPTO_VU_REG_BIT(modReg) | CY_CRYPTO_VU_REG_BIT(inverseModuloReg) | CY_CRYPTO_VU_REG_BIT(barrettReg) | CY_CRYPTO_VU_REG_BIT(rBarReg));
return (myResult);
return (tmpResult);
}
/** \} group_crypto_lld_asymmetric_functions */
#endif /* #if (CPUSS_CRYPTO_VU == 1) */
#endif /* CY_IP_MXCRYPTO */

View File

@ -39,15 +39,15 @@
typedef enum
{
#if (CPUSS_CRYPTO_SHA1 == 1)
CY_CRYPTO_V1_SHA_CTL_MODE_SHA1 = 0u,
CY_CRYPTO_V1_SHA_CTL_MODE_SHA1 = 0U,
#endif /* #if (CPUSS_CRYPTO_SHA1 == 1) */
#if (CPUSS_CRYPTO_SHA256 == 1)
CY_CRYPTO_V1_SHA_CTL_MODE_SHA256 = 1u,
CY_CRYPTO_V1_SHA_CTL_MODE_SHA256 = 1U,
#endif /* #if (CPUSS_CRYPTO_SHA256 == 1) */
#if (CPUSS_CRYPTO_SHA512 == 1)
CY_CRYPTO_V1_SHA_CTL_MODE_SHA512 = 2u,
CY_CRYPTO_V1_SHA_CTL_MODE_SHA512 = 2U,
#endif /* #if (CPUSS_CRYPTO_SHA512 == 1) */
} cy_en_crypto_v1_sha_hw_mode_t;
@ -60,7 +60,7 @@ typedef enum
* All addresses must be 4-Byte aligned!
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to a Hash State.
@ -99,7 +99,7 @@ void Cy_Crypto_Core_V1_Sha_ProcessBlock(CRYPTO_Type *base,
* The function to initialize SHA operation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to a Hash State.
@ -109,10 +109,10 @@ void Cy_Crypto_Core_V1_Sha_ProcessBlock(CRYPTO_Type *base,
* CY_CRYPTO_SHA512, CY_CRYPTO_SHA384, CY_CRYPTO_SHA512_224, CY_CRYPTO_SHA512_256
*
* \param shaBuffers
* The pointer to memory buffers storage
* The pointer to the memory buffers storage.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
@ -120,6 +120,8 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
cy_en_crypto_sha_mode_t mode,
void *shaBuffers)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
/* Initialization vectors for different modes of the SHA algorithm */
#if (CPUSS_CRYPTO_SHA1 == 1)
static const uint32_t sha1InitHash[] =
@ -190,7 +192,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
#if (CPUSS_CRYPTO_SHA1 == 1)
case CY_CRYPTO_MODE_SHA1:
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00u, sizeof(cy_stc_crypto_v1_sha1_buffers_t));
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00U, sizeof(cy_stc_crypto_v1_sha1_buffers_t));
hashState->block = (uint8_t*)((cy_stc_crypto_v1_sha1_buffers_t*)shaBuffers)->block;
hashState->hash = (uint8_t*)((cy_stc_crypto_v1_sha1_buffers_t*)shaBuffers)->hash;
@ -208,7 +210,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
#if (CPUSS_CRYPTO_SHA256 == 1)
case CY_CRYPTO_MODE_SHA224:
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00u, sizeof(cy_stc_crypto_v1_sha256_buffers_t));
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00U, sizeof(cy_stc_crypto_v1_sha256_buffers_t));
hashState->block = (uint8_t*)((cy_stc_crypto_v1_sha256_buffers_t*)shaBuffers)->block;
hashState->hash = (uint8_t*)((cy_stc_crypto_v1_sha256_buffers_t*)shaBuffers)->hash;
@ -223,7 +225,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
break;
case CY_CRYPTO_MODE_SHA256:
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00u, sizeof(cy_stc_crypto_v1_sha256_buffers_t));
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00U, sizeof(cy_stc_crypto_v1_sha256_buffers_t));
hashState->block = (uint8_t*)((cy_stc_crypto_v1_sha256_buffers_t*)shaBuffers)->block;
hashState->hash = (uint8_t*)((cy_stc_crypto_v1_sha256_buffers_t*)shaBuffers)->hash;
@ -241,7 +243,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
#if (CPUSS_CRYPTO_SHA512 == 1)
case CY_CRYPTO_MODE_SHA384:
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00u, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00U, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
hashState->block = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->block;
hashState->hash = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->hash;
@ -255,7 +257,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
break;
case CY_CRYPTO_MODE_SHA512:
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00u, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00U, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
hashState->block = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->block;
hashState->hash = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->hash;
@ -269,7 +271,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
break;
case CY_CRYPTO_MODE_SHA512_224:
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00u, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00U, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
hashState->block = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->block;
hashState->hash = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->hash;
@ -283,7 +285,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
break;
case CY_CRYPTO_MODE_SHA512_256:
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00u, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
Cy_Crypto_Core_V1_MemSet(base, shaBuffers, 0x00U, sizeof(cy_stc_crypto_v1_sha512_buffers_t));
hashState->block = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->block;
hashState->hash = (uint8_t*)((cy_stc_crypto_v1_sha512_buffers_t*)shaBuffers)->hash;
@ -298,13 +300,14 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
#endif /* #if (CPUSS_CRYPTO_SHA512 == 1) */
default:
tmpResult = CY_CRYPTO_BAD_PARAMS;
break;
}
/* Set the SHA mode */
REG_CRYPTO_SHA_CTL(base) = (uint32_t)(_VAL2FLD(CRYPTO_SHA_CTL_MODE, (uint32_t)shaHwMode));
return (CY_CRYPTO_SUCCESS);
return (tmpResult);
}
/*******************************************************************************
@ -314,33 +317,33 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Init(CRYPTO_Type *base,
* Initializes the initial hash vector.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Start(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
{
hashState->blockIdx = 0u;
hashState->messageSize = 0u;
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if (hashState != NULL)
{
if (hashState->hashSize != 0)
hashState->blockIdx = 0U;
hashState->messageSize = 0U;
if (hashState->hashSize != 0U)
{
Cy_Crypto_Core_V1_MemCpy(base, hashState->hash, hashState->initialHash, (uint16_t)hashState->hashSize);
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -350,7 +353,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Start(CRYPTO_Type *base, cy_stc_cryp
* Performs the SHA calculation on one message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
@ -362,12 +365,12 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Start(CRYPTO_Type *base, cy_stc_cryp
* The size of the message whose Hash is being computed.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \note
* This function can be called several times only with message lengths dividable
* by block size. Only the last call to the function can process a message with
* the not dividable size.
* by the block size. Only the last call to the function can process a message with
* a not-dividable size.
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Update(CRYPTO_Type *base,
@ -375,13 +378,13 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Update(CRYPTO_Type *base,
uint8_t const *message,
uint32_t messageSize)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if ((hashState != NULL) && (message != NULL))
{
if (hashState->blockSize != 0)
if (hashState->blockSize != 0U)
{
if (messageSize > 0)
if (messageSize != 0U)
{
uint32_t blockSizeTmp = hashState->blockSize;
hashState->messageSize += messageSize;
@ -394,28 +397,28 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Update(CRYPTO_Type *base,
messageSize -= blockSizeTmp;
}
/* Remaining block will be calculated in Finish function */
/* The remaining block will be calculated in the Finish function. */
hashState->blockIdx = messageSize;
/* Copy the end of the message to the block */
Cy_Crypto_Core_V1_MemCpy(base, hashState->block, message, (uint16_t)(messageSize & (blockSizeTmp - 1u)));
}
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_V1_Sha_Finish
****************************************************************************//**
*
* Completes SHA calculation.
* Completes the SHA calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
@ -424,14 +427,14 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Update(CRYPTO_Type *base,
* The pointer to the calculated hash digest.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Finish(CRYPTO_Type *base,
cy_stc_crypto_sha_state_t *hashState,
uint8_t *digest)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if ((hashState != NULL) && (digest != NULL))
{
@ -439,7 +442,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Finish(CRYPTO_Type *base,
uint8_t *blockTmp = hashState->block;
uint32_t blockSizeTmp = hashState->blockSize;
uint32_t blockIdxTmp = hashState->blockIdx;
uint64_t finalMessageSizeInBits = (uint64_t)hashState->messageSize * 8u;
uint64_t finalMessageSizeInBits = (uint64_t)hashState->messageSize * 8U;
uint32_t size;
if (CY_CRYPTO_SHA512_BLOCK_SIZE == blockSizeTmp)
@ -452,10 +455,10 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Finish(CRYPTO_Type *base,
}
/* Append 1 bit to the end of the message */
blockTmp[blockIdxTmp] = 0x80u;
blockTmp[blockIdxTmp] = 0x80U;
/* Clear the rest of the block */
Cy_Crypto_Core_V1_MemSet(base, (void* )&blockTmp[blockIdxTmp + 1u], 0x00u, (uint16_t)(blockSizeTmp - blockIdxTmp - 1u));
Cy_Crypto_Core_V1_MemSet(base, (void* )&blockTmp[blockIdxTmp + 1U], 0x00U, (uint16_t)(blockSizeTmp - blockIdxTmp - 1U));
if (blockIdxTmp >= size)
{
@ -466,32 +469,32 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Finish(CRYPTO_Type *base,
Cy_Crypto_Core_V1_MemSet(base, blockTmp, 0x00u, (uint16_t)blockSizeTmp);
}
blockTmp[blockSizeTmp - 4u] = (uint8_t)((finalMessageSizeInBits) >> 24u);
blockTmp[blockSizeTmp - 3u] = (uint8_t)((finalMessageSizeInBits) >> 16u);
blockTmp[blockSizeTmp - 2u] = (uint8_t)((finalMessageSizeInBits) >> 8u);
blockTmp[blockSizeTmp - 1u] = (uint8_t)(finalMessageSizeInBits);
blockTmp[blockSizeTmp - 4U] = (uint8_t)((finalMessageSizeInBits) >> 24U);
blockTmp[blockSizeTmp - 3U] = (uint8_t)((finalMessageSizeInBits) >> 16U);
blockTmp[blockSizeTmp - 2U] = (uint8_t)((finalMessageSizeInBits) >> 8U);
blockTmp[blockSizeTmp - 1U] = (uint8_t)(finalMessageSizeInBits);
/* Process the last block */
Cy_Crypto_Core_V1_Sha_ProcessBlock(base, hashState, (uint8_t*)blockTmp);
/* Invert endians of the hash and copy it to digest, re-use the size variable */
size = (uint32_t)(hashState->digestSize / 4u);
size = (uint32_t)(hashState->digestSize / 4U);
for(; size != 0u; size--)
for(; size != 0U; size--)
{
*(digest) = *(hashTmp+3);
*(digest+1) = *(hashTmp+2);
*(digest+2) = *(hashTmp+1);
*(digest+3) = *(hashTmp);
digest += 4;
hashTmp += 4;
digest += 4U;
hashTmp += 4U;
}
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -501,30 +504,30 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Finish(CRYPTO_Type *base,
* Clears the used memory buffers.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Free(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if (hashState != NULL)
{
/* Clears the memory buffer. */
Cy_Crypto_Core_V1_MemSet(base, hashState->block, 0x00u, (uint16_t)hashState->blockSize);
Cy_Crypto_Core_V1_MemSet(base, hashState->hash, 0x00u, (uint16_t)hashState->hashSize);
Cy_Crypto_Core_V1_MemSet(base, hashState->roundMem, 0x00u, (uint16_t)hashState->roundMemSize);
Cy_Crypto_Core_V1_MemSet(base, hashState->block, 0x00U, (uint16_t)hashState->blockSize);
Cy_Crypto_Core_V1_MemSet(base, hashState->hash, 0x00U, (uint16_t)hashState->hashSize);
Cy_Crypto_Core_V1_MemSet(base, hashState->roundMem, 0x00U, (uint16_t)hashState->roundMemSize);
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
return (myResult);
return (tmpResult);
}
@ -535,7 +538,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Free(CRYPTO_Type *base, cy_stc_crypt
* Performs the SHA Hash function.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param mode
* \ref cy_en_crypto_sha_mode_t
@ -550,7 +553,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha_Free(CRYPTO_Type *base, cy_stc_crypt
* The pointer to the hash digest.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha(CRYPTO_Type *base,
@ -559,31 +562,31 @@ cy_en_crypto_status_t Cy_Crypto_Core_V1_Sha(CRYPTO_Type *base,
uint8_t *digest,
cy_en_crypto_sha_mode_t mode)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
void *shaBuffers = (void *)REG_CRYPTO_MEM_BUFF(base);
cy_stc_crypto_sha_state_t myHashState;
cy_stc_crypto_sha_state_t myHashState = { 0 };
myResult = Cy_Crypto_Core_V1_Sha_Init (base, &myHashState, mode, shaBuffers);
tmpResult = Cy_Crypto_Core_V1_Sha_Init (base, &myHashState, mode, shaBuffers);
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V1_Sha_Start (base, &myHashState);
tmpResult = Cy_Crypto_Core_V1_Sha_Start (base, &myHashState);
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V1_Sha_Update (base, &myHashState, message, messageSize);
tmpResult = Cy_Crypto_Core_V1_Sha_Update (base, &myHashState, message, messageSize);
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V1_Sha_Finish (base, &myHashState, digest);
tmpResult = Cy_Crypto_Core_V1_Sha_Finish (base, &myHashState, digest);
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V1_Sha_Free (base, &myHashState);
tmpResult = Cy_Crypto_Core_V1_Sha_Free (base, &myHashState);
}
return (myResult);
return (tmpResult);
}

View File

@ -42,7 +42,7 @@
* The function to initialize SHA operation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to a Hash State.
@ -52,10 +52,10 @@
* CY_CRYPTO_SHA512, CY_CRYPTO_SHA384, CY_CRYPTO_SHA512_224, CY_CRYPTO_SHA512_256
*
* \param shaBuffers
* The pointer to memory buffers storage
* The pointer to the memory buffers storage.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Init(CRYPTO_Type *base,
@ -63,6 +63,8 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Init(CRYPTO_Type *base,
cy_en_crypto_sha_mode_t mode,
void *shaBuffers)
{
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
/* Initialization vectors for different modes of the SHA algorithm */
#if (CPUSS_CRYPTO_SHA1 == 1)
static const uint8_t sha1InitHash[] =
@ -149,7 +151,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Init(CRYPTO_Type *base,
CY_ASSERT_L1(hashState != NULL);
Cy_Crypto_Core_V2_MemSet(base, hashState, 0x00u, sizeof(cy_stc_crypto_sha_state_t));
Cy_Crypto_Core_V2_MemSet(base, hashState, 0x00U, sizeof(cy_stc_crypto_sha_state_t));
switch (mode)
{
@ -209,10 +211,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Init(CRYPTO_Type *base,
break;
#endif /* #if (CPUSS_CRYPTO_SHA512 == 1) */
default:
tmpResult = CY_CRYPTO_BAD_PARAMS;
break;
}
return (CY_CRYPTO_SUCCESS);
return (tmpResult);
}
/*******************************************************************************
@ -222,39 +225,39 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Init(CRYPTO_Type *base,
* Initializes the initial hash vector.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Start(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
{
hashState->blockIdx = 0u;
hashState->messageSize = 0u;
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if (hashState != NULL)
{
if (hashState->hashSize != 0)
hashState->blockIdx = 0U;
hashState->messageSize = 0U;
if (hashState->hashSize != 0U)
{
Cy_Crypto_Core_V2_RBClear(base);
Cy_Crypto_Core_V2_Sync(base);
Cy_Crypto_Core_V2_FFStart(base, CY_CRYPTO_V2_RB_FF_LOAD0, hashState->initialHash, hashState->hashSize);
Cy_Crypto_Core_V2_RBXor(base, 0u, hashState->hashSize);
Cy_Crypto_Core_V2_RBXor(base, 0U, hashState->hashSize);
Cy_Crypto_Core_V2_Sync(base);
Cy_Crypto_Core_V2_RBSwap(base);
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -264,7 +267,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Start(CRYPTO_Type *base, cy_stc_cryp
* Performs the SHA calculation on one message.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
@ -276,12 +279,12 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Start(CRYPTO_Type *base, cy_stc_cryp
* The size of the message whose Hash is being computed.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* \note
* This function can be called several times only with message lengths dividable
* by block size. Only the last call to the function can process a message with
* the not dividable size.
* by the block size. Only the last call to the function can process a message with
* a not-dividable size.
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Update(CRYPTO_Type *base,
@ -289,13 +292,13 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Update(CRYPTO_Type *base,
uint8_t const *message,
uint32_t messageSize)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if ((hashState != NULL) && (message != NULL))
{
if (hashState->blockSize != 0)
if (hashState->blockSize != 0U)
{
if (messageSize > 0)
if (messageSize != 0U)
{
hashState->messageSize += messageSize;
@ -303,7 +306,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Update(CRYPTO_Type *base,
while (messageSize >= hashState->blockSize)
{
Cy_Crypto_Core_V2_RBXor(base, 0u, hashState->blockSize);
Cy_Crypto_Core_V2_RBXor(base, 0U, hashState->blockSize);
messageSize -= hashState->blockSize;
@ -314,11 +317,11 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Update(CRYPTO_Type *base,
hashState->blockIdx = messageSize;
}
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -328,7 +331,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Update(CRYPTO_Type *base,
* Completes SHA calculation.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
@ -337,21 +340,21 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Update(CRYPTO_Type *base,
* The pointer to the calculated hash digest.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Finish(CRYPTO_Type *base,
cy_stc_crypto_sha_state_t *hashState,
uint8_t *digest)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if ((hashState != NULL) && (digest != NULL))
{
uint32_t myBlockSize = hashState->blockSize;
uint32_t myBlockIdx = hashState->blockIdx;
uint64_t finalMessageSizeInBits = (uint64_t)hashState->messageSize * 8u;
uint64_t finalMessageSizeInBits = (uint64_t)hashState->messageSize * 8U;
uint32_t size;
if (CY_CRYPTO_SHA512_BLOCK_SIZE == myBlockSize)
@ -364,13 +367,13 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Finish(CRYPTO_Type *base,
}
/* Load the end of the message (tail that less then block size) to the register buffer */
Cy_Crypto_Core_V2_RBXor(base, 0u, myBlockIdx);
Cy_Crypto_Core_V2_RBXor(base, 0U, myBlockIdx);
/* Sync until XOR operation is completed */
Cy_Crypto_Core_V2_Sync(base);
/* Append 1 bit to the end of the message */
Cy_Crypto_Core_V2_RBSetByte(base, myBlockIdx, 0x80u);
Cy_Crypto_Core_V2_RBSetByte(base, myBlockIdx, 0x80U);
if (myBlockIdx >= size)
{
@ -381,12 +384,12 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Finish(CRYPTO_Type *base,
/* Append message size into last of the block */
/* In case of u32SizeInByte * 8 > u32Max */
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 5u, (uint8_t)(finalMessageSizeInBits >> 32u));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 5U, (uint8_t)(finalMessageSizeInBits >> 32U));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 4u, (uint8_t)(finalMessageSizeInBits >> 24u));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 3u, (uint8_t)(finalMessageSizeInBits >> 16u));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 2u, (uint8_t)(finalMessageSizeInBits >> 8u));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 1u, (uint8_t)(finalMessageSizeInBits));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 4U, (uint8_t)(finalMessageSizeInBits >> 24U));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 3U, (uint8_t)(finalMessageSizeInBits >> 16U));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 2U, (uint8_t)(finalMessageSizeInBits >> 8U));
Cy_Crypto_Core_V2_RBSetByte(base, myBlockSize - 1U, (uint8_t)(finalMessageSizeInBits));
Cy_Crypto_Core_V2_Run(base, hashState->mode);
Cy_Crypto_Core_V2_Sync(base);
@ -394,14 +397,14 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Finish(CRYPTO_Type *base,
/* Write digest. */
Cy_Crypto_Core_V2_FFStart(base, CY_CRYPTO_V2_RB_FF_STORE, digest, hashState->digestSize);
Cy_Crypto_Core_V2_RBSwap(base);
Cy_Crypto_Core_V2_RBStore(base, 0u, hashState->digestSize);
Cy_Crypto_Core_V2_RBStore(base, 0U, hashState->digestSize);
Cy_Crypto_Core_V2_FFStoreSync(base);
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -411,31 +414,31 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Finish(CRYPTO_Type *base,
* Clears the used memory buffers.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param hashState
* The pointer to the SHA context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
* *******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Free(CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
if (hashState != NULL)
{
Cy_Crypto_Core_V2_MemSet(base, hashState, 0x00u, sizeof(cy_stc_crypto_sha_state_t));
Cy_Crypto_Core_V2_MemSet(base, hashState, 0x00U, sizeof(cy_stc_crypto_sha_state_t));
/* Clears the memory buffer. */
Cy_Crypto_Core_V2_RBClear(base);
Cy_Crypto_Core_V2_Sync(base);
myResult = CY_CRYPTO_SUCCESS;
tmpResult = CY_CRYPTO_SUCCESS;
}
return (myResult);
return (tmpResult);
}
/*******************************************************************************
@ -445,7 +448,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Free(CRYPTO_Type *base, cy_stc_crypt
* Performs the SHA Hash function.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param mode
* \ref cy_en_crypto_sha_mode_t
@ -460,7 +463,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha_Free(CRYPTO_Type *base, cy_stc_crypt
* The pointer to the hash digest.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha(CRYPTO_Type *base,
@ -469,32 +472,32 @@ cy_en_crypto_status_t Cy_Crypto_Core_V2_Sha(CRYPTO_Type *base,
uint8_t *digest,
cy_en_crypto_sha_mode_t mode)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_BAD_PARAMS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_BAD_PARAMS;
/* Allocate space for the structure which stores the SHA context */
cy_stc_crypto_sha_state_t hashState;
cy_stc_crypto_sha_state_t hashState = { 0 };
/* No any buffers needed for Crypto_ver2 IP block */
myResult = Cy_Crypto_Core_V2_Sha_Init (base, &hashState, mode, NULL);
/* No buffers are needed for the Crypto_ver2 IP block. */
tmpResult = Cy_Crypto_Core_V2_Sha_Init (base, &hashState, mode, NULL);
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V2_Sha_Start (base, &hashState);
tmpResult = Cy_Crypto_Core_V2_Sha_Start (base, &hashState);
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V2_Sha_Update (base, &hashState, message, messageSize);
tmpResult = Cy_Crypto_Core_V2_Sha_Update (base, &hashState, message, messageSize);
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V2_Sha_Finish (base, &hashState, digest);
tmpResult = Cy_Crypto_Core_V2_Sha_Finish (base, &hashState, digest);
}
if (CY_CRYPTO_SUCCESS == myResult)
if (CY_CRYPTO_SUCCESS == tmpResult)
{
myResult = Cy_Crypto_Core_V2_Sha_Free (base, &hashState);
tmpResult = Cy_Crypto_Core_V2_Sha_Free (base, &hashState);
}
return (myResult);
return (tmpResult);
}

View File

@ -41,10 +41,10 @@ static void Cy_Crypto_Core_V1_Trng_Init(CRYPTO_Type *base);
* Function Name: Cy_Crypto_Core_V1_Trng_Init
****************************************************************************//**
*
* Initializes the TRND parameters.
* Initializes the TRNG parameters.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
static void Cy_Crypto_Core_V1_Trng_Init(CRYPTO_Type *base)
@ -57,15 +57,15 @@ static void Cy_Crypto_Core_V1_Trng_Init(CRYPTO_Type *base)
REG_CRYPTO_TR_MON_AP_CTL(base) = CY_CRYPTO_V1_TR_AC_CUTOFF;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_V1_Trng
****************************************************************************//**
*
* Generates a True Random Number and returns it in the
* cfContext->trngNumPtr.
* Generates a True Random Number.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param GAROPol
* The polynomial for the programmable Galois ring oscillator.
@ -80,7 +80,7 @@ static void Cy_Crypto_Core_V1_Trng_Init(CRYPTO_Type *base)
* The pointer to a generated true random number. Must be 4-byte aligned.
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V1_Trng(CRYPTO_Type *base,

View File

@ -40,10 +40,10 @@ static void Cy_Crypto_Core_V2_Trng_Init(CRYPTO_Type *base);
* Function Name: Cy_Crypto_Core_V2_Trng_Init
****************************************************************************//**
*
* Initializes the TRND parameters.
* Initializes the TRNG parameters.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
*******************************************************************************/
static void Cy_Crypto_Core_V2_Trng_Init(CRYPTO_Type *base)
@ -56,15 +56,15 @@ static void Cy_Crypto_Core_V2_Trng_Init(CRYPTO_Type *base)
REG_CRYPTO_TR_MON_AP_CTL(base) = CY_CRYPTO_V2_TR_AC_CUTOFF;
}
/*******************************************************************************
* Function Name: Cy_Crypto_Core_V2_Trng
****************************************************************************//**
*
* Generates a True Random Number and returns it in the
* cfContext->trngNumPtr.
* Generates a True Random Number.
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param GAROPol
* The polynomial for the programmable Galois ring oscillator.
@ -79,7 +79,7 @@ static void Cy_Crypto_Core_V2_Trng_Init(CRYPTO_Type *base)
* The pointer to a generated true random number. Must be 4-byte aligned.
*
* \return
* A Crypto status \ref en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
cy_en_crypto_status_t Cy_Crypto_Core_V2_Trng(CRYPTO_Type *base,

View File

@ -46,7 +46,7 @@ void Cy_Crypto_Core_Vu_SetMemValue(CRYPTO_Type *base, uint32_t dstReg, uint8_t c
Cy_Crypto_Core_Vu_WaitForComplete(base);
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
CY_CRYPTO_VU_SAVE_REG(base, CY_CRYPTO_VU_HW_REG0, &reg0_data);
CY_CRYPTO_VU_SAVE_REG(base, CY_CRYPTO_VU_HW_REG1, &reg1_data);
@ -61,10 +61,10 @@ void Cy_Crypto_Core_Vu_SetMemValue(CRYPTO_Type *base, uint32_t dstReg, uint8_t c
CY_ASSERT_L1(size <= Cy_Crypto_Core_Vu_RegBitSizeRead(base, dstReg));
CY_ASSERT_L1(((uint32_t)Cy_Crypto_Core_Vu_RegMemPointer(base, dstReg) + byteSize - 1) < ((uint32_t)REG_CRYPTO_MEM_BUFF(base) + CY_CRYPTO_MEM_BUFF_SIZE) );
CY_ASSERT_L1( (((uint32_t)Cy_Crypto_Core_Vu_RegMemPointer(base, dstReg) + byteSize) - 1u) < ((uint32_t)REG_CRYPTO_MEM_BUFF(base) + CY_CRYPTO_MEM_BUFF_SIZE));
Cy_Crypto_Core_MemCpy(base, (void*)Cy_Crypto_Core_Vu_RegMemPointer(base, dstReg), (const void*)src, byteSize);
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
CY_CRYPTO_VU_RESTORE_REG(base, CY_CRYPTO_VU_HW_REG0, reg0_data);
CY_CRYPTO_VU_RESTORE_REG(base, CY_CRYPTO_VU_HW_REG1, reg1_data);
@ -78,7 +78,7 @@ void Cy_Crypto_Core_Vu_GetMemValue(CRYPTO_Type *base, uint8_t *dst, uint32_t src
Cy_Crypto_Core_Vu_WaitForComplete(base);
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
CY_CRYPTO_VU_SAVE_REG(base, CY_CRYPTO_VU_HW_REG0, &reg0_data);
CY_CRYPTO_VU_SAVE_REG(base, CY_CRYPTO_VU_HW_REG1, &reg1_data);
@ -92,11 +92,11 @@ void Cy_Crypto_Core_Vu_GetMemValue(CRYPTO_Type *base, uint8_t *dst, uint32_t src
}
CY_ASSERT_L1(size <= Cy_Crypto_Core_Vu_RegBitSizeRead(base, srcReg));
CY_ASSERT_L1(((uint32_t)Cy_Crypto_Core_Vu_RegMemPointer(base, srcReg) + byteSize - 1) < ((uint32_t)REG_CRYPTO_MEM_BUFF(base) + CY_CRYPTO_MEM_BUFF_SIZE) );
CY_ASSERT_L1((((uint32_t)Cy_Crypto_Core_Vu_RegMemPointer(base, srcReg) + byteSize) - 1u) < ((uint32_t)REG_CRYPTO_MEM_BUFF(base) + CY_CRYPTO_MEM_BUFF_SIZE) );
Cy_Crypto_Core_MemCpy(base, (void*)dst, (void*)Cy_Crypto_Core_Vu_RegMemPointer(base, srcReg), byteSize);
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
CY_CRYPTO_VU_RESTORE_REG(base, CY_CRYPTO_VU_HW_REG0, reg0_data);
CY_CRYPTO_VU_RESTORE_REG(base, CY_CRYPTO_VU_HW_REG1, reg1_data);
@ -129,7 +129,7 @@ cy_en_crypto_status_t Cy_Crypto_Core_Cleanup(CRYPTO_Type *base)
/* AES */
REG_CRYPTO_AES_CTL(base) = 0u;
if (cy_device->cryptoVersion == 1u)
if (CY_CRYPTO_HW_V1)
{
REG_CRYPTO_CRC_LFSR_CTL(base) = 0u;
REG_CRYPTO_SHA_CTL(base) = 0u;
@ -145,69 +145,69 @@ cy_en_crypto_status_t Cy_Crypto_Core_Cleanup(CRYPTO_Type *base)
Cy_Crypto_Core_V2_RBClear(base);
}
Cy_Crypto_Core_MemSet(base, (void *)REG_CRYPTO_MEM_BUFF(base), 0u, CY_CRYPTO_MEM_BUFF_SIZE);
Cy_Crypto_Core_MemSet(base, (void *)REG_CRYPTO_MEM_BUFF(base), 0u, (uint16_t)CY_CRYPTO_MEM_BUFF_SIZE);
return (CY_CRYPTO_SUCCESS);
}
bool Cy_Crypto_Core_Vu_IsRegZero(CRYPTO_Type *base, uint32_t srcReg)
{
bool result;
uint16_t status;
bool tmpResult;
uint32_t status;
CY_CRYPTO_VU_TST(base, srcReg);
status = Cy_Crypto_Core_Vu_StatusRead(base);
if (status & CY_CRYPTO_VU_STATUS_ZERO_BIT)
if (0u != (status & CY_CRYPTO_VU_STATUS_ZERO_BIT))
{
result = true;
tmpResult = true;
}
else
{
result = false;
tmpResult = false;
}
return result;
return tmpResult;
}
bool Cy_Crypto_Core_Vu_IsRegEqual(CRYPTO_Type *base, uint32_t srcReg0, uint32_t srcReg1)
{
bool result;
uint16_t status;
bool tmpResult;
uint32_t status;
CY_CRYPTO_VU_CMP_SUB (base, srcReg1, srcReg0); /* C = (a >= b) */
status = Cy_Crypto_Core_Vu_StatusRead(base);
if (status & CY_CRYPTO_VU_STATUS_ZERO_BIT)
if (0u != (status & CY_CRYPTO_VU_STATUS_ZERO_BIT))
{
result = true;
tmpResult = true;
}
else
{
result = false;
tmpResult = false;
}
return result;
return tmpResult;
}
bool Cy_Crypto_Core_Vu_IsRegLess(CRYPTO_Type *base, uint32_t srcReg0, uint32_t srcReg1)
{
bool result;
uint16_t status;
bool tmpResult;
uint32_t status;
CY_CRYPTO_VU_CMP_SUB (base, srcReg1, srcReg0); /* C = (a >= b) */
status = Cy_Crypto_Core_Vu_StatusRead(base);
if (status & CY_CRYPTO_VU_STATUS_CARRY_BIT)
if (0u != (status & CY_CRYPTO_VU_STATUS_CARRY_BIT))
{
result = true;
tmpResult = true;
}
else
{
result = false;
tmpResult = false;
}
return result;
return tmpResult;
}

View File

@ -46,7 +46,7 @@
#if defined(CY_IP_MXCRYPTO)
/* The pointer to the CRYPTO instance address. */
/* The pointer to the CRYPTO instance. */
#define CY_CRYPTO_BASE ((CRYPTO_Type *)cy_device->cryptoBase)
typedef struct
@ -724,19 +724,19 @@ void Cy_Crypto_Server_GetDataHandler(void)
* This function is internal and should not to be called directly by user software
*
* \param base
* The pointer to the CRYPTO instance address.
* The pointer to the CRYPTO instance.
*
* \param cryptoContext
* The pointer to cy_stc_crypto_context_t structure which stores
* the Crypto driver context.
*
* \return
* A Crypto status \ref cy_en_crypto_status_t.
* \ref cy_en_crypto_status_t
*
*******************************************************************************/
static cy_en_crypto_status_t Cy_Crypto_Core_CheckHwForErrors(cy_stc_crypto_context_t *cryptoContext)
{
cy_en_crypto_status_t myResult = CY_CRYPTO_SUCCESS;
cy_en_crypto_status_t tmpResult = CY_CRYPTO_SUCCESS;
uint32_t myErrorStatus0;
uint32_t myErrorStatus1;
@ -750,7 +750,7 @@ static cy_en_crypto_status_t Cy_Crypto_Core_CheckHwForErrors(cy_stc_crypto_conte
if (_FLD2VAL(CRYPTO_ERROR_STATUS1_VALID, myErrorStatus1) == 1u)
{
myResult = CY_CRYPTO_HW_ERROR;
tmpResult = CY_CRYPTO_HW_ERROR;
cy_crypto_serverContext->isHwErrorOccured = true;
}
@ -763,7 +763,7 @@ static cy_en_crypto_status_t Cy_Crypto_Core_CheckHwForErrors(cy_stc_crypto_conte
if (_FLD2VAL(CRYPTO_ERROR_STATUS1_VALID, myErrorStatus1) == 1u)
{
myResult = CY_CRYPTO_HW_ERROR;
tmpResult = CY_CRYPTO_HW_ERROR;
}
cy_crypto_serverContext->isHwErrorOccured = false;
@ -772,7 +772,7 @@ static cy_en_crypto_status_t Cy_Crypto_Core_CheckHwForErrors(cy_stc_crypto_conte
cryptoContext->hwErrorStatus.errorStatus0 = myErrorStatus0;
cryptoContext->hwErrorStatus.errorStatus1 = myErrorStatus1;
return (myResult);
return (tmpResult);
}
#endif /* CY_IP_MXCRYPTO */