Crypto
Crypto
Cryptography
2
Cryptography
3
Cryptography
4
Cryptography
5
Cryptography
6
History of Cryptography
7
Transposition Cipher Example
Decrypt: ITGIIAJKCILUIUSESNRSMOEYPAJSTM
A U T H O R
I A M J U S
T J O K I N
G S E C U R
I T Y I S S
I M P L E
8
History of Cryptography
● Caesar Cipher
○ Substitution Cipher
○ Used a key (0 to 25) that indicates no. of letters to shift before
replacing
DWWDFN EULGJH DW GDZQ
10
Random Substitution Cipher
● Enigma (WWII)
Vigenere Cipher
14
Vigenere Cipher
IAMJUSTACLOWN
DECRYPTDECRYP
15
Vigenere Cipher The Key
16
Vigenere Cipher
Decrypt this:
Wmrpnwff hto ngh jrgpnl hii ntpzss
Key is :
Bellaso
17
Vigenere Cipher
18
Vigenere Cipher
● Autotext / Autokey
○ Pad the key with the plaintext, rather than repetitions of the key
■ Decryptyouare
■ Still vulnerable to frequency analysis
■ Can exploit statistical properties if fragment of ciphertext
recovered large enough
19
Vigenere Cipher
● Autotext
○ Pad the key with the plaintext, rather than repetitions of the key
■ Decryptyouare
■ Still vulnerable to frequency analysis
■ Can exploit statistical properties if fragment of ciphertext
recovered large enough
● Use a key as long as the text and statistically independent
(Vernam Cipher)
20
Vernam Cipher
21
One-time Pad
22
One-time Pad
● Because the key is truly random, the same ciphertext can map
into any plaintext
● So, one-time pad is invulnerable to cryptanalysis
23
One-time Pad
24
Rotor Machines
25
Rotor Machines
27
Rotor Machines
28
Rotor Machines
29
Rotor Machines
30
Rotor Machines
33
CS431 Computer and Network Security
Symmetric Key
Cryptography
Abhishek Bichhawat 01/02/2023
Keys
2
Keys
● Ciphertext-only attack
○ Access only to the ciphertext
● Known-plaintext attack
○ Knows ciphertext and (partial) plaintext
● Replay attack
○ Replays the encrypted message between the two parties
● Chosen plaintext attack
○ Trick Alice into encrypting Eve’s messages (check ciphertexts)
● Chosen ciphertext attack
○ Trick Bob into decrypting some ciphertexts (use later)
4
Symmetric Key Cryptography
5
Symmetric Key Cryptography
C = EK(P)
P = DK (EK(P))
HI
P P
HI
CS431
C
EK DK
6
Stream Ciphers
8
Stream Ciphers - Key Reuse Attack
10
Stream Ciphers - Bit-flipping Attack
13
Block Ciphers
15
Block Ciphers
16
Block Cipher
17
Feistel Cipher
18
Feistel Cipher
19
Data Encryption Standard
20
Data Encryption Standard
● Function F of DES
● 48 bit subkeys derived from K
● Operates on half block
○ Expanded to 48-bits in E
● Mixed both and divided into 8
● S-boxes substitutes the 6 bits with 4 bits
● P-box rearranges the 32 bits(generates a permutation)
21
Data Encryption Standard
22
Double DES
23
Double DES
24
Double DES - Meet-in-the-middle
25
Meet-in-the-middle attack
26
Triple DES
● Encryption:
Use two (three) keys, encrypt twice and decrypt once:
C = EK1(DK2(EK1(P))
C = EK3(DK2(EK1(P))
● Decryption:
P = DK1(EK2(DK1(C))
P = DK3(EK2(DK1(C))
● Successor to DES
● Open competition in 1997
○ Finalists included Schneier, Anderson, Wagner and others
○ Winners: Joan Daemen & Vincent Rijmen from Belgium
■ Rijndael
○ Substitution permutation network
○ Supports {128, 192, 256}-bit key size and 128-bit blocks
● http://www.moserware.com/2009/09/stick-figure-guide-to-ad
vanced.html
29
CS431 Computer and Network Security
Modes of Operation
● Successor to DES
● Open competition in 1997
○ Finalists included Schneier, Anderson, Wagner and others
○ Winners: Joan Daemen & Vincent Rijmen from Belgium
■ Rijndael
○ Substitution permutation network
○ Supports {128, 192, 256}-bit key size and 128-bit blocks
● http://www.moserware.com/2009/09/stick-figure-guide-to-ad
vanced.html
2
Modes of Operation
3
Block Cipher - Modes of Operation
4
ECB
5
Cipher Block Chaining
6
Cipher Block Chaining - Encryption
7
Cipher Block Chaining - Decryption
Ciphertext : C0C1…Cn; C0 = IV
Compute Pi = DK(Ci) ⊕ Ci-1
8
Challenges with Symmetric Key Cryptography
9
Challenges with Symmetric Key Cryptography
10
Diffie-Hellman-Merkle (DH) Key Exchange
11
Asymmetric Key Cryptography
12
DH Key Exchange
13
One-way Functions and Discrete Log Problems
● One-way function
○ Mathematical equivalent of the earlier examples
○ f(x) = y, given x you can compute f(x) but cannot compute x from y
○ Various functions that are one-way
● Exponentiation modulo prime
○ Choose g (some generator) and p (large prime) (both public)
○ f(x) = gx mod p
● Discrete logarithm problem (discrete log problem)
○ Given g, p, gx mod p for random x, it is computationally hard to find x
14
DH Key Exchange
g and p are
public values
Generate x Generate y
15
DH Key Exchange Why mod p?
g and
g = 5p are
public
P = values
23
Generate x = 4 Generate y = 3
16
DH Key Exchange
17
DH Key Exchange
18
DH Key Exchange
● Steps
○ Agree publicly on g (base) and p (large prime) s.t. g < p - 1
○ Pick secret values x and y
○ Compute gx mod p and gy mod p
○ Send them to the other party, respectively
○ Compute gxy mod p, which is the new shared secret
● Eve can get gx mod p and gy mod p but cannot derive x and y
● Desired Property
○ Alice and Bob should know the shared secret
● What if there is a (wo)man-in-the-middle?
g and p are public values
m is Mallory’s secret
gx mod p gm mod p gy mod p
20
Man-in-the-middle Attack
● Desired Property
○ Alice and Bob should know the shared secret
● What if there is a man-in-the-middle?
○ Alice thinks she is talking to Bob
○ Bob thinks he is talking to Alice
○ But, both are talking to Mallory who
now shares secret keys with both
Alice and Bob (reading all their
messages comfortably)!
○ DH (as is described) is not secure against a MITM
21
Diffie-Hellman Key Exchange
22
CS431 Computer and Network Security
Asymmetric Key
Cryptography
Abhishek Bichhawat 10/02/2023
Challenges with Symmetric Key Cryptography
2
Challenges with Symmetric Key Cryptography
3
Diffie-Hellman-Merkle (DH) Key Exchange
4
DH Key Exchange
5
DH Key Exchange
g and p are
public values
Generate x Generate y
6
Man-in-the-middle Attack
● Desired Property
○ Alice and Bob should know the shared secret
● What if there is a man-in-the-middle?
○ Alice thinks she is talking to Bob
○ Bob thinks he is talking to Alice
○ But, both are talking to Mallory who
now shares secret keys with both
Alice and Bob (reading all their
messages comfortably)!
○ DH (as is described) is not secure against a MITM
7
Public Key Cryptography
● Key generation:
○ Choose two large prime numbers p and q such that p ≠ q,
randomly and independently of each other.
○ Pick integer e coprime with (p-1)(q-1) (i.e., gcd(e, (p-1)(q-1)) = 1)
○ Compute d such that
ed mod (p-1)(q-1) = 1 mod (p-1)(q-1) (or) ed mod (p-1)(q-1) = 1
○ n = pq (Factoring problem)
○ Private key = (n, d)
○ Public key = (n, e)
● Messages are a numbers
11
RSA
● Encryption:
○ E(n, e)(m) = me mod n
● Decryption:
○ D(n, d)(c) = cd mod n
● D(n, d)(E(n, e)(m)) = m (ed mod (p-1)(q-1) = 1)
(ed - 1 = h(p-1) = k(q-1))
12
RSA
● Encryption:
○ E(n, e)(m) = me mod n
● Decryption:
○ D(n, d)(c) = cd mod n
● Let p = 7 and q = 17
○ n = 7 * 17 = 119
○ (p-1)(q-1) = 96
○ e should be coprime with 96 - choose 5
○ Compute d such that ed mod (p-1)(q-1) = 1, i.e., 5*d mod 96 = 1
■ Assume d is 77
13
RSA
● Encryption:
○ E(n, e)(m) = me mod n
● Decryption:
○ D(n, d)(c) = cd mod n
● D(n, d)(E(n, e)(m)) = m (ed - 1 = h(p-1) = k(q-1))
(me mod pq)d mod pq = m mod pq
med mod pq = m mod pq
14
RSA
● Encryption:
○ E(n, e)(m) = me mod n
● Decryption:
○ D(n, d)(c) = cd mod n
● D(n, d)(E(n, e)(m)) = m (ed - 1 = h(p-1) = k(q-1))
(me mod pq)d mod pq = m mod pq
med mod pq = m mod pq
med mod p = m mod p med mod q = m mod q
med - 1 m mod p = m mod p …
m(p - 1)h m mod p = m mod p … Fermat’s little theorem
(m(p - 1))h m mod p = m mod p … ap − 1 ≡ 1 (mod p) 15
RSA
● Encryption:
○ E(n, e)(m) = me mod n
● Decryption:
○ D(n, d)(c) = cd mod n
● D(n, d)(E(n, e)(m)) = m (ed - 1 = h(p-1) = k(q-1))
(me mod pq)d mod pq = m mod pq
med mod pq = m mod pq
med mod p = m mod p med mod q = m mod q
med - 1 m mod p = m mod p …
m(p - 1)h m mod p = m mod p …
(m(p - 1))h m mod p = m mod p … Fermat’s little theorem
1h m mod p = m mod p … ap − 1 ≡ 1 (mod p) 16
Attacks on RSA
● Bleichenbacher attack
○ Encryption with e = 3 can be decrypted easily
● Hastad’s broadcast attack (Coppersmith’s attack)
○ Clear-text message m sent to e or more recipients that share the
same exponent e, but different n (p and q), can be decrypted easily
via the Chinese remainder theorem.
○ c1 = m3 mod n1, c2 = m3 mod n2, c3 = m3 mod n3
○ Chinese remainder theorem gives c’ = m3 mod n1*n2*n3 = m3
(m3 .is smaller than n1*n2*n3)
17
Attacks on RSA
● Bleichenbacher attack
○ Encryption with e = 3 can be decrypted easily
● Hastad’s broadcast attack (Coppersmith’s attack)
● Deterministic encryption algorithm
○ Chosen plaintext attack against the cryptosystem
○ RSA without padding is not semantically secure
18
Attacks on RSA
● Bleichenbacher attack
○ Encryption with e = 3 can be decrypted easily
● Hastad’s broadcast attack (Coppersmith’s attack)
● Deterministic encryption algorithm
○ Chosen plaintext attack against the cryptosystem
● Vulnerable to chosen ciphertext attack
○ Product of two ciphertexts is equal to the encryption of the
product of the respective plaintexts
19
Attacks on RSA
● Bleichenbacher attack
○ Encryption with e = 3 can be decrypted easily
● Hastad’s broadcast attack (Coppersmith’s attack)
● Deterministic encryption algorithm
○ Chosen plaintext attack against the cryptosystem
● Vulnerable to chosen ciphertext attack
○ Product of two ciphertexts is equal to the encryption of the
product of the respective plaintexts
● Timing and power attacks
○ Measure time and power consumption to figure operations
20
Digital Signatures
21
Digital Signatures
22
Digital Signatures
YES!
Certificate Authority
Is this Alice’s
signature? 23
Digital Signatures
D E
M S S,M
24
RSA Signatures
● Existential forgery
○ The attacker manages to forge a signature of (at least) one
message, but not necessarily of his choice
● Selective forgery
○ The attacker manages to forge a signature of (at least) one
message of his choice
● Universal forgery
○ The attacker manages to forge a signature of any message
26
Summary
27
CS431 Computer and Network Security
Message Authentication
Codes
Abhishek Bichhawat 22/02/2023
Message Authentication Codes (MAC)
2
Message Authentication Codes
4
Hash Message Authentication Code (HMAC)
● Hash-based MAC
○ Cryptographic hash
○ Secret key
● Provide authentication using a shared secret instead of using
digital signatures
● Normally, we could have done MAC = H(Key || Message)
but this is susceptible to length extension attacks
● Instead, we do MAC = H(Key || H(Key || Message))
5
HMAC
6
Randomness
8
Pseudorandom number generators (PRNGs)
9
Insecure PRNGs
10
Authenticated Encryption
11
Authenticated Encryption
12
Authenticated Encryption
13
MAC-then-Encrypt
15
Authenticated Encryption
16
Authenticated Encryption with Additional Data
17
CS431 Computer and Network Security
E D
M C M
2
Public Key Infrastructure
● Certificate Authority
○ Issues certificates
■ Endorses the public key of a participant
■ Binds the participant’s name to the public key
● Trust Anchor
○ Entity for which trust is assumed and not derived
○ Trust others’ data through the anchor
○ Identify a certificate authority using a root certificate
○ Stores certificates for all the participants that trust the anchor
○ Establish a chain of trust
■ Verify the sender and intermediate certificate issuers
3
Chain of Trust Charlie
{KC}KA’
Alice
{KA}KCA’
DeeDee
{KD}KA’ Elsa
{KE}KD’
Trust anchor
{KCA}KCA’ Bob
{KB}KCA’
4
Trust Anchors
5
Trust Anchors
6
Trust Anchors
7
Trust Anchors
8
Web-of-Trust
9
Web-of-Trust
10
Web-of-Trust
● Challenges
○ Trust is not transitive
■ Just because Alice trusts Bob and Bob trusts Charlie,
it does not mean that Alice trusts Charlie
○ Trust is not absolute
■ You may trust someone for specific tasks but not other tasks
■ Some security expert:
“I trust my bank with my money but not with my children;
I trust my relatives with my children but not with my money.”
11
Stored Certificates
12
Certificate Revocation
14
Pretty Good Privacy
15
Passwords
16
Passwords
17
Passwords
18
Passwords
19
Passwords
20
Passwords
21
Password Hashes
22
Attacks on Hashes
23
Offline Attacks on Password Hashes
● Add salt
○ Unique random number per user
○ For each user, store: username, salt,
H(password || salt)
○ To verify a password, look up the user’s
salt in the file, compute H(password || salt),
and check it matches the hash in the file
○ Salts are not secret
25
Solutions for Offline Attacks on Password Hashes
● Slow Hash
○ Use a hash function that computes hashes slowly
○ Legitimate users will not notice if it takes 0.0001 seconds or 0.1 seconds
for the server to check a password.
○ However, adversaries need to compute millions of hashes; using a slow
hash can slow the brute-force attack making them impractical
26
Online Attacks on Password Hashes
27
Solution to Online Attacks on Passwords
● Rate-limiting
○ Limit the number of tries within a time limit
○ Lock accounts if a certain number of tries fail
○ May result in DoS
● Impose password requirements
○ Make it harder to guess password
● CAPTCHAs
○ Make it longer for adversary to complete a guess
○ Can remove the possibility of automated checks
● These may not help against untargeted attacks
28
Choosing Passwords
https://xkcd.com/538/ 29