Module 2 P
Module 2 P
3
Terminology
Cryptography – More practical (engineering) development and study of encryption
systems
Cryptology – More academic (mathematical) study of encryption and their
properties
Cryptanalysis – Analysing and breaking cryptographic systems.
4
Goals of Cryptography
Confidentiality: Only authorised people get to see the data.
Integrity: There is certain assurance that data has not been manipulated or
corrupted.
Authenticity: There is certain assurance we know who sent/created the data.
Non-Repudiation: Certain assurance that the author/sender cannot deny an
action.
(Note: Availability is NOT a goal of crypto)
5
Symmetric Key Encryption
K K
BOB
ALICE
D(C, K) → M
E(M, K) → C
Ciphertext C Ciphertext C Plaintext M
Plaintext M
ROT13
How to attack?
Try n=1,2,…25
Used in news groups
Simple brute force
8
Historic Symmetric Ciphers
Vigenère cipher ABCDEFGHIJKLMNOPQRSTUVWXYZ
How to attack?
Frequency Analysis
9
Historic Symmetric Ciphers
SUBSTITUTION cipher
ABCDEFGHIJKLMNOPQRSTUVWXYZ
https://www.dcode.fr/frequency-analysis 11
Historic Symmetric Ciphers
POLYGRAPHIC SUBSTITUTION cipher
ME ET AT TH HU B
ME ➔ KY ET➔RD etc
C Y B E R
S C A G H
I M L K N
O P Q D T
U V W X Z
12
Transposition Cipher
Create anagram of the message by doing column transposition.
The key dictates the number of columns and the ordering.
Properties MK=C
• A {0} = A
• A {1} = ~A
• A A = {0} C K=M
• AB = B A
• A (B C) = (A B) C
E(M,K) = XOR(M,K)
D(C,K) = XOR(C,K)
16
One-Time Pad
C=1011101010100000111010…1111010101100110001110110101010010
K=1010001001111010001100…0110001101001010111010010010010101
NOT PRACTICAL
17
N-Time Pad?
C=1011101010100000111010…1111010101100110001110110101010010
K=1010001001111010001100…0110001101001010111010010010010101
C1 C2 = (M1 K) (M2 K)
= (M1 M2)
You can deduce locations of spaces, then work out M1 and M2 and K 17
Block vs Stream Ciphers
• Block cipher (most common type)
o Encrypts data in blocks of predetermined size
o Different modes of operation
▪ Electronic Code Book (ECB)
▪ Cipher Block Chaining (CBC)
▪ Counter Mode (CTR) – NIST recommended mode
• Stream cipher
o Encrypts data one bit at a time
o Faster and less resources than block ciphers
o Not as strong as block ciphers
Block Ciphers
Fixed length KEY
M {0,1}n → E(M,K) {0,1}n
KEY KEY
M E C D M
K K K K K K
C1 C2 C3 C4 C5 C6
21
ECB vs CBC
ECB
CBC
23
CTR – Counter Mode
24
Common Ciphers
• Block Ciphers
o DES – Data Encryption Standard (no longer secure – prone to BEAST attack)
Key size: 56 bits
o 3DES (Triple DES: DES used 3 times: encrypt with K1, decrypt with K2, then
encrypt again with K1) key size: 168, 112 or 56 bits.
o AES (Advanced Encryption Standard also known as Rijndael) Key size: 64,
128, 192, 256, 512, 1024 bits)
▪ current standard
• Stream Ciphers
o RC4 – Used in wireless networks
o A5 – Used in mobile networks
25
Diffie-Hellman Key Exchange (DH)
a b
A=ga mod p B=gb mod p
A B BOB
ALICE
K= Ba mod p = gba mod p K= Ab mod p = gab mod p
A,B,p,g 25
DH Colour Analogy
https://en.wikipedia.org/wiki/Diffie–Hellman_key_exchange
a => ga mod p = A EASY
A => a HARD
Example p,g
Colour Analogy
https://www.youtube.com/watch?v=U1kybvKaUeQ
28
Symmetric Key Limitations
How to securely exchange the secret key?
What if there are N people? You need to manage
(N! / 2) number of keys!! Exponentially increases.
B
A
E
D
29
Asymmetric Key Encryption
KENC KDEC
M E C D M
31
Asymmetric Encryption Public Key Cryptography
(RSA)
KApriv KBpriv
KApub BOB
ALICE KBpub
Alice only needs to know Only Bob (with knowledge of private key KBpriv ) can
Bob’s public key KBpub decrypt ciphertext encrypted with KBpub
32
RSA
• Based on factorisation of VERY large primes (~1000 bits)
• Suppose there are large primes p and q
• n = p*q is easy to compute
• Factorising n into p and q is computationally hard
• Kpub (or Kenc) = f(n) => only knowledge of n required
• Kpriv (or Kdec) = g(p,q) => requires knowledge of p and q
33
RSA used as Digital Signature
KApriv KBpriv
KApub BOB
ALICE KBpub
Only Alice can create S Anyone can verify by decryption S using Alice’s
public key KApub
34
Cryptographic Hash
• Digital ”fingerprint” of a piece of data
• One-way function
• Practically collision free
• Variable input, fixed-length output
• MD5, SHA1, SHA256, etc
de9f2c7fd25e1b3afad3e85
M SHA-1
a0bd17d9b100db4b3
36
MD5 Collision
broken in 2004
https://natmchugh.blogspot.com/2014/11/three-way-md5-collision.html
38
Document Signing
39
How can you trust the public key advertised by
Alice? Is it really Alice?
MITM
OK Here is my Certificate,
containing my public key
Alice H(password)
47
Rainbow Table
• Precomputed table of hashes paired with plaintext password
• Used for “reversing” hashes to original plaintext (remember, you cannot
unhash a hash, but you can keep a table of plaintext-hash pairs and do a
reverse lookup.)
http://project-rainbowcrack.com
50
Slow Password Hashing
Salting does NOT reduce computational
difficulty of cracking one password
• BCrypt (Blowfish), Argon2 SCrypt, PBKDF2
• Use “stretching” to hash many times over
• H(H(H(H(……..secret))))))))…..)))))
• Make it difficult to parallelise using GPU
• No efficient way to create rainbow tables
• Example: ~100 guesses/sec with bcrypt (vs 1,000,000,000
guesses/sec with SHA1 on a desktop GPU)
51
Password Attack Tools
• Offline Password Cracking
• John the Ripper
• Hashcat
• Rules for “mangling” passwords
• Uses GPU
• Online Password Cracking
• THC Hydra
• Brutus
• Other
• Cewl – dictionary-builder
• etc
53
Lecture 0x02 - Summary
• We have covered
o Symmetric Encryption
o Asymmetric Encryption
o Hash Functions
o TLS Example
o Cryptanalysis and Attacks
• Cryptography is difficult to get right, both in design and implementation…
DON’T try to write your own cryptography algorithms – use a library that is
tried and true.
• Key length is important, choose a cipher of sufficient length to ensure it
cannot be broken
54