HAL HASH Functions

HASH initialization and de-initialization functions

group HASH_Exported_Functions_Group1

This section provides functions allowing to:

  • Initialize the HASH handle and associate it to a given HASH peripheral instance.

  • DeInitialize the HASH peripheral.

Functions

hal_status_t HAL_HASH_Init ( hal_hash_handle_t * hhash , hal_hash_t instance )

Initialize the selected HAL HASH handle and associate an HASH peripheral instance.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_OK – HASH handle has been correctly initialized.

void HAL_HASH_DeInit ( hal_hash_handle_t * hhash )

DeInitialize the HASH peripheral.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

HASH set and get configuration functions

group HASH_Exported_Functions_Group2

This subsection provides a set of functions allowing to set and get the HASH configuration.

  • Use the function HAL_HASH_SetConfig() to Configure HASH with the specified parameters in the hal_hash_config_t Parameters which are :

    • Data Swapping : no swap or half word swap or bit swap or byte swap.

    • algorithm : SHA-1, SHA2-224, SHA2-256, and on some supported devices SHA2-384, SHA2-512224, SHA2-512256 and SHA2-512.

  • Use the function HAL_HASH_GetConfig() to retrieve the HAL HASH configuration.

Functions

hal_status_t HAL_HASH_SetConfig ( hal_hash_handle_t * hhash , const hal_hash_config_t * p_config )

Configure the HASH according to the specified parameters in the hal_hash_config_t.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_OK – HASH instance has been correctly configured.

void HAL_HASH_GetConfig ( const hal_hash_handle_t * hhash , hal_hash_config_t * p_config )

Get HASH Configuration parameters.

Parameters :

HASH processing functions

group HASH_Exported_Functions_Group3

This section provides API allowing to calculate the hash value using one of the HASH algorithms supported by the peripheral.

For a single buffer to be hashed, user can resort to one of three processing functions available:

In case of multi-buffer HASH processing (a single digest is computed while several buffers are fed to the peripheral), the user can resort to successive calls to :

To retrieve the digest computation, call HAL_HASH_Finish().

Functions

hal_status_t HAL_HASH_Compute ( hal_hash_handle_t * hhash , const void * p_input_buffer , uint32_t input_size_byte , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte , uint32_t timeout_ms )

Compute HASH input buffer in polling mode then retrieve the computed digest in the output buffer and its size in bytes.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – Size of the input buffer in bytes.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the size of the digest in bytes.

  • timeout_ms – Specify timeout value in millisecond

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_TIMEOUT – A timeout has occurred.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – Operation completed.

hal_status_t HAL_HASH_Compute_IT ( hal_hash_handle_t * hhash , const void * p_input_buffer , uint32_t input_size_byte , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte )

Compute HASH input buffer in interrupt mode then retrieve the computed digest in the output buffer and its size in bytes.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – Size of the input buffer in bytes.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the size of the digest in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – Operation started correctly.

hal_status_t HAL_HASH_Compute_DMA ( hal_hash_handle_t * hhash , const void * p_input_buffer , uint32_t input_size_byte , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte )

Compute HASH input buffer in DMA mode then retrieve the computed digest in the output buffer and its size in bytes.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – Size of the input buffer in bytes.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the size of the digest in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – Operation started correctly.

hal_status_t HAL_HASH_Update ( hal_hash_handle_t * hhash , const void * p_add_input_buffer , uint32_t input_size_byte , uint32_t timeout_ms )

HASH update process in polling mode with several input buffers.

Note

Consecutive calls to HAL_HASH_Update() can be used to feed several input buffers back-to-back to the peripheral that will yield a single HASH signature once all buffers have been entered. Wrap-up of input buffers feeding and retrieval of digest is done by a call to HAL_HASH_Finish().

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_add_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

  • timeout_ms – Specify timeout value in millisecond.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_TIMEOUT – A timeout has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_ERROR – An error has occurred.

  • HAL_OK – Input buffer fed correctly.

