Information Security ยท Unit 5
Hash Functions and Message Authentication
Exam-focused notes for Hash Functions and Message Authentication (Information Security, BIT303): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
Hash Functions and Message Authentication in short
A hash function gives a short fingerprint of any data. Together with message authentication codes and digital signatures, hashes let a receiver check that a message is real and unchanged. This chapter covers hash design, MD5, SHA-1, SHA-2 and signatures.
What this unit covers
- Hash function properties and design
- MD5 algorithm and hash value generation
- SHA-1 algorithm and padding
- SHA-2 hash function
- Message authentication purposes
- Digital signatures for authentication
Message authentication purposes
2082 ยท 10 marks
What are the purposes of message authentication? Explain the working mechanism of MD5.[10]
Show solved answerHide answer
Message Authentication: Purposes and MD5 Working Mechanism
Part 1: Purposes of Message Authentication
Message authentication is a mechanism used to verify the integrity and origin of a message. The main purposes are:
1. Message Integrity
Ensures that the message has not been altered (accidentally or intentionally) during transmission. The receiver can verify that the received message is exactly what was sent.
2. Message Authentication (Source Verification)
Confirms that the message actually came from the claimed sender and not from an imposter or attacker.
3. Non-repudiation
Prevents the sender from later denying that they sent the message. This is important in legal and financial transactions.
4. Protection Against Masquerade
Prevents an unauthorized party from pretending to be a legitimate sender and injecting false messages.
5. Protection Against Replay Attack
Ensures that a previously sent valid message cannot be captured and retransmitted by an attacker to produce an unauthorized effect.
6. Protection Against Modification
Detects any unauthorized changes to the content, sequence, or timing of a message.
7. Sequence Control
Ensures messages are received in the correct order and none are missing or duplicated.
Part 2: MD5 (Message Digest 5) - Working Mechanism
MD5 was designed by Ronald Rivest in 1991. It produces a 128-bit (16-byte) message digest from an input message of arbitrary length.
Overview
Input Message (any length)
|
v
[Padding + Length]
|
v
[512-bit Blocks]
|
v
[4 Rounds of Processing per Block]
|
v
128-bit Message Digest
Step-by-Step Working of MD5
Step 1: Append Padding Bits
- The original message is padded so that its length becomes congruent to 448 mod 512.
- Padding is always added, even if the message is already the right length.
- Padding consists of a single '1' bit followed by as many '0' bits as needed.
Padded Length โก 448 (mod 512)
Step 2: Append Length
- A 64-bit representation of the original message length (before padding) is appended.
- This makes the total message length a multiple of 512 bits.
Total Length = Multiple of 512 bits
Step 3: Initialize MD Buffer (Initial Hash Values)
MD5 uses a 128-bit buffer divided into four 32-bit registers:
| Register | Initial Value (hex) |
|---|---|
| A | 67452301 |
| B | EFCDAB89 |
| C | 98BADCFE |
| D | 10325476 |
These are fixed constants (little-endian format).
Step 4: Process Message in 512-bit Blocks
Each 512-bit block is divided into sixteen 32-bit sub-blocks (M[0] to M[15]).
Each block goes through 4 rounds, and each round has 16 operations (total = 64 operations per block).
Four Auxiliary (Non-linear) Functions:
| Round | Function | Formula |
|---|---|---|
| 1 | F(B,C,D) | (B AND C) OR (NOT B AND D) |
| 2 | G(B,C,D) | (B AND D) OR (C AND NOT D) |
| 3 | H(B,C,D) | B XOR C XOR D |
| 4 | I(B,C,D) | C XOR (B OR NOT D) |
Each Operation:
Each of the 64 operations follows this general form:
a = b + ((a + F(b,c,d) + M[k] + T[i]) <<< s)
Where:
a, b, c, dare the four registers (rotated each step)Fis the round function (F, G, H, or I)M[k]is a 32-bit sub-block of the messageT[i]is a constant derived from|sin(i)| ร 2^32(precomputed table of 64 constants)<<<denotes left circular shift bysbitssis a per-step shift amount
Step 5: Update Buffer
After processing each 512-bit block, the output of the four rounds is added to the previous buffer values:
A = A + AA
B = B + BB
C = C + CC
D = D + DD
Where AA, BB, CC, DD are the saved values of A, B, C, D before processing the block.
Step 6: Output
After all blocks are processed, the 128-bit message digest is the concatenation of registers:
MD5 Digest = A || B || C || D (128 bits)
Summary Diagram of MD5
Message
|
+---> Padding (to 448 mod 512) + 64-bit length
|
+---> Divide into 512-bit blocks
|
For each block:
|
+----+----+----+----+
| A | B | C | D | <-- 128-bit buffer
+----+----+----+----+
|
Round 1 (16 ops using F)
Round 2 (16 ops using G)
Round 3 (16 ops using H)
Round 4 (16 ops using I)
|
Add to previous A,B,C,D
|
Final Output: 128-bit Digest
Key Properties of MD5
| Property | Value |
|---|---|
| Output size | 128 bits |
| Block size | 512 bits |
| Number of rounds |
SHA-2 hash function
2081 ยท 5 marks
How hash value is generated by the SHA-2 hash function. [5]
SHA-1 algorithm and padding
2080 ยท 10 marks
Describe the role of hash functions in authenticating message? How SHA-1 algorithm is used to produce hash value of a message? Explain.[10]
0 ยท 10 marks
SHA-1 Hash Function Properties and Computation
What are properties of hash function? In a hash function SHA-1, how padded message is computed before hash function computation? Using elongated message blocks from $w_0$ to $w_{79}$ how can you compute the final hash value? For the 160 bit hash value represented by 5 words A, B, C, D, E, write the expressions for $A_{79}$, $B_{79}$, $C_{79}$ after the last pass of the algorithm?[10]
Show solved answerHide answer
SHA-1: Properties, Padding, and Hash Computation
Given
- Hash algorithm: SHA-1
- Output size: 160-bit hash, represented as five 32-bit words $A, B, C, D, E$
- Message schedule words: $w_0$ to $w_{79}$ (80 words)
- Required: properties of hash functions, padding procedure, hash computation, and expressions for $A_{79}, B_{79}, C_{79}$ after the last pass.
No numeric message is provided; the answer is derived from the standard SHA-1 specification.
Solution
1. Properties of a Hash Function
| Property | Description |
|---|---|
| Compression | Maps arbitrary-length input to a fixed-length output (160 bits for SHA-1) |
| Ease of computation | $H(x)$ is fast and easy to compute for any $x$ |
| Pre-image resistance | Given $h$, infeasible to find $x$ with $H(x)=h$ (one-way) |
| Second pre-image resistance | Given $x$, infeasible to find $x'\ne x$ with $H(x')=H(x)$ (weak collision) |
| Collision resistance | Infeasible to find any $x\ne x'$ with $H(x)=H(x')$ (strong collision) |
| Avalanche effect | A tiny input change flips ~half the output bits |
| Deterministic | Same input always gives the same digest |
2. Padded Message Computation in SHA-1
SHA-1 works on 512-bit blocks. For a message $M$ of length $L$ bits:
- Append a single
1bit. - Append
kzero bits, where $k$ is the smallest non-negative integer with $$L + 1 + k \equiv 448 \pmod{512}$$ - Append the original length $L$ as a 64-bit big-endian integer.
The result is a total length that is a multiple of 512: $$\text{Padded length} = N \times 512 \text{ bits}, \quad N \ge 1$$
Example (M = "abc", $L = 24$): append 1 โ 25 bits, append 423 zeros โ 448 bits, append 64-bit length 24 โ 512 bits.
3. Computing the Final Hash Value ($w_0 \dots w_{79}$)
Initial hash values: $$H_0=\texttt{67452301},\ H_1=\texttt{EFCDAB89},\ H_2=\texttt{98BADCFE},\ H_3=\texttt{10325476},\ H_4=\texttt{C3D2E1F0}$$
Message schedule expansion: the block gives $w_0 \dots w_{15}$; the rest are: $$w_t = \text{ROTL}^{1}(w_{t-3}\oplus w_{t-8}\oplus w_{t-14}\oplus w_{t-16}), \quad 16 \le t \le 79$$
Round constants $K_t$ and functions $f_t(B,C,D)$:
| $t$ | $K_t$ | $f_t(B,C,D)$ |
|---|---|---|
| 0-19 | 5A827999 | $(B\wedge C)\vee(\neg B\wedge D)$ |
| 20-39 | 6ED9EBA1 | $B\oplus C\oplus D$ |
| 40-59 | 8F1BBCDC | $(B\wedge C)\vee(B\wedge D)\vee(C\wedge D)$ |
| 60-79 | CA62C1D6 | $B\oplus C\oplus D$ |
Compression loop. Initialize: $$A=H_0,\ B=H_1,\ C=H_2,\ D=H_3,\ E=H_4$$
For $t = 0$ to $79$: $$T = \text{ROTL}^{5}(A) + f_t(B,C,D) + E + w_t + K_t \pmod{2^{32}}$$ $$E=D,\quad D=C,\quad C=\text{ROTL}^{30}(B),\quad B=A,\quad A=T$$
After all 80 rounds, update: $$H_0{+}{=}A,\ H_1{+}{=}B,\ H_2{+}{=}C,\ H_3{+}{=}D,\ H_4{+}{=}E$$
Final digest: $$\text{Hash}=H_0,|,H_1,|,H_2,|,H_3,|,H_4 \quad (160 \text{ bits})$$
4. Expressions for $A_{79}, B_{79}, C_{79}$ (after the last pass, $t=79$)
Let subscript $t$ denote the value after round $t$ (so $A_{78},B_{78},\dots$ are the values entering round 79). The update rules give:
$A_{79}$ (the new $A = T$ using round-79 inputs): $$\boxed{A_{79} = \text{ROTL}^{5}(A_{78}) + f_{79}(B_{78},C_{78},D_{78}) + E_{78} + w_{79} + K_{79}}$$ with $f_{79}=B_{78}\oplus C_{78}\oplus D_{78}$ and $K_{79}=\texttt{CA62C1D6}$.
$B_{79}$ (new $B$ = old $A$): $$\boxed{B_{79} = A_{78}}$$
$C_{79}$ (new $C$ = ROTL$^{30}$ of old $B$): $$\boxed{C_{79} = \text{ROTL}^{30}(B_{78})}$$
(For completeness: $D_{79}=C_{78}$, $E_{79}=D_{78}$.)
These $A_{79},\dots,E_{79}$ are then added to the initial $H_0,\dots,H_4$ to form the block's contribution to the final hash.
Digital signatures for authentication
2080 ยท 5 marks
What is the role of digital signature in message authentication? List any two natures of zombies. [5]
0 ยท 5 marks
What is digital signature? How it can be used for message authentication? [5]
MD5 algorithm and hash value generation
2079 ยท 10 marks
What is hash function? Describe how 128-bit of hash value is generated by taking an input message of variable size using MD5 algorithm?[10]
Make Unit 5 stick
Practice BIT303 with flashcards & quizzes