Incorrect tag output when using AES / GCM on SAMD51G19A.

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

The device I am using is SAMD51G19A.

 

I used ASF's AES SYNC driver to use AES / GCM.

 

The ciphertext value is displayed normally, but the authentication tag value is displayed abnormally.

 

Below is the code I wrote

 

    BYTE key[16] = {0};
    BYTE iv[16] = {0};

    BYTE aad[16] = {0};

    BYTE tag[16] = {0};

    BYTE pt[32] = {0};

    BYTE ct[32] = {0};

    memset(aad, 0xAA, sizeof(aad));

    

    aes_sync_init(&CRYPTOGRAPHY_0, AES);

    aes_sync_enable(&CRYPTOGRAPHY_0);

    aes_sync_set_encrypt_key(&CRYPTOGRAPHY_0, key, AES_KEY_128);

    aes_sync_gcm_crypt_and_tag(&CRYPTOGRAPHY_0, AES_ENCRYPT, pt, ct, sizeof(pt), iv, sizeof(iv), aad, sizeof(aad), tag, sizeof(tag));

 

 

This is an output 

 

KEY(16) :
0000 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

IV(16) :

0000 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

AAD(16) :

0000 | AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA

PT(32) :

0000 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

0001 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

CT(32) :

0000 | A3 B2 2B 84 49 AF AF BC D6 C0 9F 2C FA 9D E2 BE

0001 | 93 8F 8B BF 23 58 63 D0 CE 02 84 27 22 FD 50 34

TAG(16) :

0000 | AB 93 F1 48 03 E0 BE EE A7 5E FB A5 CD F0 03 96

 

 

In other programs, the authentication tag value is shown below 

 

 

 

How can I fix this?

 

Last Edited: Fri. Mar 6, 2020 - 05:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

i'm using the same54p20a and got the same problem with aes gcm.

The input data will be decrypted right but the tag isn't the expected tag.

 

Does somebody got a solution in the meantime?

 

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

found my mistake, i used a wrong size of aad.

My aad was a string and c terminates a string with a 0, so my size of the array was the string size + 1.

Now aes gcm works as expected.