Message Authentication and Digital Signatures · Cryptography and Network Security

HMAC

1. What Is HMAC? (beginner — hash + key done RIGHT!)

Naive Hash(K+m)Hash(K + m) breaks (length-extension!). HMAC nests TWO hashes with padded keys (RFC 2104!): inner (KK + ipad + mm) then outer (KK + opad + inner!). Safe with SHA-256/512!

HMAC(K,m)=H((K+opad)+H((K+ipad)+m))HMAC(K, m) = H((K + opad) + H((K + ipad) + m))

2. Steps (exam recipe!)

1. key > block? hash it! key < block? pad zeros to block size!
2. inner pad: K XOR 0x36 repeated (ipad!) → hash with message!
3. outer pad: K XOR 0x5c repeated (opad!) → hash inner result!
4. send (message, HMAC)! receiver recomputes + constant-time compares!

3. Why Nested? (exam why!)

Single hash leaks extendable state (attacker appends!). Outer hash hides inner digest (extension dies!). Even MD5-based HMAC survived (structure saves weak hash — though use SHA-256!).

4. Uses (exam map!)

API tokens, cookies, JWT signatures (HMAC-SHA256!), TLS records, GitHub webhooks! Variants: HMAC-SHA256 (standard!), HMAC-SHA512, KMAC (SHA-3 native!).

5. Exam Points

  • Formula + ipad/opad steps — 7 marks, very frequent.
  • Why not Hash(K+m)Hash(K+m) (extension!) — 5 marks, favourite trap.
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Cryptography and Network Security modules