Is there a reason why the following code listing does not output the same encryption?
void print_array(byte *b, unsigned int sz)
{
unsigned int n;
for( n = 0; n < sz; n++ )
{
fprintf(stdout, "%02x ", b[n]);
}
fprintf(stdout, "\r\n");
}
int main(void)
{
Aes enc1;
Aes enc2;
byte aes_key[16];
byte aes_cipher[16];
byte aes_gcm_cipher[16];
byte aes_tag[16];
byte zeros[16];
memset(zeros, 0, 16);
memset(aes_key, 0, 16);
wc_AesSetKeyDirect(&enc1, (const byte*)aes_key, 16, NULL, AES_ENCRYPTION);
wc_AesGcmSetKey(&enc2, (const byte*)aes_key, 16);
wc_AesEncryptDirect(&enc1, aes_cipher, zeros);
wc_AesGcmEncrypt(&enc2, aes_gcm_cipher, zeros, 16, zeros, 16, aes_tag, 16, NULL, 0);
fprintf(stdout, "original: ");
print_array(zeros, 16);
fprintf(stdout, "cipher: ");
print_array(aes_cipher, 16);
fprintf(stdout, "gcm cipher: ");
print_array(aes_gcm_cipher, 16);
return 0;
}
Even though GCM has an extra XOR, the XOR is against zeros, and should still result in the same encrypted data. I'm a little confused on why the outputs are not identical? Thanks!
Here's the output from the program:
original: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
cipher: 66 e9 4b d4 ef 8a 2c 3b 88 4c fa 59 ca 34 2b 2e
gcm cipher: a3 b2 2b 84 49 af af bc d6 c0 9f 2c fa 9d e2 be
Is there a reason why the following code listing does not output the same encryption?
Even though GCM has an extra XOR, the XOR is against zeros, and should still result in the same encrypted data. I'm a little confused on why the outputs are not identical? Thanks!
Here's the output from the program: