Cypher using AES 128 CTR
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;
else
{
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,
