Hi,
Im trying to encryp using AES 128 CTR but i dont get the same result that online calculators.
Im using this online calculator:
https://cryptii.com/pipes/aes-encryption
My code is the next:
uint8_t IVKey[] = {0xDD, 0xF9, 0x11, 0xA6, 0xDD, 0xF9, 0x11, 0xA6, 0xDD, 0xF9, 0x11, 0xA6, 0xDD, 0xF9, 0x11, 0xA6};
AesDeInit();
// CTR AES
hcryp.Instance = AES;
hcryp.Init.DataType = CRYP_DATATYPE_1B;
hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
hcryp.Init.pKey = (uint32_t *)AESKey;
hcryp.Init.Algorithm = CRYP_AES_CTR;
hcryp.Init.pInitVect = (uint32_t *)IVKey;
if (HAL_CRYP_Init(&hcryp) != HAL_OK)
Error_Handler();
}
and the AESKey is the next:
const uint8_t AESKey[] =
{0x44, 0x26, 0x44, 0x20, 0x45, 0x6C, 0x65, 0x74, 0x74, 0x72, 0x6F, 0x6E, 0x69, 0x63, 0x61, 0x20
};
My AES function is the next:
int16_t AesEncrypt(char *In,int16_t Len)
uint8_t Buf[16];
if (Len & 0x0F)
Len+=16-(Len & 0x0F);
if (HAL_CRYP_DeInit(&hcryp)!=HAL_OK)
Len=0;
else if (HAL_CRYP_Init(&hcryp)!=HAL_OK)
Len=0;
for (int16_t i=Len;i>0;i-=16) // Encripta paquete
if (HAL_CRYP_Encrypt(&hcryp,(uint32_t *)In,16,(uint32_t *)Buf,255)!=HAL_OK)
Len=0;
break;
memcpy(In,Buf,16);
In+=16;
return Len;
}
and the string insert into the function is
char Message2[] = {0x50, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x01, 0x03, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00};
The result with the online calculator is: 6c 9d 95 e6 9a 75 ed 03 7c a2 81 80 f9 a6 c3 18
The result that im getting is: c4, b0, c3, 8d, 2d, b2, 5b, 20, 89,75, 57 76, 83, 06, be, 1e
My result is wrong t i dont know what am i doing wrong.
Any suggestion?
Thanks,
Best Regards,
Confirming on-line result with C library here, Decrypting in this case, but symmetrical..
KEY
0000 : 44 26 44 20 45 6C 65 74-74 72 6F 6E 69 63 61 20 D&D Elettronica
0000 : DD F9 11 A6 DD F9 11 A6-DD F9 11 A6 DD F9 11 A6 ................
CRYPT-TEXT
0000 : 50 00 30 30 30 30 30 31-01 03 08 20 00 00 00 00 P.000001... ....
PLAIN-TEXT
0000 : 6C 9D 95 E6 9A 75 ED 03-7C A2 81 80 F9 A6 C3 18 l....u..|.......
Can someone suggest me Best controller for my CAN device purpose with all possible securities ?
in
STM32 MCUs Security
STM32L082 (CMWX1ZZABZ-078) hardfaults while running HAL's CRYP_ProcessData()
in
STM32 MCUs Products
Unable to make HW AES work for STM32L476
in
STM32 MCUs Security