Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

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.

http://blogs.msdn.com/b/shawnfa/archive/2009/03/17/authenticated-symmetric-encryption-in-net.aspx

  1. 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");
    
  2. 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();
    
  3. 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

share|improve this question

migrated from security.stackexchange.com Jul 12 '12 at 16:27

This question came from our site for Information security professionals.

add comment

1 Answer 1

up vote 3 down vote accepted

Well, I'm unfamiliar with this specific C# library, and so I can't answer questions about its API. I could guess, but I suspect you want something better than that.

However, I can answer generic GCM questions.

1a. What does the AAD consist of?

Well, AAD is another service that GCM provides. When encrypting messages, it is actually quite common to want to bind some context to the encrypted message; specifically so that message cannot be decrypted in a different context. What GCM does is stir in the AAD along with the ciphertext data when generating the tag; if the decryptor doesn't have this same AAD when he decrypts, he will compute a different tag, and so the decryption attempt will fail. Hence, this plaintext AAD is bound to the ciphertext; you need both to decrypt.

Here's one example of where you might use this: in a TLS record, you have a record type that is not encrypted, followed by encrypted data. One of the things you might want to make sure is that an attacker cannot extract an encrypted data, and reinject it with a different record type. In this case, you can include the record type in with the AAD; then, if the attacker does reuse the ciphertext with a different record type, the decryption will fail, and the record that the attacker modified will be rejected.

1b. Where should the AAD be stored?

That depends on what you're using it for. You might be authenticating unencrypted data that is included with the encrypted message (as in the TLS example); in that case, the decryptor would just extract it from the message. You might be authenticating some state that is shared between the encryptor and the decryptor; in that case, the decryptor would extract it from his database. You might be doing a combination of both; in this case, we'd extract parts of the AAD from different places.

1c. Is it detrimental to the operation of the cipher if I leave the AAD blank?

Not at all. AAD is a service that GCM provides for you; if you don't need that specific capability, you can just leave it blank.

share|improve this answer
    
well at least question 1 is out of the way, thanks –  crawfish Jul 12 '12 at 18:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.