CAT2 Peripheral Driver Library
Hash operations (SHA)

Functions

cy_en_crypto_status_t Cy_Crypto_Sha (CRYPTO_Type *base, uint8_t const *message, uint32_t messageSize, uint8_t *digest, cy_en_crypto_sha_mode_t mode)
 This function calculates the secure hash algorithm (SHA) hash for the given message. More...
 
cy_en_crypto_status_t Cy_Crypto_Sha_Init (CRYPTO_Type *base, cy_en_crypto_sha_mode_t mode, cy_stc_crypto_sha_context_t *shaContext)
 This function initializes the SHA operation. More...
 
cy_en_crypto_status_t Cy_Crypto_Sha_Partial (CRYPTO_Type *base, uint8_t const *message, uint32_t messageSize, cy_stc_crypto_sha_context_t *shaContext)
 This function performs the SHA Hash calculation on partial data which is part of a complete message. More...
 
cy_en_crypto_status_t Cy_Crypto_Sha_Finish (CRYPTO_Type *base, uint8_t *digest, cy_stc_crypto_sha_context_t *shaContext)
 This function completes the SHA hash calculation for the message provided with Cy_Crypto_Sha_Partial() function. More...
 
cy_en_crypto_status_t Cy_Crypto_Sha_Free (CRYPTO_Type *base, cy_stc_crypto_sha_context_t *shaContext)
 This function clears the SHA operation context. More...
 

Detailed Description

Function Documentation

◆ Cy_Crypto_Sha()

cy_en_crypto_status_t Cy_Crypto_Sha ( CRYPTO_Type *  base,
uint8_t const *  message,
uint32_t  messageSize,
uint8_t *  digest,
cy_en_crypto_sha_mode_t  mode 
)

This function calculates the secure hash algorithm (SHA) hash for the given message.

This function can be called without calling Cy_Crypto_Sha_Init().

Note
Use this function when the data to be hashed is available in a contiguous block. For non-contiguous blocks of memory, use the Cy_Crypto_Sha_Partial() and Cy_Crypto_Sha_Finish() functions.
Parameters
baseBase address of the Crypto block registers
modeSHA mode. cy_en_crypto_sha_mode_t
messagePointer to the message whose hash value is being computed
messageSizeSize of the message in bytes
digestPointer to store the calculated hash digest
Returns
cy_en_crypto_status_t
Function Usage
uint8_t sha256PlainText[3] = "abc";
uint8_t sha256Digest[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0};
cy_en_crypto_status_t cryptoStatus;
/* Hash the message by using the Crypto SHA operation with SHA-256 mode */
cryptoStatus = Cy_Crypto_Sha(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText, /* Pointer to message */
sizeof(sha256PlainText), /* Message size (in bytes) */
sha256Digest, /* Pointer to digest buffer */
CY_CRYPTO_MODE_SHA256); /* Hash mode */
/* ... check for errors... */

◆ Cy_Crypto_Sha_Init()

cy_en_crypto_status_t Cy_Crypto_Sha_Init ( CRYPTO_Type *  base,
cy_en_crypto_sha_mode_t  mode,
cy_stc_crypto_sha_context_t shaContext 
)

This function initializes the SHA operation.

