Message Authentication and Hash Functions
Message Authentication and Hash Functions
Authentication Requirements
Kind of attacks (threats) in the context of communications across
a network
1. Disclosure
2. Traffic analysis (discover the pattern)
3. Masquerade (insert a message from a fraudulent source)
4. Content modification
5. Sequence modification (insert, delete, reorder)
6. Timing modification (delay or replay)
7. Source Repudiation (denial of a transmission)
8. Destination Repudiation (denial of a receipt)
Authentication Requirements
Message authentication
A procedure to verify that messages come from the alleged
source and have not been altered
Message authentication may also verify sequencing and
timeliness
Digital signature
An authentication technique that also includes measures to counter
repudiation by either source or destination
Authentication Functions
Message authentication or digital signature mechanism can be
viewed as having two levels
authenticator and High level authentication protocol
Message Encryption
Conventional encryption can serve as authenticator
Conventional encryption provides authentication as well as
confidentiality
if symmetric encryption is used then:
receiver knows sender must have created it
knows content cannot be altered, if message has suitable structure,
redundancy or a checksum to detect any changes
if public-key encryption is used:
encryption provides confidentiality, but not authentication
can provide authentication as well as signature, but at the cost of
two public key uses on the message.
Hash Function
Accepts a variable-size message M as input and produces a fixed-
size hash code H(M){ some times called message digest} as output
The hash code is a function of all the bits of the message and
provides an error-detection capability.
Can be used with encryption for authentication
E(M || H)
M || E(H)
M || signed H
E( M || signed H ) gives confidentiality
M || H( M || K )
E( M || H( M || K ) )
Hash Functions
h = H(M)
M is a variable-length message, h is a fixed-length hash value,
H is a hash function
The hash value is appended at the source
The receiver authenticates the message by recomputing the
hash value
Because the hash function itself is not considered to be
secret, some means is required to protect the hash value
HASH Algorithms
MD5 Logic
Step 1: Append padding bits
Padded so that its bit length 448 mod 512 (i.e., the length of padded message is 64
bits less than an integer multiple of 512 bits)
Padding is always added, even if the message is already of the desired length
(1 to 512 bits)
Padding bits: 1000….0 (a single 1-bit followed by the necessary number of 0-bits)
The expanded message is Y0, Y1, …, YL-1; the total length is L 512 bits
The expanded message can be thought of as a multiple of 16 32-bit words
Let M[0 … N-1] denote the word of the resulting message, where N = L 16
MD5 Logic
Step 3: Initialize MD buffer
128-bit buffer (four 32-bit registers A,B,C,D) is used to hold intermediate and
final results of the hash function
A,B,C,D are initialized to the following values
A = 67452301, B = EFCDAB89, C = 98BADCFE, D = 10325476
Stored in little-endian format (least significant byte of a word in the low-
address byte position)
E.g. word A: 01 23 45 67 (low address … high address)
MD5 Logic
Table T, constructed from the sine function
– T[i] = integer part of 232 abs(sin(i)), where i is in radians
MD5 Logic
Step 5: Output
After all L 512-bit blocks have been processed, the output from the Lth stage is
the 128-bit message digest
CV0 = IV
CVq+1 = SUM32(CVq, RFI[Yq, RFH[Yq, RFG[Yq, RFF[Yq, CVq]]])
MD = CVL
where
IV = initial value of the ABCD buffer, defined in step 3
Yq = the qth 512-bit block of the message
L = the number of blocks in the message (including padding and
length fields)
CVq = chaining variable processed with the qth block of the message
RFx = round function using primitive logical function x
MD = final message digest value
SUM32 = addition modulo 232 performed separately on each word
Truth table
X[k]
The array of 32-bit words X[0..15] holds the value of current
512-bit input block being processed
Within a round, each of the 16 words of X[i] is used exactly
once, during one step
The order in which these words is used varies from round to
round
In the first round, the words are used in their original order
For rounds 2 through 4, the following permutations are used
2(i) = (1 + 5i) mod 16
3(i) = (5 + 3i) mod 16
4(I) = 7i mod 16
MD4
Precursor to MD5
Design goals of MD4 (which are carried over to MD5)
Security
Speed
Simplicity and compactness
Favor little-endian architecture
Main differences between MD5 and MD4
1. A fourth round has been added.
2. Each step now has a unique additive constant.
3. The function g in round 2 was changed from (bc v bd v cd) to
(bd v cd’) to make g less symmetric.
4. Each step now adds in the result of the previous step. This
promotes a faster "avalanche effect".
5. The order in which input words are accessed in rounds 2 and 3 is
changed, to make these patterns less like each other.
6. The shift amounts in each round have been approximately
optimized, to yield a faster "avalanche effect." The shifts in
different rounds are distinct.
SHA-512 Overview
Algorithm Steps
Step 4: Process the message in 1024-bit (128-word) blocks:-
The heart of the algorithm is a module that consists of 80
rounds.Each round takes as input the 512-bit buffer value
abcdefgh, and updates the contents of the buffer.
Step 5: Output the final state value as the resulting hash:-After
all N 1024-bit blocks have been processed, the output from
the Nth stage is the 512-bit message digest.
Wt
The first 16 values of Wt are taken directly from the 16 words of
the current block. The remaining values are defined as follows
HMAC
Increased Interest in recent years in developing a MAC based on a hash function
MD5 and SHA-1 run faster than symmetric block ciphers such as DES
Code for hash functions widely available
No export restrictions for cryptographic hash functions
Cryptographic functions (even those used in MAC) restricted
Hash values not intended for MAC –they are not protected by secret keys
Some protection needs to be built on top of the hash value
The one approach that gained wide support is HMAC (RFC 2104) included in IP
security and SSL
HMAC Algorithm
hash includes a key along with message
original proposal:
KeyedHash = Hash(Key|Message)
some weaknesses were found with this
eventually led to development of HMAC
specified as Internet standard RFC2104
Idea: append a secret key to the message and compute the hash
value
To avoid a brute-force attack, apply the hash twice to mangle
thoroughly the bits of the key with those of the message
HMAC Algorithm
H=embedded hash function
IV=initial value to the has function
M=message input to HMAC (including the padding specific to the
hash function)
Yi=i-th block of M
L=number of blocks in M
b=number of bits in a block
n=length of the hash code
K=secret key, if its length is greater than b –will be given as input
to the hash function to produce n-bit key
K+=K padded with 0 on the left to make a b-bit key, if the
original length of K is smaller than b
ipad= 00110110 (36 in hexadecimal)repeated b/8 times
opad=01011100 (5C in hexadecimal)repeated b/8 times
HMAC Overview
HMAC Algorithm
1. Append zeros to the left end of K to create a b-bit string
K+(e.g., if K is of length 160 bits and b = 512 then K will be
appended with 44 zero bytes 0 x 00).
2. XOR (bitwise exclusive-OR) K+ with ipad to produce the b-
bit block Si.
3. Append M to Si.
4. Apply H to the stream generated in step 3.
5. XOR K+ with opad to produce the b-bit block So
6. Append the hash result from step 4 to So
7. Apply H to the stream generated in step 6 and output the
result.
HMAC Security
proved security of HMAC relates to that of the underlying
hash algorithm
attacking HMAC requires either:
Brute-force attack requires an effort on the level 2n-1for a
key of length n
Birthday attack:-
The main idea in this attack is that attacker can compute the
hash values of many messages and try to find a match
In HMAC, he is unable to do that because the hash is protected
by a secret key
attacker will have to rely on messages that he observes on the
link:- for MD5 she will have to wait in average for 264messages
generated using the same key
On a 1 Gbps-link she needs to observe a continuous stream of
messages with no change in the key for about 150 000 years
With SHA-1 280messages are needed
For HMAC, using MD5 is secure (and fast)
Assignment
1. Explain with neat diagrams the cipher block
modes of operations for block ciphers
2. Differentiate between symmetric block ciphers
and symmetric stream ciphers
3. Explain various Key distribution methods
4. Describe the various steps of encryption and
decryption in an AES algorithm
5. Write about Message authentication
6. Explain various steps involved in HMAC
algorithm