cancel
Showing results for 
Search instead for 
Did you mean: 

AES encryption not working

vchau.2
Associate III

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);

5 REPLIES 5
KDJEM.1
ST Employee

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.

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

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for your suggestion,

I verified PLL is running , tried on 168 MHz and 48 Mhz,

Enabled assert() - No any error

CRYP unit clock is enabled AHB2

I tried all the examples

CRYP_TDESModes

CRYP_AESModes_DMA

CRYP_AESModes

All are stucked in CRYP_WaitOnOFNEFlag() function

Kindly let me know Is there any Hardware dependency for CRYPTO Engine to make it running

vchau.2
Associate III

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)