1
$\begingroup$

So, my believe is that, in some way, GCM mode or any other authenticated encryption mode is useful to provide encryption and integrity for the ciphertext altogether instead of having to handle the encryption en HMAC separately (as in CBC + HMAC).

My confusion, and this might be a little bit directly related to Java API.., is that using GCM mode I can specify:

a nonce, AAD data

So, my questions:

Is the nonce used to generate a "probabilistic ciphertext", as with IV in CBC mode? Is the nonce also used as key to generate the HMAC for the ciphertext? And therefore only specifying this one I would already obtain an authenticated ciphertext (without having to specify the AAD data)?

Or is the AAD data the one used to generate the HMAC for the ciphertext (I'm pretty sure it's not)? And if not, what is the AAD used for? "To provide an additional context HMAC to accompany the ciphertext"? Could somebody provide an example of this?

ALSO.., independently of which element is used as key to generate the HMAC for the ciphertext.. How must this one be protected? As far as I know, the nonce does not have to be random, it can be a numeric sequence like 1, 2, 3.. for each encrypted message. This seems pretty guessable by an attacker. So isn't it dangerous to use a guessable nonce, or even send it in clear with the cyphertext?

Thank you, and forgive me if I have misused some cryptography terms or words.

$\endgroup$
5
$\begingroup$

Is the nonce used to generate a "probabilistic ciphertext", as with IV in CBC mode? Is the nonce also used as key to generate the HMAC for the ciphertext? And therefore only specifying this one I would already obtain an authenticated ciphertext (without having to specify the AAD data)?

Yes, it provides probabilistic ciphertext.

Contrary to you mentioning HMAC, GCM does use a MAC construction but it is called GMAC. The GMAC tag value is encrypted using the initial counter value, so the authentication tag - the MAC value generated by GMAC - does rely on the IV.

Or is the AAD data the one used to generate the HMAC for the ciphertext (I'm pretty sure it's not)? And if not, what is the AAD used for? "To provide an additional context HMAC to accompany the ciphertext"? Could somebody provide an example of this?

AAD - the additional authenticated data - is included in the authentication, but it isn't responsible for creating the authentication tag. Actually, it is often empty. It can be used for any data that needs to be authenticated, but doesn't need to be confidential.

For instance the header data of a mail message or IP packet could be AAD data. It might be useful to authenticate it so the receiver address isn't altered, but of course the data to route the package to the right address needs to be readable by the routers in between.

ALSO.., independently of which element is used as key to generate the HMAC for the ciphertext.. How must this one be protected? As far as I know, the nonce does not have to be random, it can be a numeric sequence like 1, 2, 3.. for each encrypted message. This seems pretty guessable by an attacker. So isn't it dangerous to use a guessable nonce, or even send it in clear with the cyphertext?

The authentication tag is protected by the same key (and for GCM, indeed, the same cipher / mode of operation) as used to keep the data confidential. So with most AEAD modes you just need one key (SIV mode cheats on this: it requires a double size key and then just splits it in half). And yes, for GCM mode you just require a unique IV/nonce, but remember that it breaks almost completely if you reuse the IV even once.


Please do not look at the Wikipedia pages to understand GCM, instead check section 7.1 of NIST. Note step 6: 6. Let $T=\operatorname{MSB}_t(\mathit{GCTR}_K(J_0,S))$ where $S$ is the outcome of GHASH and $J_0$ is directly derived from the IV ($T$ is the tag, $t$ the tag size and MSB the most significant - leftmost - bits, to be complete). Note that the hash is not secure without this block encrypt.

So the authentication tag is always dependent on the IV value. Note that a unique IV is required even if no data is being encrypted by GCM mode. The GMAC relies on the uniqueness of the IV, as this answer by poncho explains.

$\endgroup$
  • $\begingroup$ If I remember correctly the GMAC calculation also relies on the IV in another way, but I'm checking that now --- when I have the time. $\endgroup$ – Maarten Bodewes Nov 3 '17 at 11:41
  • $\begingroup$ Thanks for your reponse. When you say "The GMAC tag value is encrypted using the initial counter value". You mean the initial counter value is the nonce value set as input? That's something that I don't get clear from this diagram. $\endgroup$ – ka3de Nov 3 '17 at 12:05
  • $\begingroup$ Yes, it uses a calculation over the nonce to create the initial counter. Note that Counter 0 in that diagram is not the value zero, it is the initial counter generated from the nonce. If this wasn't the case then the CTR mode would always use the same counter value, obviously breaking confidentiality. Counter 1 will be the value of counter 0 plus 1 (in big endian notation if I remember correctly). $\endgroup$ – Maarten Bodewes Nov 3 '17 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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