I am trying to learn more about GCM mode and how it differs between CBC. I already know that GCM provides a MAC which is used for message authentication. From what I have read, and from the code snippets I've seen, GCM does an exclusive or much like CBC, but I'm not sure what the exclusive-or is against. In CBC mode, the exclusive-or is plaintext against the previous ciphertext block, except for the first block which uses a random IV. Does GCM do the same, or does it do the exclusive-or against something else? If so, can someone please briefly explain how GCM uses the IV and how the exclusive-or is done.

  • 5
    $\begingroup$ If you disregard authentication, GCM behaves like CTR mode, not like CBC mode. Look those up on wikipedia. $\endgroup$ – CodesInChaos Apr 8 '12 at 23:30
  • 8
    $\begingroup$ Just because it isn't defined on this page... GCM = Galois/Counter Mode, and CBC = Cipher Block Chaining... other definitions include MAC (Message Authentication Code), IV (Initialisation Vector), and CTR (CounTeR Mode). $\endgroup$ – Craig Francis Mar 4 '16 at 10:53

GCM and CBC modes internally work quite differently; they both involve a block cipher and an exclusive-or, but they use them in different ways.

In CBC mode, you encrypt a block of data by taking the current plaintext block and exclusive-oring that wth the previous ciphertext block (or IV), and then sending the result of that through the block cipher; the output of the block cipher is the ciphertext block.

GCM mode provides both privacy (encryption) and integrity. To provide encryption, GCM maintains a counter; for each block of data, it sends the current value of the counter through the block cipher. Then, it takes the output of the block cipher, and exclusive or's that with the plaintext to form the ciphertext.

Note two key differences:

  • What's being exclusive-or'ed; in CBC mode, the plaintext is exclusive-or'ed with data that the attacker knows (the IV or a previous ciphertext block); hence, that in itself does not provide any inherent security (instead, we do it to minimize the chance that we send the same block twice through the block cipher). In GCM mode, the plaintext is exclusive-or'ed with output from the block cipher; it is inherent in the security model that the attacker cannot guess that output (unless he already knows the plaintext and the ciphertext).

  • What's being sent through the block cipher; in CBC mode, the plaintext is sent through the block cipher (after it's been 'randomized' with an exclusive-or); in GCM mode, what's being sent through the block cipher doesn't actually depend on the data being encrypted, but instead only on internal state.

As for how GCM uses an IV (I personally consider 'nonce' a better term for what GCM uses, because that emphesizes the idea that with GCM, you cannot use the same nonce for the same key twice), well, it is used to initialize the counter.

  • 2
    $\begingroup$ Very interesting... If I understand correctly, you are saying that in GCM mode the ciphertext of a block is exlusive-or'ed against the plaintext that was just put through the cipher and that block is then sent. If this is true, then how is that block decrypted? Isn't the ciphertext from the AES (for example) encryption required to decrypt the data? How is that obtained? Also, if the original encrypted text is obtained, then it could be used to exclusive-or the sent ciphertext which would return the plaintext and would not need further decryption... I'm missing something... $\endgroup$ – Bob Bryan Apr 9 '12 at 4:23
  • 5
    $\begingroup$ No, in GCM, we take a counter, send that through the block cipher, and then exclusive-or that with the plaintext to form the ciphertext. On the decryption side, we maintain the same counter, send that through the block cipher, and then exclusive-or that with the ciphertext to form the plaintext. $\endgroup$ – poncho Apr 9 '12 at 12:41
  • $\begingroup$ @poncho So in GCM we don’t need the “decryption” part of the block cipher? Because we use “encryption” on both side. $\endgroup$ – Franklin Yu Feb 28 '18 at 4:51
  • 1
    $\begingroup$ If you use the same nonce twice with the same key, you open yourself up to ... what attack? $\endgroup$ – Robert Siemer Apr 19 '18 at 0:38
  • 1
    $\begingroup$ @RobertSiemer: two attacks: a) the attacker gains a significant amount of information of the two messages encrypted with the same nonce (possibly enough to deduce both contents), and b) the attack gains information that would allow him to alter messages without being detected $\endgroup$ – poncho Apr 19 '18 at 13:18

Your Answer