hal_status_t HAL_HASH_Update_IT ( hal_hash_handle_t * hhash , const void * p_add_input_buffer , uint32_t input_size_byte )

HASH update process in interrupt mode several input buffers.

Note

Consecutive calls to HAL_HASH_Update_IT() can be used to feed several input buffers back-to-back to the peripheral that will yield a single HASH signature once all buffers have been entered. Wrap-up of input buffers feeding and retrieval of digest is done by a call to HAL_HASH_Finish().

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_add_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – The update of the given buffer has been processed correctly.

hal_status_t HAL_HASH_Update_DMA ( hal_hash_handle_t * hhash , const void * p_add_input_buffer , uint32_t input_size_byte )

HASH update process in DMA mode with several input buffers.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_add_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – The update of the given buffer has been processed correctly.

hal_status_t HAL_HASH_Finish ( hal_hash_handle_t * hhash , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte , uint32_t timeout_ms )

Finish HASH update process.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the size of the digest in bytes.

  • timeout_ms – Specify timeout value in millisecond.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_TIMEOUT – A timeout has occurred.

  • HAL_ERROR – An error has occurred.

  • HAL_OK – Hash operation correctly completed and digest available in the output buffer.

HASH HMAC Set and Get configurations functions

group HASH_Exported_Functions_Group4

This subsection provides a set of functions allowing to set and get the HASH HMAC configuration.

  • Use the function HAL_HASH_HMAC_SetConfig() to Configure HASH HMAC with the specified parameters in the hal_hash_hmac_config_t Parameters which are :

    • Data Swapping : no swap or half word swap or bit swap or byte swap.

    • Key and key size in byte to use for the HMAC operation

  • Use the function HAL_HASH_HMAC_GetConfig() to retrieve the HAL HASH HMAC configuration.

Functions

hal_status_t HAL_HASH_HMAC_SetConfig ( hal_hash_handle_t * hhash , const hal_hash_hmac_config_t * p_config )

Configure the HASH HMAC according to the specified parameters in the hal_hash_hmac_config_t.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_OK – Operation started correctly.

void HAL_HASH_HMAC_GetConfig ( const hal_hash_handle_t * hhash , hal_hash_hmac_config_t * p_config )

Get HASH HMAC Configuration parameters.

Parameters :

HMAC processing functions

group HASH_Exported_Functions_Group5

This section provides API allowing to calculate the HMAC (keyed-hash message authentication code).

To calculate the HMAC for a single buffer, user can resort to one of three processing functions available:

In case of multi-buffer HMAC processing (a single digest is computed while several buffers are fed to the peripheral), the user can resort to successive calls to :

To retrieve the digest computation, call HAL_HASH_HMAC_Finish().

Functions

hal_status_t HAL_HASH_HMAC_Compute ( hal_hash_handle_t * hhash , const void * p_input_buffer , uint32_t input_size_byte , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte , uint32_t timeout_ms )

Compute HASH HMAC input buffer in polling mode, then retrieve the computed digest in the output buffer and its size in bytes.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the size of the digest in bytes.

  • timeout_ms – Specify timeout value in millisecond.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_TIMEOUT – A timeout has occurred.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – Operation completed.

hal_status_t HAL_HASH_HMAC_Compute_IT ( hal_hash_handle_t * hhash , const void * p_input_buffer , uint32_t input_size_byte , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte )

Compute HASH HMAC input buffer in interrupt mode, retrieve the computed digest in the output buffer and its size in bytes.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the length of the computed digest in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – Operation started correctly.

hal_status_t HAL_HASH_HMAC_Compute_DMA ( hal_hash_handle_t * hhash , const void * p_input_buffer , uint32_t input_size_byte , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte )

Compute HASH HMAC input buffer in DMA mode, then retrieve the computed digest in the output buffer and its size in bytes.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the length of the computed digest in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – Operation started correctly.

