← back to all posts

One GCM implementation pitfall

blog

If you look at Go’s implementation of GCM, in particular this, you can see that the counter is set to nonce||1:

```go if len(nonce) == gcmStandardNonceSize { // Init counter to nonce||1 copy(counter[:], nonce) counter[gcmBlockSize-1] = 1 } ````

It needs to be. Without it, the first block of keystream is the encryption of 0 if the nonce is 0 (which can happen if nonces are generated from a counter). The encryption of 0 is also… the authentication key!

← back to all posts blog • 2017-03-13

recent posts

elsewhere

book Real-World Cryptography Applied cryptography, from Manning. podcast Two And A Half Coins Crypto, banking & distributed systems. youtube Cryptography videos Concepts & security, explained.