STM32F4 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F4 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Enumerator Groups

HASH driver modules. More...

Modules

 HASH_Exported_Constants
 
 HASH_Private_Functions
 

Data Structures

struct  HASH_InitTypeDef
 HASH Init structure definition. More...
 
struct  HASH_MsgDigest
 HASH message digest result structure definition. More...
 
struct  HASH_Context
 HASH context swapping structure definition. More...
 

Macros

#define MD5BUSY_TIMEOUT   ((uint32_t) 0x00010000)
 
#define SHA1BUSY_TIMEOUT   ((uint32_t) 0x00010000)
 

Functions

void HASH_DeInit (void)
 Deinitializes the HASH peripheral registers to their default reset values. More...
 
void HASH_Init (HASH_InitTypeDef *HASH_InitStruct)
 Initializes the HASH peripheral according to the specified parameters in the HASH_InitStruct structure. More...
 
void HASH_StructInit (HASH_InitTypeDef *HASH_InitStruct)
 Fills each HASH_InitStruct member with its default value. More...
 
void HASH_Reset (void)
 Resets the HASH processor core, so that the HASH will be ready to compute the message digest of a new message. More...
 
void HASH_DataIn (uint32_t Data)
 Writes data in the Data Input FIFO. More...
 
uint8_t HASH_GetInFIFOWordsNbr (void)
 Returns the number of words already pushed into the IN FIFO. More...
 
void HASH_SetLastWordValidBitsNbr (uint16_t ValidNumber)
 Configure the Number of valid bits in last word of the message. More...
 
void HASH_StartDigest (void)
 Starts the message padding and calculation of the final message. More...
 
void HASH_GetDigest (HASH_MsgDigest *HASH_MessageDigest)
 Provides the message digest result. More...
 
void HASH_SaveContext (HASH_Context *HASH_ContextSave)
 Save the Hash peripheral Context. More...
 
void HASH_RestoreContext (HASH_Context *HASH_ContextRestore)
 Restore the Hash peripheral Context. More...
 
void HASH_DMACmd (FunctionalState NewState)
 Enables or disables the HASH DMA interface. More...
 
void HASH_ITConfig (uint8_t HASH_IT, FunctionalState NewState)
 Enables or disables the specified HASH interrupts. More...
 
FlagStatus HASH_GetFlagStatus (uint16_t HASH_FLAG)
 Checks whether the specified HASH flag is set or not. More...
 
void HASH_ClearFlag (uint16_t HASH_FLAG)
 Clears the HASH flags. More...
 
ITStatus HASH_GetITStatus (uint8_t HASH_IT)
 Checks whether the specified HASH interrupt has occurred or not. More...
 
void HASH_ClearITPendingBit (uint8_t HASH_IT)
 Clears the HASH interrupt pending bit(s). More...
 
ErrorStatus HASH_SHA1 (uint8_t *Input, uint32_t Ilen, uint8_t Output[20])
 Compute the HASH SHA1 digest. More...
 
ErrorStatus HMAC_SHA1 (uint8_t *Key, uint32_t Keylen, uint8_t *Input, uint32_t Ilen, uint8_t Output[20])
 Compute the HMAC SHA1 digest. More...
 
ErrorStatus HASH_MD5 (uint8_t *Input, uint32_t Ilen, uint8_t Output[16])
 Compute the HASH MD5 digest. More...
 
ErrorStatus HMAC_MD5 (uint8_t *Key, uint32_t Keylen, uint8_t *Input, uint32_t Ilen, uint8_t Output[16])
 Compute the HMAC MD5 digest. More...
 

Detailed Description

HASH driver modules.

Function Documentation

void HASH_ClearFlag ( uint16_t  HASH_FLAG)

Clears the HASH flags.

Parameters
HASH_FLAG,:specifies the flag to clear. This parameter can be any combination of the following values:
  • HASH_FLAG_DINIS: Data Input Flag
  • HASH_FLAG_DCIS: Digest Calculation Completion Flag