Note
This function must be called prior to the Cy_Crypto_Sha_Partial() function.
Parameters
baseBase address of the Crypto block registers
modeSHA mode. cy_en_crypto_sha_mode_t
shaContextPointer to the SHA context structure cy_stc_crypto_sha_context_t allocated by the user. This structure is used by the Crypto driver for the SHA hash calculation. Do not modify the values of this structure.
Returns
cy_en_crypto_status_t
Function Usage
uint8_t sha256PlainText1[3] = "abc"; /* In this example, the message is processed in two parts - first 3 then 4 bytes */
uint8_t sha256PlainText2[4] = "defg";
uint8_t sha256Digest[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0};
cy_en_crypto_status_t cryptoStatus;
/* Initialize Crypto SHA operation */
cryptoStatus = Cy_Crypto_Sha_Init(
CRYPTO, /* Base address of the Crypto block registers */
CY_CRYPTO_MODE_SHA256, /* Hash mode */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText1, /* Pointer to message */
sizeof(sha256PlainText1), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText2 , /* Pointer to message */
sizeof(sha256PlainText2), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Finish the SHA operation */
cryptoStatus = Cy_Crypto_Sha_Finish(
CRYPTO, /* Base address of the Crypto block registers */
sha256Digest, /* Pointer to digest buffer */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Free the SHA context */
cryptoStatus = Cy_Crypto_Sha_Free(
CRYPTO, /* Base address of the Crypto block registers */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */

◆ Cy_Crypto_Sha_Partial()

cy_en_crypto_status_t Cy_Crypto_Sha_Partial ( CRYPTO_Type *  base,
uint8_t const *  message,
uint32_t  messageSize,
cy_stc_crypto_sha_context_t shaContext 
)

This function performs the SHA Hash calculation on partial data which is part of a complete message.

Cy_Crypto_Sha_Init() must be called before calling this function. This function can be called multiple times with partial data and at the end, the user must call Cy_Crypto_Sha_Finish() to get the final SHA hash digest.

Parameters
baseBase address of the Crypto block registers
shaContextPointer to the SHA context structure cy_stc_crypto_sha_context_t allocated by the user. This structure is used by the Crypto driver for the SHA hash calculation. Do not modify the values of this structure.
messagePointer to the message whose Hash is being computed
messageSizeSize (in bytes) of the message whose Hash is being computed
Returns
cy_en_crypto_status_t
Function Usage
uint8_t sha256PlainText1[3] = "abc"; /* In this example, the message is processed in two parts - first 3 then 4 bytes */
uint8_t sha256PlainText2[4] = "defg";
uint8_t sha256Digest[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0};
cy_en_crypto_status_t cryptoStatus;
/* Initialize Crypto SHA operation */
cryptoStatus = Cy_Crypto_Sha_Init(
CRYPTO, /* Base address of the Crypto block registers */
CY_CRYPTO_MODE_SHA256, /* Hash mode */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText1, /* Pointer to message */
sizeof(sha256PlainText1), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText2 , /* Pointer to message */
sizeof(sha256PlainText2), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Finish the SHA operation */
cryptoStatus = Cy_Crypto_Sha_Finish(
CRYPTO, /* Base address of the Crypto block registers */
sha256Digest, /* Pointer to digest buffer */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Free the SHA context */
cryptoStatus = Cy_Crypto_Sha_Free(
CRYPTO, /* Base address of the Crypto block registers */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */

◆ Cy_Crypto_Sha_Finish()

cy_en_crypto_status_t Cy_Crypto_Sha_Finish ( CRYPTO_Type *  base,
uint8_t *  digest,
cy_stc_crypto_sha_context_t shaContext 
)

This function completes the SHA hash calculation for the message provided with Cy_Crypto_Sha_Partial() function.

Parameters
baseBase address of the Crypto block registers
shaContextPointer to the SHA context structure cy_stc_crypto_sha_context_t allocated by the user. This structure is used by the Crypto driver for the SHA hash calculation. Do not modify the values of this structure.
digestPointer to store the calculated Hash digest
Returns
cy_en_crypto_status_t
Function Usage
uint8_t sha256PlainText1[3] = "abc"; /* In this example, the message is processed in two parts - first 3 then 4 bytes */
uint8_t sha256PlainText2[4] = "defg";
uint8_t sha256Digest[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0};
cy_en_crypto_status_t cryptoStatus;
/* Initialize Crypto SHA operation */
cryptoStatus = Cy_Crypto_Sha_Init(
CRYPTO, /* Base address of the Crypto block registers */
CY_CRYPTO_MODE_SHA256, /* Hash mode */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText1, /* Pointer to message */
sizeof(sha256PlainText1), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText2 , /* Pointer to message */
sizeof(sha256PlainText2), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Finish the SHA operation */
cryptoStatus = Cy_Crypto_Sha_Finish(
CRYPTO, /* Base address of the Crypto block registers */
sha256Digest, /* Pointer to digest buffer */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Free the SHA context */
cryptoStatus = Cy_Crypto_Sha_Free(
CRYPTO, /* Base address of the Crypto block registers */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */

◆ Cy_Crypto_Sha_Free()

cy_en_crypto_status_t Cy_Crypto_Sha_Free ( CRYPTO_Type *  base,
cy_stc_crypto_sha_context_t shaContext 
)

This function clears the SHA operation context.

Parameters
baseBase address of the Crypto block registers
shaContextPointer to the SHA context structure cy_stc_crypto_sha_context_t allocated by the user. This structure is used by the Crypto driver for the SHA hash calculation. Do not modify the values of this structure.
Returns
cy_en_crypto_status_t
Function Usage
uint8_t sha256PlainText1[3] = "abc"; /* In this example, the message is processed in two parts - first 3 then 4 bytes */
uint8_t sha256PlainText2[4] = "defg";
uint8_t sha256Digest[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0};
cy_en_crypto_status_t cryptoStatus;
/* Initialize Crypto SHA operation */
cryptoStatus = Cy_Crypto_Sha_Init(
CRYPTO, /* Base address of the Crypto block registers */
CY_CRYPTO_MODE_SHA256, /* Hash mode */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText1, /* Pointer to message */
sizeof(sha256PlainText1), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Set the partial message for SHA operation */
cryptoStatus = Cy_Crypto_Sha_Partial(
CRYPTO, /* Base address of the Crypto block registers */
sha256PlainText2 , /* Pointer to message */
sizeof(sha256PlainText2), /* Message size (in bytes) */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Finish the SHA operation */
cryptoStatus = Cy_Crypto_Sha_Finish(
CRYPTO, /* Base address of the Crypto block registers */
sha256Digest, /* Pointer to digest buffer */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */
/* Free the SHA context */
cryptoStatus = Cy_Crypto_Sha_Free(
CRYPTO, /* Base address of the Crypto block registers */
&shaContext); /* Pointer to SHA context */
/* ... check for errors... */