Modified version of the mbed library for use with the Nucleo boards.

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
--- a/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_hash.c	Tue Aug 18 15:00:09 2015 +0100
+++ b/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_hash.c	Thu Aug 20 10:45:13 2015 +0100
@@ -2,8 +2,8 @@
   ******************************************************************************
   * @file    stm32f4xx_hal_hash.c
   * @author  MCD Application Team
-  * @version V1.3.0
-  * @date    09-March-2015
+  * @version V1.3.2
+  * @date    26-June-2015
   * @brief   HASH HAL module driver.
   *          This file provides firmware functions to manage the following 
   *          functionalities of the HASH peripheral:
@@ -176,7 +176,7 @@
         buffersize = hhash->Init.KeySize;
       }
       /* Configure the number of valid bits in last word of the message */
-      HASH->STR |= 8 * (buffersize % 4);
+      MODIFY_REG(HASH->STR, HASH_STR_NBLW, 8 * (buffersize % 4));
       
       /* Set the HASH DMA transfer complete */
       hhash->hdmain->XferCpltCallback = HASH_DMAXferCplt;
@@ -345,7 +345,7 @@
 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash)
 {
   /* Check the hash handle allocation */
-  if(hhash == HAL_NULL)
+  if(hhash == NULL)
   {
     return HAL_ERROR;
   }
@@ -392,7 +392,7 @@
 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash)
 { 
   /* Check the HASH handle allocation */
-  if(hhash == HAL_NULL)
+  if(hhash == NULL)
   {
     return HAL_ERROR;
   }
@@ -714,10 +714,15 @@
   * @param  pInBuffer: Pointer to the input buffer (buffer to be hashed).
   * @param  Size: Length of the input buffer in bytes.
   *          If the Size is not multiple of 64 bytes, the padding is managed by hardware.
+  * @note  Input buffer size in bytes must be a multiple of 4 otherwise the digest computation is corrupted.
   * @retval HAL status
   */
 HAL_StatusTypeDef HAL_HASH_SHA1_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
 {
+  
+  /* Check the parameters */
+  assert_param(IS_HASH_SHA1_BUFFER_SIZE(Size));
+  
   /* Process Locked */
   __HAL_LOCK(hhash);
   
@@ -792,14 +797,6 @@
   /* Process Locked */
   __HAL_LOCK(hhash);
   
-  if(hhash->HashITCounter == 0)
-  {
-    hhash->HashITCounter = 1;
-  }
-  else
-  {
-    hhash->HashITCounter = 0;
-  }
   if(hhash->State == HAL_HASH_STATE_READY)
   {
     /* Change the HASH state */
@@ -818,6 +815,8 @@
          the message digest of a new message */
       HASH->CR |= HASH_CR_INIT;
     }
+    /* Reset interrupt counter */
+    hhash->HashITCounter = 0;
     
     /* Set the phase */
     hhash->Phase = HAL_HASH_PHASE_PROCESS;
@@ -851,11 +850,17 @@
       hhash->State = HAL_HASH_STATE_READY;
       /* Call digest computation complete callback */
       HAL_HASH_DgstCpltCallback(hhash);
+      
+      /* Process Unlocked */
+      __HAL_UNLOCK(hhash);
+      
+      /* Return function status */
+      return HAL_OK;
     }
   }
   if(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))
   {
-    if(hhash->HashInCount > 64)
+    if(hhash->HashInCount >= 68)
     {
       inputaddr = (uint32_t)hhash->pHashInBuffPtr;
       /* Write the Input block in the Data IN register */
@@ -876,8 +881,11 @@
         }
         else
         {
-          hhash->HashInCount -= 64;
+          hhash->HashInCount = 0;
+          hhash->pHashInBuffPtr+= hhash->HashInCount;
         }
+        /* Set Interrupt counter */
+        hhash->HashITCounter = 1;
       }
       else
       {
@@ -901,7 +909,10 @@
       {
         inputcounter = (inputcounter+4-inputcounter%4);
       }
-      
+      else if ((inputcounter < 4) && (inputcounter != 0))
+      {
+        inputcounter = 4;
+      }
       /* Write the Input block in the Data IN register */
       for(buffercounter = 0; buffercounter < inputcounter/4; buffercounter++)
       {
@@ -912,11 +923,12 @@
       __HAL_HASH_START_DIGEST();
       /* Reset buffer counter */
       hhash->HashInCount = 0;
+      
+      /* Call Input data transfer complete callback */
+      HAL_HASH_InCpltCallback(hhash);
     }
-    /* Call Input data transfer complete callback */
-    HAL_HASH_InCpltCallback(hhash);
   }
