4 Cryptographic Hash Functions And Digital Signatures

Cryptography · Unit 4 · 8 hrs

Cryptographic Hash Functions and Digital Signatures

Exam-focused notes for Cryptographic Hash Functions and Digital Signatures (Cryptography, CSC327): what the TU syllabus asks and how it has actually been tested, with 12 solved past questions from this unit.

Cryptographic Hash Functions and Digital Signatures in short

Confidentiality, provided by the ciphers of Units 1 to 3, is only half the picture: a recipient also needs to know a message truly came from its claimed sender and was not altered in transit. This unit covers message authentication, the cryptographic hash functions and MACs that provide it, and the digital signature schemes built on top of them.

Cryptographic Hash Functions and Digital Signatures: notes

Message Authentication and Message Authentication Functions

Message authentication is the mechanism that verifies a message's integrity and the identity of its sender; a message is authentic when it genuinely originates from its claimed source and has not been altered. It is concerned with three goals: protecting the integrity of the message, validating the identity of the originator, and providing non-repudiation of origin (the sender cannot later deny sending it). Any authentication or signature scheme has two levels: a lower-level function that produces an authenticator, a compact value derived from the message that stands in for it, and a higher-level protocol that uses that authenticator to let a receiver verify authenticity. The functions used to produce an authenticator fall into three classes: a hash function maps a message of any length to a fixed-length value that serves as the authenticator; message encryption uses the ciphertext of the entire message itself as the authenticator, since only someone holding the key could have produced valid ciphertext; and a message authentication code (MAC) is a function of both the message and a shared secret key that produces a fixed-length authenticator, combining ideas from the other two.

Message Authentication Codes

A MAC is computed as $\mathrm{MAC} = C(M, K)$, where $C$ is the MAC function, $M$ the message, and $K$ a secret key shared in advance by sender and receiver. The sender computes the MAC over the message and transmits the message together with the MAC value; the receiver recomputes the MAC over the received message using the same shared key and compares the two values. If they match, the receiver accepts that the message is both authentic (only someone with $K$ could have produced a matching MAC) and unaltered (any change to the message in transit would change its MAC); if they differ, the message is rejected. Unlike a plain hash, a MAC's security depends on the secrecy of $K$ rather than on hiding the function $C$ itself, which is why the MAC function can be public knowledge while the key stays private, exactly as with a symmetric cipher.

Hash Functions and their Properties

A cryptographic hash function $H$ maps an input message $M$ of arbitrary length to a fixed-length output $h = H(M)$, called the hash value or message digest. Five properties are what make a hash function suitable for security use rather than just for a data structure's hash table. One-way (preimage resistance): given a hash value $h$, it must be computationally hard to find any message $m$ with $H(m) = h$. Weak collision resistance (second-preimage resistance): given one message $m_1$, it must be computationally hard to find a different message $m_2$ with $H(m_1) = H(m_2)$. Strong collision resistance: it must be computationally hard to find any two distinct messages $m_1 \ne m_2$ with $H(m_1) = H(m_2)$ at all, without either message being fixed in advance; this is strictly harder to guarantee than weak collision resistance, because the birthday bound means a strong collision can be found in roughly $2^{n/2}$ attempts for an $n$-bit hash, quadratically fewer attempts than the $2^n$ a preimage search needs. Fixed-length output: regardless of the input's size, the digest is always the same number of bits. Applicability to any input size: the function must be defined for messages of any length, from a single byte to a multi-gigabyte file. Most cryptographic hash functions achieve this by processing the message through a Merkle-Damgard construction: the message is padded and split into fixed-size blocks, and a fixed-size internal compression function folds each block into a running chaining value, starting from a public initial value, with the final chaining value output as the digest; this structure is what MD4, MD5, and SHA-1 below all share.

What this unit covers

  • Message Authentication
  • Message Authentication Functions
  • Message Authentication Codes
  • Hash Functions
  • Properties of Hash functions
  • Applications of Hash Functions
  • Message Digests: MD4 and MD5
  • Secure Hash Algorithms: SHA-1 and SHA-2
  • Digital Signatures: Direct Digital Signatures, Arbitrated Digital Signature
  • Digital Signature Standard: The DSS Approach, Digital Signature Algorithm
  • Digital Signature Standard: The RSA Approach

Properties of Hash functions

2082 · 10 marks

Describe the properties of hash functions. Discuss how hash value is generated using SHA-1 algorithm.[10]

A hash function is a function that maps a message of any length into a fixed-length hash value, which serves as the authenticator. Cryptographic hash functions play a fundamental role in efficient and secure information processing. Property Description ------ Variable Input Size H can be applied ...

Open this answer on its own page →

2081 · 5 marks

Write short notes on (any two) a. Totient value of any positive integer. b. Properties of hash function. c. Virus or Worms. [5]

