cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with encryption in STM32H747BI board

SLuit.1
Associate III

HI,

I have successfully implemented encryption in my project using STM32 cryptographic firmware library software expansion for STM32Cube. It works fine with 128 bit AES encryption (i.e. using 16 bytes long AES key).

However, I need to implement 256 bit AES encryption and if I change the 16 bytes long key to 32 bytes, then the encryption does not work anymore. It seems that the default setting for encryption key is 16 bytes long.

So could you please let me know what should I do other than changing the length of the key. I mean is there some library files or some other files where I have to make some changes to make 256 bit AES encryption working.

It would be a great help for me because I have been stuck in the situation for quite a long time.

4 REPLIES 4

Or just use, and understand the HAL CRYP libraries..

STM32Cube_FW_H7_V1.8.0\Projects\STM32H743I-EVAL\Examples\CRYP\CRYP_AESModes\Src\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Jocelyn RICARD
ST Employee

Hello @SLuit.1​ 

the new cryptolib contains examples for using AES CBC

I made a quick test using

STM32CubeExpansion_Crypto_V4.0.1\Projects\NUCLEO-L476RG\Applications\Cipher\AES_CBC_EncryptDecrypt\

and data from NIST https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf

Chapter F2.5 that provides a test pattern for 256 bits AES key

Just replacing the data in the test by the data provided in this test:

const uint8_t Key[] =
{
0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
};
const uint8_t IV[] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
const uint8_t Plaintext[] =
{
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
 
};
const uint8_t Expected_Ciphertext[] =
{
0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d, 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d,
0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf, 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61,
0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc, 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b
};

the example works fine.

Best regards

Jocelyn

> Or just use, and understand the HAL CRYP libraries..

CRYP examples are for crypto enabled H75x. In the Cube library examples for these two MCUs (743 and 753) are in one folder because otherwise they are same.