Return values
None
void HASH_ClearITPendingBit ( uint8_t  HASH_IT)

Clears the HASH interrupt pending bit(s).

Parameters
HASH_IT,:specifies the HASH interrupt pending bit(s) to clear. This parameter can be any combination of the following values:
  • HASH_IT_DINI: Data Input interrupt
  • HASH_IT_DCI: Digest Calculation Completion Interrupt
Return values
None
void HASH_DataIn ( uint32_t  Data)

Writes data in the Data Input FIFO.

Parameters
Data,:new data of the message to be processed.
Return values
None
void HASH_DeInit ( void  )

Deinitializes the HASH peripheral registers to their default reset values.

Parameters
None
Return values
None
void HASH_DMACmd ( FunctionalState  NewState)

Enables or disables the HASH DMA interface.

Note
The DMA is disabled by hardware after the end of transfer.
Parameters
NewState,:new state of the selected HASH DMA transfer request. This parameter can be: ENABLE or DISABLE.
Return values
None
void HASH_GetDigest ( HASH_MsgDigest HASH_MessageDigest)

Provides the message digest result.

Note
In MD5 mode, Data[4] filed of HASH_MsgDigest structure is not used and is read as zero.
Parameters
HASH_MessageDigest,:pointer to a HASH_MsgDigest structure which will hold the message digest result
Return values
None
FlagStatus HASH_GetFlagStatus ( uint16_t  HASH_FLAG)

Checks whether the specified HASH flag is set or not.

Parameters
HASH_FLAG,:specifies the HASH flag to check. This parameter can be one of the following values:
  • HASH_FLAG_DINIS: Data input interrupt status flag
  • HASH_FLAG_DCIS: Digest calculation completion interrupt status flag
  • HASH_FLAG_BUSY: Busy flag
  • HASH_FLAG_DMAS: DMAS Status flag
  • HASH_FLAG_DINNE: Data Input register (DIN) not empty status flag
Return values
Thenew state of HASH_FLAG (SET or RESET)
uint8_t HASH_GetInFIFOWordsNbr ( void  )

Returns the number of words already pushed into the IN FIFO.

Parameters
None
Return values
Thevalue of words already pushed into the IN FIFO.
ITStatus HASH_GetITStatus ( uint8_t  HASH_IT)

Checks whether the specified HASH interrupt has occurred or not.

Parameters
HASH_IT,:specifies the HASH interrupt source to check. This parameter can be one of the following values:
  • HASH_IT_DINI: Data Input interrupt
  • HASH_IT_DCI: Digest Calculation Completion Interrupt
Return values
Thenew state of HASH_IT (SET or RESET).
void HASH_Init ( HASH_InitTypeDef HASH_InitStruct)

Initializes the HASH peripheral according to the specified parameters in the HASH_InitStruct structure.

Note
the hash processor is reset when calling this function so that the HASH will be ready to compute the message digest of a new message. There is no need to call HASH_Reset() function.
Parameters
HASH_InitStruct,:pointer to a HASH_InitTypeDef structure that contains the configuration information for the HASH peripheral.
Note
The field HASH_HMACKeyType in HASH_InitTypeDef must be filled only if the algorithm mode is HMAC.
Return values
None
void HASH_ITConfig ( uint8_t  HASH_IT,
FunctionalState  NewState 
)

Enables or disables the specified HASH interrupts.

Parameters
HASH_IT,:specifies the HASH interrupt source to be enabled or disabled. This parameter can be any combination of the following values:
  • HASH_IT_DINI: Data Input interrupt
  • HASH_IT_DCI: Digest Calculation Completion Interrupt
NewState,:new state of the specified HASH interrupt. This parameter can be: ENABLE or DISABLE.
Return values
None
ErrorStatus HASH_MD5 ( uint8_t *  Input,
uint32_t  Ilen,
uint8_t  Output[16] 
)

Compute the HASH MD5 digest.

Parameters
Input,:pointer to the Input buffer to be treated.
Ilen,:length of the Input buffer.
Output,:the returned digest
Return values
AnErrorStatus enumeration value:
  • SUCCESS: digest computation done
  • ERROR: digest computation failed
