Client Functions¶
-
group
group_crypto_cli_functions
Functions
-
cy_en_crypto_status_t
Cy_Crypto_Init
(cy_stc_crypto_config_t const *config, cy_stc_crypto_context_t *context) This function initializes the Crypto context buffer and configures the Crypto driver.
Must be called at first.
To start working with Crypto methods after Crypto_Init(), call Crypto_Enable() to turn-on the Crypto Hardware.
- Function Usage
/* Scenario: Configure Server and Client as follows: * Server: * - IPC channel for communication: 13 * - IPC interrupt structure used for new request notifications: 13 * - Data request handler: default * - Hardware errors handler: default * Client: * - IPC channel for communication: 13 * - IPC interrupt structure used for data ready notifications: 14 * - Data Complete callback: not used */ #define MY_CHAN_CRYPTO (uint32_t)(13u) /* IPC data channel for the Crypto */ #define MY_INTR_CRYPTO_SRV (uint32_t)(13u) /* IPC interrupt structure for the Crypto server */ #define MY_INTR_CRYPTO_CLI (uint32_t)(14u) /* IPC interrupt structure for the Crypto client */ #define MY_INTR_CRYPTO_SRV_MUX (IRQn_Type)(2u) /* CM0+ IPC interrupt mux number the Crypto server */ #define MY_INTR_CRYPTO_CLI_MUX (IRQn_Type)(3u) /* CM0+ IPC interrupt mux number the Crypto client */ #define MY_INTR_CRYPTO_ERR_MUX (IRQn_Type)(4u) /* CM0+ ERROR interrupt mux number the Crypto server */ const cy_stc_crypto_config_t myCryptoConfig = { /* .ipcChannel */ MY_CHAN_CRYPTO, /* .acquireNotifierChannel */ MY_INTR_CRYPTO_SRV, /* .releaseNotifierChannel */ MY_INTR_CRYPTO_CLI, /* .releaseNotifierConfig */ { #if (CY_CPU_CORTEX_M0P) /* .intrSrc */ MY_INTR_CRYPTO_CLI_MUX, /* .cm0pSrc */ cpuss_interrupts_ipc_14_IRQn, /* depends on selected releaseNotifierChannel value */ #else /* .intrSrc */ cpuss_interrupts_ipc_14_IRQn, /* depends on selected releaseNotifierChannel value */ #endif /* .intrPriority */ 2u, }, /* .userCompleteCallback */ NULL, /* .userGetDataHandler */ NULL, /* .userErrorHandler */ NULL, /* .acquireNotifierConfig */ { #if (CY_CPU_CORTEX_M0P) /* .intrSrc */ MY_INTR_CRYPTO_SRV_MUX, /* to use with DeepSleep mode should be in DeepSleep capable muxer's range */ /* .cm0pSrc */ cpuss_interrupts_ipc_13_IRQn, /* depends on selected acquireNotifierChannel value */ #else /* .intrSrc */ cpuss_interrupts_ipc_13_IRQn, /* depends on selected acquireNotifierChannel value */ #endif /* .intrPriority */ 2u, }, /* .cryptoErrorIntrConfig */ { #if (CY_CPU_CORTEX_M0P) /* .intrSrc */ MY_INTR_CRYPTO_ERR_MUX, /* .cm0pSrc */ cpuss_interrupt_crypto_IRQn, #else /* .intrSrc */ cpuss_interrupt_crypto_IRQn, #endif /* .intrPriority */ 2u, } }; cy_stc_crypto_context_t myCryptoContext; cy_en_crypto_status_t cryptoStatus; cryptoStatus = Cy_Crypto_Init(&myCryptoConfig, &myCryptoContext); /* ... check for errors... */ cryptoStatus = Cy_Crypto_Enable(); /* ... check for errors... */
- Parameters
config – The pointer to the Crypto configuration structure.
context – The pointer to the cy_stc_crypto_context_t instance of structure that stores the Crypto driver common context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_DeInit
(void) This function de-initializes the Crypto driver.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Enable
(void) This function enables (turns on) the Crypto hardware.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Disable
(void) This function disables (turns off) the Crypto hardware.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Sync
(bool isBlocking) This function waits or just checks (depending on the parameter) for the Crypto operation to complete.
- Parameters
isBlocking – Set whether Crypto_Sync is blocking: True - is blocking. False - is not blocking.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_GetErrorStatus
(cy_stc_crypto_hw_error_t *hwErrorCause) This function returns a cause of a Crypto hardware error.
It is independent of the Crypto previous state.
- Parameters
hwErrorCause – cy_stc_crypto_hw_error_t.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Prng_Init
(uint32_t lfsr32InitState, uint32_t lfsr31InitState, uint32_t lfsr29InitState, cy_stc_crypto_context_prng_t *cfContext) This function initializes parameters of the PRNG.
Call to initialize this encryption technique before using any associated functions. You must initialize this technique again after using any other encryption technique. Invoking this function resets the pseudo random sequence.
- Function Usage
/* Initialization seed values fro Pseudo Random Generator */ #define LFSR32_INITSTATE (0xd8959bc9) #define LFSR31_INITSTATE (0x2bb911f8) #define LFSR29_INITSTATE (0x060c31b7) #define MAX_PRNG_VALUE (255UL) /* Generated Random Number */ uint32_t rndNum = 0; cy_stc_crypto_context_prng_t cryptoPrngContext; cy_en_crypto_status_t cryptoStatus; /* Initialize Pseudo Random Generator in Crypto Driver */ cryptoStatus = Cy_Crypto_Prng_Init( LFSR32_INITSTATE, LFSR31_INITSTATE, LFSR29_INITSTATE, &cryptoPrngContext); /* ... check for errors... */ /* Generate Pseudo Random number into rndNum variable */ cryptoStatus = Cy_Crypto_Prng_Generate(MAX_PRNG_VALUE, &rndNum, &cryptoPrngContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
lfsr32InitState – A non-zero seed value for the first LFSR. User selected.
lfsr31InitState – A non-zero seed value for the second LFSR. User selected.
lfsr29InitState – A non-zero seed value for the third LFSR. User selected.
cfContext – The pointer to the cy_stc_crypto_context_prng_t structure that stores the Crypto function context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Prng_Generate
(uint32_t max, uint32_t *randomNum, cy_stc_crypto_context_prng_t *cfContext) This function generates 32-bit the Pseudo Random Number.
It depends on Cy_Crypto_Prng_Init that should be called before.
- Function Usage
/* Initialization seed values fro Pseudo Random Generator */ #define LFSR32_INITSTATE (0xd8959bc9) #define LFSR31_INITSTATE (0x2bb911f8) #define LFSR29_INITSTATE (0x060c31b7) #define MAX_PRNG_VALUE (255UL) /* Generated Random Number */ uint32_t rndNum = 0; cy_stc_crypto_context_prng_t cryptoPrngContext; cy_en_crypto_status_t cryptoStatus; /* Initialize Pseudo Random Generator in Crypto Driver */ cryptoStatus = Cy_Crypto_Prng_Init( LFSR32_INITSTATE, LFSR31_INITSTATE, LFSR29_INITSTATE, &cryptoPrngContext); /* ... check for errors... */ /* Generate Pseudo Random number into rndNum variable */ cryptoStatus = Cy_Crypto_Prng_Generate(MAX_PRNG_VALUE, &rndNum, &cryptoPrngContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
max – The maximum value of a generated random number.
randomNum – The pointer to a variable to store the generated pseudo random number. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_prng_t structure that stores the Crypto function context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Aes_Init
(uint32_t *key, cy_en_crypto_aes_key_length_t keyLength, cy_stc_crypto_context_aes_t *cfContext) This function initializes the AES operation by setting key and key length.
Call to initialize this encryption technique before using any associated functions. You must initialize this technique again after using any other encryption technique.
- Function Usage
/* All data arrays should be 4-byte aligned */ CY_ALIGN(4) uint8_t aesKey[CY_CRYPTO_AES_128_KEY_SIZE] = { 0x2Bu, 0x7Eu, 0x15u, 0x16u, 0x28u, 0xAEu, 0xD2u, 0xA6u, 0xABu, 0xF7u, 0x15u, 0x88u, 0x09u, 0xCFu, 0x4Fu, 0x3Cu }; CY_ALIGN(4) uint8_t aesEcbPlainText[CY_CRYPTO_AES_BLOCK_SIZE] = { 0x6Bu, 0xC0u, 0xBCu, 0xE1u, 0x2Au, 0x45u, 0x99u, 0x91u, 0xE1u, 0x34u, 0x74u, 0x1Au, 0x7Fu, 0x9Eu, 0x19u, 0x25u }; CY_ALIGN(4) uint8_t aesEcbCipherText[CY_CRYPTO_AES_BLOCK_SIZE] = {0}; cy_stc_crypto_context_aes_t cryptoAesContext; cy_en_crypto_status_t cryptoStatus; /* Initialize Crypto AES functionality */ cryptoStatus = Cy_Crypto_Aes_Init( (uint32_t *)aesKey, CY_CRYPTO_KEY_AES_128, &cryptoAesContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */ /* Encrypt one block (16Bytes) by AES128 */ cryptoStatus = Cy_Crypto_Aes_Ecb_Run( CY_CRYPTO_ENCRYPT, (uint32_t*)aesEcbCipherText, (uint32_t*)aesEcbPlainText, &cryptoAesContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
key – The pointer to the encryption/decryption key. Must be 4-byte aligned.
keyLength – cy_en_crypto_aes_key_length_t
cfContext – The pointer to the cy_stc_crypto_context_aes_t structure that stores all internal variables the Crypto driver requires.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Aes_Ecb_Run
(cy_en_crypto_dir_mode_t dirMode, uint32_t *dstBlock, uint32_t *srcBlock, cy_stc_crypto_context_aes_t *cfContext) This function performs AES operation on one 16-byte block (see CY_CRYPTO_AES_BLOCK_SIZE).
The AES key must be set before by invoking Cy_Crypto_Aes_Init().
- Function Usage
/* All data arrays should be 4-byte aligned */ CY_ALIGN(4) uint8_t aesKey[CY_CRYPTO_AES_128_KEY_SIZE] = { 0x2Bu, 0x7Eu, 0x15u, 0x16u, 0x28u, 0xAEu, 0xD2u, 0xA6u, 0xABu, 0xF7u, 0x15u, 0x88u, 0x09u, 0xCFu, 0x4Fu, 0x3Cu }; CY_ALIGN(4) uint8_t aesEcbPlainText[CY_CRYPTO_AES_BLOCK_SIZE] = { 0x6Bu, 0xC0u, 0xBCu, 0xE1u, 0x2Au, 0x45u, 0x99u, 0x91u, 0xE1u, 0x34u, 0x74u, 0x1Au, 0x7Fu, 0x9Eu, 0x19u, 0x25u }; CY_ALIGN(4) uint8_t aesEcbCipherText[CY_CRYPTO_AES_BLOCK_SIZE] = {0}; cy_stc_crypto_context_aes_t cryptoAesContext; cy_en_crypto_status_t cryptoStatus; /* Initialize Crypto AES functionality */ cryptoStatus = Cy_Crypto_Aes_Init( (uint32_t *)aesKey, CY_CRYPTO_KEY_AES_128, &cryptoAesContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */ /* Encrypt one block (16Bytes) by AES128 */ cryptoStatus = Cy_Crypto_Aes_Ecb_Run( CY_CRYPTO_ENCRYPT, (uint32_t*)aesEcbCipherText, (uint32_t*)aesEcbPlainText, &cryptoAesContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
dirMode – Can be CY_CRYPTO_ENCRYPT or CY_CRYPTO_DECRYPT (cy_en_crypto_dir_mode_t).
srcBlock – The pointer to a 16-byte source block. Must be 4-byte aligned.
dstBlock – The pointer to a 16-byte destination cipher block. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_aes_t instance of structure that stores all AES internal variables.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Aes_Cbc_Run
(cy_en_crypto_dir_mode_t dirMode, uint32_t srcSize, uint32_t *ivPtr, uint32_t *dst, uint32_t *src, cy_stc_crypto_context_aes_t *cfContext) This function performs AES operation on a plain text with Cipher Block Chaining (CBC).
The key must be set before by invoking Cy_Crypto_Aes_Init().
- Parameters
dirMode – Can be CY_CRYPTO_ENCRYPT or CY_CRYPTO_DECRYPT (cy_en_crypto_dir_mode_t)
srcSize – The size of the source plain text.
ivPtr – The pointer to the initial vector. Must be 4-byte aligned.
dst – The pointer to a destination cipher text. Must be 4-byte aligned.
src – The pointer to a source plain text. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_aes_t structure that stores all internal variables the Crypto driver requires.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Aes_Cfb_Run
(cy_en_crypto_dir_mode_t dirMode, uint32_t srcSize, uint32_t *ivPtr, uint32_t *dst, uint32_t *src, cy_stc_crypto_context_aes_t *cfContext) This function performs AES operation on a plain text with Cipher Feedback mode (CFB).
The key must be set before by invoking Cy_Crypto_Aes_Init().
- Parameters
dirMode – Can be CY_CRYPTO_ENCRYPT or CY_CRYPTO_DECRYPT (cy_en_crypto_dir_mode_t)
srcSize – The size of the source plain text.
ivPtr – The pointer to the initial vector. Must be 4-byte aligned.
dst – The pointer to the destination cipher text. Must be 4-byte aligned.
src – The pointer to the source plain text. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_aes_t structure that stores all internal variables the Crypto driver requires.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Aes_Ctr_Run
(cy_en_crypto_dir_mode_t dirMode, uint32_t srcSize, uint32_t *srcOffset, uint32_t nonceCounter[CY_CRYPTO_AES_BLOCK_SIZE / 8u], uint32_t streamBlock[CY_CRYPTO_AES_BLOCK_SIZE / 8u], uint32_t *dst, uint32_t *src, cy_stc_crypto_context_aes_t *cfContext) This function performs AES operation on a plain text with Cipher Block Counter mode (CTR).
NOTE: preparation of the unique nonceCounter for each block is the user’s responsibility. This function is dependent on the key being set before invoking Cy_Crypto_Aes_Init().
- Parameters
dirMode – Can be CY_CRYPTO_ENCRYPT or CY_CRYPTO_DECRYPT (cy_en_crypto_dir_mode_t)
srcSize – The size of a source plain text.
srcOffset – The size of an offset within the current block stream for resuming within the current cipher stream.
nonceCounter – The 128-bit nonce and counter. Must be 4-byte aligned.
streamBlock – The saved stream-block for resuming. Is over-written by the function. Must be 4-byte aligned.
dst – The pointer to the destination cipher text. Must be 4-byte aligned.
src – The pointer to the source plain text. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_aes_t structure that stores all internal variables the Crypto driver requires.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Aes_Cmac_Run
(uint32_t *src, uint32_t srcSize, uint32_t *key, cy_en_crypto_aes_key_length_t keyLength, uint32_t *cmacPtr, cy_stc_crypto_context_aes_t *cfContext) This function performs the cipher-block chaining-message authentication-code.
There is no Init function. Provide the required parameters and the pointer to the context structure when making this function call.
- Function Usage
/* All data arrays should be 4-byte aligned */ CY_ALIGN(4) uint8_t cmacKey[CY_CRYPTO_AES_256_KEY_SIZE] = { 0x60u, 0x3Du, 0xEBu, 0x10u, 0x15u, 0xCAu, 0x71u, 0xBEu, 0x2Bu, 0x73u, 0xAEu, 0xF0u, 0x85u, 0x7Du, 0x77u, 0x81u, 0x1Fu, 0x35u, 0x2Cu, 0x07u, 0x3Bu, 0x61u, 0x08u, 0xD7u, 0x2Du, 0x98u, 0x10u, 0xA3u, 0x09u, 0x14u, 0xDFu, 0xF4u }; CY_ALIGN(4) uint8_t cmac256PlainText[16] = { 0x6Bu, 0xC1u, 0xBEu, 0xE2u, 0x2Eu, 0x40u, 0x9Fu, 0x96u, 0xE9u, 0x3Du, 0x7Eu, 0x11u, 0x73u, 0x93u, 0x17u, 0x2Au }; /* Calculated CMAC */ CY_ALIGN(4) uint8_t cmac[CY_CRYPTO_AES_BLOCK_SIZE] = {0}; cy_stc_crypto_context_aes_t cryptoAesContext; cy_en_crypto_status_t cryptoStatus; /* CMAC from the text message using AES-256 */ cryptoStatus = Cy_Crypto_Aes_Cmac_Run( (uint32_t *)cmac256PlainText, sizeof(cmac256PlainText), (uint32_t *)cmacKey, CY_CRYPTO_KEY_AES_256, (uint32_t *)cmac, &cryptoAesContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
src – The pointer to the source plain text. Must be 4-byte aligned.
srcSize – The size of a source plain text.
key – The pointer to the encryption key. Must be 4-byte aligned.
keyLength – cy_en_crypto_aes_key_length_t
cmacPtr – The pointer to the calculated CMAC. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_aes_t structure that stores all internal variables the Crypto driver requires.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Sha_Run
(uint32_t *message, uint32_t messageSize, uint32_t *digest, cy_en_crypto_sha_mode_t mode, cy_stc_crypto_context_sha_t *cfContext) This function performs the SHA Hash function.
There is no Init function. Provide the required parameters and the pointer to the context structure when making this function call. It is independent of the previous Crypto state because it already contains preparation, calculation, and finalization steps.
- Function Usage
/* All data arrays should be 4-byte aligned */ /* Message is: "abc" */ CY_ALIGN(4) uint8_t sha256PlainText_1[3] = "abc"; /* Calculated SHA-256 digest */ CY_ALIGN(4) uint8_t sha256Digest[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0}; cy_stc_crypto_context_sha_t cryptoShaContext; cy_en_crypto_status_t cryptoStatus; /* Hash the message by SHA256 */ cryptoStatus = Cy_Crypto_Sha_Run( (uint32_t *)sha256PlainText_1, sizeof(sha256PlainText_1), (uint32_t *)sha256Digest, CY_CRYPTO_MODE_SHA256, &cryptoShaContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
mode – cy_en_crypto_sha_mode_t
message – The pointer to a message whose hash value is being computed. Must be 4-byte aligned.
messageSize – The size of a message.
digest – The pointer to the hash digest. The hash size depends on the selected SHA mode (from 20 to 64 bytes, see CY_CRYPTO_SHA_MAX_DIGEST_SIZE). Must be 4-byte aligned.
cfContext – the pointer to the cy_stc_crypto_context_sha_t structure that stores all internal variables for Crypto driver.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Hmac_Run
(uint32_t *hmac, uint32_t *message, uint32_t messageSize, uint32_t *key, uint32_t keyLength, cy_en_crypto_sha_mode_t mode, cy_stc_crypto_context_sha_t *cfContext) This function performs HMAC calculation.
There is no Init function. Provide the required parameters and the pointer to the context structure when making this function call. It is independent of the previous Crypto state because it already contains preparation, calculation, and finalization steps.
- Function Usage
/* All data arrays should be 4-byte aligned */ CY_ALIGN(4) uint8_t hmac256Key[32] = { 0x00u, 0x01u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x07u, 0x08u, 0x09u, 0x0Au, 0x0Bu, 0x0Cu, 0x0Du, 0x0Eu, 0x0Fu, 0x10u, 0x11u, 0x12u, 0x13u, 0x14u, 0x15u, 0x16u, 0x17u, 0x18u, 0x19u, 0x1Au, 0x1Bu, 0x1Cu, 0x1Du, 0x1Eu, 0x1Fu }; CY_ALIGN(4) uint8_t hmac256PlainText[34] = { 0x53u, 0x61u, 0x6Du, 0x70u, 0x6Cu, 0x65u, 0x20u, 0x6Du, 0x65u, 0x73u, 0x73u, 0x61u, 0x67u, 0x65u, 0x20u, 0x66u, 0x6Fu, 0x72u, 0x20u, 0x6Bu, 0x65u, 0x79u, 0x6Cu, 0x65u, 0x6Eu, 0x3Cu, 0x62u, 0x6Cu, 0x6Fu, 0x63u, 0x6Bu, 0x6Cu, 0x65u, 0x6Eu }; /* Calculated HMAC */ CY_ALIGN(4) uint8_t hmac256[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0}; cy_stc_crypto_context_sha_t cryptoShaContext; cy_en_crypto_status_t cryptoStatus; /* HMAC from the text message using SHA256 */ cryptoStatus = Cy_Crypto_Hmac_Run( (uint32_t *)hmac256, (uint32_t *)hmac256PlainText, sizeof(hmac256PlainText), (uint32_t *)hmac256Key, sizeof(hmac256Key), CY_CRYPTO_MODE_SHA256, &cryptoShaContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
hmac – The pointer to the calculated HMAC. Must be 4-byte aligned.
message – The pointer to a message whose hash value is being computed. Must be 4-byte aligned.
messageSize – The size of a message.
key – The pointer to the key. Must be 4-byte aligned.
keyLength – The length of the key.
mode – cy_en_crypto_sha_mode_t
cfContext – the pointer to the cy_stc_crypto_context_sha_t structure that stores all internal variables for the Crypto driver.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Str_MemCpy
(void *dst, void const *src, uint16_t size, cy_stc_crypto_context_str_t *cfContext) This function copies a memory block.
It operates on data in the user SRAM and doesn’t use Crypto internal SRAM.
There is no alignment restriction. This function is independent of the previous Crypto state.note
Memory blocks should not overlap.
- Parameters
dst – The pointer to the destination of MemCpy.
src – The pointer to the source of MemCpy.
size – The size in bytes of the copy operation. Maximum size is 65535 Bytes.
cfContext – The pointer to the cy_stc_crypto_context_str_t structure that stores all internal variables for the Crypto driver.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Str_MemSet
(void *dst, uint8_t data, uint16_t size, cy_stc_crypto_context_str_t *cfContext) This function sets the memory block.
It operates on data in the user SRAM and doesn’t use Crypto internal SRAM.
There is no alignment restriction. This function is independent from the previous Crypto state.
- Parameters
dst – The pointer to the destination of MemSet.
data – The value to be set.
size – The size in bytes of the set operation. Maximum size is 65535 Bytes.
cfContext – the pointer to the cy_stc_crypto_context_str_t structure that stores all internal variables for the Crypto driver.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Str_MemCmp
(void const *src0, void const *src1, uint16_t size, uint32_t *resultPtr, cy_stc_crypto_context_str_t *cfContext) This function compares memory blocks.
It operates on data in the user SRAM and doesn’t use Crypto internal SRAM.
There is no alignment restriction. This function is independent from the previous Crypto state.
- Parameters
src0 – The pointer to the first source of MemCmp.
src1 – The pointer to the second source of MemCmp.
size – The size in bytes of the compare operation. Maximum size is 65535 Bytes.
resultPtr – The pointer to the result of compare (must be 4-byte aligned):
0 - if Source 1 equal Source 2
1 - if Source 1 not equal Source 2
cfContext – the pointer to the cy_stc_crypto_context_str_t structure that stores all internal variables for the Crypto driver.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Str_MemXor
(void const *src0, void const *src1, void *dst, uint16_t size, cy_stc_crypto_context_str_t *cfContext) This function calculates the XOR of two memory blocks.
It operates on data in the user SRAM and doesn’t use Crypto internal SRAM.
There is no alignment restriction. This function is independent from the previous Crypto state.note
Memory structures should not overlap.
- Parameters
src0 – The pointer to the first source of MemXor.
src1 – The pointer to the second source of MemXor.
dst – The pointer to the destination of MemXor.
size – The size in bytes of the compare operation. Maximum size is 65535 Bytes.
cfContext – the pointer to the cy_stc_crypto_context_str_t structure that stores all internal variables for the Crypto driver.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Crc_Init
(uint32_t polynomial, uint8_t dataReverse, uint8_t dataXor, uint8_t remReverse, uint32_t remXor, cy_stc_crypto_context_crc_t *cfContext) This function performs CRC initialization.
Call to initialize this encryption technique before using any associated functions. You must initialize this technique again after using any other encryption technique.
Below is the table with known polynomials with different parameters and their calculated CRCs from the string “123456789”:
Name
Width
Poly
Init
Data Rev
Data XOR
Rem Rev
Rem XOR
Expected CRC
CRC-3 / ROHC
3
0x3
0x7
1
0
1
0x0
0x6
CRC-4 / ITU
4
0x3
0x0
1
0
1
0x0
0x7
CRC-5 / EPC
5
0x9
0x9
0
0
0
0x0
0x0
CRC-5 / ITU
5
0x15
0x0
1
0
1
0x0
0x7
CRC-5 / USB
5
0x5
0x1F
1
0
1
0x1F
0x19
CRC-6 / CDMA2000-A
6
0x27
0x3F
0
0
0
0x0
0xD
CRC-6 / CDMA2000-B
6
0x7
0x3F
0
0
0
0x0
0x3B
CRC-6 / DARC
6
0x19
0x0
1
0
1
0x0
0x26
CRC-6 / ITU
6
0x3
0x0
1
0
1
0x0
0x6
CRC-7
7
0x9
0x0
0
0
0
0x0
0x75
CRC-7 / ROHC
7
0x4F
0x7F
1
0
1
0x0
0x53
CRC-8
8
0x7
0x0
0
0
0
0x0
0xF4
CRC-8 / CDMA2000
8
0x9B
0xFF
0
0
0
0x0
0xDA
CRC-8 / DARC
8
0x39
0x0
1
0
1
0x0
0x15
CRC-8 / DVB-S2
8
0xD5
0x0
0
0
0
0x0
0xBC
CRC-8 / EBU
8
0x1D
0xFF
1
0
1
0x0
0x97
CRC-8 / I-CODE
8
0x1D
0xFD
0
0
0
0x0
0x7E
CRC-8 / ITU
8
0x7
0x0
0
0
0
0x55
0xA1
CRC-8 / MAXIM
8
0x31
0x0
1
0
1
0x0
0xA1
CRC-8 / ROHC
8
0x7
0xFF
1
0
1
0x0
0xD0
CRC-8 / WCDMA
8
0x9B
0x0
1
0
1
0x0
0x25
CRC-10
10
0x233
0x0
0
0
0
0x0
0x199
CRC-10 / CDMA2000
10
0x3D9
0x3FF
0
0
0
0x0
0x233
CRC-11
11
0x385
0x1A
0
0
0
0x0
0x5A3
CRC-12 / 3GPP
12
0x80F
0x0
0
0
1
0x0
0xDAF
CRC-12 / CDMA2000
12
0xF13
0xFFF
0
0
0
0x0
0xD4D
CRC-12 / DECT
12
0x80F
0x0
0
0
0
0x0
0xF5B
CRC-13 / BBC
13
0x1CF5
0x0
0
0
0
0x0
0x4FA
CRC-14 / DARC
14
0x805
0x0
1
0
1
0x0
0x82D
CRC-15
15
0x4599
0x0
0
0
0
0x0
0x59E
CRC-15 / MPT1327
15
0x6815
0x0
0
0
0
0x1
0x2566
CRC-24
24
0x0864CFB
0x00B704CE
0
0
0
0x0
0x21CF02
CRC-24 / FLEXRAY-A
24
0x05D6DCB
0x00FEDCBA
0
0
0
0x0
0x7979BD
CRC-24 / FLEXRAY-B
24
0x05D6DCB
0x00ABCDEF
0
0
0
0x0
0x1F23B8
CRC-31 / PHILIPS
31
0x4C11DB7
0x7FFFFFFF
0
0
0
0x7FFFFFFF
0xCE9E46C
CRC-16 / ARC
16
0x8005
0x0000
1
0
1
0x0000
0xBB3D
CRC-16 / AUG-CCITT
16
0x1021
0x1D0F
0
0
0
0x0000
0xE5CC
CRC-16 / BUYPASS
16
0x8005
0x0000
0
0
0
0x0000
0xFEE8
CRC-16 / CCITT-0
16
0x1021
0xFFFF
0
0
0
0x0000
0x29B1
CRC-16 / CDMA2000
16
0xC867
0xFFFF
0
0
0
0x0000
0x4C06
CRC-16 / DDS-110
16
0x8005
0x800D
0
0
0
0x0000
0x9ECF
CRC-16 / DECT-R
16
0x0589
0x0000
0
0
0
0x0001
0x007E
CRC-16 / DECT-X
16
0x0589
0x0000
0
0
0
0x0000
0x007F
CRC-16 / DNP
16
0x3D65
0x0000
1
0
1
0xFFFF
0xEA82
CRC-16 / EN-13757
16
0x3D65
0x0000
0
0
0
0xFFFF
0xC2B7
CRC-16 / GENIBUS
16
0x1021
0xFFFF
0
0
0
0xFFFF
0xD64E
CRC-16 / MAXIM
16
0x8005
0x0000
1
0
1
0xFFFF
0x44C2
CRC-16 / MCRF4XX
16
0x1021
0xFFFF
1
0
1
0x0000
0x6F91
CRC-16 / RIELLO
16
0x1021
0xB2AA
1
0
1
0x0000
0x63D0
CRC-16 / T10-DIF
16
0x8BB7
0x0000
0
0
0
0x0000
0xD0DB
CRC-16 / TELEDISK
16
0xA097
0x0000
0
0
0
0x0000
0x0FB3
CRC-16 / TMS37157
16
0x1021
0x89EC
1
0
1
0x0000
0x26B1
CRC-16 / USB
16
0x8005
0xFFFF
1
0
1
0xFFFF
0xB4C8
CRC-A
16
0x1021
0xC6C6
1
0
1
0x0000
0xBF05
CRC-16 / KERMIT
16
0x1021
0x0000
1
0
1
0x0000
0x2189
CRC-16 / MODBUS
16
0x8005
0xFFFF
1
0
1
0x0000
0x4B37
CRC-16 / X-25
16
0x1021
0xFFFF
1
0
1
0xFFFF
0x906E
CRC-16 / XMODEM
16
0x1021
0x0000
0
0
0
0x0000
0x31C3
CRC-32
32
0x04C11DB7
0xFFFFFFFF
1
0
1
0xFFFFFFFF
0xCBF43926
CRC-32 / BZIP2
32
0x04C11DB7
0xFFFFFFFF
0
0
0
0xFFFFFFFF
0xFC891918
CRC-32C
32
0x1EDC6F41
0xFFFFFFFF
1
0
1
0xFFFFFFFF
0xE3069283
CRC-32D
32
0xA833982B
0xFFFFFFFF
1
0
1
0xFFFFFFFF
0x87315576
CRC-32 / MPEG-2
32
0x04C11DB7
0xFFFFFFFF
0
0
0
0x00000000
0x0376E6E7
CRC-32 / POSIX
32
0x04C11DB7
0x00000000
0
0
0
0xFFFFFFFF
0x765E7680
CRC-32Q
32
0x814141AB
0x00000000
0
0
0
0x00000000
0x3010BF7F
CRC-32 / JAMCRC
32
0x04C11DB7
0xFFFFFFFF
1
0
1
0x00000000
0x340BC6D9
CRC-32 / XFER
32
0x000000AF
0x00000000
0
0
0
0x00000000
0xBD0BE338
note
The polynomial, initial seed and remainder XOR values are always provided as MSB aligned (so actual higher bit should be located in 31s bit of the parameter value).
Calculated CRC value is MSB aligned only when dataReverse is zero.- Function Usage
/* CRC parameters for some CRC algorithms: +---------------------+-----+------------+------------+------+------+-----+------------+------------+ | CRC algorithm Name | CRC | Polynom | Initial | Data | Data | Rem | Remainder | Expected | | | len | | seed | REV | XOR | REV | XOR | CRC | | ------------------- | --- | ---------- |----------- | ---- | ---- | --- | ---------- | ---------- | | CRC-6 / CDMA2000-A | 6 | 0x27 | 0x3F | 0 | 0 | 0 | 0x00 | 0x0D | | CRC-6 / CDMA2000-B | 6 | 0x07 | 0x3F | 0 | 0 | 0 | 0x00 | 0x3B | | CRC-6 / DARC | 6 | 0x19 | 0x00 | 1 | 0 | 1 | 0x00 | 0x26 | | CRC-6 / ITU | 6 | 0x03 | 0x00 | 1 | 0 | 1 | 0x00 | 0x06 | | CRC-8 / ITU | 8 | 0x07 | 0x00 | 0 | 0 | 0 | 0x55 | 0xA1 | | CRC-8 / MAXIM | 8 | 0x31 | 0x00 | 1 | 0 | 1 | 0x00 | 0xA1 | | CRC-8 / ROHC | 8 | 0x07 | 0xFF | 1 | 0 | 1 | 0x00 | 0xD0 | | CRC-8 / WCDMA | 8 | 0x9B | 0x00 | 1 | 0 | 1 | 0x00 | 0x25 | | CRC-16 / CCITT-0 | 16 | 0x1021 | 0xFFFF | 0 | 0 | 0 | 0x0000 | 0x29B1 | | CRC-16 / CDMA2000 | 16 | 0xC867 | 0xFFFF | 0 | 0 | 0 | 0x0000 | 0x4C06 | | CRC-32 | 32 | 0x04C11DB7 | 0xFFFFFFFF | 1 | 0 | 1 | 0xFFFFFFFF | 0xCBF43926 | | CRC-32 / BZIP2 | 32 | 0x04C11DB7 | 0xFFFFFFFF | 0 | 0 | 0 | 0xFFFFFFFF | 0xFC891918 | +---------------------+-----+------------+------------+------+------+-----+------------+------------+ */ /* Use "CRC-16/CCITT-0" calculation */ #define CRC_BITLEN (16u) #define CRC_POLYNOMIAL (0x1021u) #define CRC_LFSR_SEED (0xffffu) #define CRC_DATA_REVERSE (0u) #define CRC_DATA_XOR (0u) #define CRC_REM_REVERSE (0u) #define CRC_REM_XOR (0x0000u) CY_ALIGN(4) uint8_t message[9] = "123456789"; CY_ALIGN(4) uint32_t calculatedCrc = 0; cy_stc_crypto_context_crc_t cryptoCrcContext; cy_en_crypto_status_t cryptoStatus; /* Initialization Crypto operation */ /* Note: Polynomial and Remainder XOR values are always MSB aligned. */ cryptoStatus = Cy_Crypto_Crc_Init((CRC_POLYNOMIAL << (32 - CRC_BITLEN)), CRC_DATA_REVERSE, CRC_DATA_XOR, CRC_REM_REVERSE, (CRC_REM_XOR << (32 - CRC_BITLEN)), &cryptoCrcContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */ /* Calculate CRC */ /* Note: Initial seed value is always MSB aligned. */ cryptoStatus = Cy_Crypto_Crc_Run((void*)message, sizeof(message), &calculatedCrc, (uint32_t)(CRC_LFSR_SEED << (32u - CRC_BITLEN)), &cryptoCrcContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */ /* Note: Calculated CRC value is MSB aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */ if (CRC_DATA_REVERSE == 0u) { calculatedCrc = calculatedCrc >> (32 - CRC_BITLEN); }
- Parameters
polynomial – The polynomial (specified using 32 bits) used in the computing CRC.
dataReverse – The order in which data bytes are processed. 0 - MSB first; 1- LSB first.
dataXor – The byte mask for XORing data
remReverse – A remainder reverse: 0 means the remainder is not reversed. 1 means reversed.
remXor – Specifies a mask with which the LFSR32 register is XORed to produce a remainder.
cfContext – The pointer to the cy_stc_crypto_context_crc_t structure that stores the Crypto driver context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Crc_Run
(void *data, uint16_t dataSize, uint32_t *crc, uint32_t lfsrInitState, cy_stc_crypto_context_crc_t *cfContext) This function performs CRC calculation on a message.
It depends on Cy_Crypto_Crc_Init(), which should be called before.
note
The polynomial, initial seed and remainder XOR values are always provided as MSB aligned (so actual higher bit should be located in 31s bit of the parameter value).
Calculated CRC value is MSB aligned only when dataReverse is zero.- Function Usage
/* CRC parameters for some CRC algorithms: +---------------------+-----+------------+------------+------+------+-----+------------+------------+ | CRC algorithm Name | CRC | Polynom | Initial | Data | Data | Rem | Remainder | Expected | | | len | | seed | REV | XOR | REV | XOR | CRC | | ------------------- | --- | ---------- |----------- | ---- | ---- | --- | ---------- | ---------- | | CRC-6 / CDMA2000-A | 6 | 0x27 | 0x3F | 0 | 0 | 0 | 0x00 | 0x0D | | CRC-6 / CDMA2000-B | 6 | 0x07 | 0x3F | 0 | 0 | 0 | 0x00 | 0x3B | | CRC-6 / DARC | 6 | 0x19 | 0x00 | 1 | 0 | 1 | 0x00 | 0x26 | | CRC-6 / ITU | 6 | 0x03 | 0x00 | 1 | 0 | 1 | 0x00 | 0x06 | | CRC-8 / ITU | 8 | 0x07 | 0x00 | 0 | 0 | 0 | 0x55 | 0xA1 | | CRC-8 / MAXIM | 8 | 0x31 | 0x00 | 1 | 0 | 1 | 0x00 | 0xA1 | | CRC-8 / ROHC | 8 | 0x07 | 0xFF | 1 | 0 | 1 | 0x00 | 0xD0 | | CRC-8 / WCDMA | 8 | 0x9B | 0x00 | 1 | 0 | 1 | 0x00 | 0x25 | | CRC-16 / CCITT-0 | 16 | 0x1021 | 0xFFFF | 0 | 0 | 0 | 0x0000 | 0x29B1 | | CRC-16 / CDMA2000 | 16 | 0xC867 | 0xFFFF | 0 | 0 | 0 | 0x0000 | 0x4C06 | | CRC-32 | 32 | 0x04C11DB7 | 0xFFFFFFFF | 1 | 0 | 1 | 0xFFFFFFFF | 0xCBF43926 | | CRC-32 / BZIP2 | 32 | 0x04C11DB7 | 0xFFFFFFFF | 0 | 0 | 0 | 0xFFFFFFFF | 0xFC891918 | +---------------------+-----+------------+------------+------+------+-----+------------+------------+ */ /* Use "CRC-16/CCITT-0" calculation */ #define CRC_BITLEN (16u) #define CRC_POLYNOMIAL (0x1021u) #define CRC_LFSR_SEED (0xffffu) #define CRC_DATA_REVERSE (0u) #define CRC_DATA_XOR (0u) #define CRC_REM_REVERSE (0u) #define CRC_REM_XOR (0x0000u) CY_ALIGN(4) uint8_t message[9] = "123456789"; CY_ALIGN(4) uint32_t calculatedCrc = 0; cy_stc_crypto_context_crc_t cryptoCrcContext; cy_en_crypto_status_t cryptoStatus; /* Initialization Crypto operation */ /* Note: Polynomial and Remainder XOR values are always MSB aligned. */ cryptoStatus = Cy_Crypto_Crc_Init((CRC_POLYNOMIAL << (32 - CRC_BITLEN)), CRC_DATA_REVERSE, CRC_DATA_XOR, CRC_REM_REVERSE, (CRC_REM_XOR << (32 - CRC_BITLEN)), &cryptoCrcContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */ /* Calculate CRC */ /* Note: Initial seed value is always MSB aligned. */ cryptoStatus = Cy_Crypto_Crc_Run((void*)message, sizeof(message), &calculatedCrc, (uint32_t)(CRC_LFSR_SEED << (32u - CRC_BITLEN)), &cryptoCrcContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */ /* Note: Calculated CRC value is MSB aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */ if (CRC_DATA_REVERSE == 0u) { calculatedCrc = calculatedCrc >> (32 - CRC_BITLEN); }
- Parameters
data – The pointer to the message whose CRC is being computed.
dataSize – The size of a message in bytes.
crc – The pointer to a computed CRC value. Must be 4-byte aligned.
lfsrInitState – The initial state of the LFSR.
cfContext – The pointer to the cy_stc_crypto_context_crc_t structure that stores the Crypto driver context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Trng_Generate
(uint32_t GAROPol, uint32_t FIROPol, uint32_t max, uint32_t *randomNum, cy_stc_crypto_context_trng_t *cfContext) This function generates a 32-bit True Random Number.
- Function Usage
/* Initialization polynomial values fro True Random Generator. Polynomial for programmable Galois ring oscillator. The polynomial is represented WITHOUT the high order bit (this bit is always assumed '1'). GARO 31 bit polynomial (0x04c1:1db7) = x31 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 Polynomial for programmable Fibonacci ring oscillator. The polynomial is represented WITHOUT the high order bit (this bit is always assumed '1'). FIRO 31 bit polynomial (0x04c1:1db7) = x31 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 */ #define GARO31_INITSTATE (0x04c11db7) #define FIRO31_INITSTATE (0x04c11db7) #define MAX_TRNG_BIT_SIZE (32UL) /* Generated Random Number */ uint32_t rndNum = 0; cy_stc_crypto_context_trng_t cryptoTrngContext; cy_en_crypto_status_t cryptoStatus; /* Generate True Random number */ cryptoStatus = Cy_Crypto_Trng_Generate( GARO31_INITSTATE, FIRO31_INITSTATE, MAX_TRNG_BIT_SIZE, &rndNum, &cryptoTrngContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
GAROPol – The polynomial for the programmable Galois ring oscillator.
FIROPol – The polynomial for the programmable Fibonacci ring oscillator.
max – The maximum length of a random number, in the range [0, 32] bits.
randomNum – The pointer to a generated true random number. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_trng_t structure that stores the Crypto driver context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Des_Run
(cy_en_crypto_dir_mode_t dirMode, uint32_t *key, uint32_t *dstBlock, uint32_t *srcBlock, cy_stc_crypto_context_des_t *cfContext) This function performs DES operation on a Single Block.
All addresses must be 4-Byte aligned. Ciphertext (dstBlock) may overlap with plaintext (srcBlock) There is no Init function. Provide the required parameters and the pointer to the context structure when making this function call.
- Parameters
dirMode – Can be CY_CRYPTO_ENCRYPT or CY_CRYPTO_DECRYPT (cy_en_crypto_dir_mode_t)
key – The pointer to the encryption/decryption key. Must be 4-byte aligned.
srcBlock – The pointer to a source block. Must be 4-byte aligned.
dstBlock – The pointer to a destination cipher block. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_des_t structure that stores the Crypto driver context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Tdes_Run
(cy_en_crypto_dir_mode_t dirMode, uint32_t *key, uint32_t *dstBlock, uint32_t *srcBlock, cy_stc_crypto_context_des_t *cfContext) This function performs the TDES operation on a single block.
All addresses Must be 4-byte aligned. Ciphertext (dstBlock) may overlap with plaintext (srcBlock). There is no Init function. Provide the required parameters and the pointer to the context structure when making this function call.
- Function Usage
/* Note: all keys are placed into the one keys array. */ #define STRING_LENGTH 8 CY_ALIGN(4) uint8_t msgString[STRING_LENGTH] = "Crypto!"; CY_ALIGN(4) uint8_t encString[STRING_LENGTH]; #define KEY1 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 #define KEY2 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF #define KEY3 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 CY_ALIGN(4) uint8_t tdesKey[] = { KEY1, KEY2, KEY3 }; cy_stc_crypto_context_des_t cryptoDesContext; cy_en_crypto_status_t cryptoStatus; cryptoStatus = Cy_Crypto_Tdes_Run ( CY_CRYPTO_ENCRYPT, (uint32_t *)tdesKey, /* Pointer to keys */ (uint32_t *)encString, /* Destination string */ (uint32_t *)msgString, /* Source String */ &cryptoDesContext ); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* ... check for errors... */
- Parameters
dirMode – Can be CY_CRYPTO_ENCRYPT or CY_CRYPTO_DECRYPT (cy_en_crypto_dir_mode_t)
key – The pointer to the encryption/decryption key. Must be 4-byte aligned.
srcBlock – The pointer to a source block. Must be 4-byte aligned.
dstBlock – The pointer to a destination cipher block. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_des_t structure that stores the Crypto driver context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Rsa_Proc
(cy_stc_crypto_rsa_pub_key_t const *pubKey, uint32_t const *message, uint32_t messageSize, uint32_t *processedMessage, cy_stc_crypto_context_rsa_t *cfContext) This function calculates (m^e mod modulo) where m is Message (Signature), e - public exponent using a public key in the next representation, it contains: modulo, public exponent, coefficient for Barrett reduction, binary inverse of the modulo, and result of (2^moduloLength mod modulo).
Not all fields in a key must be given. Modulo and public exponents are mandatory; Barrett coefficient, inverse modulo, and r-bar are optional. If they don’t exist, their according pointers should be NULL. These coefficients could be calculated by Cy_Crypto_Rsa_CalcCoefs. Their presence accelerates performance by five times. Approximate performance for 1024-bit modulo is 41.6 ms; for 2048-bit modulo is 142 ms when using a 25 MHz clock for Crypto HW. These numbers just for reference. They depend on many factors (compiler, optimization level, etc.).
Returns the processed value and a success value.
note
Incoming message and result processed message must be in little-endian order.
The modulus and exponent values in the cy_stc_crypto_rsa_pub_key_t must also be in little-endian order.
Use Cy_Crypto_InvertEndianness function to convert to or from little-endian order.- Parameters
pubKey – The pointer to the cy_stc_crypto_rsa_pub_key_t structure that stores public key.
message – The pointer to the message to be processed. Must be 4-byte aligned.
messageSize – The length of the message to be processed.
processedMessage – The pointer to processed message. Must be 4-byte aligned.
cfContext – The pointer to the cy_stc_crypto_context_rsa_t structure that stores the RSA context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Rsa_CalcCoefs
(cy_stc_crypto_rsa_pub_key_t const *pubKey, cy_stc_crypto_context_rsa_t *cfContext) This function calculates constant coefficients (which is dependent only on modulo and independent on message).
With this pre-calculated coefficients calculations speed-up by five times.
These coefficients are: coefficient for Barrett reduction, binary inverse of the modulo, result of (2^moduloLength mod modulo)
Calculated coefficients will be placed by addresses provided in the pubKey structure for according coefficients. Function overwrites previous values. Approximate performance for 1024-bit modulo is 33.2 ms; for 2048-bit modulo is 113 ms when using a 25 MHz clock for Crypto HW. These numbers are just for reference. They depend on many factors (compiler, optimization level, etc.).
- Parameters
pubKey – The pointer to the cy_stc_crypto_rsa_pub_key_t structure that stores a public key.
cfContext – The pointer to the cy_stc_crypto_context_rsa_t structure that stores the RSA context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_Rsa_Verify
(cy_en_crypto_rsa_ver_result_t *verResult, cy_en_crypto_sha_mode_t digestType, uint32_t const *digest, uint32_t const *decryptedSignature, uint32_t decryptedSignatureLength, cy_stc_crypto_context_rsa_ver_t *cfContext) This function does an RSA verification with checks for content, paddings, and signature format.
The SHA digest of the message and decrypted message should be calculated first. 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 cy_en_crypto_rsa_ver_result_t.
- Parameters
verResult – The pointer to the verification result cy_en_crypto_rsa_ver_result_t.
digestType – SHA mode used for hash calculation cy_en_crypto_sha_mode_t.
digest – The pointer to the hash of the message whose signature is to be verified. Must be 4-byte aligned.
decryptedSignature – The pointer to the decrypted signature to be verified. Must be 4-byte aligned.
decryptedSignatureLength – The length of the decrypted signature to be verified (in bytes)
cfContext – The pointer to the cy_stc_crypto_context_rsa_ver_t structure that stores the RSA context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_ECDSA_SignHash
(const uint8_t *hash, uint32_t hashlen, uint8_t *sig, const cy_stc_crypto_ecc_key *key, const uint8_t *messageKey, cy_stc_crypto_context_ecc_t *cfContext) Sign a message digest.
- Parameters
hash – The message digest to sign. Provided as is in data buffer.
hashlen – The length of the digest in bytes.
sig – [out] The destination for the signature, ‘R’ followed by ‘S’.
key – Key used for signature generation. See cy_stc_crypto_ecc_key.
messageKey – Message key.
cfContext – The pointer to the cy_stc_crypto_context_ecc_t structure that stores the ECC operation context.
- Returns
status code. See cy_en_crypto_status_t.
-
cy_en_crypto_status_t
Cy_Crypto_ECDSA_VerifyHash
(const uint8_t *sig, const uint8_t *hash, uint32_t hashlen, uint8_t *stat, const cy_stc_crypto_ecc_key *key, cy_stc_crypto_context_ecc_t *cfContext) Verify an ECC signature.
- Parameters
sig – The signature to verify, ‘R’ followed by ‘S’.
hash – The message digest that was signed. Provided as is in data buffer.
hashlen – The length of the digest in bytes.
stat – Result of signature, 1==valid, 0==invalid.
key – The corresponding public ECC key. See cy_stc_crypto_ecc_key.
cfContext – The pointer to the cy_stc_crypto_context_ecc_t structure that stores the ECC operation context.
- Returns
status code. See cy_en_crypto_status_t.
-
cy_en_crypto_status_t
Cy_Crypto_SetMemBufAddress
(uint32_t const *newMembufAddress, uint32_t newMembufSize, cy_stc_crypto_context_str_t *cfContext) This function sets a new operation memory buffer.
note
This function sets the default device specific values when vuMemoryAddr parameter is NULL and vuMemorySize parameter is zero.
note
New memory buffer should be allocated in a memory region that is not protected by a protection scheme for use by Crypto hardware.
- Parameters
newMembufAddress – The pointer to the new operation memory buffer. Must be 4-byte aligned.
newMembufSize – The size of the new memory buffer (in bytes)
cfContext – The pointer to the cy_stc_crypto_context_str_t structure that stores the data context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_GetMemBufAddress
(uint32_t **membufAddress, cy_stc_crypto_context_str_t *cfContext) This function gets an operation memory buffer location.
- Parameters
membufAddress – The pointer of the operation memory buffer.
cfContext – The pointer to the cy_stc_crypto_context_str_t structure that stores the data context.
- Returns
-
cy_en_crypto_status_t
Cy_Crypto_GetMemBufSize
(uint32_t *membufSize, cy_stc_crypto_context_str_t *cfContext) This function gets an operation memory buffer size.
- Parameters
membufSize – The size of the memory buffer (in bytes)
cfContext – The pointer to the cy_stc_crypto_context_str_t structure that stores the data context.
- Returns
-
void
Cy_Crypto_InvertEndianness
(void *inArrPtr, uint32_t byteSize) This function reverts byte-array memory block, like:
inArr[0] <
—> inArr[n]
inArr[1] <
—> inArr[n-1]
inArr[2] <
—> inArr[n-2]
……………………
inArr[n/2] <—> inArr[n/2-1]Odd or even byteSize are acceptable.
- Parameters
inArrPtr – The pointer to the memory whose endianness is to be inverted.
byteSize – The length of the memory array whose endianness is to be inverted (in bytes)
-
cy_en_crypto_status_t