Is the AES-GCM in Python Crypto.Cipher library can take care the AAD portion

1.6k Views Asked by At

Looking at the description below, it doesn't looks like the AES-GCM mode in Crypto. Cipher library can take in AAD data. Do we need to handle it separately for using this? Can advise if my understanding is correct. How to achieve the AES-GCM encryption with using this library if I have the AAD portion in my content need to be take care?

enter image description here

1

There are 1 best solutions below

0
On

As Topaco said in comment, use update(). For example:

from Crypto.Cipher import AES
nonce = bytes(12)
data = bytes(0)
ad = bytes(16)
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
cipher.update(ad)
ciphertext, tag = cipher.encrypt_and_digest(data)