void HASH_Reset ( void  )

Resets the HASH processor core, so that the HASH will be ready to compute the message digest of a new message.

Note
Calling this function will clear the HASH_SR_DCIS (Digest calculation completion interrupt status) bit corresponding to HASH_IT_DCI interrupt and HASH_FLAG_DCIS flag.
Parameters
None
Return values
None
void HASH_RestoreContext ( HASH_Context HASH_ContextRestore)

Restore the Hash peripheral Context.

Note
After calling this function, user can restart the processing from the point where it has been interrupted.
Parameters
HASH_ContextRestore,:pointer to a HASH_Context structure that contains the repository for saved context.
Return values
None
void HASH_SaveContext ( HASH_Context HASH_ContextSave)

Save the Hash peripheral Context.

Note
The context can be saved only when no block is currently being processed. So user must wait for DINIS = 1 (the last block has been processed and the input FIFO is empty) or NBW != 0 (the FIFO is not full and no processing is ongoing).
Parameters
HASH_ContextSave,:pointer to a HASH_Context structure that contains the repository for current context.
Return values
None
void HASH_SetLastWordValidBitsNbr ( uint16_t  ValidNumber)

Configure the Number of valid bits in last word of the message.

Parameters
ValidNumber,:Number of valid bits in last word of the message. This parameter must be a number between 0 and 0x1F.
  • 0x00: All 32 bits of the last data written are valid
  • 0x01: Only bit [0] of the last data written is valid
  • 0x02: Only bits[1:0] of the last data written are valid
  • 0x03: Only bits[2:0] of the last data written are valid
  • ...
  • 0x1F: Only bits[30:0] of the last data written are valid
Note
The Number of valid bits must be set before to start the message digest competition (in Hash and HMAC) and key treatment(in HMAC).
Return values
None
ErrorStatus HASH_SHA1 ( uint8_t *  Input,
uint32_t  Ilen,
uint8_t  Output[20] 
)

Compute the HASH SHA1 digest.

Parameters
Input,:pointer to the Input buffer to be treated.
Ilen,:length of the Input buffer.
Output,:the returned digest
Return values
AnErrorStatus enumeration value:
  • SUCCESS: digest computation done
  • ERROR: digest computation failed
void HASH_StartDigest ( void  )

Starts the message padding and calculation of the final message.

Parameters
None
Return values
None
void HASH_StructInit ( HASH_InitTypeDef HASH_InitStruct)

Fills each HASH_InitStruct member with its default value.

Parameters
HASH_InitStruct: pointer to a HASH_InitTypeDef structure which will be initialized.
Note
The default values set are : Processor mode is HASH, Algorithm selected is SHA1, Data type selected is 32b and HMAC Key Type is short key.
Return values
None
ErrorStatus HMAC_MD5 ( uint8_t *  Key,
uint32_t  Keylen,
uint8_t *  Input,
uint32_t  Ilen,
uint8_t  Output[16] 
)

Compute the HMAC MD5 digest.

Parameters
Key,:pointer to the Key used for HMAC.
Keylen,:length of the Key used for HMAC.
Input,:pointer to the Input buffer to be treated.
Ilen,:length of the Input buffer.
Output,:the returned digest
Return values
AnErrorStatus enumeration value:
  • SUCCESS: digest computation done
  • ERROR: digest computation failed
ErrorStatus HMAC_SHA1 ( uint8_t *  Key,
uint32_t  Keylen,
uint8_t *  Input,
uint32_t  Ilen,
uint8_t  Output[20] 
)

Compute the HMAC SHA1 digest.

Parameters
Key,:pointer to the Key used for HMAC.
Keylen,:length of the Key used for HMAC.
Input,:pointer to the Input buffer to be treated.
Ilen,:length of the Input buffer.
Output,:the returned digest
Return values
AnErrorStatus enumeration value:
  • SUCCESS: digest computation done
  • ERROR: digest computation failed