Live data from Hacker News

AES-GCM and breaking it on nonce reuse

frereit.de

31–40 of 64 posts

Re: AES-GCM and breaking it on nonce reuse

#31
GCM is well known to have sudden death on nonce reuse, which is why we used GCM-SIV for the ZeroTier v1 protocol. (Our new protocol that stiiiil is not in product is Noise based.)

Nonce reuse in SIV is much less catastrophic. Reuse of a nonce can reveal if two packets are identical but doesn’t let you do anything else.

Of course there are categorically better modes than GCM but they are not widely supported. ChaChaPoly is better cryptographically but no hardware acceleration, which matters on small devices.

Re: AES-GCM and breaking it on nonce reuse

#32
post #26
post #19

Earlier quoted context omitted.

> When I use AES-GCM I just use a bigger nonce and use a random one. I don't think nonces bigger than 12 bytes will help. My quick reading of the AES-GCM spec is that when using a nonce that's not 96 bits (12 bytes), it is hashed to 96 bits. So either the nonce (called iv in the spec) is carefully constructed from a counter and set to exactly 96 bits, or the number of invocations is limited. The spec still restricts…

Nonces (called IVs in the spec) of any length other than 96 bits are fed into GHASH before use, which has 128 bits of output. This means that IVs can't contribute more than 128 bits of entropy but they may be able to contribute up to that many; it's not clear to me what effect GHASH has on the entropy of the IV though.

You're right, GHASH has 128 bits output. I'd wrongly assumed it was 96 from my quick reading of the conclusion on p29:

> unless an implementation only uses 96-bit IVs that are generated by the deterministic construction: The total number of invocations of the authenticated encryption function shall not exceed 2^32, including all IV lengths...

Which would be the conclusion if the hash was always reduced to 96 bits. What it actually goes on to say though is:

> For the RBG-based construction of IVs, the above requirement, in conjunction with the requirement that r(i)≥96, is sufficient to ensure the uniqueness requirement in Sec. 8

So, it's a bound. If there are at least 96 random bits, it should all be ok. But it strangely leaves open the possibility, without saying either way, that a longer iv, with r(i)>96 random bits might allow generating more iv's. As you point out, it will depend on the properties of GHASH (and potentially on how the result is used downstream from there). At this point I don't know, but the spec says:

> For IVs, it is recommended that implementations restrict support to the length of 96 bits, to promote interoperability, efficiency, and simplicity of design.

So personally, not being an expert, I'd follow the advice and use 96 bit iv's. And if using random iv's, re-key before using the key a billion times. I'd certainly want a reference to a careful analysis before assuming that I could ever use an AES-GCM key with longer random iv's more than that.

Re: AES-GCM and breaking it on nonce reuse

#33
post #32
post #26

Earlier quoted context omitted.

Nonces (called IVs in the spec) of any length other than 96 bits are fed into GHASH before use, which has 128 bits of output. This means that IVs can't contribute more than 128 bits of entropy but they may be able to contribute up to that many; it's not clear to me what effect GHASH has on the entropy of the IV though.

You're right, GHASH has 128 bits output. I'd wrongly assumed it was 96 from my quick reading of the conclusion on p29: > unless an implementation only uses 96-bit IVs that are generated by the deterministic construction: The total number of invocations of the authenticated encryption function shall not exceed 2^32, including all IV lengths... Which would be the conclusion if the hash was always reduced to 96 bits. Wh…

Yeah, interoperability basically dictates 96-bit nonces. I'd say GCM is hard to use correctly for any situation where you have an indefinite amount of data to encrypt and you can't do deterministic nonce generation and you can't rekey easily.

Re: AES-GCM and breaking it on nonce reuse

#34
post #18
post #14

I dunno, nonce means number-used-once, it should be kinda obvious that it should be used only once?

Correct. However, some implementations actually incorrectly refer to the nonce as an "IV" (initialization vector), where it's not so obvious. Also, it's not entirely clear just how bad a reuse actually is. For example, in AES-CBC, reusing the IV has much less impact than reusing the nonce with AES-GCM.

NIST calls it an IV (or at least did when it came out).

Re: AES-GCM and breaking it on nonce reuse

#35
post #9
post #7

It's worth mentioning AES-GCM-SIV[1], which is the fix for this issue. [1] https://www.rfc-editor.org/rfc/rfc8452.html

The alternative, which I prefer, is an XGCM-like construction that just gives you a large enough nonce to comfortably use random nonces.

Could this be extended to give us XOCB? I am not sure it would make much sense with the OCB size recommendations.

Re: AES-GCM and breaking it on nonce reuse

