I am implementing an AES cipher in GCM mode in c# and have a few questions. My code is based on the code found here for reference. I'll copy in the relevant portions.
I am having difficulty understand the "additional authenticated data" (AAD) of the GCM implementation. (a) What does the AAD consist of? (b) where should the AAD be stored? (c) Is it detrimental to the operation of the cipher if I leave the AAD blank?
// Authenticated data becomes part of the authentication tag that is generated during // encryption, however it is not part of the ciphertext. That is, when decrypting the // ciphertext the authenticated data will not be produced. However, if the // authenticated data does not match at encryption and decryption time, the // authentication tag will not validate. aes.AuthenticatedData = Encoding.UTF8.GetBytes("Additional authenticated data");
I also do not understand how I am supposed to utilize the "tag" property. (a) Do I need to store the tag once it is created? (b) is the data authentication portion of GCM automatically implemented?
tag = encryptor.GetTag();
I'm not certain how to retrieve the IV (nonce) from the encrypted data. The code I am referencing simply makes this call:
aes.IV = GetNonce();
(a) Is this implicitly removing the first 12 bytes from the encrypted data?
If someone is actually able to answer these questions I'd be completely surprised, but its worth a shot. Thanks