hal_status_t HAL_HASH_HMAC_Update ( hal_hash_handle_t * hhash , const void * p_add_input_buffer , uint32_t input_size_byte , uint32_t timeout_ms )

HASH HMAC update process in polling mode with several input buffers.

Note

Consecutive calls to HAL_HASH_HMAC_Update() can be used to feed several input buffers back-to-back to the peripheral that will yield a single HASH signature once all buffers have been entered. Wrap-up of input buffers feeding and retrieval of digest is done by a call to HAL_HASH_HMAC_Finish().

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_add_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

  • timeout_ms – Specify timeout value in millisecond.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_TIMEOUT – A timeout has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – The update of the given buffer has been processed correctly.

hal_status_t HAL_HASH_HMAC_Update_IT ( hal_hash_handle_t * hhash , const void * p_add_input_buffer , uint32_t input_size_byte )

HASH HMAC update process in IT mode with several input buffers.

Note

Consecutive calls to HAL_HASH_HMAC_Update_IT() can be used to feed several input buffers back-to-back to the peripheral that will yield a single HASH signature once all buffers have been entered. Wrap-up of input buffers feeding and retrieval of digest is done by a call to HAL_HASH_HMAC_Finish().

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_add_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – The update of the given buffer has been processed correctly.

hal_status_t HAL_HASH_HMAC_Update_DMA ( hal_hash_handle_t * hhash , const void * p_add_input_buffer , uint32_t input_size_byte )

HASH HMAC update process in DMA mode with several input buffers.

Note

Multi-buffer HMAC processing is possible, consecutive calls to HAL_HASH_HMAC_Update_DMA() can be used to feed several input buffers back-to-back to the peripheral that will yield a single HASH signature once all buffers have been entered. Wrap-up of input buffers feeding and retrieval of digest is done by a call to HAL_HASH_HMAC_Finish().

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_add_input_buffer – Pointer to the input buffer (buffer to be hashed).

  • input_size_byte – length of the input buffer in bytes.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_BUSY – Process is already ongoing.

  • HAL_OK – The update of the given buffer has been processed correctly.

hal_status_t HAL_HASH_HMAC_Finish ( hal_hash_handle_t * hhash , void * p_output_buffer , uint32_t output_buffer_size_byte , uint32_t * p_output_hash_size_byte , uint32_t timeout_ms )

Finish HASH update process.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_output_buffer – Pointer to the computed digest.

  • output_buffer_size_byte – Size of the output buffer in bytes provided by the user.

  • p_output_hash_size_byte – Pointer to the size of the digest in bytes.

  • timeout_ms – Specify timeout value in millisecond.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_TIMEOUT – A timeout has occurred.

  • HAL_ERROR – An error has occurred.

  • HAL_OK – Hash operation correctly completed and digest available in the output buffer.

HASH Abort functions

group HASH_Exported_Functions_Group6

This section provides functions allowing to:

Functions

hal_status_t HAL_HASH_Abort ( hal_hash_handle_t * hhash , uint32_t timeout_ms )

Abort HASH/HMAC in polling mode.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • timeout_ms – Specify timeout value in millisecond.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_TIMEOUT – A timeout has occurred.

  • HAL_ERROR – In case of user timeout.

  • HAL_OK – Operation completed.

hal_status_t HAL_HASH_Abort_IT ( hal_hash_handle_t * hhash )

Abort HASH/HMAC in interrupt mode.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_OK – Operation completed.

HASH suspend/resume functions

group HASH_Exported_Functions_Group8

This section provides HASH suspend and resume functions.

Functions

hal_status_t HAL_HASH_RequestSuspendComputation ( hal_hash_handle_t * hhash )

Request suspension for hash interrupt mode computation.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has occurred.

  • HAL_OK – The HASH processing suspension is well requested.

hal_status_t HAL_HASH_ResumeComputation ( hal_hash_handle_t * hhash )

