SlideShare a Scribd company logo
CNIT 141
Cryptography for Computer Networks
3. Cryptographic Security
Topics
• What is a Block Cipher
• How to Construct Block Ciphers
• The Advanced Encryption Standard (AES)
• Implementing AES
• Modes of Operation
• How Things Can Go Wrong
History
• US: Federal standard: DES (1979 - 2005)
• KGB: GOST 28147-89 (1990 - present)
• in 2000, NIST selected AES, developed in
Belgium
• They are all block ciphers
What is a Block Cipher
Block Cipher
E Encryption algorithm
K Key
P Plaintext block
C Ciphertext block
C = E(K, P)
D Decryption algorithm
P = D(K, C)
Security Goals
• Block cipher should be a pseudorandom
permutation (PRP)
• Attacker can't compute output without the
key
• Attackers should be unable to find patterns in
the inputs/output values
• The ciphertext should appear random
Block Size
• DES: 64 bit
• AES: 128 bit
• Chosen to fit into registers of CPUs for speed
• Block sizes below 64 are vulnerable to a
codebook attack
• Encrypt every possible plaintext, place in a
codebook
• Look up blocks of ciphertext in the codebook
How to Construct Block
Ciphers
Two Techniques
• Substitution-permutation (AES)
• Feistel (DES)
Rounds
• R is a round --in practice, a simple
transformation
• A block cipher with three rounds:
• C = R3(R2(R1(P)))
• iR is the inverse round function
• I = iR1(iR2(iR3(C)))
Round Key
• The round functions R1 R2 R3 use the same
algorithm
• But a different round key
• Round keys are K1, K2, K3, ... derived from
the main key K using a key schedule
The Slide Attack and Round Keys
• Consider a block cipher with three rounds, and
with all the round keys identical
The Slide Attack and Round Keys
• If an attacker can find plaintext blocks with 

