Ghash
The GF(2^128) polynomial hash at the core of AES-GCM and GMAC
Experimental or unclassified. Root API only. Reach it with NextSSL(root=True) in Python or the nextssl_root_* functions in C.
About Ghash
Ghash is a message authentication code. It uses a 16-byte (128-bit) key, a 16-byte (128-bit) authentication tag and a 16-byte (128-bit) block. Its registry entry cites NIST SP 800-38D (GHASH). NextSSL lists it in the research tier and exposes it through the root API only (NextSSL(root=True) in Python, nextssl_root_* in C).
Overview
GHASH is a universal hash function defined in NIST SP 800-38D as the authentication component of GCM and GMAC. On its own it is not a MAC; it must be combined with a secret, one-time mask to give a secure tag.
GHASH treats its input as a sequence of 128-bit blocks X1, …, Xn and computes the polynomial X1·H^n ⊕ X2·H^(n-1) ⊕ … ⊕ Xn·H in the field GF(2^128), where H is a secret hash key. Evaluation uses Horner's rule, one field multiplication per block. Modern CPUs implement this multiplication with carry-less multiply instructions such as PCLMULQDQ or PMULL.
GHASH is an ε-almost-XOR-universal hash: for two distinct messages of bounded length, the probability that their hashes differ by any particular value is small. NextSSL exposes GHASH as a research primitive for building and testing GCM-family constructions. POLYVAL, used in AES-GCM-SIV, is a closely related function with a different bit ordering.
History
2004–2007GHASH published by David McGrew, John Viega
Specified in NIST SP 800-38D
Security notes
GHASH alone is linear in its input and provides no authentication. Leaking H, or reusing a GCM nonce, enables forgeries. Use AES-GCM or GMAC rather than raw GHASH.
Typical uses
Sizes
| Field | Bytes | Meaning |
|---|---|---|
| key | 16 | Secret key |
| tag | 16 | Authentication tag |
| block | 16 | Block |
Use it
from nextssl_demo import NextSSL
root = NextSSL(root=True) # tier 'research' is reachable from the root API only
key = root.random(16)
tag = root.call("mac", "ghash", None, key, b"message", 0)[0]
ok = root.check("mac_verify", "ghash", None, key, b"message", tag)
nextssl_root_mac("ghash", NULL, key, data, 0, tag);
nextssl_root_mac_verify("ghash", NULL, key, data, tag);
use nextssl_core::Params;
use nextssl_registry::{self as reg, Policy};
let alg = reg::new_mac_in(reg::all(), Policy::Any, "ghash", &Params::new())?;
let tag = alg.tag(&key, b"message")?;
let ok = alg.verify(&key, b"message", &tag)?;
Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.
Similar names
Looking for something else?More message authentication codes
All 30Frequently asked questions
What is Ghash?
Ghash is a MAC in the GHASH family. GHASH is a universal hash function defined in NIST SP 800-38D as the authentication component of GCM and GMAC.
What are the Ghash sizes?
In NextSSL, Ghash uses: key 16 bytes, tag 16 bytes, block 16 bytes.
Who designed Ghash and when?
Ghash belongs to the GHASH family, first published in 2004 by David McGrew, John Viega. Its origin: NIST SP 800-38D.
Which standards define Ghash?
Ghash is referenced by NIST SP 800-38D (GHASH).
Is Ghash safe to use?
Ghash is in the research tier. Experimental or unclassified. Root API only. It is only reachable through the root API (NextSSL(root=True) in Python, nextssl_root_* in C).