Resumption of the suspended HASH processing computation.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_BUSY – Process is already ongoing.

  • HAL_ERROR – An error has occurred.

  • HAL_OK – HASH suspended processing is resumed.

hal_status_t HAL_HASH_RequestSuspendUpdate ( hal_hash_handle_t * hhash )

Request suspension for hash interrupt mode processing update.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – An error has been occurred.

  • HAL_OK – The HASH processing suspension is well requested.

hal_status_t HAL_HASH_ResumeUpdate ( hal_hash_handle_t * hhash )

Resumption of the suspended HASH processing update.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :
  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_BUSY – Process is already ongoing.

  • HAL_ERROR – An error has been occurred.

  • HAL_OK – HASH suspended processing is resumed.

void HAL_HASH_SaveContext ( hal_hash_handle_t * hhash , hal_hash_suspended_context_t * p_context )

Save parameters of the suspended HASH processing.

Parameters :
void HAL_HASH_RestoreContext ( hal_hash_handle_t * hhash , const hal_hash_suspended_context_t * p_context )

Restore the HASH context in case of processing resumption.

Parameters :

HASH peripheral state, error, and user data functions

group HASH_Exported_Functions_Group9

This subsection provides a set of functions to get the HASH error information and state:

Functions

hal_hash_state_t HAL_HASH_GetState ( const hal_hash_handle_t * hhash )

Return the HASH handle state.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :

HAL – HASH global state.

uint32_t HAL_HASH_GetLastErrorCodes ( const hal_hash_handle_t * hhash )

Return the HASH handle error code.

Note

When the return is 0xAAAAAAAAU this is a HAL_INVALID_PARAM

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :

HASH – last error Codes.

void HAL_HASH_SetUserData ( hal_hash_handle_t * hhash , const void * p_user_data )

Store the user data pointer into the HASH handle.

Parameters :
  • hhash – Pointer to a hal_hash_handle_t structure.

  • p_user_data – Pointer to the user data.

const void * HAL_HASH_GetUserData ( const hal_hash_handle_t * hhash )

Retrieve the user data from the HASH handle.

Parameters :

hhash – Pointer to a hal_hash_handle_t structure.

Return values :

Pointer – to the user data.

HASH static inline functions

group HASH_Exported_Functions_Group10

This section provides functions that allow you to manage HASH interrupts and flags:

Functions

uint32_t HAL_HASH_IsActiveFlag ( const hal_hash_handle_t * hhash , uint32_t flag )

Check whether the specified HASH flag is set.

Parameters :
  • hhash – Specifies the HASH handle.

  • flag – Specifies the flag to check. This parameter must be a combination of HASH flags definitions.

Return values :

uint32_t – The state of flag (0 or 1).

uint32_t HAL_HASH_GetITSource ( const hal_hash_handle_t * hhash , uint32_t interrupt )

Check whether the specified HASH interrupt source is enabled.

Parameters :
  • hhash – Specifies the HASH handle.

  • interrupt – Source to check. This parameter must be a combination of HASH interrupts definitions.

Return values :

uint32_t – State of the interrupt (0 or 1).

void HAL_HASH_EnableIT ( hal_hash_handle_t * hhash , uint32_t interrupt )

Enable the specified HASH interrupt.

Parameters :
  • hhash – Specifies the HASH handle.

  • interrupt – Specifies the HASH interrupt source to enable. This parameter must be a combination of HASH interrupts definitions.

void HAL_HASH_DisableIT ( hal_hash_handle_t * hhash , uint32_t interrupt )

Disable the specified HASH interrupt.

Parameters :
  • hhash – Specifies the HASH handle.

  • interrupt – Specifies the HASH interrupt source to disable. This parameter must be a combination of HASH interrupts definitions.

void HAL_HASH_ClearFlag ( hal_hash_handle_t * hhash , uint32_t flag )

Clear the specified HASH flag.

Parameters :
  • hhash – Specifies the HASH handle.

  • flag – Specifies the flag to clear. This parameter must be a combination of HASH flags definitions.