Recent from talks
Nothing was collected or created yet.
Galois/Counter Mode
View on WikipediaIn cryptography, Galois/Counter Mode (GCM)[1] is a mode of operation for symmetric-key cryptographic block ciphers which is widely adopted for its performance. GCM throughput rates for state-of-the-art, high-speed communication channels can be achieved with inexpensive hardware resources.[2]
The GCM algorithm provides data authenticity, integrity and confidentiality and belongs to the class of authenticated encryption with associated data (AEAD) methods. This means that as input it takes a key K, some plaintext P, and some associated data AD; it then encrypts the plaintext using the key to produce ciphertext C, and computes an authentication tag T from the ciphertext and the associated data (which remains unencrypted). A recipient with knowledge of K, upon reception of AD, C and T, can decrypt the ciphertext to recover the plaintext P and can check the tag T to ensure that neither ciphertext nor associated data were tampered with.
GCM uses a block cipher with block size 128 bits (commonly AES-128) operated in counter mode for encryption, and uses arithmetic in the Galois field GF(2128) to compute the authentication tag; hence the name.
Galois Message Authentication Code (GMAC) is an authentication-only variant of the GCM which can form an incremental message authentication code. Both GCM and GMAC can accept initialization vectors of arbitrary length.
Different block cipher modes of operation can have significantly different performance and efficiency characteristics, even when used with the same block cipher. GCM can take full advantage of parallel processing and implementing GCM can make efficient use of an instruction pipeline or a hardware pipeline. By contrast, the cipher block chaining (CBC) mode of operation incurs pipeline stalls that hamper its efficiency and performance.
Basic operation
[edit]Like in normal counter mode, blocks are numbered sequentially, and then this block number is combined with an initialization vector (IV) and encrypted with a block cipher E, usually AES. The result of this encryption is then XORed with the plaintext to produce the ciphertext. Like all counter modes, this is essentially a stream cipher, and so it is essential that a different IV is used for each stream that is encrypted.
The ciphertext blocks are considered coefficients of a polynomial which is then evaluated at a key-dependent point H, using finite field arithmetic. The result is then encrypted, producing an authentication tag that can be used to verify the integrity of the data. The encrypted text then contains the IV, ciphertext, and authentication tag.

