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.

  • 4
    If you disregard authentication, GCM behaves like CTR mode, not like CBC mode. Look those up on wikipedia. – CodesInChaos Apr 8 '12 at 23:30
  • 7
    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). – Craig Francis Mar 4 '16 at 10:53
up vote 76 down vote accepted

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
    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... – Bob Bryan Apr 9 '12 at 4:23
  • 4
    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. – poncho Apr 9 '12 at 12:41
  • @poncho So in GCM we don’t need the “decryption” part of the block cipher? Because we use “encryption” on both side. – Franklin Yu Feb 28 at 4:51
  • 1
    If you use the same nonce twice with the same key, you open yourself up to ... what attack? – Robert Siemer Apr 19 at 0:38
  • 1
    @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 – poncho Apr 19 at 13:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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