Applied Cryptography
6COSC019W- Cyber Security
Dr Tom Oliver
February 16, 2026
Prepared by Dr Ayman El Hajjar
Overview
1. Stream and Cipher modes
2. Cryptographic algorithms
3. Keys Distribution
4. Hashing Algorithms
5. Digital signatures
| 1
Symmetric Encryption - A recap
Shared Shared
secret: secret:
Key Key
Plaintext Encryption Ciphertext Decryption Plaintext
| 2
Asymmetric Encryption
• Commonly known as public key cryptography
• Uses a pair of keys: a private key that is kept secret and a public key
that can be sent to anyone
– Security reliant upon resistance to deducing one key, given the other
• Public key systems, because of their design, also form the basis for
digital signatures
– A cryptographic method for securely identifying people
Public and Public and
Private Keys Private
Private
of Alice Keys of Bob
Public key Key of
of Bob bob
Plaintext Encryption Ciphertext Decryption Plaintext
| 3
Cipher Modes
• When dealing with block algorithms, there is a need to deal with
multiple blocks of identical data to prevent multiple blocks of
cyphertext that would identify the blocks of identical input data
– There are multiple modes of operation
◦ Electronic Codebook (ECB)
◦ Cipher Block Chaining (CBC)
◦ Counter Mode (CTR)
Stream and Cipher modes | 4
Electronic Code Book (ECB)
• A block cipher mode describes the way a block cipher encrypts and decrypts a
sequence of message blocks.
• Electronic Code Book (ECB) Mode (is the simplest):
– Block P[i] encrypted into ciphertext block C[i] = EK(P[i])
– Block C[i] decrypted into plaintext block M[i] = DK(C[i])
Plaintext 1 Plaintext 2 Plaintext 3
Key Block Cipher Encryption Key Block Cipher Encryption Key Block Cipher Encryption
Ciphertext 1 Ciphertext 2 Ciphertext 3
Stream and Cipher modes | 5
Cipher Block Chaining (CBC) Mode
• In Cipher Block Chaining (CBC) Mode
– The previous ciphertext block is combined with the current plaintext block
C[i] = EK(C[i − 1] ⊕ P [i])
– C[−1] = V , a random block separately transmitted encrypted (known as the
initialization vector)
– Decryption: P [i] = C[i − 1] ⊕ DK(C[i])
Plaintext 1 Plaintext 2 Plaintext 3
Initialisation vector ⊕ ⊕ ⊕
Key Block Cipher Encryption Key Block Cipher Encryption Key Block Cipher Encryption
Ciphertext 1 Ciphertext 2 Ciphertext 3
Stream and Cipher modes | 6
Counter Mode (CTR)
• The Counter Mode or CTR is a simple counter-based block cipher that encrypts
each counter value and use it as an input to XOR it with plaintext which results in
ciphertext block.
– This turns block cipher into a stream cipher.
• The CTR mode is independent of feedback use.
3- Encrypt the counter
to generate a key
stream for each block.
1- Initialise Counter
with a unique counter Counter1 incr Counter2 ... incr Countern
value (IV).
Key Encrypt Key Encrypt Key Encrypt
Plaintext1 ⊕ Plaintext2 ⊕ Plaintextn ⊕
4- XOR the encrypted
2- Split plaintext counter (key stream) with
into fixed-size CipherText1 each plaintext block to CipherText2 CipherTextn
blocks. create ciphertext.
Stream and Cipher modes | 7
DES
• Data Encryption Standard (DES) is a block cipher
– Block size of 64 bits—64 bits of plaintext outputs 64 bits of ciphertext
– 56-bit key length
– Performs a substitution and permutation based on the key 16 rounds
on every 64-bit block
• Problems with DES
– Weak key: less secure than the majority of keys allowed in the
keyspace of the algorithm
– Semi-weak keys: two keys that will encrypt plaintext to identical
ciphertext
• DES was found to be reasonably secure
– Has been for more than two decades
Cryptographic algorithms | 8
3DES
Plaintext 1 Plaintext 2
Key A Encryption Decryption Key A
Nested application of DES Key B Decryption Encryption Key B
with three different keys KA ,
KB , and KC
Key C Encryption Decryption Key C
Ciphertext
C = EKC (DKB (EK A(P ))); P = DKA (EK B(DK C(C)))
Cryptographic algorithms | 9
3DES
• Depending on the variant, it uses either two or three keys
• Multiple encryption; goes through the DES algorithm three times
• The Encrypt and Decrypt combination is equivalent to DES when
KA=KB=KC (backward compatible)
• Stronger than DES but has similar weakness
• The longer key length makes it more resistant to brute force attacks
• Still popular and widely supported
• AES has taken over as the symmetric encryption standard
Cryptographic algorithms | 10
Advanced Encryption Standard (AES)
• A Cryptography algorithm that uses Symmetric encryption with block cipher
of 128 bits.
• AES-256 is the symmetric encryption algorithm of choice nowadays. It won
the NIST 2001 Competition.
• In practice, there has been no demonstrated attack that can break AES
encryption. Even brute force operations is infeasible with current
technologies 2128 = 3.4 ∗ 1038 .
• Variable key sizes used (128, 192, 256 bits)
Input
AES Output
Key
Cryptographic algorithms | 11
Rivest Cipher 4 (RC4)
• Symmetric encryption algorithm designed in 1987 by Ron Rivest for
RSA Security and remained a trade secret until 1994.
• keys length: up to 2,048 bits
• RC4 was popular for its remarkable speed and simplicity in
software-based encryption in applications such early versions of
TLS/SSL, WEP and WPA.
• It is now deprecated due to its several weaknesses.
Initialisation
Plain Text
Vector
Random
Number
Secret Key (K)
Generator
Keystream ⊕ Cipher Text
(RC4)
Cryptographic algorithms | 12
RSA Algorithm
• One of the first public key cryptosystems invented
– Published in 1977
– Used for encryption and digital signatures
• Uses the product of two very large prime numbers
– Works on the principle of difficulty in factoring such large numbers
• A simple algorithm that has withstood the test of more than 20 years
of analysis
• Process divided into two parts:
– Keys generation
– Encryption/Decryption
Cryptographic algorithms | 13
RSA Keys generation
Choose two large
primes p and q
ϕ(n) represents the number of integers relatively
Compute n = p · q
prime to (n), called the Euler quotient function
usually e starts from 65537 as it provides better resistance
Compute ϕ(n) = (p − 1)(q − 1) against small exponent attacks compared to smaller values
like
Choose e such that 1 < e < ϕ(n)
and gcd(e, ϕ(n)) = 1
The modular inverse of e mod ϕ(n) is d to ensure that
Compute d
e and d are mathematically linked for encryption and
where e · d ≡ 1 mod ϕ(n)
decryption in RSA.
Public Key Private Key
Kpu : (e, n) Kpr : (d, n)
Cryptographic algorithms | 14
RSA Encryption/Decryption
Condition: Sender Receiver
M <n Request Public key
Receive Public key (e, n)
This condition ensures the
mathematical validity and
Encrypt M
reversibility of RSA encryption
C = M e mod n
and decryption. This constraint
is a fundamental property of RSA’s Send Ciphertext C
modular arithmetic
Decrypt C
M = C e mod n
Cryptographic algorithms | 15
Key Distribution
• For symmetric encryption to work, the two parties to an exchange must share
the same key, and that key must be protected from access by others
• Key distribution techniques
– The means of delivering a key to two parties that wish to exchange data, without
allowing others to see the key
– Paper distribution : It requires no technology to use.
– Digital distribution
◦ can be in the form of digital storage or email but must be protected during
transmission.
◦ The Internet Security relies on this form of Keys distribution called public key
infrastructure (PKI).
– Hardware distribution
◦ Keys Distributed via hardware such as a smart card, or a plug-in module.
◦ The advantage is that no copies exist outside of these components.
Keys Distribution | 16
Session Keys
• Symmetric keys used for encrypting messages during a
communication session
– Generated from random seeds
– Used for the duration of a communication session
• Session key advantages
– Symmetric encryption, speed, strength, simplicity
– Significant levels of automated security
Keys Distribution | 17
Public Key Infrastructure (PKI)
• PKI provides a mechanism through which two parties can establish a trusted
relationship even if the parties have no prior knowledge of one another
• PKI brings trust, integrity, and security to electronic transactions
• PKI framework used to manage, create, store, and distribute keys and digital
certificates
• One of the most common PKI protocols in use today is the Diffie Hellman
protocol
– The purpose of the algorithm is to enable two users to exchange a secret key
securely that can then be used for subsequent encryption of messages.
– Plays a role in the electronic key exchange method of Transport Layer Security
(TLS), Secure Shell (SSH), and IP Security (IPSec) protocols
– The algorithm itself is limited to the exchange of the keys.
Keys Distribution | 18
Diffie-Hellman Key exchange
Alice and Bob agree
on a common colour.
Alice and Bob
agree on a public
prime number
Alice Bob
p and a base g.
Alice chooses Bob chooses
Selects private key (a) Selects private key (b)
a secret colour. a secret colour.
Public colour pubic key of Alice: pubic key of Bob: Public colour
Public Transport Channels
of Alice. PuA = g a mod p Pub = g b mod p of Bob.
Alice mixes Bob mixes
her secret colour Computes: (g b mod pa mod p) Computes: (g a mod p)b mod p) his secret colour
with the colour = g ab mod p = g ab mod p with the colour
received. received.
The Shared Secret Key is
K = g ab mod (p)
Shared secret colour.
Keys Distribution | 19
Diffie-Hellman Key Exchange process
1. Common colour: Both Alice & Bob agree on
using a common colour.
1. Alice & Bob agree on a public prime
2. Secret Colours: Alice & Bob each choose a
number and a base.
secret colour.
2. Alice & Bob chooses their secret values.
3. Mixing Colours: Alice & Bob mix their
3. Alice & Bob Calculate their public values
secret colours with the publicly agreed
and then exchange them using the Public
colours and valueexchange them using the
channel.
Public channel.
4. Each of them calculates the shared secret
4. The common colour: Each respectively
key using their private value and the
create the common secret using their
other’s public value.
secret colour.
5. Alice & bob now have a shared secret key.
5. Alice & bob now have a common secret
colour (key) .
Keys Distribution | 20
Key Distribution Centres
• Rather than each organisation creating the infrastructure to manage
its own keys, a number of hosts could agree to trust a
key-distribution center (KDC)
• All parties must trust the KDC
• With a KDC, each entity requires only one secret key pair—between
itself and the KDC
• Kerberos use the concept of a KDC.
– Kerberos is one of the most commonly used KDCs .
Keys Distribution | 21
Kerberos
• Key distribution and user authentication service developed at MIT
• Provides a centralised authentication server whose function is to
authenticate users to servers and servers to users.
• Relies exclusively on symmetric encryption, making no use of
public-key encryption
Keys Distribution | 22
The problem Kerberos solves
• Assume an open distributed environment in which users at
workstations wish to access services on servers distributed
throughout the network. In this environment, a workstation cannot
be trusted to identify its users correctly to network services.
• In particular, the following three threats exist:
1. A user may gain access to a workstation and pretend to be another
user operating from it.
2. A user may alter the network address of a workstation so that the
requests sent from the altered workstation appear to come from the
impersonated workstation.
3. A user may eavesdrop on exchanges and use a replay attack to gain
entrance to a server or to disrupt operations.
Keys Distribution | 23
How Kerberos works
2- AS Creates ticket-granting
ticket and session key and
1- User logs on to a sent encrypted using key
workstation and requests derived from user’s password.
service on host
Client. 1- AS Request
Key Distribution Center (KDC)
Authentication Database
2- AS Response
Server
Ticket Granting
3- TGS Request
4- TGS Response
Server
3- Workstation decrypt (TGS).
6- Application Response
incoming TGS with
password, then send 4- TGS decrypts ticket
Application Server and authenticator, verifies
ticket and authenticator
with user name to request then creates ticket
request service with for requested application
time to TGS. 5- Application request server.
5- Workstation
6- Host verifies that the
sends ticket and
ticket and authenticator
authenticator to
match then grants access
host.
to service.
Keys Distribution | 24
Common Hashing Algorithms : Message Digest
• A message digest is a fixed-size numerical representation of a
message.
– Works in the same manner as SHA: secure method employed to
compress the file and generate a computed output of a specified
number of bits
– A message digest must have the following properties
◦ Deterministic: Same input Same output.
◦ Irreversible: Hard to reconstruct input from the digest.
◦ Collision-Resistant: Hard to find two different inputs with the same
digest.
• MD5 message digest algorithm—Takes an input of any arbitrary
length and generates a 128-bit message digest that is
computationally infeasible to match by finding another input.
• MD5 provides Integrity verification, only.
Hashing Algorithms | 25
Common Hashing Algorithms: SHA256
• Secure Hashing Algorithm (SHA) variants are the most
common variants of hashing functions found in
commercial software
– Secure Hash Algorithm (SHA-1)—Produces a 160-bit
hash from a message of any arbitrary length.
– SHA256 with a digest size of 256 bits is one the most Figure 1: HashCalc -A
widely used hash algorithms. program that accepts an
input and produce a hash
value to compare and
verify with original file.
Hashing Algorithms | 26
SHA256
Padding
512 bits blocks
Message Message .Message
..
block1 block2 blockn
256 bits 256 bits
Hash
IV C1 C2 Cn
256 bits
Hashing Algorithms | 27
Digital Signatures
• A digital signature is a cryptographic implementation designed to
demonstrate authenticity and identity associated with a message
• Based on hashing functions and asymmetric cryptography
– Both encryption methods play an important role in signing digital
documents
• It’s operation is similar to that of the MAC
• The hash value of a message is encrypted with a user’s private key
• Anyone who knows the user’s public key can verify the integrity of
the message
• An attacker who wishes to alter the message would need to know the
user’s private key
• Implications of digital signatures go beyond just message
authentication
Digital signatures | 28
Digital Signature example without Confidentiality
3- Concatenates with message
and send Hash
Message H
Concatenate 5- Verifies the
Compare signed hash
by comparing
M P Ra
||
hashes
D
4- Decrypts the signed
H E E(P Ra , H(M )) P Ua hash with public key of
sender
Hash 2- Sender signs the hash with
1- Sender hashes the Sender Private key
message
This provides authentication. It also provides a digital signature because only the
sender could have produced the encrypted hash code.
Digital signatures | 29
Digital Signature example with Confidentiality
7- Verifies the signed hash
4- Encrypts with receiver public key by comparing hashes
5- Decrypts with receiver private
3- Concatenates with key Hash
message and send
P Ub P Rb k H
Message
Concatenate
Compare
M P Ra
|| E D
D
EP U (k, [M ||E(P Ra , H(M ))]
b
DP R (k, [M ||E(P Ra , H(M ))]
H E b P Ua
Hash 2- Sender signs the hash with
E(P Ra , H(M ))
Sender Private key
1- Sender hashes the 6- Decrypts the signed hash
message with public key of sender
This provides confidentiality in addition to authentication. It also provides a digital signature because only
the sender could have produced the encrypted hash code.
Digital signatures | 30
Hashes vs Digital Signature
Method Integrity Authentication Confidentiality Non-Repudiation Keys Example
PGP (encrypted
HMAC ✓ ✓ (hash) ✗ ✗ Symmetric
email)
✓ (symmetric Hash + AES (file
CMAC ✓ ✗ ✗ Symmetric
key) integrity)
CHMAC + AES
Authenticated ✓ (symmetric
✓ ✓ (hash) ✗ Symmetric (API auth, TLS,
Encryption key)
file protection)
Digital Digital
✓ (sender
Signature (no ✓ ✗ ✗ Asymmetric Signatures
private key)
confidentiality) (RSA)
Digital
Digital
Signature ✓ (receiver ✓ (receiver ✓ (sender
✓ Asymmetric Signatures
(with public key) private key) private key)
(RSA)
confidentiality)
Table 1: Comparison of Hash-based authentication vs Digital Signatures
Digital signatures | 31
References
• The lecture notes and contents were compiled from my own notes
and from various sources.
• The lecture notes are very detailed. If you attend the lecture, you
should be able to understand the topics.
– Chapter 2- Cryptographic Concepts, Hacker Techniques, Tools, and
Incident Handling
– Chapter 8- Encryption, Computer Security Fundamentals
– Chapter 7- Cryptography, Fundamentals of Information Systems
Security
• Recommended Readings note: Focus on what was covered in the
class.
References | 32