Use it when configuring, checking or troubleshooting HMAC in Cryptography.
HMAC
HMAC combines a cryptographic hash with a shared secret key to authenticate message integrity and origin among holders of that key without exposing the key itself.
1. HMAC authenticates messages with a shared key.
2. Used for API signatures, webhooks, JWT HS256.
3. Compare in constant time.
4. Keep keys secret and long.
5. Prefer AEAD for encryption + integrity.
message + key → HMAC → verify
Context & applicabilityCommon mistakes · platform/version boundaries
A valid HMAC shows a holder of the shared key produced the tag for those bytes; it does not provide confidentiality, non-repudiation, freshness or identity among key holders.
Suspicious evidence: plain hash used as MAC, one key across contexts, tag truncation without policy, MAC checked after parsing, timing leak, replay accepted or old/new rotation keys confused.
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
shared MAC key + canonical message/context → HMAC → message/tag → receiver recomputation and constant-time compare → accept/reject/replay control
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- HMAC ≠ unkeyed hash.
- HMAC ≠ encryption or confidentiality.
- Valid HMAC ≠ which shared-key holder created the message.
- Long key ≠ safe key distribution and separation.
openssl dgst -sha256 -hmac <key> <file>— compute HMACpython3 -c 'import hmac,hashlib;print(hmac.new(b"k",b"m",hashlib.sha256).hexdigest())'— library- Constant-time comparison — hmac.compare_digest
ReferenceWhat it is1 section · depth on demand
Using HMAC
openssl dgst -sha256 -hmac "<key>" file
python3 -c "import hmac,hashlib;print(hmac.new(b'key',b'msg',hashlib.sha256).hexdigest())"
Compare HMACs in constant time (hmac.compare_digest) to avoid timing attacks. Used in JWT HS256, webhook signatures (GitHub, Stripe), API request signing (AWS SigV4) and TOTP.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
A valid HMAC shows a holder of the shared key produced the tag for those bytes; it does not provide confidentiality, non-repudiation, freshness or identity among key holders.
In depth
HMAC (Hash-based Message Authentication Code) combines a secret key with a hash function to produce a tag that shows a message's integrity and authenticity to anyone who shares the key. Unlike a plain hash, an attacker cannot compute a valid HMAC without the key.
| Use | Example |
|---|---|
| Webhook signatures | GitHub X-Hub-Signature-256 |
| API request signing | Cloud API signatures (AWS SigV4) |
| Tokens | JWT with HS256 |
| OTP | HOTP/TOTP |
| Protocols | IPsec and TLS integrity (legacy suites) |
import hmac, hashlib
tag = hmac.new(secret, body, hashlib.sha256).hexdigest()
hmac.compare_digest(tag, received_tag) # constant-time comparison
Always compare tags in constant time to avoid timing attacks.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Cryptography → HMAC. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://csrc.nist.gov/pubs/fips/197/final · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Cryptography → HMAC proof map
Fast scope, effective cryptographic state, verification and closure boundaries for Cryptography → HMAC.
| Boundary | Establish | Does not establish |
|---|---|---|
| Scope and intent | Asset/data/peer, security property, identity/name, protocol and time | Does not prove algorithm, key, trust or endpoint correctness |
| Effective cryptographic state | Exact version, algorithm/mode/parameters, key/certificate/path and negotiated result | Configuration or object presence does not prove correct use |
| Verification outcome | Positive, negative, tamper, expiry/revoke and failure tests correlated with evidence | One success does not prove every peer, client, path or lifecycle stage |
| Closure | Original operation succeeds; old/unsafe state is retired and regression checks pass | Administrative workflow completion alone is not closure |