Studio 15 - Secure Networking
TCP/IP
The TCP/IP protocol includes a series of protocols, also known as the TCP/IP protocol suite. It provides a point-to-point connection mechanism and standardizes the encapsulation, addressing, transmission, routing, and reception of data frames.
TCP/IP vs. OSI
Unlike OSI Model, which has 7 layers, TCP/IP usually has four layers:
Application
Transport
Network
Network Interface: Sometimes this layer is divided into two layers
Physical Layer
Link Layer

Application Layer
The Application Layer of the TCP/IP protocol handles protocols that enable communication between applications. For example, HTTP (Hypertext Transfer Protocol) is used for web browsing, allowing clients to request web pages from servers and receive the corresponding data.
Transport Layer
The Transport Layer of the TCP/IP protocol handles end-to-end communication and ensures reliable data delivery between devices. Its main functions include:
Providing transport services for end-to-end connections.
Offering both reliable (TCP) and unreliable (UDP) transport services.
Managing flow control, error control, and Quality of Service (QoS).
There are two main protocols in the Transport Layer:
TCP (Transmission Control Protocol) is a connection-oriented, reliable protocol that ensures data arrives intact, in order, and without errors. It provides flow control and congestion management to avoid network overload and guarantees data delivery.
UDP (User Datagram Protocol) is a connectionless, unreliable protocol. It does not guarantee delivery or order, making it faster but less reliable. It's typically used for applications where speed is critical and some data loss is acceptable (e.g., video streaming or chat applications).
In summary, TCP offers high reliability but lower efficiency, while UDP offers higher efficiency but lower reliability, making it suitable for real-time applications with less stringent reliability requirements.
Network Layer
The Network Layer of the TCP/IP protocol is responsible for finding an appropriate path for transmitting data packets across complex network environments. In simple terms, the Network Layer ensures that data is delivered to the correct destination address, which may be connected through multiple networks and routers.
Key protocols at the Network Layer include:
ICMP (Internet Control Message Protocol)
IP (Internet Protocol)
These protocols help with routing, error reporting, and managing network traffic between different networks.
Network Interface Layer
The Network Interface Layer, which includes the Link Layer and Physical Layer, handles the hardware connections in a network. This layer includes device drivers, Network Interface Cards (NICs), optical fibers, and all physical transmission media. At this layer, the unit of data transmission is a bit.
Key protocols at the Link Layer include:
ARP (Address Resolution Protocol)
RARP (Reverse Address Resolution Protocol)
These protocols are responsible for mapping IP addresses to MAC addresses and vice versa, enabling devices on a local network to communicate effectively.
Example
When using TCP/IP for network communication, data packets are transmitted according to the layered model.
The sender transmits from the application layer downwards,
the receiver processes from the network interface layer upwards.
The order of data transmission for each frame from the client to the server is as follows: Application Layer → Transport Layer → Network Layer → Network Interface Layer → Network Interface Layer → Network Layer → Transport Layer → Application Layer.

Data Encapsulation and Decapsulation
When data is transmitted over the internet, it cannot be sent without any identifiers, as that would lead to chaos.
Therefore, when sending data, specific identifiers need to be added. This process is known as data encapsulation.
When the data is used, these identifiers are removed, and this process is called decapsulation.
The data encapsulation and decapsulation process in the TCP/IP protocol is generally as shown in the figure below:

