Skip to main content
vchau.2
Associate III
January 23, 2023
Question

AES encryption not working

  • January 23, 2023
  • 2 replies
  • 2152 views

Dear Team,

I want use inbuild AES encryption engine to encrypt the data, therefore I used CubeMX to initialize the AES engine, when i'm going to encrypt the payload, it stuck in

static HAL_StatusTypeDef CRYP_WaitOnOFNEFlag(CRYP_HandleTypeDef *hcryp, uint32_t Timeout) and return HAL_Error.

Kindly let me know what wrong am I doing to initialize the AES engine.

MCU = STM32F417VET

/********************* Code ****************************/

static void MX_CRYP_Init(void)

{

 hcryp.Instance = CRYP;

 hcryp.Init.DataType = CRYP_DATATYPE_8B;

 hcryp.Init.pKey = (uint32_t *)pKeyCRYP;

 hcryp.Init.pInitVect = (uint32_t *)pInitVectCRYP;

 hcryp.Init.Algorithm = CRYP_DES_CBC;

 hcryp.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_BYTE;

 if (HAL_CRYP_Init(&hcryp) != HAL_OK)

 {

  Error_Handler();

 }

}

HAL_CRYP_Encrypt(&hcryp, input, sizeof(input), output, 1000);

This topic has been closed for replies.

2 replies

KDJEM.1
Technical Moderator
January 24, 2023

Hello @Community member​ and welcome to the Community :),

I advise you to get inspired from the available CRYP_AESModes example in the STM32CubeF4 MCU package. This example may help you in the configuration by following the instructions "How to use the CRYP peripheral to encrypt using AES" in the readme file.

I hope this helps!

Thank you.

Koauthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
vchau.2
vchau.2Author
Associate III
January 30, 2023

Thanks for reply,

I test STM324xG_EVAL\Examples\CRYP\CRYP_AESModes project but it is also stuck in same function

static HAL_StatusTypeDef CRYP_WaitOnOFNEFlag(CRYP_HandleTypeDef *hcryp, uint32_t Timeout)

I don't know why its happening,

Please guide if some know this issue

Tesla DeLorean
Guru
January 30, 2023

On the F4's

Perhaps make sure the PLL's are running, and there is a 48 MHz clock source for the CRYP unit.

Enable assert()'s so you can catch bad parameters

Review the source to the library, it's all available.

Check the CRYP unit clock is enabled, and the registers readback non-zero values, could be these parts lack CRYP/HASH units.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
vchau.2
vchau.2Author
Associate III
February 10, 2023

Hi All,

Some one use AES on STM32F4 series,

I check ERRATA sheet also but didn't get meaningful results

Main Issue is CRYPEN bit isn't high in CRYP_CR register.

I'm using existing example source code(without any change) provided by STmicroelectronics (STM32CubeF4-master examples)