Cryptography & Network Security
INF 3201 / INF 3202
Complete Study Notes
Module 3 & Module 4
Module 3 Topics Module 4 Topics
• PEM (Privacy Enhanced Mail)
• Message Digest (Hash Function) • PGP (Pretty Good Privacy)
• MAC (Message Authentication Code) • Firewall & Types
• Digital Signature • SSL Protocol (Handshake, Record, Alert)
■ Includes PYQ Answers from 2023, 2024 & 2025 Exams
Heritage Institute of Technology | [Link] IT
MODULE 3 — Message Digest, MAC & Digital
Signature
1. Message Digest (Hash Function)
A Hash Function takes any input message (of any size) and produces a fixed-size output called a
message digest or hash value. Think of it like a fingerprint of a document — even if one character
changes, the fingerprint changes completely.
Simple Idea:
Input: Any size (text, file, password) → Output: Fixed size (e.g., 256 bits always)
Real-life Example:
You give a big book → you get a unique fingerprint. If even 1 word changes → fingerprint changes
completely.
Properties of Hash Function (5 Requirements — Very Important)
Property Meaning Simple Words
Fixed Length Output Output is always same size 200 pages or 2 pages → same
regardless of input size length hash
Fast to Compute Hash should be calculated quickly No delay in generating hash
One-Way (Pre-image Cannot reverse the hash to get From fingerprint, you can't rebuild
resistant) original message the book
Avalanche Effect A small change in input causes a 1 letter change → totally different
huge change in output hash
Collision Resistant No two different inputs should give Two different files must NOT have
same hash output same hash
Common Hash Algorithms:
Algorithm Output Size Status
MD5 128 bits Not secure now (broken)
SHA-1 160 bits Weak (deprecated)
SHA-256 256 bits Secure — used today
■ Exam Tip: MD5 produces 128-bit hash. SHA-1 produces 160-bit hash. SHA-256 is currently the most
used secure hash. The question 'which produces 128-bit hash?' answer is MD5.
■ PYQ 2025 (INFO 3201 Q1-vi): Which algorithm produces 128 bit hash value?
Answer: (a) MD5
MD5 (Message Digest 5) produces a 128-bit hash value. SHA-1 produces 160 bits, not 128 bits.
So the correct answer is MD5 only.
■ PYQ 2025 (INFO 3201 Q1-xiii): When two different message digests have the same value, it
is called ___
Answer: Collision
When two different input messages produce the same hash output, it is called a Collision. This is
a serious weakness and hash functions must be collision-resistant to avoid this.
■ PYQ 2023 (INFO 4242 Q6-c): Discuss five requirements of Hash Function
The five requirements (properties) of a good Hash Function are:
1. Fixed Length Output: Whatever the size of input, output is always fixed size.
2. Fast to Compute: Hash value must be easy and fast to compute.
3. One-Way / Pre-image Resistant: It is computationally impossible to reverse the hash to find
the original message.
4. Avalanche Effect: A tiny change in input (even 1 bit) must produce a completely different hash
output.
5. Collision Resistant: It must be computationally impossible for two different inputs to produce
the same hash output.
2. Message Authentication Code (MAC)
MAC is used to verify that a message came from a trusted sender and has not been changed during
transmission. It uses a secret key shared between sender and receiver.
Formula:
MAC = Hash(Message + Secret Key)
How it works:
• Sender computes MAC using message + secret key and sends both message + MAC.
• Receiver computes MAC again using the same key and compares.
• If MAC matches → message is authentic and unchanged.
Real-life example:
You and your friend share a secret password. You send a message + MAC. Friend checks using the
same key. If MAC matches → message is trusted.
■ Exam Tip: MAC uses a symmetric (same) key for both sender and receiver. It provides Integrity +
Authentication but NOT Non-repudiation (because both parties share the key).
3. Digital Signature
Digital Signature is used to prove that a message really came from a specific person and has not
been tampered with. It uses asymmetric (public-key) cryptography.
Purpose:
✔ Authentication — proves who sent the message
✔ Integrity — proves message was not changed
✔ Non-repudiation — sender cannot later deny sending it
How it works — Step by Step:
Sender Side:
Step 1: Create hash of the original message
Step 2: Encrypt the hash using sender's PRIVATE KEY → this is the Digital Signature
Step 3: Send (Original Message + Digital Signature) to receiver
Receiver Side:
Step 1: Hash the received message using the same algorithm
Step 2: Decrypt the Digital Signature using sender's PUBLIC KEY → get original hash
Step 3: Compare both hashes → If same, message is valid and authentic
Real-life example:
Like signing a document ✍■ — Only you can sign (private key). Anyone can verify the signature
(public key).
Key Comparison Table (VERY IMPORTANT for Exams):
Feature Hash MAC Digital Signature
Key Used No key Secret key (symmetric) Public + Private key
(asymmetric)
Provides Integrity only Integrity + Integrity + Authentication +
Authentication Non-repudiation
Type One-way function Symmetric Asymmetric
Can deny? N/A Yes (both share key) No (non-repudiation
guaranteed)
■ PYQ 2025 (INFO 3201 Q6-b): Discuss three properties of Digital Signature
The three main properties of a Digital Signature are:
1. Authentication: It proves the identity of the sender. The receiver can verify that the message
actually came from the claimed sender, because only the sender has the private key used to
create the signature.
2. Integrity: It ensures the message has not been altered during transmission. If even one
character is changed, the hash comparison at the receiver end will fail.
3. Non-repudiation: The sender cannot later deny having sent the message. Since the signature
is created with the sender's private key (which only they possess), they cannot claim someone
else sent it.
■ PYQ 2025 (INFO 3201 Q6-a): Differentiate between Certificate-based authentication and
Biometric authentication
Certificate-based Authentication:
• Uses a digital certificate issued by a Certificate Authority (CA) to prove identity.
• Works using public-key cryptography — user has a digital certificate with public key.
• Used in SSL/TLS, email security (PEM, PGP).
• Not based on physical characteristics — certificate can be shared or stolen.
Biometric Authentication:
• Uses unique physical characteristics of a person — fingerprint, retina, voice, face.
• FAR (False Acceptance Rate) and FRR (False Rejection Rate) are configurable parameters.
• Cannot be stolen or shared like a certificate.
• More secure for physical identity but needs special hardware (scanners).
MODULE 4 — PEM, PGP, Firewall & SSL
1. PEM — Privacy Enhanced Mail
PEM is an email security standard adopted by the Internet Architecture Board (IAB). It secures emails
sent over the Internet. It works at the Application Layer.
Security Features:
✔ Encryption — no one except receiver can read the email
✔ Non-Repudiation — sender cannot deny sending the email
✔ Message Integrity — email is not changed during travel
Steps of PEM Operation (Step by Step):
Step 1 — Canonical Conversion: Email is converted into a universal standard format. This is
needed because different operating systems might interpret the email differently. Canonical
conversion ensures the format is same everywhere.
Step 2 — Digital Signature: A hash (message digest) of the email is created using MD2 or MD5
algorithm. The hash is then encrypted with the sender's private key to create the digital
signature.
Step 3 — Encryption: The original email + digital signature are encrypted together using a
symmetric key algorithm — specifically DES or Triple DES in CBC mode.
Step 4 — Base-64 Encoding (Radix-64): Converts arbitrary binary data into printable ASCII
characters so the email can safely travel over the internet.
Block Diagram Canonical Conversion → Digital Signature → Encryption → Base-64 Encoding
■ PYQ 2025 (INFO 3201 Q8-b): Explain with neat sketch, the working mechanism of PEM
mail security protocol
PEM (Privacy Enhanced Mail) secures emails using 4 steps:
1. Canonical Conversion: Converts email to a standard universal format (important because
different OS/hardware may interpret bytes differently, which could corrupt the email during
transmission).
2. Digital Signature: Hash of email is created using MD2 or MD5. The hash is encrypted with the
sender's private key to form the digital signature. This ensures integrity and non-repudiation.
3. Encryption: The email + digital signature are encrypted using DES or Triple DES in CBC
(Cipher Block Chaining) mode using a symmetric session key.
4. Base-64 Encoding: The binary encrypted output is converted to printable ASCII characters
using Radix-64 encoding, so it can travel safely through email systems.
Block Diagram: Canonical Conversion → Digital Signature → Encryption → Base-64 Encoding
2. PGP — Pretty Good Privacy
PGP is another widely used email security system. It is similar to PEM but differs in the steps and
algorithms used. It uses IDEA algorithm and adds a Compression step.
Steps of PGP Operation (Step by Step):
Step 1 — Digital Signature: Hash is created using SHA-1 algorithm. Hash is encrypted with
sender's private key to form digital signature.
Step 2 — Compression: Original email + digital signature are compressed to reduce size using
Lempel-Ziv (lossless) algorithm. No data is lost.
Step 3 — Encryption: Compressed message is encrypted using IDEA algorithm in CFB mode
with a symmetric session key.
Step 4 — Digital Enveloping: The symmetric key used in Step 3 is encrypted with the receiver's
public key. The encrypted message + encrypted key together form the Digital Envelope. At
receiver side: receiver decrypts key with private key → then decrypts message.
Step 5 — Base-64 Encoding: Same as PEM — converts binary to printable ASCII using Radix-64.
Block Diagram Digital Signature → Compression → Encryption → Digital Enveloping → Base-64
Encoding
Quick Comparison: PEM vs PGP (VERY IMPORTANT)
Feature PEM PGP
Hash Algorithm MD2 / MD5 SHA-1
Symmetric Cipher DES / Triple-DES (CBC mode) IDEA (CFB mode)
Compression No compression step Lempel-Ziv (lossless)
Digital Envelope Not present Present (Step 4)
Canonical Conversion Yes (Step 1 — first step) Not present
First Step Canonical Conversion Digital Signature
3. Firewall
A Firewall is a security system that protects a local computer or network from external threats (like the
Internet), while still allowing authorized communication to pass through.
Characteristics:
• All traffic going in or out MUST pass through the firewall — no other path left open.
• Only authorized traffic (as defined by security policy) is allowed through.
• The firewall itself must be immune to penetration.
Limitations:
■ Cannot protect against attacks that bypass the firewall.
■ Cannot protect against internal threats (e.g., a disgruntled employee inside the network).
■ Cannot protect against virus-infected files being transferred.
3.1 Types of Firewall
Type 1 — Packet-Filtering Router
Looks at each IP packet and decides to allow or block it based on rules.
Filtering is based on: Source IP, Destination IP, Source/Destination Port, Interface.
Advantages Disadvantages
Simple to configure Cannot examine upper-layer (application) data
Fast processing Limited logging functionality
Does not support advanced user authentication
Attacks on Packet-Filtering Router:
1. IP Address Spoofing: Attacker sends packets from outside but uses an internal IP address as
source. Countermeasure: Discard all packets arriving on external interface that have an internal
source IP.
2. Source Routing Attack: Attacker specifies exact route of packet, hoping to bypass security
checks. Countermeasure: Discard all packets that use the source routing option.
3. Tiny Fragment Attack: Attacker fragments packet into tiny pieces, forcing TCP header into a
separate fragment. Router checks only first fragment. Countermeasure: Discard all packets
where protocol = TCP and IP fragment offset = 1.
■ PYQ 2025 (INFO 3201 Q9-b): Discuss the attacks possible on Packet Filtering Router
There are three main attacks on a Packet Filtering Router:
1. IP Address Spoofing Attack: The attacker sends packets from outside the network but fakes
the source IP address to look like an internal (trusted) host. The router gets tricked into thinking
the packet came from inside. Countermeasure: Block all packets arriving on the external interface
that have an internal source IP address.
2. Source Routing Attack: The attacker specifies the exact route the packet should take (source
routing option in IP header). This can be used to bypass the firewall's security rules.
Countermeasure: Discard all packets that use the source routing option.
3. Tiny Fragment Attack: The attacker breaks the packet into very tiny fragments so that the
TCP header information is pushed into a separate fragment. The router checks only the first
fragment and may allow the remaining fragments through without checking. Countermeasure:
Discard all packets where the protocol is TCP and the IP fragment offset is 1.
■ PYQ 2025 (INFO 3201 Q1-ix): Which firewall suffers from Source Routing Attack?
Answer: (b) Packet Filter Router
The Packet Filter Router is the one that suffers from the Source Routing Attack. This is because it
checks IP packet headers but cannot examine application-layer data, and attackers can specify a
route in the IP header to bypass its rules.
Type 2 — Application-Level Gateway (Proxy Server)
Also called a Proxy Server. Acts as a middleman between user and destination. User connects to
gateway, gateway connects to destination server — it handles communication on behalf of the user.
When a user tries to access a remote host, the gateway asks for: valid user ID + authentication info.
Only after verification does it relay data.
Advantages Disadvantages
More secure than packet-filtering router Extra processing overhead — slower
Can audit/log all traffic at application level
Type 3 — Circuit-Level Gateway
Does NOT allow direct end-to-end TCP connection between two hosts. Instead, creates two separate
TCP connections:
• Connection 1: Between itself and the internal host
• Connection 2: Between itself and the external host
Relays TCP data between the two without examining the actual content.
■ PYQ 2025 (INFO 3201 Q8-a): Explain three types of firewall configuration with neat
diagrams
The three main firewall configurations are:
1. Screened Host Firewall — Single Homed Bastion: Uses a Packet Filtering Router (PFR) +
Application-Level Gateway (Bastion Host). Internal hosts connect to both the gateway and the
router. Weakness: If the PFR is compromised, internal hosts are directly exposed.
2. Screened Host Firewall — Dual Homed Bastion: Same as above but internal hosts connect
ONLY to the Application-Level Gateway. The gateway connects to the router. Even if the router is
compromised, attacker still faces the gateway before reaching internal hosts.
3. Screened Subnet Firewall (DMZ): Uses TWO packet filtering routers + one Application-Level
Gateway. Path: Internet → PFR 2 → Gateway → PFR 1 → Internal Network. Maximum security
— even if PFR 2 is compromised, attacker faces gateway + PFR 1 before reaching internal hosts.
■ PYQ 2025 (INFO 3201 Q1-xv): Which firewall architecture has at least three network
interfaces?
Answer: DMZ (Demilitarized Zone) / Screened Subnet Firewall
The DMZ architecture uses at least three network interfaces: (1) Internal private network, (2)
Internet (external), and (3) Public servers (the DMZ zone where web servers, FTP servers etc.
are placed). Even if the DMZ is attacked, the internal private network remains safe.
3.2 Bastion Host
A Bastion Host is a specially secured computer identified by the firewall administrator as a critical
security point. It serves as the platform for application-level or circuit-level gateways.
Properties:
• Runs a secure version of its operating system — trusted system.
• Only essential services are installed — nothing extra.
• May require additional authentication before granting access.
• Each proxy maintains detailed audit logs — all traffic, connections, and duration.
• Each proxy is independent of other proxies on the bastion host.
4. SSL — Secure Socket Layer
SSL is an internet protocol for secure communication between a web browser (client) and a web
server. It provides authentication and confidentiality.
Position of SSL in TCP/IP Model:
SSL is placed between the Application Layer and the Transport Layer. This is the correct position
because it only encrypts application data, not the addresses.
Why NOT Between Transport & Internet: Port gets encrypted → communication breaks.
elsewhere? Between Internet & Data Link: IP address gets encrypted → communication
breaks. Between Data Link & Physical: MAC address gets encrypted →
communication breaks.
■ PYQ 2025 (INFO 3201 Q1-x): What is the position of SSL in TCP/IP model?
Answer: (a) Between Transport and Application Layer
SSL is placed between the Transport Layer and the Application Layer in the TCP/IP model. It
encrypts only the application data (like HTTP data), keeping TCP/IP addresses intact so that
routing and communication continue to work properly.
SSL Protocol Stack:
Layer Protocol
Application Layer (e.g., HTTP) Uses SSL
SSL Sub-protocols Handshake Protocol | Change Cipher Spec Protocol | Alert
Protocol
SSL Record Protocol Handles encryption and integrity
Transport Layer TCP
Internet Layer IP
4.1 SSL Handshake Protocol
The Handshake Protocol is used by client and server to establish a secure SSL connection. They
exchange a series of messages in 4 phases.
Each Handshake Message has 3 fields:
• Type (1 byte): Type of message (e.g., Client Hello, Server Hello)
• Length (3 bytes): Length of the message in bytes
• Content (1+ bytes): Parameters/data of the message
Phase 1 — Establish Security Capabilities:
Used to initiate connection and agree on security settings.
• Client Hello contains: SSL Version | Random number (date+time + 28 random bytes) | Session
ID | Cipher Suite list (preferred algorithms) | Compression method list
• Server Hello contains: Selected SSL Version | Random number | Session ID | Single chosen
Cipher Suite | Single chosen Compression method
Phase 2 — Server Authentication & Key Exchange:
Server sends all messages; client only receives.
• Certificate: Server sends its digital certificate to client for authentication.
• Server Key Exchange (optional): Only sent if server has no certificate.
• Certificate Request (optional): Server may ask for client's certificate.
• Server Hello Done: No parameters — signals server has finished Phase 2.
Phase 3 — Client Authentication & Key Exchange:
Client sends all messages; server only receives.
• Certificate (optional): Only if server requested it. If client has none, it sends 'No Certificate'.
• Client Key Exchange: Client creates a 48-byte premaster secret, encrypts it with the server's
public key, and sends it. This establishes the symmetric key for the session.
• Certificate Verify (optional): Client encrypts a hash of (client random + server random +
premaster secret) with its own private key — proves it is the legitimate certificate holder.
Phase 4 — Finish:
• Change Cipher Spec: Signals that all future packets will be protected using negotiated algorithms
and symmetric key.
• Finished: All messages sent. Handshake complete and secure connection established.
Key Generation:
Master Secret Premaster Secret + Client Random + Server Random → (via Message Digest
Algorithm) → Master Secret
Symmetric Key Master Secret + Client Random + Server Random → (via Message Digest
Algorithm) → Symmetric Key
■ PYQ 2025 (INFO 3201 Q9-a): Explain the working of Handshake Protocol in detail
The SSL Handshake Protocol works in 4 phases to establish a secure SSL connection between
client and server:
Phase 1 — Establish Security Capabilities: Client sends 'Client Hello' containing: SSL version,
a random number, session ID, list of supported cipher suites, and compression methods. Server
replies with 'Server Hello' selecting one cipher suite and one compression method.
Phase 2 — Server Authentication & Key Exchange: Server sends its digital Certificate for
authentication. Server may optionally send Server Key Exchange (if no certificate). Server may
optionally request the client's certificate. Server sends 'Server Hello Done' to signal end of phase
2.
Phase 3 — Client Authentication & Key Exchange: Client optionally sends its Certificate if
requested. Client sends 'Client Key Exchange' — a 48-byte premaster secret encrypted with the
server's public key. Client may send 'Certificate Verify' — a hash signed with client's private key to
prove it owns the certificate.
Phase 4 — Finish: Both sides send 'Change Cipher Spec' (signals switching to encrypted
communication). Both send 'Finished' message — handshake is complete and secure channel is
ready.
Master Secret is derived from: Premaster Secret + Client Random + Server Random. Symmetric
keys are then derived from the Master Secret.
4.2 SSL Record Protocol
After Handshake completes, the Record Protocol starts. It provides Confidentiality (encryption) and
Integrity (MAC).
Steps:
Step 1 — Fragmentation: Application message is broken into blocks of size ≤ 214 bytes.
Step 2 — Compression: Blocks are optionally compressed using a lossless algorithm.
Step 3 — Add MAC: MAC (Message Authentication Code) is calculated for each block using the
shared symmetric key. Ensures integrity.
Step 4 — Encryption: Data + MAC is encrypted using the symmetric key.
Step 5 — Append Header: Header is added with: Content type (8 bits) | Major version (8 bits) |
Minor version (8 bits) | Compressed length (16 bits).
Flow Fragment → Compress → Add MAC → Encrypt → Add Header
4.3 SSL Alert Protocol
When either client or server detects an error, it sends an Alert Message to the other side.
Alert Message = 2 bytes:
• Byte 1: Value = 1 → Warning | Value = 2 → Fatal Error
• Byte 2: Specifies the actual error type
Type Byte 1 Value Examples Action
Warning 1 No certificate, Certificate expired, Both sides handle error and
Certificate unknown continue session
Fatal 2 Unexpected message, Bad record Both sides terminate SSL
MAC, Handshake failure connection immediately;
destroy session ID and
symmetric key
■ PYQ 2025 (INFO 3201 Q1-viii): If the first byte of Alert message in SSL has value 1, what
does it indicate?
Answer: (b) Warning
In the SSL Alert Protocol, Byte 1 (the first byte) indicates the severity level: Value 1 = Warning,
Value 2 = Fatal Error. When it is a Warning, the session continues. When it is Fatal, the session is
terminated immediately.
4.4 Buffer Overflow Attacks on SSL
A Buffer Overflow occurs when a program stores more data than the buffer (temporary storage area)
can hold. This can allow attackers to execute malicious code.
Attack What Happens
SSL Version 2 Client sends oversized master key → overflows buffer → allows malicious
code execution on server
SSL Version 3 SSL Handshake Protocol fails due to malformed (incorrectly formatted)
session ID → buffer overflow
64-bit OS Buffers to store ASCII representation of integers are smaller than needed on
64-bit OS → overflow
QUICK REVISION — PYQ ANSWER KEY (2023, 2024,
2025)
MCQ Answer Key (from PYQs):
Q. No. Question Answer
Q1-vi (2025) Which produces 128-bit hash? MD5
Q1-viii (2025) SSL Alert Byte 1 = 1 means? Warning
Q1-ix (2025) Which firewall has Source Routing Attack? Packet Filter Router
Q1-x (2025) Position of SSL in TCP/IP? Between Transport
and Application
Q1-xiii (2025) Two digests same value is called? Collision
Q1-xv (2025) Firewall with 3+ network interfaces? DMZ (Screened
Subnet)
Q1-xiv (2025) Handshake protocol in SSL has ___ phases 4 (Four)
Q1-xi (2025) Attack in authentication is called? Masquerade /
Fabrication
All Topics Covered Summary:
Topic Key Points to Remember
Hash Function Fixed output, one-way, avalanche effect, collision resistant, fast.
MD5=128bit, SHA-1=160bit, SHA-256=256bit
MAC Uses secret (symmetric) key. Provides integrity + authentication. Formula:
Hash(Message + Key)
Digital Signature Uses private key to sign, public key to verify. Provides integrity + auth +
NON-REPUDIATION
PEM Steps: Canonical → Digital Sig (MD2/MD5) → Encryption (DES/3DES CBC)
→ Base64
PGP Steps: Digital Sig (SHA-1) → Compression (Lempel-Ziv) → Encryption (IDEA
CFB) → Digital Envelope → Base64
Packet Filter Router Attacks: IP Spoofing, Source Routing, Tiny Fragment
SSL Position Between Application and Transport layers
SSL Handshake 4 Phases: Security Capabilities → Server Auth → Client Auth → Finish
SSL Alert 2 bytes: Byte1=1 (Warning), Byte1=2 (Fatal). Fatal terminates session.
SSL Record Steps: Fragment → Compress → MAC → Encrypt → Add Header
■ Exam Tip: Always remember: PEM uses MD2/MD5 and DES. PGP uses SHA-1 and IDEA. Digital
Signature = private key sign + public key verify. SSL is between Application and Transport layers.
Handshake has 4 phases.