-  
+
   /* Process Unlocked */
   __HAL_UNLOCK(hhash);
   
@@ -945,14 +957,6 @@
   /* Process Locked */
   __HAL_LOCK(hhash);
   
-  if(hhash->HashITCounter == 0)
-  {
-    hhash->HashITCounter = 1;
-  }
-  else
-  {
-    hhash->HashITCounter = 0;
-  }
   if(hhash->State == HAL_HASH_STATE_READY)
   {
     /* Change the HASH state */
@@ -972,6 +976,9 @@
       HASH->CR |= HASH_CR_INIT;
     }
     
+    /* Reset interrupt counter */
+    hhash->HashITCounter = 0;
+    
     /* Set the phase */
     hhash->Phase = HAL_HASH_PHASE_PROCESS;
     
@@ -1005,11 +1012,17 @@
       hhash->State = HAL_HASH_STATE_READY;
       /* Call digest computation complete callback */
       HAL_HASH_DgstCpltCallback(hhash);
+      
+      /* Process Unlocked */
+      __HAL_UNLOCK(hhash);
+      
+      /* Return function status */
+      return HAL_OK;
     }
   }
   if(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))
   {
-    if(hhash->HashInCount > 64)
+    if(hhash->HashInCount >= 68)
     {
       inputaddr = (uint32_t)hhash->pHashInBuffPtr;
       /* Write the Input block in the Data IN register */
@@ -1021,7 +1034,6 @@
       if(hhash->HashITCounter == 0)
       {
         HASH->DIN = *(uint32_t*)inputaddr;
-      
         if(hhash->HashInCount >= 68)
         {
           /* Decrement buffer counter */
@@ -1030,8 +1042,11 @@
         }
         else
         {
-          hhash->HashInCount -= 64;
+          hhash->HashInCount = 0;
+          hhash->pHashInBuffPtr+= hhash->HashInCount;
         }
+        /* Set Interrupt counter */
+        hhash->HashITCounter = 1;
       }
       else
       {
@@ -1055,7 +1070,10 @@
       {
         inputcounter = (inputcounter+4-inputcounter%4);
       }
-      
+      else if ((inputcounter < 4) && (inputcounter != 0))
+      {
+        inputcounter = 4;
+      }
       /* Write the Input block in the Data IN register */
       for(buffercounter = 0; buffercounter < inputcounter/4; buffercounter++)
       {
@@ -1066,9 +1084,10 @@
       __HAL_HASH_START_DIGEST();
       /* Reset buffer counter */
       hhash->HashInCount = 0;
+
+      /* Call Input data transfer complete callback */
+      HAL_HASH_InCpltCallback(hhash);
     }
-    /* Call Input data transfer complete callback */
-    HAL_HASH_InCpltCallback(hhash);
   }
   
   /* Process Unlocked */
@@ -1089,11 +1108,11 @@
   switch(HASH->CR & HASH_CR_ALGO)
   {
     case HASH_ALGOSELECTION_MD5:
-       HAL_HASH_MD5_Start_IT(hhash, HAL_NULL, 0, HAL_NULL);
+       HAL_HASH_MD5_Start_IT(hhash, NULL, 0, NULL);
     break;
     
     case HASH_ALGOSELECTION_SHA1:
-      HAL_HASH_SHA1_Start_IT(hhash, HAL_NULL, 0, HAL_NULL);
+      HAL_HASH_SHA1_Start_IT(hhash, NULL, 0, NULL);
     break;
     
     default: