コード例 #1
0
ファイル: main.c プロジェクト: blackphoenix208/ARMWork
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* USART configuration */
  USART_Config();

  /* Display the original message */
  Display_MainMessage(INPUT_TAB_SIZE);

  /* Enable HASH clock */
  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_HASH, ENABLE);


/*=============================================================================
   SHA-1 Digest Computation
==============================================================================*/

  /* SHA-1 Digest Computation */
  HASH_SHA1((uint8_t *)Input, INPUT_TAB_SIZE, Sha1output);

  /* Display the  SHA1 digest */
  Display_SHA1Digest();

/*=============================================================================
   MD5 Digest Computation
==============================================================================*/

  /*  MD5 Digest Computation */
  HASH_MD5((uint8_t *)Input, INPUT_TAB_SIZE, Md5output); 

  /* Display the  MD5 digest */
  Display_MD5Digest();

  while(1);
}
コード例 #2
0
ファイル: main.c プロジェクト: bmaxfie/Cerulean-Hardware
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main.
     */

  /* TIM6 configuration to get a regular interrupt */
  TIM6_Config();

  /* USART configuration */
  USART_Config();

  /* Display the original message */
  Display_MainMessage();

  /* Enable HASH clock */
  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_HASH, ENABLE);

/*=============================================================================
  SHA1/ MD5 Digest Computation without context swap
==============================================================================*/
  printf("\n\r>> MD5 Digest Computation without context swap \n\r");
  printf(">>> Start \n\r");

  /* MD5 Digest Computation *******************************/
  HASH_MD5((uint8_t*)Md5Input, MD5_INPUT_TAB_SIZE,Md5output); 
  printf(">>> Done \n\r");

  /* Display the MD5 digest */
  Display_MD5Digest();

  printf("\n\r>> SHA1 Digest Computation without context swap \n\r");
  printf(">>> Start \n\r");

  /* SHA1 Digest Computation */
  HASH_SHA1((uint8_t*)Sha1Input, SHA1_INPUT_TAB_SIZE, Sha1output); 
  printf(">>> Done \n\r");

  /* Display the SHA1 digest */
  Display_SHA1Digest();

/*=============================================================================
   SHA1 / MD5 Digest Computation with context swap
==============================================================================*/
  printf("\n\r>> MD5 Digest Computation with context swap \n\r");
  printf(">>> Start \n\r");

  /* Enable TIM6 */
  TIM_Cmd(TIM6, ENABLE);

  /* MD5 Digest Computation */
  HASH_MD5((uint8_t*)Md5Input, MD5_INPUT_TAB_SIZE, Md5output); 

  /* Disable TIM2 : no more interrupts */
  TIM_Cmd(TIM6, DISABLE);

  printf(" ====> During MD5 digest calculation, the context is saved and restored (%d) times to calculate the SHA1 digest \n\r", ContextSwapCounter);
  printf(">>> Done \n\r");

  /* Display the MD5 digest */
  Display_MD5Digest();

  printf(">> SHA1 Digest computed during MD5 context swap \n\r");

  /* Display the SHA1 digest */
  Display_SHA1Digest();

  while(1);  
}