AES 256 GCM Decryption on STM32L562
Hello,
I am trying to decrypt some data on the L5. The data below can be fed directly into a python crypto library and get a valid result. I am trying to understand the 32-bit alignment requirements of the L5 as well as any possible byte swapping needed. Also, the lengths of the data and the header -- do they get specified in words or bytes? My header is 3 bytes in length and my data is 20 bytes.
How do I set this up to make it work? Apologies for the state of the code -- it's a "work in progress" . :)
Thank you in advance!
D i c k
uint8_t iv8[16] = {0x04, 0xbc, 0xca, 0xab, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
uint8_t key8[32]= {32 bytes};
//uint8_t iv8[12] = {0x04, 0xbc, 0xca, 0xab, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
uint8_t aad8[3] = {0x42, 0x24, 0x02};
uint8_t dc8[20] = {0x66, 0x9b, 0xaa, 0xd4, 0xbc, 0x87, 0xed, 0x03, 0xfa, 0xbf, 0x66, 0xfc, 0x0e, 0x6b, 0x36, 0x85, 0xb7, 0x3a, 0xd7, 0x45};
uint8_t plaintext8[20];
uint8_t outtag8[16];
uint32_t key32[8];
memset(key32, 0, sizeof(key32));
memcpy(key32, key8, sizeof(key8));
uint32_t aad32[4];
memset(aad32, 0, sizeof(aad32));
memcpy(aad32, aad8, sizeof(aad8));
uint32_t iv32[4];
memset(iv32, 0, sizeof(iv32));
memcpy(iv32, iv8, sizeof(iv8));
uint32_t dc32[12];
memset(dc32, 0, sizeof(dc32));
memcpy(dc32, dc8, sizeof(dc8));
uint32_t plaintext32[10];
memset(plaintext32, 0x66, sizeof(plaintext32));
uint32_t outtag32[4];
memset(outtag32, 0x99, sizeof(outtag32));
hcryp.Instance = AES;
hcryp.Init.Algorithm = CRYP_AES_GCM_GMAC;
hcryp.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_BYTE;
hcryp.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
hcryp.Init.DataType = CRYP_DATATYPE_8B;
hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
hcryp.Init.pKey = key32;
hcryp.Init.Algorithm = CRYP_AES_GCM_GMAC;
hcryp.Init.pInitVect = iv32;
hcryp.Init.Header = aad32;
hcryp.Init.HeaderSize = 3;
if (HAL_CRYP_Init(&hcryp) != HAL_OK)
{
Error_Handler();
}
if (HAL_CRYP_Decrypt(&hcryp, dc32, 20, plaintext32,99999)!= HAL_OK)
{
Error_Handler();
}
/* Wait for processing to be done */
while (HAL_CRYP_GetState(&hcryp) != HAL_CRYP_STATE_READY);
/* Compute the authentication TAG */
if (HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp, outtag32, 99999) != HAL_OK)
{
/* Processing Error */
Error_Handler();
}