stm32f4xx_hash.c
Go to the documentation of this file.
1 
122 /* Includes ------------------------------------------------------------------*/
123 #include "stm32f4xx_hash.h"
124 #include "stm32f4xx_rcc.h"
125 
135 /* Private typedef -----------------------------------------------------------*/
136 /* Private define ------------------------------------------------------------*/
137 /* Private macro -------------------------------------------------------------*/
138 /* Private variables ---------------------------------------------------------*/
139 /* Private function prototypes -----------------------------------------------*/
140 /* Private functions ---------------------------------------------------------*/
141 
171 void HASH_DeInit(void)
172 {
173  /* Enable HASH reset state */
175  /* Release HASH from reset state */
177 }
178 
191 void HASH_Init(HASH_InitTypeDef* HASH_InitStruct)
192 {
193  /* Check the parameters */
195  assert_param(IS_HASH_DATATYPE(HASH_InitStruct->HASH_DataType));
196  assert_param(IS_HASH_ALGOMODE(HASH_InitStruct->HASH_AlgoMode));
197 
198  /* Configure the Algorithm used, algorithm mode and the datatype */
200  HASH->CR |= (HASH_InitStruct->HASH_AlgoSelection | \
201  HASH_InitStruct->HASH_DataType | \
202  HASH_InitStruct->HASH_AlgoMode);
203 
204  /* if algorithm mode is HMAC, set the Key */
205  if(HASH_InitStruct->HASH_AlgoMode == HASH_AlgoMode_HMAC)
206  {
208  HASH->CR &= ~HASH_CR_LKEY;
209  HASH->CR |= HASH_InitStruct->HASH_HMACKeyType;
210  }
211 
212  /* Reset the HASH processor core, so that the HASH will be ready to compute
213  the message digest of a new message */
214  HASH->CR |= HASH_CR_INIT;
215 }
216 
225 void HASH_StructInit(HASH_InitTypeDef* HASH_InitStruct)
226 {
227  /* Initialize the HASH_AlgoSelection member */
228  HASH_InitStruct->HASH_AlgoSelection = HASH_AlgoSelection_SHA1;
229 
230  /* Initialize the HASH_AlgoMode member */
231  HASH_InitStruct->HASH_AlgoMode = HASH_AlgoMode_HASH;
232 
233  /* Initialize the HASH_DataType member */
234  HASH_InitStruct->HASH_DataType = HASH_DataType_32b;
235 
236  /* Initialize the HASH_HMACKeyType member */
237  HASH_InitStruct->HASH_HMACKeyType = HASH_HMACKeyType_ShortKey;
238 }
239 
249 void HASH_Reset(void)
250 {
251  /* Reset the HASH processor core */
252  HASH->CR |= HASH_CR_INIT;
253 }
291 void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber)
292 {
293  /* Check the parameters */
295 
296  /* Configure the Number of valid bits in last word of the message */
297  HASH->STR &= ~(HASH_STR_NBW);
298  HASH->STR |= ValidNumber;
299 }
300 
306 void HASH_DataIn(uint32_t Data)
307 {
308  /* Write in the DIN register a new data */
309  HASH->DIN = Data;
310 }
311 
318 {
319  /* Return the value of NBW bits */
320  return ((HASH->CR & HASH_CR_NBW) >> 8);
321 }
322 
335 void HASH_GetDigest(HASH_MsgDigest* HASH_MessageDigest)
336 {
337  /* Get the data field */
338  HASH_MessageDigest->Data[0] = HASH->HR[0];
339  HASH_MessageDigest->Data[1] = HASH->HR[1];
340  HASH_MessageDigest->Data[2] = HASH->HR[2];
341  HASH_MessageDigest->Data[3] = HASH->HR[3];
342  HASH_MessageDigest->Data[4] = HASH->HR[4];
343  HASH_MessageDigest->Data[5] = HASH_DIGEST->HR[5];
344  HASH_MessageDigest->Data[6] = HASH_DIGEST->HR[6];
345  HASH_MessageDigest->Data[7] = HASH_DIGEST->HR[7];
346 }
347 
354 {
355  /* Start the Digest calculation */
356  HASH->STR |= HASH_STR_DCAL;
357 }
396 void HASH_SaveContext(HASH_Context* HASH_ContextSave)
397 {
398  uint8_t i = 0;
399 
400  /* save context registers */
401  HASH_ContextSave->HASH_IMR = HASH->IMR;
402  HASH_ContextSave->HASH_STR = HASH->STR;
403  HASH_ContextSave->HASH_CR = HASH->CR;
404  for(i=0; i<=53;i++)
405  {
406  HASH_ContextSave->HASH_CSR[i] = HASH->CSR[i];
407  }
408 }
409 
418 void HASH_RestoreContext(HASH_Context* HASH_ContextRestore)
419 {
420  uint8_t i = 0;
421 
422  /* restore context registers */
423  HASH->IMR = HASH_ContextRestore->HASH_IMR;
424  HASH->STR = HASH_ContextRestore->HASH_STR;
425  HASH->CR = HASH_ContextRestore->HASH_CR;
426 
427  /* Initialize the hash processor */
428  HASH->CR |= HASH_CR_INIT;
429 
430  /* continue restoring context registers */
431  for(i=0; i<=53;i++)
432  {
433  HASH->CSR[i] = HASH_ContextRestore->HASH_CSR[i];
434  }
435 }
466 {
467  /* Check the parameters */
469 
470  if (NewState != DISABLE)
471  {
472  /* Enable the auto start of the final message digest at the end of DMA transfer */
473  HASH->CR &= ~HASH_CR_MDMAT;
474  }
475  else
476  {
477  /* Disable the auto start of the final message digest at the end of DMA transfer */
478  HASH->CR |= HASH_CR_MDMAT;
479  }
480 }
481 
490 {
491  /* Check the parameters */
493 
494  if (NewState != DISABLE)
495  {
496  /* Enable the HASH DMA request */
497  HASH->CR |= HASH_CR_DMAE;
498  }
499  else
500  {
501  /* Disable the HASH DMA request */
502  HASH->CR &= ~HASH_CR_DMAE;
503  }
504 }
581 void HASH_ITConfig(uint32_t HASH_IT, FunctionalState NewState)
582 {
583  /* Check the parameters */
584  assert_param(IS_HASH_IT(HASH_IT));
586 
587  if (NewState != DISABLE)
588  {
589  /* Enable the selected HASH interrupt */
590  HASH->IMR |= HASH_IT;
591  }
592  else
593  {
594  /* Disable the selected HASH interrupt */
595  HASH->IMR &= (uint32_t)(~HASH_IT);
596  }
597 }
598 
610 FlagStatus HASH_GetFlagStatus(uint32_t HASH_FLAG)
611 {
612  FlagStatus bitstatus = RESET;
613  uint32_t tempreg = 0;
614 
615  /* Check the parameters */
616  assert_param(IS_HASH_GET_FLAG(HASH_FLAG));
617 
618  /* check if the FLAG is in CR register */
619  if ((HASH_FLAG & HASH_FLAG_DINNE) != (uint32_t)RESET )
620  {
621  tempreg = HASH->CR;
622  }
623  else /* The FLAG is in SR register */
624  {
625  tempreg = HASH->SR;
626  }
627 
628  /* Check the status of the specified HASH flag */
629  if ((tempreg & HASH_FLAG) != (uint32_t)RESET)
630  {
631  /* HASH is set */
632  bitstatus = SET;
633  }
634  else
635  {
636  /* HASH_FLAG is reset */
637  bitstatus = RESET;
638  }
639 
640  /* Return the HASH_FLAG status */
641  return bitstatus;
642 }
651 void HASH_ClearFlag(uint32_t HASH_FLAG)
652 {
653  /* Check the parameters */
654  assert_param(IS_HASH_CLEAR_FLAG(HASH_FLAG));
655 
656  /* Clear the selected HASH flags */
657  HASH->SR = ~(uint32_t)HASH_FLAG;
658 }
667 ITStatus HASH_GetITStatus(uint32_t HASH_IT)
668 {
669  ITStatus bitstatus = RESET;
670  uint32_t tmpreg = 0;
671 
672  /* Check the parameters */
673  assert_param(IS_HASH_GET_IT(HASH_IT));
674 
675 
676  /* Check the status of the specified HASH interrupt */
677  tmpreg = HASH->SR;
678 
679  if (((HASH->IMR & tmpreg) & HASH_IT) != RESET)
680  {
681  /* HASH_IT is set */
682  bitstatus = SET;
683  }
684  else
685  {
686  /* HASH_IT is reset */
687  bitstatus = RESET;
688  }
689  /* Return the HASH_IT status */
690  return bitstatus;
691 }
692 
701 void HASH_ClearITPendingBit(uint32_t HASH_IT)
702 {
703  /* Check the parameters */
704  assert_param(IS_HASH_IT(HASH_IT));
705 
706  /* Clear the selected HASH interrupt pending bit */
707  HASH->SR = (uint32_t)(~HASH_IT);
708 }
709 
726 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define HASH_AlgoMode_HMAC
FlagStatus
Definition: stm32f4xx.h:706
#define HASH_STR_DCAL
Definition: stm32f4xx.h:6771
uint32_t HASH_HMACKeyType
#define HASH_CR_DMAE
Definition: stm32f4xx.h:6747
#define IS_HASH_GET_IT(IT)
void HASH_ClearFlag(uint32_t HASH_FLAG)
Clears the HASH flags.
#define HASH_FLAG_DINNE
FunctionalState
Definition: stm32f4xx.h:708
void HASH_Reset(void)
Resets the HASH processor core, so that the HASH will be ready to compute the message digest of a new...
#define IS_HASH_CLEAR_FLAG(FLAG)
#define HASH_CR_NBW
Definition: stm32f4xx.h:6755
FlagStatus HASH_GetFlagStatus(uint32_t HASH_FLAG)
Checks whether the specified HASH flag is set or not.
#define IS_HASH_IT(IT)
void HASH_ITConfig(uint32_t HASH_IT, FunctionalState NewState)
Enables or disables the specified HASH interrupts.
uint32_t Data[8]
uint32_t HASH_CSR[54]
#define HASH
Definition: stm32f4xx.h:2146
void assert_param(int val)
void HASH_ClearITPendingBit(uint32_t HASH_IT)
Clears the HASH interrupt pending bit(s).
uint32_t HASH_STR
uint8_t HASH_GetInFIFOWordsNbr(void)
Returns the number of words already pushed into the IN FIFO.
uint32_t HASH_AlgoSelection
#define HASH_CR_LKEY
Definition: stm32f4xx.h:6762
#define IS_FUNCTIONAL_STATE(STATE)
Definition: stm32f4xx.h:709
uint32_t HASH_CR
#define HASH_CR_ALGO
Definition: stm32f4xx.h:6752
#define IS_HASH_VALIDBITSNUMBER(VALIDBITS)
#define HASH_DataType_32b
HASH context swapping structure definition.
Definition: stm32f4xx.h:706
enum FlagStatus ITStatus
#define HASH_CR_MDMAT
Definition: stm32f4xx.h:6761
This file contains all the functions prototypes for the HASH firmware library.
void HASH_AutoStartDigest(FunctionalState NewState)
Enables or disables auto-start message padding and calculation of the final message digest at the end...
#define HASH_CR_DATATYPE
Definition: stm32f4xx.h:6748
#define IS_HASH_GET_FLAG(FLAG)
void HASH_Init(HASH_InitTypeDef *HASH_InitStruct)
Initializes the HASH peripheral according to the specified parameters in the HASH_InitStruct structur...
#define IS_HASH_DATATYPE(DATATYPE)
void HASH_SaveContext(HASH_Context *HASH_ContextSave)
Save the Hash peripheral Context.
void HASH_DeInit(void)
De-initializes the HASH peripheral registers to their default reset values.
void HASH_StructInit(HASH_InitTypeDef *HASH_InitStruct)
Fills each HASH_InitStruct member with its default value.
#define HASH_AlgoMode_HASH
#define IS_HASH_HMAC_KEYTYPE(KEYTYPE)
void HASH_GetDigest(HASH_MsgDigest *HASH_MessageDigest)
Provides the message digest result.
#define HASH_CR_INIT
Definition: stm32f4xx.h:6746
#define IS_HASH_ALGOMODE(ALGOMODE)
HASH message digest result structure definition.
void HASH_DMACmd(FunctionalState NewState)
Enables or disables the HASH DMA interface.
uint32_t HASH_DataType
#define HASH_STR_NBW
Definition: stm32f4xx.h:6765
void HASH_RestoreContext(HASH_Context *HASH_ContextRestore)
Restore the Hash peripheral Context.
void HASH_StartDigest(void)
Starts the message padding and calculation of the final message.
uint32_t HASH_IMR
#define HASH_HMACKeyType_ShortKey
ITStatus HASH_GetITStatus(uint32_t HASH_IT)
Checks whether the specified HASH interrupt has occurred or not.
#define HASH_AlgoSelection_SHA1
#define IS_HASH_ALGOSELECTION(ALGOSELECTION)
void RCC_AHB2PeriphResetCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
Forces or releases AHB2 peripheral reset.
HASH Init structure definition.
void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber)
Configure the Number of valid bits in last word of the message.
#define HASH_DIGEST
Definition: stm32f4xx.h:2147
void HASH_DataIn(uint32_t Data)
Writes data in the Data Input FIFO.
uint32_t HASH_AlgoMode
#define HASH_CR_MODE
Definition: stm32f4xx.h:6751


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:49