COMPUTER NETWORKS/Student Engineering Notebook
Page 12·notes
NETWORK SECURITY, CRYPTOGRAPHY & FIREWALLS—~28 MIN READ

Network Security: Cryptography, RSA Math, Diffie-Hellman & Firewalls

“Symmetric vs asymmetric ciphers, RSA modular exponentiation, Diffie-Hellman, and packet-filtering firewalls.”

1.Security Fundamentals & Symmetric vs Asymmetric Ciphers

Network security encompasses four fundamental pillars (the CIA+N model):

• Confidentiality: Only authorized sender and receiver understand message content (achieved via encryption).

• Integrity: Ensuring the message was not altered in transit (achieved via cryptographic hashes and MACs).

• Authentication: Confirming the true identity of the communicating peer.

• Non-Repudiation: Proving that the sender genuinely sent the message (achieved via digital signatures).

Symmetric vs Asymmetric Cryptographic Paradigms:

1. Symmetric Key Cryptography: Sender and receiver share the identical secret key K. Very fast, computationally light, used for bulk data encryption. Examples: DES (56-bit key, obsolete), Triple-DES (3DES, 168-bit key), AES (Advanced Encryption Standard, Rijndael with 128, 192, or 256-bit keys). Key distribution problem: How do sender and receiver agree on K over an untrusted internet?

2. Asymmetric (Public-Key) Cryptography: Each entity owns an asymmetric key pair: a publicly published Public Key (K_pub) and a strictly guarded Private Key (K_priv). A message encrypted with K_pub can only be decrypted by the matching K_priv. Solves the key distribution problem. Examples: RSA, Diffie-Hellman, ECC (Elliptic Curve Cryptography).

2.The RSA Public-Key Cryptosystem: Mathematical Derivation

Invented in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman, RSA is the most widely deployed public-key algorithm. Its security rests on the computational intractability of factoring large composite integers into their prime components.

RSA Algorithm Step-by-Step:

1. Choose two large, distinct prime numbers p and q.

2. Compute modulus n = p * q. The bit length of n is the key length (e.g. 2048 bits).

3. Compute Euler's Totient function: phi(n) = (p - 1) * (q - 1).

4. Select public exponent e such that 1 < e < phi(n) and gcd(e, phi(n)) = 1 (e is coprime to phi(n)). Commonly chosen values in practice are 3, 17, or 65537 (2^16 + 1).

5. Compute private decryption exponent d such that: d = e^(-1) mod phi(n), meaning: (e * d) mod phi(n) = 1.

This is solved efficiently using the Extended Euclidean Algorithm.

6. Key Pairs: Public Key = (e, n); Private Key = (d, n).

7. Encryption (by Sender using Public Key):

$c = m^e \bmod n \quad (where plaintext integer 0 ≤ m < n)$

8. Decryption (by Recipient using Private Key):

$m = c^d \bmod n$

