5 Hash Functions And Message Authentication

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.

Hash Functions and Message Authentication: notes

Hash function properties and design

A hash function $H$ takes a message of any length and returns a fixed-length hash value (digest).

$$h = H(M)$$

Required properties:

  • Variable input, fixed output: any size input gives the same size digest.
  • Easy to compute: fast for any message.
  • Pre-image resistance (one-way): given $h$, it is hard to find $M$ with $H(M)=h$.
  • Second pre-image resistance: given $M_1$, it is hard to find a different $M_2$ with the same hash.
  • Collision resistance: it is hard to find any two messages with the same hash.
  • Avalanche effect: a one-bit change in the input changes about half of the output bits.

A digest of $n$ bits needs about $2^{n/2}$ tries to find a collision (the birthday attack). So a 128-bit hash gives only about 64 bits of collision safety.

Most hashes use the Merkle-Damgard design. The message is padded, split into blocks, and each block is mixed into a running state by a compression function. The last state is the digest.

Uses: checking file integrity, storing passwords (with a salt), digital signatures and message authentication codes.

MD5 algorithm and hash value generation

MD5 produces a 128-bit digest from blocks of 512 bits. It is now broken for collisions, so it must not be used for security, though it is still seen for file checks.

Process:

  • Padding: add a single 1 bit and then 0 bits until the length is 448 mod 512.
  • Length: add the original length as a 64-bit number. The total is now a multiple of 512 bits.
  • Initialise four 32-bit registers A, B, C, D with fixed constants (0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476).
  • Process each 512-bit block in 4 rounds of 16 steps (64 steps in all). Each round uses a different non-linear function (F, G, H, I), the 16 message words, a constant from a table and a left rotation.
  • The block result is added to A, B, C, D. After the last block, A, B, C, D joined give the 128-bit hash.

Padding example: a 3-letter message "abc" is 24 bits. We add one 1 bit and 423 zero bits to reach 448, then 64 length bits. $24+1+423+64=512$, so one block is enough.

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 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:

RegisterInitial Value (hex)
A67452301
BEFCDAB89
C98BADCFE
D10325476

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:
RoundFunctionFormula
1F(B,C,D)(B AND C) OR (NOT B AND D)
2G(B,C,D)(B AND D) OR (C AND NOT D)
3H(B,C,D)B XOR C XOR D
4I(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, d are the four registers (rotated each step)
  • F is the round function (F, G, H, or I)
  • M[k] is a 32-bit sub-block of the message
  • T[i] is a constant derived from |sin(i)| ร— 2^32 (precomputed table of 64 constants)
  • <<< denotes left circular shift by s bits
  • s is 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

PropertyValue
Output size128 bits
Block size512 bits
Number of rounds
Open this answer on its own page โ†’

SHA-2 hash function

2081 ยท 5 marks

How hash value is generated by the SHA-2 hash function. [5]

Note: No specific reference notes were found for this topic. The following answer is based on standard cryptography curriculum content appropriate for BSc CSIT. --- SHA-2 (Secure Hash Algorithm 2) is a family of cryptographic hash functions designed by the NSA and published by NIST. It includes v...

Open this answer on its own page โ†’

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]

A hash function H is a mathematical function that maps a variable-length input message M to a fixed-length output called the message digest or hash value. The basic authentication process works as follows: At the Sender Side: 1. Sender computes hash value: h = H(M) 2. Sender transmits the message...

Open this answer on its own page โ†’

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 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

PropertyDescription
CompressionMaps 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 resistanceGiven $h$, infeasible to find $x$ with $H(x)=h$ (one-way)
Second pre-image resistanceGiven $x$, infeasible to find $x'\ne x$ with $H(x')=H(x)$ (weak collision)
Collision resistanceInfeasible to find any $x\ne x'$ with $H(x)=H(x')$ (strong collision)
Avalanche effectA tiny input change flips ~half the output bits
DeterministicSame 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:

  1. Append a single 1 bit.
  2. Append k zero bits, where $k$ is the smallest non-negative integer with $$L + 1 + k \equiv 448 \pmod{512}$$
  3. 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-195A827999$(B\wedge C)\vee(\neg B\wedge D)$
20-396ED9EBA1$B\oplus C\oplus D$
40-598F1BBCDC$(B\wedge C)\vee(B\wedge D)\vee(C\wedge D)$
60-79CA62C1D6$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.

Open this answer on its own page โ†’

Digital signatures for authentication

2080 ยท 5 marks

What is the role of digital signature in message authentication? List any two natures of zombies. [5]

--- A digital signature is a cryptographic mechanism that provides a way to verify the authenticity and integrity of a digital message or document. It plays the following key roles in message authentication: A digital signature confirms the identity of the sender. Since the signature is created u...

Open this answer on its own page โ†’

0 ยท 5 marks

What is digital signature? How it can be used for message authentication? [5]

A digital signature is an electronic equivalent of a handwritten signature that provides a way to authenticate the identity of the sender of a message or the signer of a document. It is a cryptographic mechanism that uses asymmetric (public-key) cryptography to bind a message to its originator, e...

Open this answer on its own page โ†’

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]

A hash function is a mathematical function that takes a variable-length input message and produces a fixed-length output called the hash value or message digest, which acts as a digital fingerprint of the original message. Property Description ------ Variable input Accepts input of any length Fix...

Open this answer on its own page โ†’