/** * @brief This function handles TIM6 global interrupt request. * @param None * @retval None */ void TIM6_DAC_IRQHandler(void) { if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) { /*============================================================================= Save MD5 Digest Computation context ==============================================================================*/ HASH_SaveContext(&Md5Context); ContextSwapCounter++; /*============================================================================= SHA1 Digest Computation ==============================================================================*/ HASH_SHA1((uint8_t*)Sha1Input, SHA1_INPUT_TAB_SIZE, Sha1output); /*============================================================================= Restore MD5 Digest Computation context ==============================================================================*/ HASH_RestoreContext(&Md5Context); TIM_ClearITPendingBit(TIM6, TIM_IT_Update); } }
/* * SHA-1 process buffer */ void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen ) { /* unsigned char* constRespect; // Used to respect the const qualifier :( constRespect = pvPortMalloc(ilen); // memcpy(constRespect, input, ilen); // if(HASH_SHA1(constRespect, ilen, ctx->buffer) == ERROR) // Stores the digest in ctx.buffer printf("ERROR in HASH_SHA1 function."); vPortFree(constRespect); */ if( HASH_SHA1( (unsigned char*) input, ilen, ctx->buffer) == ERROR) // Stores the digest in ctx.buffer printf("ERROR in HASH_SHA1 function."); }
/** * @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); }
/** * @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); }