CBS 323 Message Authentication Codes (HMAC)
CBS 323 Message Authentication Codes (HMAC)
Idea:
1. Alice encrypts 𝒎 and sends 𝒄 = 𝐄𝐧𝐜(𝒌, 𝒎) to Bob.
2. Bob computes 𝐃𝐞𝐜(𝒌, 𝒎), and if it “makes sense” accepts it.
Hope: only Alice knows 𝒌, so nobody else can produce a valid ciphertext.
𝒌 𝒌
𝒌 is chosen randomly
from some set K
Correctness
it always holds that:
𝐕𝐫𝐟𝐲𝒌(𝒎, 𝐓𝐚𝐠𝒌(𝒎)) = 𝐲𝐞𝐬.
Message authentication – multiple messages
𝒎𝟏 𝒕𝟏 = 𝐓𝐚𝐠𝒌(𝒎𝟏)
𝒎𝟐 𝒕𝟐 = 𝐓𝐚𝐠𝒌(𝒎𝟐)
...
...
𝐀𝐥𝐢𝐜𝐞 Bob
𝒎𝒘 𝒕𝒘 = 𝐓𝐚𝐠𝒌(𝒎𝒘 )
𝒌 𝒌
If Tag is deterministic, then Vrfy just computes Tag and compares the result.
We assume that:
1. The adversary is allowed to chose 𝒎𝟏, … , 𝒎𝒘 .
2. The goal of the adversary is to produce a valid tag on
some 𝒎’ such that 𝒎’ ∉ {𝒎𝟏, … , 𝒎𝒘 } .
security parameter
selects a random 𝒌 ∈ {𝟎, 𝟏}𝒏
𝟏𝒏
𝒎𝟏
adversary
(𝒎𝟏, 𝒕 = 𝐓𝐚𝐠𝒌(𝒎𝟏))
oracle
...
𝒎𝒘
(𝒎𝒘 , 𝒕 = 𝐓𝐚𝐠𝒌(𝒎𝒘 ))
We say that the adversary breaks the MAC scheme at the end she
outputs (𝒎’, 𝒕’) such that
𝐕𝐫𝐟𝐲𝒌(𝒎’, 𝒕’) = 𝐲𝐞𝐬
and
𝒎’ ∉ {𝒎𝟏, … , 𝒎𝒘 }
Warning: MACs do not offer protection against the “replay attacks”.
(𝒎, 𝒕)
𝐀𝐥𝐢𝐜𝐞 𝐁𝐨𝐛
3. MACs can also be constructed from the hash functions NMAC, HMAC).
A simple construction from a block cipher
Let
𝑭 ∶ {𝟎, 𝟏}𝒏 × {𝟎, 𝟏}𝒏 → {𝟎, 𝟏}𝒏
𝑭(𝒌, 𝒎)
be a block cipher (a PRF).
...
𝑭𝒌 𝑭𝒌
r l 1 m1 r l d md
𝒙𝟏 𝒙𝒅
This works!
𝐓𝐚𝐠𝒌(𝒎)
𝑭𝒌 𝑭𝒌 ... 𝑭𝒌
𝒓 ℓ 𝟏 𝒎𝟏 𝒓 ℓ 𝟐 𝒎𝟐 ... r ℓ 𝒅 𝒎𝒅
𝒙𝟏 𝒙𝟐 𝒙𝒅
one-way functions
exist
computationally-secure PRPs/PRFs
MACs exist exist
𝑭𝒌 𝑭𝒌 𝑭𝒌 𝑭𝒌 𝑭𝒌
|𝒎| 𝒎𝟏 𝒎𝟐 𝒎𝟑 ... 𝒎𝒅
Why is this
needed?
𝒎𝟏 𝒎𝟐
𝒕’ = 𝐓𝐚𝐠𝒌(𝒎’)
𝒕𝟏 𝒕’ = 𝒕𝟐
𝒎’
A better idea
M. Bellare, R. Canetti, and H. Krawczyk (1996):
2nd if faster hash function available remove existing hash function module and drop the
new module. Replacing SHA2 with SHA3 since security of HMAC retained simply by replacing the
embedded hash function with a more secure one.
• Main advantage of HMAC over other proposed hash-based schemes? HMAC can be proven secure
provided that the embedded hash function has some reasonable cryptographic strengths.
In HMAC, the ipad and opad are two fixed values used in the key expansion process.
1. The ipad (inner pad) is a sequence of bytes used to XOR with the secret key before hashing the message.
2. The opad (outer pad) is another sequence of bytes used to XOR with the secret key after hashing the message
HMAC Structure • H = embedded hash function (e.g., MD5, SHA-1, RIPEMD-160)
• IV = initial value input to hash function
• M = message input to HMAC (including the padding specified
in the embedded hash function)
• Yi = i th block of M, 0 … i … (L - 1)
• L = number of blocks in M
• b = number of bits in a block
• n = length of hash code produced by embedded hash
function
• K = secret key; recommended length is n; if key length is
greater than b, the key is input to the hash function to
produce an n-bit key
• K+ = K padded with zeros on the left so that the result is b
bits in length
• Hashing followed by encryption (H → E): 1st cryptographic hash function over M as h = H(M). Then encrypt
message plus hash function: E(K, (M} h)).
• Authentication followed by encryption (A → E): Use two keys. 1st authenticate plaintext by computing the MAC
value as T = MAC(K1, M). Then encrypt message plus tag: E(K2, [M}T]). Applied on SSL/TLS protocols
• Encryption followed by authentication (E → A): Use two keys. 1st encrypt message to yield the ciphertext C =
E(K2, M). Then authenticate the ciphertext with T = MAC(K1, C) to yield the pair (C, T). Applied on IPSec protocol
• Independently encrypt and authenticate (E + A). Use two keys. 1st Encrypt message to yield ciphertext C = E(K2,
M). Then Authenticate plaintext with T = MAC(K1, M) to yield pair (C, T). Applied on SSH protocol
For H → E, A → E, and E + A, decrypt first, then verify. For E → A, verify first, then decrypt.
Authentication + encryption, options:
• Encrypt-and-authenticate:
𝒄 ∶= 𝐄𝐧𝐜𝒌𝟏 (𝒎) and 𝒕 ≔ 𝐓𝐚𝐠 𝒌 𝟐 (𝒎), send (𝒄, 𝒕)
wrong
𝒄 ∶= 𝐄𝐧𝐜𝒌𝟏 (𝒎) 𝒎 𝒕 ≔ 𝐓𝐚𝐠 𝒌 𝟐 (𝒎)
• Authenticate-then-encrypt:
𝒕 ∶= 𝐓𝐚𝐠 𝒌 𝟐 (𝒎) and 𝒄 ≔ 𝐄𝐧𝐜𝒌 𝟏 (𝒎||𝒕), send 𝒄
better
𝒄 ≔ 𝐄𝐧𝐜𝒌 𝟏 (𝒎||𝒕) 𝒎 𝒕 ≔ 𝐓𝐚𝐠 𝒌 𝟐 (𝒎)
• Encrypt-then-authenticate:
𝒄 ≔ 𝐄𝐧𝐜𝒌𝟏 (𝒎) and 𝒕 ≔ 𝐓𝐚𝐠 𝒌 𝟐 (𝒄), send (𝒄, 𝒕)
the best