AES256 CTR Mode FAILS
kingingo opened this issue · 0 comments
kingingo commented
The encryption works right but unfortunately if i try to decrypt it again than it is failing...
int i;
uint8_t iv[16] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff };
uint8_t key[32] = { 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 };
uint8_t in[64] = { 0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5, 0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28,
0xf4, 0x43, 0xe3, 0xca, 0x4d, 0x62, 0xb5, 0x9a, 0xca, 0x84, 0xe9, 0x90, 0xca, 0xca, 0xf5, 0xc5,
0x2b, 0x09, 0x30, 0xda, 0xa2, 0x3d, 0xe9, 0x4c, 0xe8, 0x70, 0x17, 0xba, 0x2d, 0x84, 0x98, 0x8d,
0xdf, 0xc9, 0xc5, 0x8d, 0xb6, 0x7a, 0xad, 0xa6, 0x13, 0xc2, 0xdd, 0x08, 0x45, 0x79, 0x41, 0xa6 };
printf("IV:");
for(i = 0; i < 16; i++)
printf("%02X",iv[i]);
printf("\n");
printf("KEY:");
for(i = 0; i < 32; i++)
printf("%02X",key[i]);
printf("\n");
struct AES_ctx ctx;
AES_init_ctx_iv(&ctx, key, iv);
printf("IN:");
for(i = 0; i < 64; i++)
printf("%02X",in[i]);
printf("\n");
AES_CTR_xcrypt_buffer(&ctx, in, 64);
printf("encrypt IN:");
for(i = 0; i < 64; i++)
printf("%02X",in[i]);
printf("\n");
AES_CTR_xcrypt_buffer(&ctx, in, 64);
printf("decrypt IN:");
for(i = 0; i < 64; i++)
printf("%02X",in[i]);
printf("\n");
IV:F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
KEY:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4
IN:601EC313775789A5B7A7F504BBF3D228F443E3CA4D62B59ACA84E990CACAF5C52B0930DAA23DE94CE87017BA2D84988DDFC9C58DB67AADA613C2DD08457941A6
encryptIN:6BC1BEE22E409F96E93D7E117393172AAE2D8A571E03AC9C9EB76FAC45AF8E5130C81C46A35CE411E5FBC1191A0A52EFF69F2445DF4F9B17AD2B417BE66C3710
decryptIN:E0B64102F73C96043ECA700D9A5CD49DE2C6EDD57E05A41FF215A4E960350BFC29064FBA9349656330ACDD59F44B0B87C2F00D4C6182FA14C90C9DE0CDBB5AF6