Unit-IV HMAC& CMAC
Unit-IV HMAC& CMAC
K. Govindaraju
Assistant Professor
Dept of Computer Science & Engineering
Aditya University
Surampalem.
Aditya Engineering College (A)
Learning Outcomes
At the end of this class, Student will be able to:
Discuss about HMAC and CMAC.
MESSAGE AUTHENTICATION
• A message digest guarantees the integrity of a message.
• It guarantees that the message has not been changed. A message digest,
however, does not authenticate the sender of the message.
• When Alice sends a message to Bob, Bob needs to know if the message is
coming from Alice.
• To provide message authentication, Alice needs to provide proof that it is Alice
sending the message and not an impostor.
• The digest created by a cryptographic hash function is normally called a
modification detection code (MDC).
• The code can detect any modification in the message. What we need for
message authentication (data origin authentication) is a message authentication
code (MAC).
TYPES OF MACs
HMAC (Hash MAC)
CMAC (Cipher MAC)
HMAC Operation
Figure illustrates the overall operation of HMAC:
HMACK = Hash[(K+ XOR opad) || Hash[(K+ XOR ipad) || M)]
where:
K+ is K padded with zeros on the left so that the result is b bits in
length
ipad is a pad value of 36 hex repeated to fill block
opad is a pad value of 5C hex repeated to fill block
M is the message input to HMAC (including the padding specified in
the embedded hash function)
Cryptography & Network
K. Govindaraju Tuesday, April 8, 2025
Security
Aditya Engineering College (A)
HMAC Operation
Note that the XOR with ipad results in flipping one-half of the bits of K.
Similarly, the XOR with opad results in flipping one-half of the bits of K,
but a different set of bits.
In effect, pseudorandomly generated two keys from K. HMAC should
execute in approximately the same time as the embedded hash
function for long messages.
HMAC adds three executions of the hash compression function (for Si,
So, and the block produced from the inner hash).
HMAC Operation
A more efficient implementation is possible by precomputing the
internal hash function on (K+ XOR opad) and (K+ XOR ipad) and
inserting the results into the hash processing at start & end.
With this implementation, only one additional instance of the
compression function is added to the processing normally produced
by the hash function.
This is especially worthwhile if most of the messages for which a MAC
is computed are short.
CMAC Overview
CMAC Operation
Figure shows the structure of CMAC. It uses the blocksize of the
underlying cipher (ie 128-bits for AES or 64-bits for triple-DES).
The message is divided into n blocks M1..Mn, padded if necessary.
The algorithm makes use of a k-bit encryption key K and an n-bit
constant K1 or K2 (depending on whether the message was padded or
not).
For AES, the key size k is 128,192, or 256 bits; for triple DES, the key
size is 112 or 168 bits.
The two constants K1 & K2 are derived from the original key K using
encryption of 0 and multiplication in GF(2^n).
Cryptography & Network
K. Govindaraju Tuesday, April 8, 2025
Security
Aditya Engineering College (A)
C1 = E(K, M1)
C2 = E(K, [M2 C1])
C3 = E(K, [M3 C2])
.
.
.
Cn = E(K, [Mn Cn-1 K1]) T = MSBTlen(Cn)
Where
Summary
Learning Outcomes
HMAC
HMAC Overview
HMAC Operation
CMAC
CMAC Overview
CMAC Operation