Show solved answer

Short Notes (Any Two)


a. Totient Value of Any Positive Integer

Definition: Euler's Totient Function, denoted by φ(n), is defined as the number of positive integers less than n that are relatively prime (coprime) to n. Two numbers are relatively prime if their greatest common divisor (GCD) is 1.

Special Property: If n is a prime number, then:

φ(n) = n - 1

This is because all integers from 1 to (n-1) are relatively prime to a prime number.

Example: Find φ(10):

  • Numbers less than 10: {1, 2, 3, 4, 5, 6, 7, 8, 9}
  • Numbers relatively prime to 10 (GCD with 10 = 1): {1, 3, 7, 9}
  • Therefore, φ(10) = 4

Example with prime: Find φ(7):

  • Since 7 is prime: φ(7) = 7 - 1 = 6

Euler's Totient Function is widely used in RSA encryption and number theory in cryptography.


b. Properties of Hash Function

Definition: A hash function is a function that maps a message of any length into a fixed-length hash value, which serves as the authenticator in message authentication and digital signatures.

Key Properties:

PropertyDescription
One-way PropertyGiven a hash value h, it is computationally infeasible to find any message m such that H(m) = h.
Weak Collision ResistanceGiven an input m1, it is computationally hard to find a different input m2 such that H(m1) = H(m2).
Strong Collision ResistanceIt is computationally hard to find any two different messages m1 and m2 such that H(m1) = H(m2).
Fixed-length OutputRegardless of input size, the hash function always produces a fixed-length output (e.g., MD5 produces 128-bit output).
Variable Input SizeA hash function can be applied to a block of data of any size.

Example:

  • MD5 produces a 128-bit (16-byte) hash value expressed as a 32-digit hexadecimal number.
  • MD4 also produces a 128-bit message digest from an input of arbitrary length.

Hash functions play a fundamental role in efficient and secure information processing in cryptography.

Open this answer on its own page →

2079 · 10 marks

Describe the properties of hash functions. Discuss how hash value is generated using SHA-1 algorithm.[10]

A hash function is a function that maps a message of any length into a fixed-length hash value, which serves as an authenticator. Cryptographic hash functions are a fundamental tool of cryptography for efficient and secure information processing. Property Description ------ Variable Input Size H ...

Open this answer on its own page →

2078 · 5 marks

List the properties of hash function. Discuss the first pass of MD4. [5]

A hash function maps a message of any length into a fixed-length hash value, which serves as an authenticator. The key properties are: 1. One-way property (Pre-image resistance): It is computationally hard to find the input (message) from the output (hash value). That is, for any given hash value...

Open this answer on its own page →

Digital Signature Standard

2082 · 5 marks

Describe the working mechanism of digital signature algorithm. [5]

A Digital Signature is a cryptographic mechanism where content is digitally signed with an individual's private key and verified using the individual's public key. It provides authentication, integrity, and non-repudiation. --- - Signing Algorithm -- used by the sender to sign the message - Verif...

Open this answer on its own page →

2076 · 5 marks

Define digital signature. Describe the approaches of DSS. [5]

A digital signature is an electronic signature that can be used to authenticate the identity of the sender of a message and to ensure that the original content of the message or document that has been sent is unchanged. Content is digitally signed with an individual's private key and is verified ...

Open this answer on its own page →

Message Authentication Codes

2081 · 10 marks

What is Message Authentication Code? List the operation of computing digest value in different passes of MD4. Describe about Needhom-Schroeder protocol.[10]

--- Definition: A Message Authentication Code (MAC) is a function of the message and a secret key that produces a fixed-length value that serves as the authenticator. Working Principle: - This technique assumes that the sender and receiver share a common secret key K. - When a sender wants to sen...

Open this answer on its own page →

2076 · 5 marks

Write down any two limitations of MAC. What do policy and mechanism mean in cryptography? Describe with a scenario. [5]

--- 1. No Non-repudiation: Since both the sender and receiver share the same secret key (symmetric key) to generate and verify the MAC, either party can forge a message. The sender can later deny sending a message, and there is no way to prove otherwise. A third party cannot distinguish who creat...

Open this answer on its own page →

Applications of Hash Functions

2080 · 10 marks

What are the applications of hash functions? Discuss how SHA-1 algorithm generates hash value from a given message.[10]

--- A hash function maps a message of any length into a fixed-length hash value, which serves as an authenticator. Hash functions are fundamental tools in cryptography and play a vital role in secure information processing. - One-way property: Computationally hard to find input from output - Weak...

Open this answer on its own page →

Digital Signatures

2079 · 5 marks

How direct digital signature different from arbitrated digital signature? How digital signature generation and verification is done using RSA. [5]

