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
stm32f4xx_hash.c File Reference

This file provides firmware functions to manage the following functionalities of the HASH / HMAC Processor (HASH) peripheral: More...

#include "stm32f4xx_hash.h"
#include "stm32f4xx_rcc.h"

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_SetLastWordValidBitsNbr (uint16_t ValidNumber)
 Configure the Number of valid bits in last word of the 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_GetDigest (HASH_MsgDigest *HASH_MessageDigest)
 Provides the message digest result. More...
 
void HASH_StartDigest (void)
 Starts the message padding and calculation of the final message. 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...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the HASH / HMAC Processor (HASH) peripheral:

Author
MCD Application Team
Version
V1.0.2
Date
05-March-2012
  • Initialization and Configuration functions
  • Message Digest generation functions
  • context swapping functions
  • DMA interface function
  • Interrupts and flags management
*                               
*          ===================================================================      
*                                   How to use this driver
*          ===================================================================
*          HASH operation : 
*          ----------------                   
*         1. Enable the HASH controller clock using 
*            RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_HASH, ENABLE) function.
*           
*         2. Initialise the HASH using HASH_Init() function. 
*               
*         3 . Reset the HASH processor core, so that the HASH will be ready 
*             to compute he message digest of a new message by using 
*             HASH_Reset() function.
*
*         4. Enable the HASH controller using the HASH_Cmd() function. 
*                
*         5. if using DMA for Data input transfer, Activate the DMA Request 
*            using HASH_DMACmd() function 
*                    
*         6. if DMA is not used for data transfer, use HASH_DataIn() function 
*            to enter data to IN FIFO.
*             
*          
*         7. Configure the Number of valid bits in last word of the message 
*            using HASH_SetLastWordValidBitsNbr() function.
*             
*         8. if the message length is not an exact multiple of 512 bits, 
*            then the function HASH_StartDigest() must be called to 
*            launch the computation of the final digest.     
*             
*         9. Once computed, the digest can be read using HASH_GetDigest() 
*            function.         
*                   
*        10. To control HASH events you can use one of the following 
*              two methods:
*               a- Check on HASH flags using the HASH_GetFlagStatus() function.  
*               b- Use HASH interrupts through the function HASH_ITConfig() at 
*                  initialization phase and HASH_GetITStatus() function into 
*                  interrupt routines in hashing phase.
*          After checking on a flag you should clear it using HASH_ClearFlag()
*          function. And after checking on an interrupt event you should 
*          clear it using HASH_ClearITPendingBit() function.     
*                     
*        11. Save and restore hash processor context using 
*            HASH_SaveContext() and HASH_RestoreContext() functions.     
*              
*
*            
*          HMAC operation : 
*          ----------------  
*          The HMAC algorithm is used for message authentication, by 
*          irreversibly binding the message being processed to a key chosen 
*          by the user. 
*          For HMAC specifications, refer to "HMAC: keyed-hashing for message 
*          authentication, H. Krawczyk, M. Bellare, R. Canetti, February 1997"
*          
*          Basically, the HMAC algorithm consists of two nested hash operations:
*          HMAC(message) = Hash[((key | pad) XOR 0x5C) | Hash(((key | pad) XOR 0x36) | message)]
*          where:
*          - "pad" is a sequence of zeroes needed to extend the key to the 
*                  length of the underlying hash function data block (that is 
*                  512 bits for both the SHA-1 and MD5 hash algorithms)
*          - "|"   represents the concatenation operator 
*          
*         
*         To compute the HMAC, four different phases are required:
*                    
*         1.  Initialise the HASH using HASH_Init() function to do HMAC 
*             operation. 
*                
*         2.  The key (to be used for the inner hash function) is then given 
*             to the core. This operation follows the same mechanism as the 
*             one used to send the message in the hash operation (that is, 
*             by HASH_DataIn() function and, finally, 
*             HASH_StartDigest() function.
*          
*         3.  Once the last word has been entered and computation has started, 
*             the hash processor elaborates the key. It is then ready to 
*             accept the message text using the same mechanism as the one 
*             used to send the message in the hash operation.
*       
*         4.  After the first hash round, the hash processor returns "ready" 
*             to indicate that it is ready to receive the key to be used for 
*             the outer hash function (normally, this key is the same as the 
*             one used for the inner hash function). When the last word of 
*             the key is entered and computation starts, the HMAC result is 
*             made available using HASH_GetDigest() function.
*               
*              
*  
Attention

© COPYRIGHT 2012 STMicroelectronics

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at:

   http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.