Correctness Proof (Euler's Totient Theorem):

Since e d = 1 (mod phi(n)), there exists an integer k such that e d = k * phi(n) + 1.

Then c^d = (m^e)^d = m^(ed) = m^(k phi(n) + 1) = (m^phi(n))^k * m.

By Euler's Theorem, if gcd(m, n) = 1, then m^phi(n) = 1 (mod n). Hence, 1^k * m = m (mod n).

notice this:— Crucial GATE Trap: Modular Base for d vs c

Private exponent d is computed modulo phi(n) = (p - 1)(q - 1). Encryption and decryption are computed modulo n = p * q! Never mix up the two moduli.

3.Diffie-Hellman Key Exchange & Digital Signatures

Diffie-Hellman Key Exchange Protocol:

Allows two parties (Alice and Bob) who have never met to establish a shared symmetric secret key over a public eavesdropped channel without transmitting the key itself.

1. Public parameters: A large prime p and a primitive root modulo p, denoted g.

2. Alice picks a secret random private number a (1 <= a < p) and sends public value A = g^a mod p.

3. Bob picks a secret random private number b (1 <= b < p) and sends public value B = g^b mod p.

4. Alice computes shared key: K = B^a mod p = (g^b)^a mod p = g^(ab) mod p.

5. Bob computes shared key: K = A^b mod p = (g^a)^b mod p = g^(ab) mod p.

Eavesdropper Eve sees p, g, A, B, but computing a or b requires solving the Discrete Logarithm Problem, which is computationally infeasible for large p (e.g. 2048-bit primes).

Digital Signatures & Secure Hash Functions (SHA-256):

A digital signature provides non-repudiation and authentication.

1. Sender computes fixed-size digest H = Hash(M) using a cryptographic hash function (SHA-256: one-way, collision-resistant).

2. Sender encrypts H using their own PRIVATE key: S = (H)^d_sender mod n_sender.

3. Receiver decrypts signature using sender's PUBLIC key: H' = (S)^e_sender mod n_sender.

4. If H' == Hash(M), the receiver has mathematical proof that the message originated from the sender and was not modified.

4.Firewalls: Packet-Filtering, Stateful & Application Gateways

A firewall is a network security appliance that monitors and filters incoming and outgoing traffic based on configured security policies.

1. Stateless Packet-Filtering Firewalls (Layer 3 & 4): Inspects individual IP datagrams in isolation. Evaluates rules based on: Source/Destination IP address, Source/Destination Port numbers, IP Protocol type (TCP, UDP, ICMP), and TCP control flags (SYN, ACK). High performance, but vulnerable to IP spoofing and cannot detect connection context.

2. Stateful Inspection Firewalls (Layer 4): Maintains an active state connection table. Verifies whether incoming packets belong to an existing, legitimately initiated TCP session (e.g. allows incoming ACK packets only if a matching outgoing SYN was previously observed).

3. Application-Level Gateways / Proxy Firewalls (Layer 7): Intercepts application traffic (HTTP, FTP, DNS) at the application layer. Can inspect message payloads, detect malicious SQL injection or cross-site scripting strings, and filter specific URLs.

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATION2 Marks (Compulsory Topic in GATE CS)

5. GATE Worked Numerical: Complete RSA Cryptosystem Calculation

⚠️ Pitfall Warning:

When calculating d = e^(-1) mod phi(n), ensure e * d mod phi(n) = 1. A common mistake is solving e * d mod n = 1!

Problem (Original Practice Problem · Modeled on GATE Pattern):

In an RSA cryptosystem, the prime numbers are p = 7 and q = 11. The public encryption exponent is chosen as e = 13.

Calculate:

(a) The modulus n and Euler's totient phi(n).

(b) The private decryption exponent d.

(c) The ciphertext c corresponding to plaintext message m = 8.

(d) Verify decryption of c back to m.

Step 1: Compute modulus n and phi(n):

n = p q = 7 11 = 77.

phi(n) = (p - 1) (q - 1) = (7 - 1) (11 - 1) = 6 * 10 = 60.

Step 2: Find private exponent d:

We require e d = 1 (mod phi(n)) => 13 d = 1 (mod 60).

Using the Extended Euclidean Algorithm or trial multiples of 60:

13 d = 60 k + 1

For k = 1: 60(1) + 1 = 61 (not divisible by 13).

For k = 2: 60(2) + 1 = 121 (not divisible by 13).

For k = 3: 60(3) + 1 = 181 (not divisible by 13).

For k = 4: 60(4) + 1 = 241 (not divisible by 13).

For k = 5: 60(5) + 1 = 301 (not divisible by 13).

For k = 6: 60(6) + 1 = 361 (not divisible by 13).

For k = 7: 60(7) + 1 = 421 (not divisible by 13).

For k = 8: 60(8) + 1 = 481 -> 481 / 13 = 37 exactly! (13 * 37 = 481).

Thus, private exponent d = 37.

(Notice: 13 37 = 481 = 8 60 + 1 = 1 mod 60).

Step 3: Encrypt plaintext m = 8:

Ciphertext c = m^e mod n = 8^13 mod 77.

Use modular exponentiation (repeated squaring):

8^1 = 8 mod 77

8^2 = 64 = -13 mod 77

8^4 = (-13)^2 = 169 = 2 * 77 + 15 = 15 mod 77

8^8 = 15^2 = 225 = 2 * 77 + 71 = 71 = -6 mod 77

Now decompose exponent 13 = 8 + 4 + 1:

8^13 = 8^8 8^4 8^1 = (-6) 15 8 mod 77

(-6 15) = -90 = -90 + 2 77 = -90 + 154 = 64 mod 77

64 8 = 512 = 6 77 + 50 = 50 mod 77.

Ciphertext c = 50.

Step 4: Decrypt ciphertext c = 50 using private exponent d = 37:

m = c^d mod n = 50^37 mod 77.

50 = -27 mod 77.

50^2 = 2500 = 32 * 77 + 36 = 36 mod 77.

50^4 = 36^2 = 1296 = 16 * 77 + 64 = 64 = -13 mod 77.

50^8 = (-13)^2 = 169 = 15 mod 77.

50^16 = 15^2 = 225 = -6 mod 77.

50^32 = (-6)^2 = 36 mod 77.

Decompose exponent 37 = 32 + 4 + 1:

50^37 = 50^32 50^4 50^1 mod 77

= 36 (-13) 50 mod 77

36 (-13) = -468 = -468 + 7 77 = -468 + 539 = 71 = -6 mod 77.

(-6) 50 = -300 = -300 + 4 77 = -300 + 308 = 8 mod 77.

Decrypted plaintext m = 8! (Matches original plaintext).

Conclusion: n = 77, phi(n) = 60, d = 37, c = 50, and decryption recovers m = 8.

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
Cryptography and Network Security: Principles and Practice (8th Edition) ·
LECTURE SERIES
Computer Networking: A Top-Down Approach (8th Edition) ·
LECTURE SERIES
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Knowledge Gate · Computer Networks for GATE↗Instructor: Sanchit Jain · Covers: OSI/TCP-IP layers, sliding window, CRC, subnetting, TCP congestion control

GATE-level numerical drilling and PYQ analysis.

Open YouTube↗
Gate Smashers · Computer Networks Full Course↗Instructor: Varun Singla · Covers: Ethernet, IP addressing, routing algorithms, TCP/UDP, DNS & HTTP

Step-by-step conceptual walkthroughs with worked GATE numericals.

Open YouTube↗
Neso Academy · Computer Networks Series↗Instructor: Neso Academy · Covers: Data link layer, framing, error detection, medium access, TCP/IP

Clear whiteboard lectures for foundational and semester exam coverage.

Open YouTube↗