--- - Involves only two parties: the sender and the receiver. - The sender signs the message using their private key. - The receiver verifies the signature using the sender's public key. - No third party is involved in the process. - Weakness: The sender can later deny sending the message (repudi...

Open this answer on its own page →

2078 · 10 marks

Explain the generic model of digital signature process. Consider the two prime numbers 7 and 19. Select 29 as public key and 41 as private key. Encrypt the plaintext 4 and decrypt the cipher text 3 using RSA.[10]

Show solved answer

Digital Signature and RSA

Part 1: Generic Model of Digital Signature Process

A digital signature uses asymmetric (public key) cryptography to provide authentication, integrity, and non-repudiation. The sender signs using their private key; the receiver verifies using the sender's public key.

Model

Sender side:

  1. Message: Sender has the original plaintext message $M$.
  2. Hashing: A hash function $H$ (e.g., SHA-1, MD5) is applied to $M$ to produce a fixed-length message digest $h = H(M)$.
  3. Signing: The digest is encrypted with the sender's private key to form the digital signature $S = E_{PR_{sender}}(h)$.
  4. Transmission: The message $M$ and signature $S$ are sent together.

Receiver side: 5. Recompute hash: Receiver applies the same hash function to the received message: $h_1 = H(M)$. 6. Decrypt signature: Receiver decrypts $S$ with the sender's public key to recover $h_2 = D_{PU_{sender}}(S)$. 7. Compare: If $h_1 = h_2$, the message is authentic and unaltered; otherwise it has been tampered with or is forged.

Sender:   M --H--> h --Encrypt(PR_sender)--> S ;  send (M, S)
Receiver: M --H--> h1
          S --Decrypt(PU_sender)--> h2
          compare h1 == h2 ? valid : invalid

Properties provided: Authentication, Integrity, Non-repudiation.


Part 2: RSA

Given data

  • $p = 7$, $q = 19$
  • Public key $e = 29$
  • Private key $d = 41$
  • Plaintext to encrypt: $M = 4$
  • Ciphertext to decrypt: $C = 3$

Step 1: Parameters

$$n = p \times q = 7 \times 19 = 133$$ $$\phi(n) = (p-1)(q-1) = 6 \times 18 = 108$$

Check: $e \times d = 29 \times 41 = 1189$, and $1189 \mod 108 = 1189 - 11\times108 = 1189-1188 = 1$. ✓ Keys valid.

Step 2: Encrypt $M = 4$

$$C = M^e \bmod n = 4^{29} \bmod 133$$

Successive squaring mod 133:

  • $4^1 = 4$
  • $4^2 = 16$
  • $4^4 = 16^2 = 256 \equiv 123$
  • $4^8 = 123^2 = 15129 \equiv 6$ (since $15129 - 113\times133 = 15129-15029=100$... recheck)

Recheck $4^8$: $15129 \div 133 = 113.75$, $113\times133 = 15029$, remainder $= 100$. So $4^8 \equiv 100$, not 6.

Redo carefully:

  • $4^4 \equiv 123$
  • $4^8 = 123^2 = 15129$; $133\times113 = 15029$; $15129-15029 = 100 \Rightarrow 4^8 \equiv 100$
  • $4^{16} = 100^2 = 10000$; $133\times75 = 9975$; $10000-9975 = 25 \Rightarrow 4^{16} \equiv 25$

Binary: $29 = 16+8+4+1$, so $$4^{29} = 4^{16}\cdot 4^{8}\cdot 4^{4}\cdot 4^{1} \equiv 25 \times 100 \times 123 \times 4 \pmod{133}$$

Step by step:

  • $25 \times 100 = 2500;\ 2500 - 18\times133 = 2500 - 2394 = 106$
  • $106 \times 123 = 13038;\ 13038 - 98\times133 = 13038 - 13034 = 4$
  • $4 \times 4 = 16$

$$\boxed{C = 4^{29} \bmod 133 = 16}$$

Step 3: Decrypt $C = 3$

$$M = C^d \bmod n = 3^{41} \bmod 133$$

Successive squaring mod 133:

  • $3^1 = 3$
  • $3^2 = 9$
  • $3^4 = 81$
  • $3^8 = 81^2 = 6561;\ 6561 - 49\times133 = 6561-6517 = 44$
  • $3^{16} = 44^2 = 1936;\ 1936 - 14\times133 = 1936-1862 = 74$
  • $3^{32} = 74^2 = 5476;\ 5476 - 41\times133 = 5476-5453 = 23$

Binary: $41 = 32 + 8 + 1$, so $$3^{41} = 3^{32}\cdot 3^{8}\cdot 3^{1} \equiv 23 \times 44 \times 3 \pmod{133}$$

  • $23 \times 44 = 1012;\ 1012 - 7\times133 = 1012 - 931 = 81$
  • $81 \times 3 = 243;\ 243 - 133 = 110$

