PSOC E8XXGP Device Support Library

| PSOC E8XXGP Device Support Library

Functions
Functions
PDL API Reference » Crypto (Cryptography) » Direct Crypto Core Access » Hash Operations (SHA)

## General Description

## Functions
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Sha (CRYPTO_Type *base, uint8_t const *message, uint32_t messageSize, uint8_t *digest, cy_en_crypto_sha_mode_t mode)
| Performs the SHA Hash function. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Sha_Init (CRYPTO_Type *base, cy_stc_crypto_sha_state_t *shaHashState, cy_en_crypto_sha_mode_t mode, void *shaBuffers)
| The function to initialize the SHA operation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Sha_Start (CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
| Initializes the initial Hash vector. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Sha_Update (CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState, uint8_t const *message, uint32_t messageSize)
| Performs the SHA calculation on one message. More...
__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)
| Completes the SHA calculation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Sha_Free (CRYPTO_Type *base, cy_stc_crypto_sha_state_t *hashState)
| Clears the used memory buffers. More...

## Function Documentation

## ◆ Cy_Crypto_Core_Sha()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha | ( | CRYPTO_Type * | base,
|  | uint8_t const * | message,
|  | uint32_t | messageSize,
|  | uint8_t * | digest,
|  | cy_en_crypto_sha_mode_t | mode
| ) |  |

Performs the SHA Hash function.

Parameters

  base | The pointer to the CRYPTO instance.
  mode | cy_en_crypto_sha_mode_t
  message | The pointer to the message whose hash value is being computed.
  messageSize | The size of the message.
  digest | The pointer to the 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 SHA256 */
  cryptoStatus = Cy_Crypto_Core_Sha(
  CRYPTO_HW, /* Pointer to Crypto instance */
  sha256PlainText, /* Pointer to message */
  sizeof(sha256PlainText), /* Message size */
  sha256Digest, /* Pointer to digest buffer */
  CY_CRYPTO_MODE_SHA256); /* Hash mode */
  /* ... check for errors... */
  cy_en_crypto_status_t
  cy_en_crypto_status_t
  Errors of the Crypto block.
  Definition: cy_crypto_common.h:532
  CY_CRYPTO_MODE_SHA256
  @ CY_CRYPTO_MODE_SHA256
  Sets the SHA256 mode.
  Definition: cy_crypto_common.h:499
  Cy_Crypto_Core_Sha
  __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha(CRYPTO_Type *base, uint8_t const *message, uint32_t messageSize, uint8_t *digest, cy_en_crypto_sha_mode_t mode)
  Performs the SHA Hash function.
  Definition: cy_crypto_core_sha.h:85
  CY_CRYPTO_SHA256_DIGEST_SIZE
  #define CY_CRYPTO_SHA256_DIGEST_SIZE
  Hash size for the SHA256 mode (in bytes)
  Definition: cy_crypto_common.h:220

## ◆ Cy_Crypto_Core_Sha_Init()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Init | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_sha_state_t * | shaHashState,
|  | cy_en_crypto_sha_mode_t | mode,
|  | void * | shaBuffers
| ) |  |

The function to initialize the SHA operation.

Parameters

  base | The pointer to the CRYPTO instance.
  shaHashState | The pointer to a Hash state.
  mode | One of these: cy_en_crypto_sha_mode_t
  shaBuffers | The pointer to the memory buffers storage. Can be one of two buffers types according to selected hardware platform: cy_stc_crypto_v1_sha_buffers_t or cy_stc_crypto_v2_sha_buffers_t

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Sha_Start()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Start | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_sha_state_t * | hashState
| ) |  |

Initializes the initial Hash vector.

Parameters

  base | The pointer to the CRYPTO instance.
  hashState | The pointer to the SHA context.

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Sha_Update()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Update | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_sha_state_t * | hashState,
|  | uint8_t const * | message,
|  | uint32_t | messageSize
| ) |  |

Performs the SHA calculation on one message.

When D-Cache is enabled parameter message must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  hashState | The pointer to the SHA context.
  message | The pointer to the message whose Hash is being computed.
  messageSize | The size of the message whose Hash is being computed.

Returns
  cy_en_crypto_status_t

Note
  This function can be called several times only with message lengths dividable by the block size. Only the last call to the function can process a message with a not-dividable size.

## ◆ Cy_Crypto_Core_Sha_Finish()

__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
| ) |  |

Completes the SHA calculation.

When D-Cache is enabled parameter digest must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  hashState | The pointer to the SHA context.
  digest | The pointer to the calculated Hash digest.

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Sha_Free()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Sha_Free | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_sha_state_t * | hashState
| ) |  |

Clears the used memory buffers.

When D-Cache is enabled parameter hashState must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  hashState | The pointer to the SHA context.

Returns
  cy_en_crypto_status_t