Exemple #1
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{

  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer 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.
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /****************************************************************************/
  /*************************** HMAC-SHA1 **************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  HashHandle.Init.pKey = (uint8_t*)aKey;
  HashHandle.Init.KeySize = KEY_TAB_SIZE;
  
  if(HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }
  
  /* Compute HMAC-SHA1 */
  if(HAL_HMAC_SHA1_Start(&HashHandle, (uint8_t*)aInput, INPUT_TAB_SIZE, aSHA1Digest, 0xFF) != HAL_OK)
  {
    Error_Handler();
  }
  /* Compare computed digest with expected one */
  if(memcmp(aSHA1Digest, aExpectSHA1Digest, sizeof(aExpectSHA1Digest)/sizeof(aExpectSHA1Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    //BSP_LED_On(LED1);
  }
  /* Add your application code here
     */


  /* Infinite loop */
  while (1)
  {
  }
}
Exemple #2
0
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx )
{
    /* HASH IP initialization */
    if (HAL_HASH_DeInit(&ctx->hhash_md5) != 0) {
        return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
    }

    /* HASH Configuration */
    ctx->hhash_md5.Init.DataType = HASH_DATATYPE_8B;
    /* clear CR ALGO value */
    HASH->CR &= ~HASH_CR_ALGO_Msk;
    if (HAL_HASH_Init(&ctx->hhash_md5) != 0) {
        return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
    }
    if (st_md5_save_hw_context(ctx) != 1) {
        // Return HASH_BUSY timeout error here
        return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
    }

    return 0;
}
Exemple #3
0
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
{
    /* HASH IP initialization */
    if (HAL_HASH_DeInit(&ctx->hhash_sha256) == HAL_ERROR) {
        return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
    }

    ctx->is224 = is224;
    /* HASH Configuration */
    ctx->hhash_sha256.Init.DataType = HASH_DATATYPE_8B;
    /* clear CR ALGO value */
    HASH->CR &= ~HASH_CR_ALGO_Msk;
    if (HAL_HASH_Init(&ctx->hhash_sha256) == HAL_ERROR) {
        // error found to be returned
        return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
    }
    if (st_sha256_save_hw_context(ctx) != 1) {
        // return HASH_BUSY timeout Error here
        return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
    }
    return 0;
}
Exemple #4
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, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /****************************************************************************/
  /******************************** SHA1 **************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  
  if(HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }
  
  /* Start HASH computation using DMA transfer */
  HAL_HASH_SHA1_Start_DMA(&HashHandle, (uint8_t*)aInput, strlen((char const*)aInput));
  while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
  /* Get the computed digest value */
  HAL_HASH_SHA1_Finish(&HashHandle, aSHA1Digest, 0xFF);
  while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
  
  /* Compare computed digest with expected one */
  if(memcmp(aSHA1Digest, aExpectSHA1Digest, sizeof(aExpectSHA1Digest)/sizeof(aExpectSHA1Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED1);
  }
  
  /****************************************************************************/
  /******************************** MD5 ***************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  
  if(HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }
  
  /* Start HASH computation using DMA transfer */
  HAL_HASH_MD5_Start_DMA(&HashHandle, (uint8_t*)aInput, strlen((char const*)aInput));
  while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
  /* Get the computed digest value */
  HAL_HASH_MD5_Finish(&HashHandle, aMD5Digest, 0xFF);
  while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
  
  /* Compare computed digest with expected one */
  if(memcmp(aMD5Digest, aExpectMD5Digest, sizeof(aExpectMD5Digest)/sizeof(aExpectMD5Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED4);
  }
  while(1)
  {
  }
}
Exemple #5
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, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /****************************************************************************/
  /*************************** HMAC-SHA1 **************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  HashHandle.Init.pKey = (uint8_t*)aKey;
  HashHandle.Init.KeySize = KEY_TAB_SIZE;
  
  if(HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }
  
  /* Compute HMAC-SHA1 */
  if(HAL_HMAC_SHA1_Start(&HashHandle, (uint8_t*)aInput, INPUT_TAB_SIZE, aSHA1Digest, 0xFF) != HAL_OK)
  {
    Error_Handler();
  }
  /* Compare computed digest with expected one */
  if(memcmp(aSHA1Digest, aExpectSHA1Digest, sizeof(aExpectSHA1Digest)/sizeof(aExpectSHA1Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED1);
  }
  /****************************************************************************/
  /*************************** HMAC-MD5 ***************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  HashHandle.Init.pKey = (uint8_t*)aKey;
  HashHandle.Init.KeySize = KEY_TAB_SIZE;
  
  if(HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }
  
  /* Compute HMAC-MD5 */
  if(HAL_HMAC_MD5_Start(&HashHandle, (uint8_t*)aInput, INPUT_TAB_SIZE, aMD5Digest, 0xFF) != HAL_OK)
  {
    Error_Handler();
  }
  /* Compare computed digest with expected one */
  if(memcmp(aMD5Digest, aExpectMD5Digest, sizeof(aExpectMD5Digest)/sizeof(aExpectMD5Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED4);
  }
  while(1)
  {
  }
}
/**
  * @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();

  /* Configure LED1, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /****************************************************************************/
  /******************************** SHA1 **************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;

  if (HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }

  /* Compute SHA1 */
  if (HAL_HASH_SHA1_Start(&HashHandle, (uint8_t *)aInput, INPUT_TAB_SIZE, aSHA1Digest, 0xFF) != HAL_OK)
  {
    Error_Handler();
  }
  /* Compare computed digest with expected one */
  if (memcmp(aSHA1Digest, aExpectSHA1Digest, sizeof(aExpectSHA1Digest) / sizeof(aExpectSHA1Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED1);
  }

  /****************************************************************************/
  /******************************** MD5 ***************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  HAL_HASH_Init(&HashHandle);

  /* Compute SHA1 */
  if (HAL_HASH_MD5_Start(&HashHandle, (uint8_t *)aInput, INPUT_TAB_SIZE, aMD5Digest, 0xFF) != HAL_OK)
  {
    Error_Handler();
  }
  /* Compare computed digest with expected one */
  if (memcmp(aMD5Digest, aExpectMD5Digest, sizeof(aExpectMD5Digest) / sizeof(aExpectMD5Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED4);
  }
  while (1)
  {
  }
}
Exemple #7
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
	
  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - 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
     */
  HAL_Init();


  /* Configure the system clock to 216 MHz */
  SystemClock_Config();

  /* Since MFX is used, LED init is done after clock config */
  /* Configure LED1, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /****************************************************************************/
  /*************************** HMAC-SHA1 **************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  HashHandle.Init.pKey = (uint8_t*)aKey;
  HashHandle.Init.KeySize = KEY_TAB_SIZE;

  if (HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }

  /* Compute HMAC-SHA1 */
  if (HAL_HMAC_SHA1_Start(&HashHandle, (uint8_t *)aInput, INPUT_TAB_SIZE, aSHA1Digest, 0xFF) != HAL_OK)
  {
    Error_Handler();
  }
  /* Compare computed digest with expected one */
  if (memcmp(aSHA1Digest, aExpectSHA1Digest, sizeof(aExpectSHA1Digest) / sizeof(aExpectSHA1Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED1);
  }

  /****************************************************************************/
  /*************************** HMAC-MD5 ***************************************/
  /****************************************************************************/
  HAL_HASH_DeInit(&HashHandle);
  HashHandle.Init.DataType = HASH_DATATYPE_8B;
  HashHandle.Init.pKey = (uint8_t*)aKey;
  HashHandle.Init.KeySize = KEY_TAB_SIZE;
  
  if(HAL_HASH_Init(&HashHandle) != HAL_OK)
  {
    Error_Handler();
  }

  /* Compute HMAC-MD5 */
  if (HAL_HMAC_MD5_Start(&HashHandle, (uint8_t *)aInput, INPUT_TAB_SIZE, aMD5Digest, 0xFF) != HAL_OK)
  {
    Error_Handler();
  }
  /* Compare computed digest with expected one */
  if (memcmp(aMD5Digest, aExpectMD5Digest, sizeof(aExpectMD5Digest) / sizeof(aExpectMD5Digest[0])) != 0)
  {
    Error_Handler();
  }
  else
  {
    BSP_LED_On(LED4);
  }
  while (1)
  {
  }
}
Exemple #8
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    /* Enable the CPU Cache */
    CPU_CACHE_Enable();

    /* STM32F7xx HAL library initialization:
         - Configure the Flash ART accelerator on ITCM interface
         - 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
       */
    HAL_Init();


    /* Configure the system clock to 216 MHz */
    SystemClock_Config();

    /* Since MFX is used, LED init is done after clock config */
    /* Configure LED1, LED3 and LED4 */
    BSP_LED_Init(LED1);
    BSP_LED_Init(LED3);
    BSP_LED_Init(LED4);

    /****************************************************************************/
    /****************************** SHA224 **************************************/
    /****************************************************************************/
    HAL_HASH_DeInit(&HashHandle);
    HashHandle.Init.DataType = HASH_DATATYPE_8B;

    if (HAL_HASH_Init(&HashHandle) != HAL_OK)
    {
        Error_Handler();
    }

    /* Start HASH computation using DMA transfer */
    if (HAL_HASHEx_SHA224_Start_DMA(&HashHandle, (uint8_t*)aInput, strlen((char const*)aInput)) != HAL_OK)
    {
        Error_Handler();
    }

    /* Get the computed digest value */
    if(HAL_HASHEx_SHA224_Finish(&HashHandle, aSHA224Digest, 0xFF) != HAL_OK)
    {
        Error_Handler();
    }

    /* Compare computed digest with expected one */
    if(memcmp(aSHA224Digest, aExpectSHA224Digest, sizeof(aExpectSHA224Digest)/sizeof(aExpectSHA224Digest[0])) != 0)
    {
        Error_Handler();
    }
    else
    {
        BSP_LED_On(LED1);
    }

    /****************************************************************************/
    /***************************** SHA256 ***************************************/
    /****************************************************************************/
    HAL_HASH_DeInit(&HashHandle);
    HashHandle.Init.DataType = HASH_DATATYPE_8B;

    if(HAL_HASH_Init(&HashHandle) != HAL_OK)
    {
        Error_Handler();
    }
    /* Start HASH computation using DMA transfer */
    if (HAL_HASHEx_SHA256_Start_DMA(&HashHandle, (uint8_t*)aInput, strlen((char const*)aInput)) != HAL_OK)
    {
        Error_Handler();
    }

    /* Get the computed digest value */
    if (HAL_HASHEx_SHA256_Finish(&HashHandle, aSHA256Digest, 0xFF) != HAL_OK)
    {
        Error_Handler();
    }

    /* Compare computed digest with expected one */
    if(memcmp(aSHA256Digest, aExpectSHA256Digest, sizeof(aExpectSHA256Digest)/sizeof(aExpectSHA256Digest[0])) != 0)
    {
        Error_Handler();
    }
    else
    {
        BSP_LED_On(LED4);
    }
    while(1)
    {
    }
}