$$\boxed{M = 3^{41} \bmod 133 = 110}$$

Final Results

  • Encryption of plaintext $4$: $C = 16$
  • Decryption of ciphertext $3$: $M = 110$
Open this answer on its own page →

Secure Hash Algorithms

2076 · 10 marks

Compare the SHA parameters between SHA-1 and SHA-2 families. Decrypt the cipher text DRIJ with the key $$\begin{pmatrix} 7 & 8 \ 11 & 11 \end{pmatrix}$$ using the Hill cipher. [10]

Show solved answer

SHA Parameters Comparison & Hill Cipher Decryption


Part 1: SHA Parameters Comparison (SHA-1 vs SHA-2 Family)

ParameterSHA-1SHA-224SHA-256SHA-384SHA-512
Message Digest Size (bits)160224256384512
Max Message Size (bits)$<2^{64}$$<2^{64}$$<2^{64}$$<2^{128}$$<2^{128}$
Block Size (bits)51251251210241024
Word Size (bits)3232326464
Number of Rounds8064648080
Collision Security (bits)80112128192256

Notes:

  • SHA-1 produces a single 160-bit digest; SHA-2 is a family of hash functions with variable output sizes.
  • SHA-1 is broken against collision attacks (SHAttered, 2017) and is deprecated.
  • SHA-2 uses more complex round functions and better resistance to known attacks.

Part 2: Hill Cipher Decryption of "DRIJ"

Key: $K = \begin{pmatrix} 7 & 8 \ 11 & 11 \end{pmatrix}$, decryption uses $P = K^{-1}C \pmod{26}$.

Step 1: Convert ciphertext to numbers (A=0, ..., Z=25)

$$D=3,\ R=17,\ I=8,\ J=9$$

$$C_1=\begin{pmatrix}3\17\end{pmatrix},\quad C_2=\begin{pmatrix}8\9\end{pmatrix}$$

Step 2: Compute $K^{-1} \pmod{26}$

Determinant: $$\det(K)=(7\cdot 11)-(8\cdot 11)=77-88=-11\equiv 15\pmod{26}$$

Inverse of determinant: find $d$ with $15d\equiv 1\pmod{26}$. $$15\times 7=105=4(26)+1\equiv 1\pmod{26}\Rightarrow 15^{-1}\equiv 7$$

Adjugate: $$\text{adj}(K)=\begin{pmatrix}11 & -8\ -11 & 7\end{pmatrix}\equiv\begin{pmatrix}11 & 18\ 15 & 7\end{pmatrix}\pmod{26}$$

Inverse: $$K^{-1}=7\begin{pmatrix}11 & 18\ 15 & 7\end{pmatrix}=\begin{pmatrix}77 & 126\ 105 & 49\end{pmatrix}\equiv\begin{pmatrix}25 & 22\ 1 & 23\end{pmatrix}\pmod{26}$$

Step 3: Decrypt first pair "DR"

$$P_1=\begin{pmatrix}25 & 22\ 1 & 23\end{pmatrix}\begin{pmatrix}3\17\end{pmatrix}\pmod{26}$$

Row 1: $25\cdot3+22\cdot17=75+374=449$; $449\bmod 26 = 449-17(26)=449-442=7$ Row 2: $1\cdot3+23\cdot17=3+391=394$; $394\bmod 26 = 394-15(26)=394-390=4$

$$P_1=\begin{pmatrix}7\4\end{pmatrix}\Rightarrow H,\ E$$

Step 4: Decrypt second pair "IJ"

$$P_2=\begin{pmatrix}25 & 22\ 1 & 23\end{pmatrix}\begin{pmatrix}8\9\end{pmatrix}\pmod{26}$$

Row 1: $25\cdot8+22\cdot9=200+198=398$; $398\bmod 26 = 398-15(26)=398-390=8$ Row 2: $1\cdot8+23\cdot9=8+207=215$; $215\bmod 26 = 215-8(26)=215-208=7$

$$P_2=\begin{pmatrix}8\7\end{pmatrix}\Rightarrow I,\ H$$

Step 5: Assemble plaintext

$$H,E,I,H \Rightarrow \boxed{\textbf{HEIH}}$$

Verification (encrypt HEIH back): $K\begin{pmatrix}7\4\end{pmatrix}=\begin{pmatrix}49+32\77+44\end{pmatrix}=\begin{pmatrix}81\121\end{pmatrix}\equiv\begin{pmatrix}3\17\end{pmatrix}=DR$ ✓ $K\begin{pmatrix}8\7\end{pmatrix}=\begin{pmatrix}56+56\88+77\end{pmatrix}=\begin{pmatrix}112\165\end{pmatrix}\equiv\begin{pmatrix}8\9\end{pmatrix}=IJ$ ✓

Decrypted plaintext: HEIH

Open this answer on its own page →