Beispiel #1
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{    
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Configure LED1, LED2 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);

  /*##-1- Configure the CRYP peripheral ######################################*/
  /* Set the CRYP parameters */
  CrypHandle.Init.DataType = CRYP_DATATYPE_8B;
  CrypHandle.Init.KeySize  = CRYP_KEYSIZE_128B;
  CrypHandle.Init.pKey     = aTDESKey;

  if(HAL_CRYP_Init(&CrypHandle)!= HAL_OK)
  {
    /* Initialization process error */
    Error_Handler();  
  }
  
  /*##-2- Start the TDES encryption in ECB chaining mode #####################*/
  if (HAL_CRYP_TDESECB_Encrypt_DMA(&CrypHandle, aPlaintext, 48, aEncryptedtext) != HAL_OK)
  {
    /* Processing error */
    Error_Handler();  
  }
  while (HAL_CRYP_GetState(&CrypHandle) != HAL_CRYP_STATE_READY);
  
  /*##-3- Check the encrypted text with the expected one #####################*/
  if(memcmp(aEncryptedtext, aCyphertext, 48) != 0)
  {
    /* Wrong encryption: Turn LED2 on */
    BSP_LED_On(LED2);
  }
  else
  {
    /* Right encryption: Turn LED1 on */  
    BSP_LED_On(LED1);
  }
  
  /* Infinite loop */  
  while (1)
  {
  }
}
Beispiel #2
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization: global MSP (MCU Support Package) initialization
     */
  HAL_Init();

  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
 
  /* Initialize LED1, LED2 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  
  /*##-1- Configure the CRYP peripheral ######################################*/
  CrypHandle.Instance = CRYP;
  
  /* Set the CRYP parameters */
  CrypHandle.Init.DataType = CRYP_DATATYPE_8B;
  CrypHandle.Init.KeySize  = CRYP_KEYSIZE_128B;
  CrypHandle.Init.pKey     = aTDESKey;

  if(HAL_CRYP_Init(&CrypHandle)!= HAL_OK)
  {
    /* Initialization process error */
    Error_Handler();  
  }
  
  /*##-2- Start the TDES encryption in ECB chaining mode #####################*/
  if (HAL_CRYP_TDESECB_Encrypt_DMA(&CrypHandle, aPlaintext, 48, aEncryptedtext) != HAL_OK)
  {
    /* Processing error */
    Error_Handler();  
  }
  while (HAL_CRYP_GetState(&CrypHandle) != HAL_CRYP_STATE_READY);
  
  /*##-3- Check the encrypted text with the expected one #####################*/
  if(memcmp(aEncryptedtext, aCyphertext, 48) != 0)
  {
    /* Wrong encryption: Turn LED2 on */
    BSP_LED_On(LED2);
  }
  else
  {
    /* Right encryption: Turn LED1 on */  
    BSP_LED_On(LED1);
  }

  /* Infinite loop */
  while(1)
  {
  }
}