2017-12-06 12:27 PM
Hi there,
i have a STM32L063 and i wanna encrypt a 32-byte packet by AES-CBC.
I have tested it with using the 'HAL_CRYP_AESCBC_Encrypt' and 'HAL_CRYP_AESCBC_Decrypt' and it worked everytime the same encrypted packet and decrypted packet matches the original packet.
Now i have changed to DMA and it worked the first cycle. The Second cycle there is not the expected behaviour.
Does anybody have an idea what could be the problem?
Thanks
Here the code:
if (HAL_CRYP_DeInit(&hcryp) != HAL_OK)
{ Error_Handler(); } MX_AES_Init();// if (HAL_CRYP_AESCBC_Encrypt_DMA(&hcryp, packet_b_aes,// AES_PACKETSIZE, packet_a_aes) != HAL_OK)// {// /* Processing Error */// Error_Handler();// } if (HAL_CRYP_AESCBC_Encrypt_DMA(&hcryp, packet_lora, AES_PACKETSIZE, packet_a_aes) != HAL_OK) { /* Processing Error */ Error_Handler(); } while (HAL_CRYP_GetState(&hcryp) != HAL_CRYP_STATE_READY) { } if (HAL_CRYP_DeInit(&hcryp) != HAL_OK) { Error_Handler(); } MX_AES_Init(); if (HAL_CRYP_AESCBC_Decrypt_DMA(&hcryp, packet_a_aes, AES_PACKETSIZE, packet_dec_aes) != HAL_OK) { /* Processing Error */ Error_Handler(); } while (HAL_CRYP_GetState(&hcryp) != HAL_CRYP_STATE_READY) { }And the Init Variables:
static const uint8_t pKeyAES[16] =
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c };static const uint8_t pInitVectAES[16] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };uint8_t packet_lora[AES_PACKETSIZE] =
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };/* AES init function */
static void MX_AES_Init(void){hcryp.Instance = AES;
hcryp.Init.DataType = CRYP_DATATYPE_8B; hcryp.Init.pKey = (uint8_t *) pKeyAES; hcryp.Init.pInitVect = (uint8_t *) pInitVectAES; if (HAL_CRYP_Init(&hcryp) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}
#stm32l0 #crypto-aes-encrypt-stm32 #dma-normal