Cryptography
Before we begin, let's take a look at the basic jargons in Cryptography
Plaintext
"Clear" data that can be intercepted and understood by anyone.
Ciphertext
"Scrambled" data that is generated from "encryption" algorithms to prevent plaintext from being understood.
Encryption
Converting from plaintext to ciphertext.
Decryption
Converting from ciphertext to plaintext.
Key
A particular value or string that is used to encrypt/decrypt messages.
Cipher, cryptosystems
Other names for encryption/decryption algorithms.
Symmetric Cipher
The same key is used to encrypt and decrypt. Also known as private key cryptosystems.
Asymmetric Cipher
A different key is used for encryption (the "public" key) than for decryption (the "private" key).
Private Key Cryptosystem
This is also known as symmetric cryptosystem. The key idea here is that we use private key to both encrypt the plaintext and decrypt the cipher.
A good example is substution cipher. In a this cryptosystem, the private key is typically a substitution alphabet or a permutation of the alphabet that is used to map each character of the plaintext to a corresponding character in the ciphertext.
Public Key Cryptosystem
This is also known as assymetric cryptosystem, or PKC. The key idea here is that we use public key to encrpty and private key to decrypt.
A public key can be sent to everyone.
A private key must be kept to oneself.
An example for PKC is the Rivest-Shamir-Addleman (RSA) algorithm. Now, suppose that Alice wants to send (her hair strands) to Bob securely. Bob generates his RSA keys.
(Bob) Choose private primes and modulus
Bob picks primes . Then compute .
Bob must keep these two prime numbers private!
(Bob) Compute Totient
(Bob) Select Public Exponent
Use the requirement that
, Bob chooses . ()
(Bob) Generate Public Key
As , Bob's public key is
(Bob) Compute Private Exponent
Bob solves in this equation:
, where is chosen arbitrary. Here, we let . So, we get
, thus
(Bob) Generate Private Key
As , Bob's private key is
Bob must keep the private key private!
(Alice) Encrpty the message using Bob's Public Key
Denote the ciphertext as , the plaintext as . To get using Bob's public key , we use this formula,
Then Alice will send , which is 3 to Bob.
(Bob) Decrypt the message using Bob's Own Private Key
Denote plaintext as again, with Bob's private key and use the following formula
Bob gets the message 12!
As a sum up, denote your cipher text as , plaintext as , and your key as (no matter public or private, so the order doesn't matter), we always have:
Encrypt using whichever key, we use the following formula,
Decrypt using whichever key (must be different from the one you choose in 1), we use the following formula,
Digital Signature
The use of digital signature is to ensure that a message is not modified and the message was signed by someone with access to the private key that corresponds to the public key! This is done by a neat feature of PKC, which is:
If we encrypt using the private key, we can also decrypt using the public key!
Still use the example of Bob and Alice above, with Bob's public key and Bob's private key . Bob sends 3 to Alice and Alice wants to know this message is not modified by others.
(Bob) Encrypt message using Bob's private key
This step is to get the ciphertext ,
(Bob) Sends message pair to Alice
Bobs sends the message and the ciphertext to Alice.
(Alice) Decrypt Bob's ciphertext to get
To decrypt to get , we use
If , Alice can make sure the message is not modified by someone else.
However, in real-world, the raw message can be quite large, which makes it harder to compute the ciphertext . To solve this, computer scientists introduce the hash function (like SHA256), which is basically used to generate a "digest" of the message . So now the steps become as follows:
Bob uses the hash function to generate , where is a much shorter summary of .
Bob encrypts (instead of ) using his private key to get the ciphertext .
Bob sends as usual to Alice.
Alice receives , then computes .
Alice decryptes using Bob's public key, and if the result is equal to , she knows that the message is not modified!
Hash Function
Below are some important properties of hash functions
Given , it must be impossible to derive .
Given even the tiniest change to , must change drastically.
It must be non-trivial to produce from .
No matter how big is, always produces a hash of exactly the same size.
The "gold standard" in hash functions is SHA256.
Real-world Applications of Digital Signature
As public keys are public, how does others know this public key is legit sent by someone? We can use digital signature to sign our public key!
For example, Bob wants to send his public key to Alice, and Alice wants to verify that this public key does come from Bob.
(Bob) Compute given Bob's public key
(Bob) Encrypt using Bob's private key , giving the ciphertext
(Bob) Bob then distributes to everyone (This pair is called a certificate)
(Alice) Compute , then decrypt using Bob's public key, if the result is equal to , then this public key is legit sent by Bob!
Sign and Digital Signature
Sign is the process (the act of creating the signature).
Signature is the value (the output of the signing process).
The sender (e.g., Bob) takes a message, creates a hash of it (using a hash function like SHA-256), and then encrypts that hash with their private key. This encrypted hash is the digital signature. This process is called signing.
The receiver (e.g., Alice) can use the public key to decrypt the digital signature, to get the hash and compare it with the hash sent by the sender. If they are the same, then the receiver can be sure the message is not modified! But who is the sender, we need a certificate to verify that the public key legit is from the sender we want!
Certificate
A certificate in cryptography is a signed statement that binds an identity (like Bob) to a public key. A certificate is usually signed by a certificate authority (CA)
Differences between Digital Signature and Certificate
Definition
A cryptographic proof that a message/document is authentic and unchanged.
A signed document that binds an identity (e.g., a person or website) to a public key.
Purpose
Ensures data integrity, authenticity, and non-repudiation.
Confirms the authenticity of a public key.
What is Signed?
A hash of a document or message.
A public key (along with identity information).
Who Signs It?
The owner of the private key uses his private key to sign it.
A trusted authority (e.g., a Certificate Authority, CA) uses his private key to sign it.
Verification
Anyone with the public key can verify the signature.
Anyone with the CA’s public key can verify the certificate.
Real-World Example
A contract signed digitally to prevent forgery.
An SSL certificate proving a website's authenticity.
Key Exchange
So, as we have seen above, to ensure the security of the communication between the Alice and Bob, we can use PKC and CA method. In this case, Alice and Bob would exchange public keys, verified by a CA, and encrypt messages using asymmetric encryption (like RSA). However, this method has drawbacks:
It relies on a trusted CA, which may not always be available.
Public-key cryptography is computationally expensive compared to symmetric encryption.
Instead, the second solution, which uses Diffie-Hellman (DH) Key Exchange lets Alice and Bob securely agree on a shared secret key without ever transmitting it directly. This shared secret key is then used for fast symmetric encryption (e.g., AES) to protect communication. And even if Eve listens in, she won’t be able to compute the key!
Diffie-Hellman Key Exchange Algorithm
(Alice and Bob) Agree on Public Parameters and
: A large prime number. It defines the range in which all calculations are done (modulo ).
: A generator (or primitive root) modulo . It’s a number such that its powers modulo can generate all numbers from 1 to . (( will produce all integers from 1 to (no repeats))
For simplicity reason, in our example we choose
(Alice and Bob) Generate their own secret numbers and
Alice picks a random private number . Let's say
Bob picks a random private number . Let's say
(Alice and Bob) Compute the public shared numbers and Exchange them and
Alice computes her public shared number:
She sends to Bob.
Bob computes his public shared number:
Bob sends to Alice.
(Alice and Bob) Compute the shared secret key and
Now, both Alice and Bob use the received public shared number ( and ) and their own secret number ( and ) to compute the shared key.
Alice computes
Bob computes
Now, both of them get the same shared key 2! They can use it with symmetric cryptosytem (or Private Key Cryptosystem) to encrypy their communication without worring the third person will know their shared secret key!)
This step can be shown vividly using the following diagram

Transport Layer Security
Transport Layer Security (TLS) is like a secure tunnel that protects messages from being read or changed by anyone except the intended recipient. It ensures that data stays private and authentic when traveling over the internet.
Let's see how TLS combines all what we have learned together with an example
TLS Handshake — Alice & Bob's Example
(Bob) Bob Sends a HELLO Message
Bob (the server) sends a "HELLO" message to Alice (the client), listing the encryption methods (ciphers) it supports (e.g., AES, DES).
(Alice) Alice Sends a HELLO Message Back
Alice replies with her chosen encryption method from the list Bob provided. In this example, we choose the symmetric cyrptosystem.
(Alice) Alice Sends Her Certificate
Alice sends Bob her digital certificate, which includes her public key.
(Bob) Bob Sends a Random Secret Encrypted with Alice’s Public Key
Bob generates a random secret (used to create a session key) and encrypts it using Alice’s public key from the certificate. He sends this encrypted secret to Alice.
(Alice) Alice Decrypts the Secret and Creates the Session Key
Alice decrypts Bob’s encrypted random secret using her private key. Both Alice and Bob now generate the session key (S) using Diffie-Hellman or another method. This session key is used for symmetric encryption (fast encryption for the actual data).
(Bob) Bob Sends a FINISHED Message
Bob sends a "FINISHED" message encrypted with the session key (S). This is a known message, so Alice can check if it matches by decrypting it.
(Alice) Alice Sends a FINISHED Message Back
Alice sends her own "FINISHED" message to Bob, encrypted with the session key (S).
Secure Communication Begins
Alice and Bob now use the session key (S) and the selected symmetric cipher (like AES) to securely exchange data.
Reference
Last updated