Pcornel
Security · Cryptography

HMAC

Cheat sheet · https://pcornel.dk/topic.php?topic=4678

Back to the Topic

Answer

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.

Remember

  • HMAC ≠ unkeyed hash.
  • HMAC ≠ encryption or confidentiality.
  • Valid HMAC ≠ which shared-key holder created the message.
  • Long key ≠ safe key distribution and separation.

First checks

  • openssl dgst -sha256 -hmac <key> <file> — compute HMAC
  • python3 -c 'import hmac,hashlib;print(hmac.new(b"k",b"m",hashlib.sha256).hexdigest())' — library
  • Constant-time comparison — hmac.compare_digest

Verify in this order

message + key → HMAC → verify

Where it usually breaks

First mismatch in key/secret generation → storage/rotation → trust/certificate validation → protocol negotiation → cryptographic operation → peer/application verification; preserve identity/policy/pre-state before mutation.

Cryptography → HMAC proof map

BoundaryEstablishDoes not establish
Scope and intentAsset/data/peer, security property, identity/name, protocol and timeDoes not prove algorithm, key, trust or endpoint correctness
Effective cryptographic stateExact version, algorithm/mode/parameters, key/certificate/path and negotiated resultConfiguration or object presence does not prove correct use
Verification outcomePositive, negative, tamper, expiry/revoke and failure tests correlated with evidenceOne success does not prove every peer, client, path or lifecycle stage
ClosureOriginal operation succeeds; old/unsafe state is retired and regression checks passAdministrative workflow completion alone is not closure

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=4678

Confirmation

Confirm action

Continue?