#36
post #20

nonce really should be renamed. if only for british slang avoidance.

I agree on principle, but I feel the next name will also be turned into another British slang term for sex offenders, if only because some lad will find it funny and become determined to see it through.

We are, after all, talking about the country that terrorized an Austrian town into changing its name after decades of sign theft and jokes [0]

[0]https://en.wikipedia.org/wiki/Fugging,_Upper_Austria

Re: AES-GCM and breaking it on nonce reuse

#37
post #20

nonce really should be renamed. if only for british slang avoidance.

I agree on principle, but I feel the next name will also be turned into another British slang term for sex offenders, if only because some lad will find it funny and become determined to see it through. We are, after all, talking about the country that terrorized an Austrian town into changing its name after decades of sign theft and jokes [0] [0] https://en.wikipedia.org/wiki/Fugging,_Upper_Austria

It's also the language/dialect where you can basically used any phrase ending in -ed to mean "drunk". The classics being pissed, plastered, wankered. But if someone came up to me and said "I got (wardrobed|hadron-collidered) last night" I'd know exactly what they meant

Re: AES-GCM and breaking it on nonce reuse

#38
Not just AES-GCM.

The vast majority of encryption algorithms must be used in a nonce-respecting scenario. This is part of the contract to achieve the claimed security properties.

Alternatives require multiple passes over the data, which is not applicable to some protocols in addition to having performance implications.

Common protocols such as TLS transparently handle nonces in a safe way. But the primitives used in TLS may require additional steps to be safely used is other contexts, especially in distributed systems.

Whenever applications try to use these primitives directly, using a fixed key and picking nonces at random is a very common practice. Unfortunately, due to their small size, nonces collisions can quickly happen.

We're missing standard constructions with large nonces that would alleviate this problem, because IETF protocols haven't needed them. But there's a lot of evidence that many custom applications and protocols do.

There are multiple great proposals to derive AES-GCM subkeys and nonces from a key and a large nonce. We may expect convergence and adoption in crypto libraries soon.

Until then, constructions such as XSalsa20 and XChaCha20 are widely implemented and deployed. If you don't need NIST compliance, they're excellent choices.

But my recommendation today would be to replace AES-GCM with the AEGIS family of algorithms whenever possible. They have nice properties that AES-GCM doesn't have, including more comfortable usage limits, much better performance and large nonces up to 256 bits.

This page [1] and that draft [2] summarize usage limits of common constructions, including when using random nonces.

[2] https://doc.libsodium.org/secret-key_cryptography/aead

[3] https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits...

Re: AES-GCM and breaking it on nonce reuse

#39
post #32
post #26

Earlier quoted context omitted.

Nonces (called IVs in the spec) of any length other than 96 bits are fed into GHASH before use, which has 128 bits of output. This means that IVs can't contribute more than 128 bits of entropy but they may be able to contribute up to that many; it's not clear to me what effect GHASH has on the entropy of the IV though.

You're right, GHASH has 128 bits output. I'd wrongly assumed it was 96 from my quick reading of the conclusion on p29: > unless an implementation only uses 96-bit IVs that are generated by the deterministic construction: The total number of invocations of the authenticated encryption function shall not exceed 2^32, including all IV lengths... Which would be the conclusion if the hash was always reduced to 96 bits. Wh…

> But it strangely leaves open the possibility, without saying either way, that a longer iv, with r(i)>96 random bits might allow generating more iv's. As you point out, it will depend on the properties of GHASH (and potentially on how the result is used downstream from there).

There is some details on the "GHASH as initial counter value" which seem to suggest that for larger nonces, the total number of messages shouldn't exceed 2^44.5 here: https://neilmadden.blog/2024/05/23/galois-counter-mode-and-r...

Re: AES-GCM and breaking it on nonce reuse

#40
post #21
post #14

I dunno, nonce means number-used-once, it should be kinda obvious that it should be used only once?

And yet... Aside from just not understanding it, it's plausible that someone would generate nonces weakly, say, from a weak source of randomness. Even using a strong source of randomness for an AES-GCM nonce is weak over enough messages, since it only gets you 48 bits of collision resistance. If you're not using random nonces, maybe you want to use a counter, and then you have to worry about race conditions, state re…

> Aside from just not understanding it, it's plausible that someone would generate nonces weakly, say, from a weak source of randomness.

This is actually generally fine for nonces (used in CTR and GCM modes, and in ChaCha20). Typically the only requirement for a nonce is that it is only used once. It is even safe to use a simple incrementing counter.

IVs, on the other hand, are required to be cryptographically random.

Post reply on HN