P2 = R(P1)
• That implies C2 = R(C1)
• Which often helps to deduce the key
The Slide Attack and Round Keys
• The solution is to make all round keys different
• Note: the key schedule in AES is not one-way
• Attacker can compute K from any Ki
• This exposes it to side-channel attacks, like
measuring electromagnetic emanations
Substitution-Permutation
Networks
• Confusion means that each ciphertext bit
depends on several key bits
• Provided by substitution using S-boxes
• Diffusion means that changing a bit of
plaintext changes many bits in the ciphertext
• Provided by permutation
Feistel Schemes
• Only half the plaintext is
encrypted in each round
• By the F substitution-
permutation function
• Halves are swapped in each
round
• DES uses 16 Feistel rounds
CNIT 141: 4. Block Ciphers
The Advanced Encryption
Standard (AES)
DES
• DES had a 56-bit key
• Cracked by brute force in 1997
• 3DES was a stronger version
• Still considered strong, but slower than AES
• AES approved as the NIST standard in 2000
• Link Ch 4a
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
AES in Python
from Crypto.Cipher import AES
plaintext = "DEAD MEN TELL NO"
key = "AAAABBBBCCCCDDDD"
cipher = AES.new(key)
ciphertext = cipher.encrypt(plaintext)
print ciphertext
??k٨?U?`???
print ciphertext.encode("hex")
8fc96bdbb85c8155896088b4ca201b7e
print cipher.decrypt(ciphertext)
DEAD MEN TELL NO
Implementing AES
Improving Efficiency
• Implementing each step
as a separate function
works, but it's slow
• Combining them with
"table-based
implementations" and
"native instructions" is
faster
• Using XORs and table
lookups
OpenSSL Code is
Table-Based
Timing Attacks
• The time required for encryption depends on
the key
• Measuring timing leaks information about the
key
• This is a problem with any efficient coding
• You could use slow code that wastes time
• A better solution relies on hardware
Native Instructions
• AES-NI
• Processor provides
dedicated assembly
instructions that perform
AES
• Plaintext in register
xmm0
• Round keys in xmm5 to
xmm15
• Ten times faster with NI
Is AES Secure?
• AES implements many good design principles
• Proven to resist many classes of
cryptoanalytic attacks
• But no one can foresee all possible future
attacks
• So far, no significant weakness in AES-128
has been found
Modes of Operation
Electronic Code Book
(ECB)
• Each plaintext block is
encrypted the same
way
• Identical plaintext
blocks produce identical
ciphertext blocks
AES-ECB
• If plaintext repeats, so does ciphertext
plaintext = "DEAD MEN TELL NODEAD MEN TELL NO"
ciphertext = cipher.encrypt(plaintext)
print ciphertext.encode("hex")
Staples Android App
• Link Ch 4b
Encrypted Password
Repeats
ECB Mode
• Encrypted image retains large blocks of solid
color
Cipher Block Chaining (CBC)
• Uses a key and an initialization vector (IV)
• Output of one block is the IV for the next block
• IV is not secret; sent in the clear
CBC Mode
• Encrypted image shows no patterns
Choosing IV
• If the same IV is used every time
• The first block is always encrypted the same
way
• Messages with the same first plaintext block
will have identical first ciphertext blocks
Parallelism
• ECB can be computed in parallel
• Each block is independent
• CBC requires serial processing
• Output of each block used to encrypt the
next block
Message Length
• AES requires 16-byte blocks of plaintext
• Messages must be padded to make them long
enough
PKCS#7 Padding
• The last byte of the plaintext is always
between 'x00' and '10'
• Discard that many bytes to get original
plaintext
Padding Oracle Attack
• Almost everything uses PKCS#7 padding
• But if the system displays a "Padding Error"
message the whole system shatters like glass
• That message is sufficient side-channel
information to allow an attacker to forge
messages without the key
Ciphertext Stealing
• Pad with zeroes
• Swap last two blocks of ciphertext
• Discard extra bytes at the end
• Images on next slides from Wikipedia
Ciphertext Stealing
Encryption
Ciphertext Stealing
Decryption
Security of Ciphertext
Stealing
• No major problems
• Inelegant and difficult to get right
• NIST SP 800-38A specifies three different
ways to implement it
• Rarely used
Counter (CTR) Mode
C1
K E
C2
K E
C2
K E
Counter (CTR) Mode
• Produces a pseudorandom byte stream
• XOR with plaintext to encrypt
Nonce
• Nonce (N) used to produce C1, C2, C3, etc.
• C1 = N ^ 1
• C2 = N ^ 2
• C3 = N ^ 3
• etc.
• Use a different N for each message
• N is not secret, sent in the clear
No Padding
• CTR mode uses a block cipher to produce a
pseudorandom byte stream
• Creates a stream cipher
• Message can have any length
• No padding required
Parallelizing
• CTR is faster than any other mode
• Stream can be computed in advance, and in
parallel
• Before even knowing the plaintext
How Things Can Go
Wrong
Two Attacks
• Meet-in-the-middle
• Padding oracle
Meet-in-the-Middle Attacks
• 3DES does three rounds of DES
• Why not 2DES?
University of Houston
Attacking 2DES
• Two 56-bit keys, total 112 bits
• End-to-end brute force would take 2^112
calculations
Attacking 2DES
• Attacker inputs known P and gets C
• Wants to find K1, K2
Attacking 2DES
• Make a list of E(K1, P) for all 2^56 values of K1
• Make a list of D(K2, P) for all 2^56 values of K2
• Find the item with the same values in each list
• This finds K1 and K2 with 2^57 computations
Meet-in-the-Middle Attack
on 3DES
• One table has 2^56 entries
• The other one has 2^112 entries
• 3DES has 112 bits of security
Padding Oracle
Padding Oracle
Padding Oracle
• Change the last byte in second block
• This changes the 17 bytes shown in red
Padding Oracle
• Try all 256 values of last byte in second block
• One of them has valid padding of 'x01'
• This determines the orange byte
Padding Oracle
• Continue, 256 guesses finds the next orange
byte
CNIT 141: 4. Block Ciphers

More Related Content

PDF
CNIT 141 13. TLS
PDF
CNIT 141 7. Keyed Hashing
PDF
CNIT 1417. Keyed Hashing
PDF
CNIT 141: 2. Randomness
PDF
CNIT 141: 6. Hash Functions
PDF
CNIT 141: 6. Hash Functions
PDF
PHDays 2018 Threat Hunting Hands-On Lab
PDF
CNIT 141: 5. Stream Ciphers
CNIT 141 13. TLS
CNIT 141 7. Keyed Hashing
CNIT 1417. Keyed Hashing
CNIT 141: 2. Randomness
CNIT 141: 6. Hash Functions
CNIT 141: 6. Hash Functions
PHDays 2018 Threat Hunting Hands-On Lab
CNIT 141: 5. Stream Ciphers

What's hot (20)

PDF
Practical Malware Analysis: Ch 11: Malware Behavior
PDF
Cyber Threat Intelligence - It's not just about the feeds
PDF
Lior rotkovitch ASM WAF unified learning – building policy with asm v12
PDF
CNIT 126 6: Recognizing C Code Constructs in Assembly
PDF
4. The Advanced Encryption Standard (AES)
PDF
CNIT 127: Ch 18: Source Code Auditing
PDF
CNIT 141: 9. Hard Problems
PPTX
Ip security
PPTX
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
PDF
Emily Stamm - Post-Quantum Cryptography
PDF
Thick Client Penetration Testing.pdf
PDF
Oscp preparation
PDF
11. Diffie-Hellman
PDF
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
PPTX
Block Cipher
PPTX
Catch Me If You Can: PowerShell Red vs Blue
PDF
Post Quantum Cryptography: Technical Overview
PPTX
PDF
CNIT 127 Ch 3: Shellcode
PPTX
Topic20 The RC4 Algorithm.pptx
Practical Malware Analysis: Ch 11: Malware Behavior
Cyber Threat Intelligence - It's not just about the feeds
Lior rotkovitch ASM WAF unified learning – building policy with asm v12
CNIT 126 6: Recognizing C Code Constructs in Assembly
4. The Advanced Encryption Standard (AES)
CNIT 127: Ch 18: Source Code Auditing
CNIT 141: 9. Hard Problems
Ip security
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
Emily Stamm - Post-Quantum Cryptography
Thick Client Penetration Testing.pdf
Oscp preparation
11. Diffie-Hellman
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
Block Cipher
Catch Me If You Can: PowerShell Red vs Blue
Post Quantum Cryptography: Technical Overview
CNIT 127 Ch 3: Shellcode
Topic20 The RC4 Algorithm.pptx
Ad

Similar to CNIT 141: 4. Block Ciphers (20)

PDF
CNIT 141: 4. Block Ciphers
PDF
4. Block Ciphers
PDF
CNIT 141: 4. Block Ciphers
PPT
Cryptography.ppt
PPTX
Symmetric encryption
PPT
DES-lecture (1).ppt
PPT
Ch08-CryptoConcepts.ppt
PPTX
Cryptography-101
PPTX
PPT
PPTX
Advanced encryption standard (aes)
PPTX
Cryptography and network security Nit701
PPTX
619cb9e9-b273-4ed7-9181-937ba84734ab-.pptx
PPT
Block Ciphers Modes of Operation
PPTX
Cryptography & Steganography
PDF
CNIT 125 Ch 4. Security Engineering (Part 2)
PPT
ch03.pptvxcvxcvxcvxcvxcvxcvcxvdsgedgeeee
PPTX
Encryption techniqudgfhgvj,hbkes (2).pptx
PPTX
Software EngineeringModule 2 (Complete).pptx
CNIT 141: 4. Block Ciphers
4. Block Ciphers
CNIT 141: 4. Block Ciphers
Cryptography.ppt
Symmetric encryption
DES-lecture (1).ppt
Ch08-CryptoConcepts.ppt
Cryptography-101
Advanced encryption standard (aes)
Cryptography and network security Nit701
619cb9e9-b273-4ed7-9181-937ba84734ab-.pptx
Block Ciphers Modes of Operation
Cryptography & Steganography
CNIT 125 Ch 4. Security Engineering (Part 2)
ch03.pptvxcvxcvxcvxcvxcvxcvcxvdsgedgeeee
Encryption techniqudgfhgvj,hbkes (2).pptx
Software EngineeringModule 2 (Complete).pptx
Ad

More from Sam Bowne (20)

PDF
Introduction to the Class & CISSP Certification
PDF
Cyberwar
PDF
3: DNS vulnerabilities
PDF
8. Software Development Security
PDF
4 Mapping the Application
PDF
3. Attacking iOS Applications (Part 2)
PDF
12 Elliptic Curves
PDF
2a Analyzing iOS Apps Part 1
PDF
9 Writing Secure Android Applications
PDF
12 Investigating Windows Systems (Part 2 of 3)
PDF
10 RSA
PDF
12 Investigating Windows Systems (Part 1 of 3
PDF
9. Hard Problems
PDF
8 Android Implementation Issues (Part 1)
PDF
11 Analysis Methodology
PDF
8. Authenticated Encryption
PDF
7. Attacking Android Applications (Part 2)
PDF
7. Attacking Android Applications (Part 1)
PDF
5. Stream Ciphers
PDF
6 Scope & 7 Live Data Collection
Introduction to the Class & CISSP Certification
Cyberwar
3: DNS vulnerabilities
8. Software Development Security
4 Mapping the Application
3. Attacking iOS Applications (Part 2)
12 Elliptic Curves
2a Analyzing iOS Apps Part 1
9 Writing Secure Android Applications
12 Investigating Windows Systems (Part 2 of 3)
10 RSA
12 Investigating Windows Systems (Part 1 of 3
9. Hard Problems
8 Android Implementation Issues (Part 1)
11 Analysis Methodology
8. Authenticated Encryption
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 1)
5. Stream Ciphers
6 Scope & 7 Live Data Collection

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Pre independence Education in Inndia.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Insiders guide to clinical Medicine.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Module 4: Burden of Disease Tutorial Slides S2 2025
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
O5-L3 Freight Transport Ops (International) V1.pdf
Week 4 Term 3 Study Techniques revisited.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial disease of the cardiovascular and lymphatic systems
O7-L3 Supply Chain Operations - ICLT Program
Supply Chain Operations Speaking Notes -ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pre independence Education in Inndia.pdf
Classroom Observation Tools for Teachers
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cell Types and Its function , kingdom of life
Basic Mud Logging Guide for educational purpose
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx

CNIT 141: 4. Block Ciphers

  • 1. CNIT 141 Cryptography for Computer Networks 3. Cryptographic Security
  • 2. Topics • What is a Block Cipher • How to Construct Block Ciphers • The Advanced Encryption Standard (AES) • Implementing AES • Modes of Operation • How Things Can Go Wrong
  • 3. History • US: Federal standard: DES (1979 - 2005) • KGB: GOST 28147-89 (1990 - present) • in 2000, NIST selected AES, developed in Belgium • They are all block ciphers
  • 4. What is a Block Cipher
  • 5. Block Cipher E Encryption algorithm K Key P Plaintext block C Ciphertext block C = E(K, P) D Decryption algorithm P = D(K, C)
  • 6. Security Goals • Block cipher should be a pseudorandom permutation (PRP) • Attacker can't compute output without the key • Attackers should be unable to find patterns in the inputs/output values • The ciphertext should appear random
  • 7. Block Size • DES: 64 bit • AES: 128 bit • Chosen to fit into registers of CPUs for speed • Block sizes below 64 are vulnerable to a codebook attack • Encrypt every possible plaintext, place in a codebook • Look up blocks of ciphertext in the codebook
  • 8. How to Construct Block Ciphers
  • 10. Rounds • R is a round --in practice, a simple transformation • A block cipher with three rounds: • C = R3(R2(R1(P))) • iR is the inverse round function • I = iR1(iR2(iR3(C)))
  • 11. Round Key • The round functions R1 R2 R3 use the same algorithm • But a different round key • Round keys are K1, K2, K3, ... derived from the main key K using a key schedule
  • 12. The Slide Attack and Round Keys • Consider a block cipher with three rounds, and with all the round keys identical
  • 13. The Slide Attack and Round Keys • If an attacker can find plaintext blocks with 
 P2 = R(P1) • That implies C2 = R(C1) • Which often helps to deduce the key
  • 14. The Slide Attack and Round Keys • The solution is to make all round keys different • Note: the key schedule in AES is not one-way • Attacker can compute K from any Ki • This exposes it to side-channel attacks, like measuring electromagnetic emanations
  • 15. Substitution-Permutation Networks • Confusion means that each ciphertext bit depends on several key bits • Provided by substitution using S-boxes • Diffusion means that changing a bit of plaintext changes many bits in the ciphertext • Provided by permutation
  • 16. Feistel Schemes • Only half the plaintext is encrypted in each round • By the F substitution- permutation function • Halves are swapped in each round • DES uses 16 Feistel rounds
  • 19. DES • DES had a 56-bit key • Cracked by brute force in 1997 • 3DES was a stronger version • Still considered strong, but slower than AES • AES approved as the NIST standard in 2000
  • 24. AES in Python from Crypto.Cipher import AES plaintext = "DEAD MEN TELL NO" key = "AAAABBBBCCCCDDDD" cipher = AES.new(key) ciphertext = cipher.encrypt(plaintext) print ciphertext ??k٨?U?`??? print ciphertext.encode("hex") 8fc96bdbb85c8155896088b4ca201b7e print cipher.decrypt(ciphertext) DEAD MEN TELL NO
  • 26. Improving Efficiency • Implementing each step as a separate function works, but it's slow • Combining them with "table-based implementations" and "native instructions" is faster • Using XORs and table lookups
  • 28. Timing Attacks • The time required for encryption depends on the key • Measuring timing leaks information about the key • This is a problem with any efficient coding • You could use slow code that wastes time • A better solution relies on hardware
  • 29. Native Instructions • AES-NI • Processor provides dedicated assembly instructions that perform AES • Plaintext in register xmm0 • Round keys in xmm5 to xmm15 • Ten times faster with NI
  • 30. Is AES Secure? • AES implements many good design principles • Proven to resist many classes of cryptoanalytic attacks • But no one can foresee all possible future attacks • So far, no significant weakness in AES-128 has been found
  • 32. Electronic Code Book (ECB) • Each plaintext block is encrypted the same way • Identical plaintext blocks produce identical ciphertext blocks
  • 33. AES-ECB • If plaintext repeats, so does ciphertext plaintext = "DEAD MEN TELL NODEAD MEN TELL NO" ciphertext = cipher.encrypt(plaintext) print ciphertext.encode("hex")
  • 36. ECB Mode • Encrypted image retains large blocks of solid color
  • 37. Cipher Block Chaining (CBC) • Uses a key and an initialization vector (IV) • Output of one block is the IV for the next block • IV is not secret; sent in the clear
  • 38. CBC Mode • Encrypted image shows no patterns
  • 39. Choosing IV • If the same IV is used every time • The first block is always encrypted the same way • Messages with the same first plaintext block will have identical first ciphertext blocks
  • 40. Parallelism • ECB can be computed in parallel • Each block is independent • CBC requires serial processing • Output of each block used to encrypt the next block
  • 41. Message Length • AES requires 16-byte blocks of plaintext • Messages must be padded to make them long enough
  • 42. PKCS#7 Padding • The last byte of the plaintext is always between 'x00' and '10' • Discard that many bytes to get original plaintext
  • 43. Padding Oracle Attack • Almost everything uses PKCS#7 padding • But if the system displays a "Padding Error" message the whole system shatters like glass • That message is sufficient side-channel information to allow an attacker to forge messages without the key
  • 44. Ciphertext Stealing • Pad with zeroes • Swap last two blocks of ciphertext • Discard extra bytes at the end • Images on next slides from Wikipedia
  • 47. Security of Ciphertext Stealing • No major problems • Inelegant and difficult to get right • NIST SP 800-38A specifies three different ways to implement it • Rarely used
  • 49. C1 K E C2 K E C2 K E Counter (CTR) Mode • Produces a pseudorandom byte stream • XOR with plaintext to encrypt
  • 50. Nonce • Nonce (N) used to produce C1, C2, C3, etc. • C1 = N ^ 1 • C2 = N ^ 2 • C3 = N ^ 3 • etc. • Use a different N for each message • N is not secret, sent in the clear
  • 51. No Padding • CTR mode uses a block cipher to produce a pseudorandom byte stream • Creates a stream cipher • Message can have any length • No padding required
  • 52. Parallelizing • CTR is faster than any other mode • Stream can be computed in advance, and in parallel • Before even knowing the plaintext
  • 53. How Things Can Go Wrong
  • 55. Meet-in-the-Middle Attacks • 3DES does three rounds of DES • Why not 2DES? University of Houston
  • 56. Attacking 2DES • Two 56-bit keys, total 112 bits • End-to-end brute force would take 2^112 calculations
  • 57. Attacking 2DES • Attacker inputs known P and gets C • Wants to find K1, K2
  • 58. Attacking 2DES • Make a list of E(K1, P) for all 2^56 values of K1 • Make a list of D(K2, P) for all 2^56 values of K2 • Find the item with the same values in each list • This finds K1 and K2 with 2^57 computations
  • 59. Meet-in-the-Middle Attack on 3DES • One table has 2^56 entries • The other one has 2^112 entries • 3DES has 112 bits of security
  • 62. Padding Oracle • Change the last byte in second block • This changes the 17 bytes shown in red
  • 63. Padding Oracle • Try all 256 values of last byte in second block • One of them has valid padding of 'x01' • This determines the orange byte
  • 64. Padding Oracle • Continue, 256 guesses finds the next orange byte