Encryption: A series of 128-bit counters is encrypted using the block cipher E with key K; this can occur in parallel. The results are combined using bitwise XOR with 128-bit plaintext blocks, producing a series of ciphertext blocks.
Authentication: The Additional Data and these ciphertext blocks are combined using multiplication with a key-dependent constant H in the Galois field GF(2128) to produce the authentication tag.
Mathematical basis
[edit]GCM combines the well-known counter mode of encryption with the new Galois mode of authentication. The key feature is the ease of parallel computation of the Galois field multiplication used for authentication. This feature permits higher throughput than encryption algorithms, like CBC, which use chaining modes. The GF(2128) field used is defined by the polynomial
The authentication tag is constructed by feeding blocks of data into the GHASH function and encrypting the result. This GHASH function is defined by
where H = Ek(0128) is the hash key, a string of 128 zero bits encrypted using the block cipher, A is data which is only authenticated (not encrypted), C is the ciphertext, m is the number of 128-bit blocks in A (rounded up), n is the number of 128-bit blocks in C (rounded up), and the variable Xi for i = 0, ..., m + n + 1 is defined below.[3]
First, the authenticated text and the cipher text are separately zero-padded to multiples of 128 bits and combined into a single message Si:
where len(A) and len(C) are the 64-bit representations of the bit lengths of A and C, respectively, v = len(A) mod 128 is the bit length of the final block of A, u = len(C) mod 128 is the bit length of the final block of C, and denotes concatenation of bit strings.
Then Xi is defined as:
The second form is an efficient iterative algorithm (each Xi depends on Xi−1) produced by applying Horner's method to the first. Only the final Xm+n+1 remains an output.
If it is necessary to parallelize the hash computation, this can be done by interleaving k times:
If the length of the IV is not 96, the GHASH function is used to calculate Counter 0:
GCM was designed by John Viega and David A. McGrew to be an improvement to Carter–Wegman counter mode (CWC mode).[4]
In November 2007, NIST announced the release of NIST Special Publication 800-38D Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC making GCM and GMAC official standards.[5]
Use
[edit]GCM mode is used in the IEEE 802.1AE (MACsec) Ethernet security, WPA3-Enterprise Wifi security protocol, IEEE 802.11ad (also dubbed WiGig), ANSI (INCITS) Fibre Channel Security Protocols (FC-SP), IEEE P1619.1 tape storage, IETF IPsec standards,[6][7] SSH,[8] TLS 1.2[1][9] and TLS 1.3.[10] AES-GCM is included in the NSA Suite B Cryptography and its latest replacement in 2018 Commercial National Security Algorithm (CNSA) suite.[11] GCM mode is used in the SoftEther VPN server and client,[12] as well as OpenVPN since version 2.4.
Performance
[edit]GCM requires one block cipher operation and one 128-bit multiplication in the Galois field per each block (128 bit) of encrypted and authenticated data. The block cipher operations are easily pipelined or parallelized; the multiplication operations are easily pipelined and can be parallelized with some modest effort (either by parallelizing the actual operation, by adapting Horner's method per the original NIST submission, or both).
Intel has added the PCLMULQDQ instruction, highlighting its use for GCM.[13] In 2011, SPARC added the XMULX and XMULXHI instructions, which also perform 64 × 64 bit carry-less multiplication. In 2015, SPARC added the XMPMUL instruction, which performs XOR multiplication of much larger values, up to 2048 × 2048 bit input values producing a 4096-bit result. These instructions enable fast multiplication over GF(2n), and can be used with any field representation.
Impressive performance results are published for GCM on a number of platforms. Käsper and Schwabe described a "Faster and Timing-Attack Resistant AES-GCM"[14] that achieves 10.68 cycles per byte AES-GCM authenticated encryption on 64-bit Intel processors. Dai et al. report 3.5 cycles per byte for the same algorithm when using Intel's AES-NI and PCLMULQDQ instructions. Shay Gueron and Vlad Krasnov achieved 2.47 cycles per byte on the 3rd generation Intel processors. Appropriate patches were prepared for the OpenSSL and NSS libraries.[15]
When both authentication and encryption need to be performed on a message, a software implementation can achieve speed gains by overlapping the execution of those operations. Performance is increased by exploiting instruction-level parallelism by interleaving operations. This process is called function stitching,[16] and while in principle it can be applied to any combination of cryptographic algorithms, GCM is especially suitable. Manley and Gregg[17] show the ease of optimizing when using function stitching with GCM. They present a program generator that takes an annotated C version of a cryptographic algorithm and generates code that runs well on the target processor.
GCM has been criticized in the embedded world (for example by Silicon Labs) because the parallel processing is not suited for performant use of cryptographic hardware engines. As a result, GCM reduces the performance of encryption for some of the most performance-sensitive devices.[18] Specialized hardware accelerators for ChaCha20-Poly1305 are less complex compared to AES accelerators.[19]
Patents
[edit]According to the authors' statement, GCM is unencumbered by patents.[20]
Security
[edit]GCM is proven secure in the concrete security model.[21] It is secure when it is used with a block cipher that is indistinguishable from a random permutation; however, security depends on choosing a unique initialization vector for every encryption performed with the same key (see stream cipher attack). For any given key and initialization vector value, GCM is limited to encrypting 239 − 256 bits of plain text (64 GiB). NIST Special Publication 800-38D[5] includes guidelines for initialization vector selection and limits the number of possible initialization vector values for a single key. As the security assurance of GCM degrades with more data being processed using the same key, the total number of blocks of plaintext and AD protected during the lifetime of a single key should be limited by 264.[5]
The authentication strength depends on the length of the authentication tag, like with all symmetric message authentication codes. The use of shorter authentication tags with GCM is discouraged. The bit-length of the tag, denoted t, is a security parameter. In general, t may be any one of the following five values: 128, 120, 112, 104, or 96. For certain applications, t may be 64 or 32, but the use of these two tag lengths constrains the length of the input data and the lifetime of the key. Appendix C in NIST SP 800-38D provides guidance for these constraints (for example, if t = 32 and the maximal packet size is 210 bytes, the authentication decryption function should be invoked no more than 211 times; if t = 64 and the maximal packet size is 215 bytes, the authentication decryption function should be invoked no more than 232 times).
Like with any message authentication code, if the adversary chooses a t-bit tag at random, it is expected to be correct for given data with probability measure 2−t. With GCM, however, an adversary can increase their likelihood of success by choosing tags with n words – the total length of the ciphertext plus any additional authenticated data (AAD) – with probability measure 2−t by a factor of n. Although, one must bear in mind that these optimal tags are still dominated by the algorithm's survival measure 1 − n⋅2−t for arbitrarily large t. Moreover, GCM is neither well-suited for use with very short tag-lengths nor very long messages.
Ferguson and Saarinen independently described how an attacker can perform optimal attacks against GCM authentication, which meet the lower bound on its security. Ferguson showed that, if n denotes the total number of blocks in the encoding (the input to the GHASH function), then there is a method of constructing a targeted ciphertext forgery that is expected to succeed with a probability of approximately n⋅2−t. If the tag length t is shorter than 128, then each successful forgery in this attack increases the probability that subsequent targeted forgeries will succeed, and leaks information about the hash subkey, H. Eventually, H may be compromised entirely and the authentication assurance is completely lost.[22]
Independent of this attack, an adversary may attempt to systematically guess many different tags for a given input to authenticated decryption and thereby increase the probability that one (or more) of them, eventually, will be considered valid. For this reason, the system or protocol that implements GCM should monitor and, if necessary, limit the number of unsuccessful verification attempts for each key.
Saarinen described GCM weak keys.[23] This work gives some valuable insights into how polynomial hash-based authentication works. More precisely, this work describes a particular way of forging a GCM message, given a valid GCM message, that works with probability of about n⋅2−128 for messages that are n × 128 bits long. However, this work does not show a more effective attack than was previously known; the success probability in observation 1 of this paper matches that of lemma 2 from the INDOCRYPT 2004 analysis (setting w = 128 and l = n × 128). Saarinen also described a GCM variant Sophie Germain Counter Mode (SGCM) based on Sophie Germain primes.
See also
[edit]References
[edit]- ^ a b J. Salowey; A. Choudhury; D. McGrew (August 2008). AES Galois Counter Mode (GCM) Cipher Suites for TLS. Network Working Group. doi:10.17487/RFC5288. RFC 5288. Proposed Standard. Updated by RFC 9325.
- ^ Lemsitzer, S.; Wolkerstorfer, J.; Felber, N.; Braendli, M. (2007). Paillier, P.; Verbauwhede, I. (eds.). Cryptographic Hardware and Embedded Systems - CHES 2007 . GCM-AES Architecture Optimized for FPGAs. Lecture Notes in Computer Science. Vol. 4727. Springer. pp. 227–238. doi:10.1007/978-3-540-74735-2_16. ISBN 978-3-540-74734-5.
- ^ McGrew, David A.; Viega, John (2005). "The Galois/Counter Mode of Operation (GCM)" (PDF). p. 5. Retrieved 20 July 2013. Note that there is a typo in the formulas in the article.
- ^ Kohno, Tadayoshi; Viega, John; Whiting, Doug (2004). "CWC: A High-Performance Conventional Authenticated Encryption Mode". In Roy, Bimal; Meier, Willi (eds.). Fast Software Encryption. Lecture Notes in Computer Science. Vol. 3017. Berlin, Heidelberg: Springer. pp. 408–426. doi:10.1007/978-3-540-25937-4_26. ISBN 978-3-540-25937-4.
- ^ a b c Dworkin, Morris (2007–2011). Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC (PDF) (Technical report). NIST. 800-38D. Retrieved 2015-08-18.
- ^ J. Viega; D. McGrew (June 2005). The Use of Galois/Counter Mode (GCM) in IPsec Encapsulating Security Payload (ESP). Network Working Group. doi:10.17487/RFC4106. RFC 4106. Proposed Standard.
- ^ D. McGrew; J. Viega (May 2006). The Use of Galois Message Authentication Code (GMAC) in IPsec ESP and AH. Network Working Group. doi:10.17487/RFC4543. RFC 4543. Proposed Standard.
- ^ K. Igoe; J. Solinas (August 2009). AES Galois Counter Mode for the Secure Shell Transport Layer Protocol. IETF Network Working Group. doi:10.17487/RFC5647. RFC 5647. Informational.
- ^ S. Kanno; M. Kanda (September 2011). Addition of the Camellia Cipher Suites to Transport Layer Security (TLS). Internet Engineering Task Force. doi:10.17487/RFC6367. ISSN 2070-1721. RFC 6367. Informational. Updated by RFC 8996.
- ^ E. Rescorla (August 2018). The Transport Layer Security (TLS) Protocol Version 1.3. Internet Engineering Task Force TLS workgroup. doi:10.17487/RFC8446. RFC 8446. Proposed Standard. Obsoletes RFC 5077, 5246 and 6961. Updates RFC 5705 and 6066.
- ^ "Algorithm Registration - Computer Security Objects Register | CSRC | CSRC". 24 May 2016.
- ^ "Why SoftEther VPN – SoftEther VPN Project".
- ^ Gueron, Shay; Kounavis, Michael (April 2014). "Intel Carry-Less Multiplication Instruction and its Usage for Computing the GCM Mode (Revision 2.02)" (PDF). Retrieved 2023-09-01.
- ^ Käsper, E.; Schwabe, P. (2009). "Faster and Timing-Attack Resistant AES-GCM". In Clavier, C.; Gaj, K. (eds.). Cryptographic Hardware and Embedded Systems - CHES 2009. Lecture Notes in Computer Science. Vol. 5747. Springer. pp. 1–17. doi:10.1007/978-3-642-04138-9_1. ISBN 978-3-642-04138-9.
- ^ Gueron, Shay. "AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?" (PDF). Workshop on Real-World Cryptography. Retrieved 8 February 2013.
- ^ Gopal, V., Feghali, W., Guilford, J., Ozturk, E., Wolrich, G., Dixon, M., Locktyukhin, M., Perminov, M. "Fast Cryptographic Computation on Intel Architecture via Function Stitching" Intel Corp. (2010)
- ^ Manley, Raymond; Gregg, David (2010). "A Program Generator for Intel AES-NI Instructions". In Gong, G.; Gupta, K.C. (eds.). Progress in Cryptology - INDOCRYPT 2010. Lecture Notes in Computer Science. Vol. 6498. Springer. pp. 311–327. doi:10.1007/978-3-642-17401-8_22. ISBN 978-3-642-17400-1.
- ^ "IoT Security Part 6: Galois Counter Mode". 2016-05-06. Retrieved 2023-10-17.
- ^ Pfau, Johannes; Reuter, Maximilian; Harbaum, Tanja; Hofmann, Klaus; Becker, Jurgen (September 2019). "A Hardware Perspective on the ChaCha Ciphers: Scalable Chacha8/12/20 Implementations Ranging from 476 Slices to Bitrates of 175 Gbit/s": 294–299. doi:10.1109/SOCC46988.2019.1570548289.
{{cite journal}}: Cite journal requires|journal=(help) - ^ McGrew, David A.; Viega, John. "The Galois/Counter Mode of Operation (GCM) Intellectual Property Statement" (PDF). Computer Security Resource Center, NIST.
- ^ McGrew, David A.; Viega, John (2004). "The Security and Performance of the Galois/counter mode (GCM) of Operation". Proceedings of INDOCRYPT 2004. Lecture Notes in Computer Science. Vol. 3348. Springer. CiteSeerX 10.1.1.1.4591. doi:10.1007/978-3-540-30556-9_27. ISBN 978-3-540-30556-9.
- ^ Niels Ferguson, Authentication Weaknesses in GCM, 2005-05-20
- ^ Markku-Juhani O. Saarinen (2011-04-20). "Cycling Attacks on GCM, GHASH and Other Polynomial MACs and Hashes". Cryptology ePrint Archive. FSE 2012.
External links
[edit]- NIST Special Publication SP800-38D defining GCM and GMAC
- IEEE 802.1AE – Media Access Control (MAC) Security
- IEEE Security in Storage Working Group developed the P1619.1 standard
- INCITS T11 Technical Committee works on Fibre Channel – Security Protocols project.
- AES-GCM and AES-CCM Authenticated Encryption in Secure RTP (SRTP)
Galois/Counter Mode
View on GrokipediaIntroduction
Definition and Purpose
Galois/Counter Mode (GCM) is a mode of operation for symmetric-key block ciphers that provides authenticated encryption with associated data (AEAD). It combines counter mode for encryption to ensure confidentiality with a Galois field-based universal hash function, known as GHASH, for authentication, enabling the generation of both ciphertext and an authentication tag in a single pass over the data.[4][10] The primary purpose of GCM is to deliver high-speed, parallelizable encryption and authentication suitable for resource-constrained environments like network protocols, where both data privacy and integrity verification are essential. It supports variable-length inputs, including additional authenticated data (AAD) that receives integrity protection without encryption, making it versatile for protocols requiring data origin authentication alongside confidentiality. GCM is defined for use with approved 128-bit block ciphers, such as AES-128, AES-192, or AES-256, and recommends a 96-bit nonce length to optimize security, interoperability, and performance.[4][10] Key benefits of GCM include its efficiency in software and hardware due to parallelizable operations in both the counter mode encryption and GHASH computation, achieving high throughput compared to modes requiring separate encryption and message authentication code (MAC) processes, such as CBC with HMAC. By integrating authentication, GCM resists certain attacks exploitable in unauthenticated modes like CBC, such as those relying on malleability or lack of integrity checks.[4][10]History and Development
Galois/Counter Mode (GCM) was developed in 2004 by David A. McGrew and John Viega at Cisco Systems, Inc., as an efficient authenticated encryption with associated data (AEAD) scheme that combines counter mode encryption with Galois field-based authentication, drawing on prior research in universal hashing and counter-based block cipher modes.[10][2] The mode addressed the growing need for high-performance, parallelizable cryptographic primitives suitable for network protocols like IPsec and SSL/TLS, where both confidentiality and integrity were required without significant overhead. The initial specification appeared in a January 2004 submission to the NIST Modes of Operation Process, co-authored by McGrew and Viega, followed by a detailed security and performance analysis published later that year.[10][2] This work motivated further IETF efforts, including a 2005 draft that outlined GCM's integration into IPsec Encapsulating Security Payload (ESP), culminating in RFC 4106.[11] GCM's adoption accelerated with its standardization by NIST in Special Publication 800-38D in November 2007, which formalized the mode for use with the Advanced Encryption Standard (AES) and included its specialization, GMAC, for authentication only.[12] Subsequent milestones included GCM's incorporation into Transport Layer Security (TLS) via RFC 5288 in August 2008, enabling AES-GCM cipher suites in TLS 1.2, and its mandatory support as an AEAD option in TLS 1.3 per RFC 8446 in August 2018.[13] Post-publication refinements, including guidance on nonce management to mitigate reuse risks, appeared in protocol specifications and analyses. In March 2024, NIST announced plans to revise SP 800-38D, with a pre-draft call for comments issued in January 2025 proposing changes such as deprecating authentication tags shorter than 96 bits and updating security considerations.[14][5] As of November 2025, GCM remains a foundational AEAD mode in widespread use across IPsec, TLS, and other standards.[12]Operational Mechanism
Counter Mode Encryption
Counter mode encryption in Galois/Counter Mode (GCM) provides confidentiality by transforming plaintext into ciphertext using a stream cipher derived from a block cipher in counter mode, ensuring semantic security under chosen-plaintext attacks when used with a unique nonce. The process generates a keystream by encrypting successive counter blocks with the secret key, which is then XORed with the plaintext blocks to produce the ciphertext. This approach allows for efficient encryption of messages of arbitrary length by dividing the plaintext into 128-bit blocks, with the final block XORed partially if necessary. The counter blocks are derived from an initialization vector (IV), typically a 96-bit nonce concatenated with a 32-bit counter value. Specifically, the initial counter block is formed as the 96-bit IV followed by 31 zero bits and a 1, represented as , where denotes concatenation. Subsequent counter blocks are obtained by incrementing in big-endian integer arithmetic: the -th counter block is , starting from . The keystream block is then computed as , where is the block cipher encryption under key . For a plaintext of length bits, divided into blocks , the ciphertext blocks are for to , and for the last block, only the first bits are XORed if partial. If the IV is not 96 bits, let ; then compute to obtain a 128-bit value, and set that value , though this is less efficient due to the additional hash computation.[4] A subkey is derived solely for use in the mode's authentication component by setting , where is a 128-bit block of zeros; this same key is used for both the counter encryption and derivation. The counter mode's design supports high parallelization, as each keystream block can be computed independently by encrypting the corresponding counter block in any order, enabling efficient implementation on multi-core processors or hardware accelerators for high-throughput applications. This parallelism contributes to GCM's performance advantages over other authenticated encryption modes.GHASH Authentication
In Galois/Counter Mode (GCM), authentication is provided by GHASH, a universal hash function that operates over the finite field GF(2^{128}) to compute an integrity tag over both the additional authenticated data (AAD) and the ciphertext.[4] This mechanism ensures that any alteration to the protected data or AAD can be detected with high probability, without requiring decryption of the ciphertext during verification.[15] The hash subkey , derived by encrypting a zero-filled 128-bit block with the underlying block cipher under the session key, serves as the fixed multiplier in the hashing process.[4] The input to GHASH is a concatenated bit string formed from the AAD , the ciphertext , and their lengths. Both and are treated as bit strings and zero-padded with the minimal number of bits (denoted as for AAD and for ciphertext) to reach lengths that are multiples of 128 bits, resulting in and full 128-bit blocks respectively. The full input is then , where and are the bit lengths of the AAD and ciphertext, represented as 64-bit big-endian integers and appended as additional 128-bit blocks.[4] This formatting ensures that GHASH processes all relevant data uniformly, covering unprotected AAD alongside the encrypted payload.[15] The computation of GHASH treats as a sequence of 128-bit blocks , and evaluates the polynomial hash: where all operations, including multiplication and addition (XOR) , occur in GF(2^{128}).[4] In practice, this is computed iteratively for efficiency: initialize , then for to , set , with the output being .[4] This structure leverages the algebraic properties of the field to produce a 128-bit hash value.[15] The multiplicative nature of GHASH, rooted in field multiplication, underpins its security as a universal hash function, ensuring that for distinct inputs, the probability of collision is at most when the hash subkey is unpredictable from the adversary's perspective.[15] This property enables efficient authentication with provable bounds on forgery success, assuming the underlying block cipher is pseudorandom.[15]Tag Generation and Verification
In Galois/Counter Mode (GCM), the authentication tag is generated during authenticated encryption by computing the GHASH function over the associated authenticated data (AAD) , the ciphertext , and their bit lengths, then XORing the result with the block cipher encryption of the initial counter block . Specifically, the input to GHASH is the concatenation , where (respectively, ) is the minimum number of bits needed to pad (respectively, ) to a multiple of 128 bits, denotes a string of zero bits, and represents the 64-bit binary representation of the length. The tag is then , where is the fixed hash subkey derived from the cipher key , is the block cipher encryption under , is the initial counter block (for a typical 96-bit IV, ; for other lengths, as defined in the Counter Mode Encryption subsection), and t is the tag length in bits (supported values: 32, 64, 96, 104, 112, 120, 128), with MSB_t denoting the most significant t bits of the 128-bit value.[4] During authenticated decryption, the receiver recomputes GHASH using the provided AAD, received ciphertext, and lengths, then computes the candidate tag as and checks if it matches the received tag exactly; if the values match, the message is accepted and the plaintext is released, otherwise it is rejected to prevent processing of tampered data.[4] GCM achieves single-pass efficiency by parallelizing the counter-mode encryption of the plaintext (to produce ciphertext) with the GHASH computation over the AAD and accumulating ciphertext blocks, allowing both operations to proceed concurrently before finalizing the tag at the end of processing. On decryption, tag verification occurs prior to plaintext recovery, ensuring integrity checks precede confidentiality release. The mode supports AAD lengths up to bits and ciphertext lengths up to bits per nonce to avoid counter overflow and maintain security bounds. Nonce reuse in GCM results in catastrophic failure, enabling attackers to forge arbitrary messages or recover keys.[4][10][15]Mathematical Foundations
Galois Field GF(2^128)
Galois/Counter Mode (GCM) relies on arithmetic in the finite field GF(2^{128}), which consists of 2^{128} elements and is constructed as the ring of polynomials over GF(2) modulo an irreducible polynomial of degree 128. Specifically, GF(2^{128}) = GF(2) / (p(x)), where p(x) = x^{128} + x^7 + x^2 + x + 1. This particular irreducible polynomial is primitive, ensuring the field has the desired cyclic structure, and was chosen for its compatibility with AES block sizes and its low Hamming weight, which enables efficient hardware implementations of field operations.[4] Elements of GF(2^{128}) are represented as 128-bit binary strings, interpreted as polynomials of degree at most 127 with coefficients in {0,1}. The representation uses little-endian byte ordering, where the bytes are arranged from least to most significant, and within each byte, the bits correspond to polynomial coefficients with the least significant bit as the coefficient of the lowest power (x^0 for the overall least significant bit). This convention aligns the bit string directly with standard 128-bit register or memory layouts for computational efficiency.[4] Addition in GF(2^{128}) is simply the bitwise XOR operation on the 128-bit representations, reflecting the characteristic 2 of the field where 1 + 1 = 0. Multiplication is defined as the multiplication of the corresponding polynomials followed by reduction modulo p(x). The polynomial multiplication step produces a result of degree up to 254 and is computed using carry-less multiplication, which avoids carries and can be accelerated by dedicated hardware instructions such as Intel's PCLMULQDQ.[4][16] The reduction modulo p(x) after multiplication involves XORing the higher-degree terms with appropriately shifted versions of the original product, leveraging the specific form of p(x) to minimize operations. For instance, if the product has terms of degree 128 or higher, those bits are XORed with the corresponding shifts of the lower bits according to the polynomial's coefficients at degrees 7, 2, 1, and 0. This process ensures the result remains a polynomial of degree less than 128. Although multiplicative inverses exist in GF(2^{128}) and can be computed using the extended Euclidean algorithm adapted for polynomials, they are not utilized in GCM's core operations.[4]Hash Function GHASH
The GHASH function serves as the core authentication primitive in Galois/Counter Mode (GCM), operating as a keyed universal hash function defined over the binary Galois field GF(2^{128}). It processes input data divided into 128-bit blocks and computes a 128-bit hash value through multiplications and additions in this field. The function is designed to provide strong collision resistance when the key-derived parameter is treated as random, contributing to the overall security of authenticated encryption in GCM. Formally, for an input string consisting of 128-bit blocks , the GHASH function with key parameter is defined as where all operations are performed in GF(2^{128}), denotes field multiplication, and denotes bitwise XOR (the field's addition operation). This polynomial evaluation ensures that distinct inputs produce distinct outputs with high probability under a random . An equivalent and computationally efficient form uses Horner's method for iterative evaluation: initialize , then for to , compute , yielding . This avoids explicit computation of high powers of and requires exactly field multiplications. GHASH belongs to the family of Wegman-Carter polynomial hashes, exhibiting strong universality: for any two distinct inputs , the probability that is at most when is chosen uniformly at random from GF(2^{128}). This property bounds the adversary's success probability in forging a valid authentication tag, providing 128 bits of security against collisions in the ideal case. The keyed nature of GHASH derives from , which is generated as the block cipher encryption of the all-zero string under the session key : . Since a secure block cipher behaves as a pseudorandom permutation, appears random to an adversary without knowledge of , preserving the universality guarantees in practice. Powers of (if needed in alternative implementations) can be computed efficiently using repeated squaring, which requires multiplications for , or via precomputed tables for small exponents in hardware-optimized settings.[2] To handle inputs not aligned to 128-bit boundaries, GHASH employs explicit zero-padding: the bit string is appended with sufficient zero bits to reach the next multiple of 128 bits, ensuring the input forms complete blocks without altering the hash properties. This padding is deterministic and preserves the universality, as it maps variable-length inputs to fixed-block representations injectively for distinct originals. The overall time complexity of GHASH is linear in the input size, for an -bit input (with field multiplications), making it suitable for high-throughput applications. Field operations, such as multiplication, rely on the irreducible polynomial defined for GF(2^{128}) (as detailed in the mathematical foundations of GCM), typically implemented via carry-less multiplication followed by reduction. Parallelization is possible by precomputing multiples of or using vectorized instructions for independent block processing in the iterative form.Implementation Aspects
Algorithm Steps
The Galois/Counter Mode (GCM) algorithm provides authenticated encryption with associated data (AEAD) using a block cipher, typically AES-128, AES-192, or AES-256, operating on 128-bit blocks. The process involves two main phases: encryption, which generates the ciphertext and authentication tag, and decryption, which verifies the tag before recovering the plaintext. All operations are performed in the finite field GF(2^{128}), with bit-level padding applied to inputs as needed to align with 128-bit block boundaries by appending zeros. The key derivation for the hash subkey H and the initial counter block J_0 are foundational to both phases.[4]Encryption Procedure
The encryption process begins by deriving the hash subkey H from the secret key K using the block cipher E: compute H = E_K(0^{128}), where 0^{128} denotes a 128-bit zero block. This H is used solely for the GHASH authentication function and is precomputed once per key. Next, form the initial counter block J_0 by concatenating the initialization vector IV (typically 96 bits) with 31 zero bits followed by a 1-bit counter value, yielding J_0 = IV || 0^{31} || 1 (expressed in 128 bits). If the IV length differs from 96 bits, let s be the bit length needed to pad IV to the next multiple of 128 bits, then compute the GHASH input as IV || 0^s || 0^{64} || [len(IV)]{64}, where [len(IV)]{64} is the 64-bit big-endian representation of the IV length in bits, and set J_0 = GHASH_H(that input) || 0^{31} || 1, but the 96-bit case is standard for efficiency.[4][10] To generate the keystream, increment J_0 to produce subsequent counter blocks. For a plaintext P of length up to 2^{64}-1 bits divided into m 128-bit blocks P_1, ..., P_m (with the last block potentially partial and zero-padded if necessary), compute the i-th counter block starting from inc_{32}(J_0), where inc_{32} increments the rightmost 32 bits of J_0 by 1 (with carry propagating left if needed), and subsequent blocks increment further. Encrypt each counter block to obtain the keystream block: S_i = E_K( inc_{32}(J_0) + (i-1) ) for i = 1 to m, where + denotes incrementing the 32-bit counter portion. The ciphertext blocks are then C_i = P_i \oplus S_i for i = 1 to m-1, and for the final block, C_m = P_m \oplus S_m truncated to the actual plaintext length (padding bits are not transmitted). The full ciphertext C is the concatenation C_1 || ... || C_m.[4] Authentication proceeds via GHASH, which hashes the associated data A (padded to a multiple of 128 bits with zeros, denoted A^), the ciphertext C (padded similarly to C^), and the 128-bit length block containing the bit lengths of A and C in big-endian 64-bit fields: len(A) || len(C). The input to GHASH is the concatenation A^* || C^* || [len(A)]{64} || [len(C)]{64}, and the GHASH output is computed iteratively over these 128-bit blocks using the polynomial multiplication in GF(2^{128}) with H. The authentication tag T of length t bits (commonly 128, 120, 112, 104, or 96) is derived as the most significant t bits of the GHASH result XORed with the encryption of J_0: T = MSB_t( GHASH(AAD, C, len) \oplus E_K(J_0) ). The final output is the IV, C, and T.[4][10] Here is pseudocode for the GCM encryption algorithm:GCM-Encrypt(K, IV, A, P, t) // Key K, IV (96 bits), AAD A, plaintext P, tag length t in bits
1. H ← E_K(0^{128})
2. if len(IV) = 96 then
J_0 ← IV || 0^{31} || 1
else
s ← 128 * ceil(len(IV)/128) - len(IV)
IV_padded ← IV || 0^s
GHASH_input ← IV_padded || 0^{64} || [len(IV)]_{64}
J_0 ← GHASH(H, GHASH_input) || 0^{31} || 1
3. S ← E_K(J_0) // For tag
4. m ← ceil(len(P)/128) // Number of plaintext blocks
5. for i = 1 to m do
Inc ← inc_{32}(J_0) + (i-1) // Increment 32-bit counter part by (i-1) from inc_32(J_0)
S_i ← E_K(Inc)
C_i ← P_i ⊕ S_i // P_i is 128-bit block, last may be partial
6. C ← C_1 || ... || C_m // Truncate last block to actual length
7. A^* ← pad(A) // Append 0s to multiple of 128 bits
8. C^* ← pad(C)
9. len_block ← [len(A)]_{64} || [len(C)]_{64} // Big-endian
10. AA ← A^* || C^* || len_block
11. G ← GHASH(H, AA) // Iterative: X_0 = 0, X_{i} = (X_{i-1} ⊕ AA_i) ⋅ H for each block AA_i
12. T ← MSB_t( G ⊕ S )
13. return IV || C || T
GCM-Encrypt(K, IV, A, P, t) // Key K, IV (96 bits), AAD A, plaintext P, tag length t in bits
1. H ← E_K(0^{128})
2. if len(IV) = 96 then
J_0 ← IV || 0^{31} || 1
else
s ← 128 * ceil(len(IV)/128) - len(IV)
IV_padded ← IV || 0^s
GHASH_input ← IV_padded || 0^{64} || [len(IV)]_{64}
J_0 ← GHASH(H, GHASH_input) || 0^{31} || 1
3. S ← E_K(J_0) // For tag
4. m ← ceil(len(P)/128) // Number of plaintext blocks
5. for i = 1 to m do
Inc ← inc_{32}(J_0) + (i-1) // Increment 32-bit counter part by (i-1) from inc_32(J_0)
S_i ← E_K(Inc)
C_i ← P_i ⊕ S_i // P_i is 128-bit block, last may be partial
6. C ← C_1 || ... || C_m // Truncate last block to actual length
7. A^* ← pad(A) // Append 0s to multiple of 128 bits
8. C^* ← pad(C)
9. len_block ← [len(A)]_{64} || [len(C)]_{64} // Big-endian
10. AA ← A^* || C^* || len_block
11. G ← GHASH(H, AA) // Iterative: X_0 = 0, X_{i} = (X_{i-1} ⊕ AA_i) ⋅ H for each block AA_i
12. T ← MSB_t( G ⊕ S )
13. return IV || C || T
Decryption Procedure
Decryption mirrors encryption but prioritizes tag verification before plaintext recovery to ensure authenticity. Using the received IV, A, C, and T, first recompute H = E_K(0^{128}) and J_0 as in encryption. Then, compute the GHASH on the received A (padded), C (padded), and lengths exactly as during encryption to obtain G. The expected tag is T' = MSB_t( G \oplus E_K(J_0) ). If T ≠ T', the message is rejected immediately, with no plaintext released to prevent partial decryption attacks; the implementation must abort without outputting any data. Modern implementations (as of 2025) incorporate side-channel protections, such as constant-time tag comparison using functions like CMP-CT (constant-time memory-secure equality check) to avoid timing leaks.[4][1] If the tag verifies, generate the keystream blocks S_i = E_K( Inc_{32}(J_0) + (i-1) ) for i = 1 to m, where m = ceil(len(C)/128), and recover P_i = C_i \oplus S_i for each block, truncating the final block to the known length. The full plaintext P is the concatenation of these blocks. No further error handling is specified beyond the initial tag check, assuming the ciphertext length is valid.[4] Pseudocode for GCM decryption:GCM-Decrypt(K, IV, A, C, T, t) // Inputs as in encryption, received T of t bits
1. H ← E_K(0^{128})
2. J_0 ← form as in encryption using IV
3. S ← E_K(J_0)
4. A^* ← pad(A)
5. C^* ← pad(C)
6. len_block ← [len(A)]_{64} || [len(C)]_{64}
7. AA ← A^* || C^* || len_block
8. G ← GHASH(H, AA)
9. T' ← MSB_t( G ⊕ S )
10. if T' ≠ T then return ⊥ // Reject, abort (use constant-time comparison)
11. m ← ceil(len(C)/128)
12. for i = 1 to m do
Inc ← inc_{32}(J_0) + (i-1) // Increment 32-bit counter part by (i-1) from inc_32(J_0)
S_i ← E_K(Inc)
P_i ← C_i ⊕ S_i
13. P ← P_1 || ... || P_m // Truncate last to len(C)
14. return P
GCM-Decrypt(K, IV, A, C, T, t) // Inputs as in encryption, received T of t bits
1. H ← E_K(0^{128})
2. J_0 ← form as in encryption using IV
3. S ← E_K(J_0)
4. A^* ← pad(A)
5. C^* ← pad(C)
6. len_block ← [len(A)]_{64} || [len(C)]_{64}
7. AA ← A^* || C^* || len_block
8. G ← GHASH(H, AA)
9. T' ← MSB_t( G ⊕ S )
10. if T' ≠ T then return ⊥ // Reject, abort (use constant-time comparison)
11. m ← ceil(len(C)/128)
12. for i = 1 to m do
Inc ← inc_{32}(J_0) + (i-1) // Increment 32-bit counter part by (i-1) from inc_32(J_0)
S_i ← E_K(Inc)
P_i ← C_i ⊕ S_i
13. P ← P_1 || ... || P_m // Truncate last to len(C)
14. return P
