SlideShare uma empresa Scribd logo
1 de 67
Baixar para ler offline
CNIT 141


Cryptography for Computer Networks
4. Block Ciphers
Updated 9-14-2022
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
Codebook Attack
• Suppose you can encrypt arbitrary plaintext,
such as in a Wi-Fi network, but you don't know
the key


• Encrypt every possible plaintext, place in a
codebook


• Look up blocks of ciphertext in the codebook
Codebook Attack
• The codebook size depends on the block size


• Blocksize of 32 bits requires 2^32 entries


• 4 billion, easily achieved


• Blocksize of 64 bits requires 2^64 entries


• Impossible to achieve


• So blocksize should be 64 or larger
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
4a
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
AES in Python 3
from Crypto.Cipher import
AE
S

key = b"0000111122223333
"

cipher = AES.new(key,
AES.MODE_ECB
)

a = b"Hello from AES!!
"

ciphertext =
cipher.encrypt(a
)

print(ciphertext.hex()
)

cipher = AES.new(key,
AES.MODE_ECB
)

d =
cipher.decrypt(ciphertext
)

print(d)
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


• NI makes AES ten times
faster
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 = b"DEAD MEN TELL NODEAD MEN TELL NO"


ciphertext = cipher.encrypt(plaintext)


ciphertext.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
• An alternative to padding


• Prevents padding oracle attacks


• Pad with zeroes


• Swap last two blocks of ciphertext


• Discard extra bytes at the end


• Images on next slides from Wikipedia
Ciphertext Stealing
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
• 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
Nonce Must not be
Reused
• The first block produces the same bitstream if
a nonce and key are re-used
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?
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
Padding Oracle
• Once the orange bytes are known


• Attacker can forge plaintext[32:48] to say
anything
4b

Mais conteúdo relacionado

Mais procurados

パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
Tatsuo Kudo
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi
 

Mais procurados (20)

Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 
CNIT 141: 12. Elliptic Curves
CNIT 141: 12. Elliptic CurvesCNIT 141: 12. Elliptic Curves
CNIT 141: 12. Elliptic Curves
 
猫でもわかるかもしれない SQLインジェクション
猫でもわかるかもしれない SQLインジェクション猫でもわかるかもしれない SQLインジェクション
猫でもわかるかもしれない SQLインジェクション
 
レイヤードアーキテクチャを意識したPHPアプリケーションの構築
レイヤードアーキテクチャを意識したPHPアプリケーションの構築レイヤードアーキテクチャを意識したPHPアプリケーションの構築
レイヤードアーキテクチャを意識したPHPアプリケーションの構築
 
Advanced encryption standard (aes)
Advanced encryption standard (aes)Advanced encryption standard (aes)
Advanced encryption standard (aes)
 
Difference between authentication and authorization in asp.net
Difference between authentication and authorization in asp.netDifference between authentication and authorization in asp.net
Difference between authentication and authorization in asp.net
 
あなたのScalaを爆速にする7つの方法(日本語版)
あなたのScalaを爆速にする7つの方法(日本語版)あなたのScalaを爆速にする7つの方法(日本語版)
あなたのScalaを爆速にする7つの方法(日本語版)
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 
Thick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptx
 
Transposition Cipher
Transposition CipherTransposition Cipher
Transposition Cipher
 
Cipher techniques
Cipher techniquesCipher techniques
Cipher techniques
 
One-Time Pad Encryption
One-Time Pad EncryptionOne-Time Pad Encryption
One-Time Pad Encryption
 
DES (Data Encryption Standard) pressentation
DES (Data Encryption Standard) pressentationDES (Data Encryption Standard) pressentation
DES (Data Encryption Standard) pressentation
 
Topic20 The RC4 Algorithm.pptx
Topic20 The RC4 Algorithm.pptxTopic20 The RC4 Algorithm.pptx
Topic20 The RC4 Algorithm.pptx
 
Rust製の全文検索エンジンライブラリ(tantivy bayard)を試してみた
Rust製の全文検索エンジンライブラリ(tantivy bayard)を試してみたRust製の全文検索エンジンライブラリ(tantivy bayard)を試してみた
Rust製の全文検索エンジンライブラリ(tantivy bayard)を試してみた
 
5 Important Secure Coding Practices
5 Important Secure Coding Practices5 Important Secure Coding Practices
5 Important Secure Coding Practices
 
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
 
Advanced Encryption System & Block Cipher Modes of Operations
Advanced Encryption System & Block Cipher Modes of OperationsAdvanced Encryption System & Block Cipher Modes of Operations
Advanced Encryption System & Block Cipher Modes of Operations
 
Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 

Semelhante a 4. Block Ciphers

CH02-CompSec4e.pptx
CH02-CompSec4e.pptxCH02-CompSec4e.pptx
CH02-CompSec4e.pptx
ams1ams11
 

Semelhante a 4. Block Ciphers (20)

CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
 
Overview on Cryptography and Network Security
Overview on Cryptography and Network SecurityOverview on Cryptography and Network Security
Overview on Cryptography and Network Security
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
AES Presentation.pptx
AES Presentation.pptxAES Presentation.pptx
AES Presentation.pptx
 
symmetric key encryption algorithms
 symmetric key encryption algorithms symmetric key encryption algorithms
symmetric key encryption algorithms
 
Cryptography-101
Cryptography-101Cryptography-101
Cryptography-101
 
Cryptography - 101
Cryptography - 101Cryptography - 101
Cryptography - 101
 
Block ciphers & public key cryptography
Block ciphers & public key cryptographyBlock ciphers & public key cryptography
Block ciphers & public key cryptography
 
8. Authenticated Encryption
8. Authenticated Encryption8. Authenticated Encryption
8. Authenticated Encryption
 
Cryptography.ppt
Cryptography.pptCryptography.ppt
Cryptography.ppt
 
section-8.ppt
section-8.pptsection-8.ppt
section-8.ppt
 
Cryptography and steganography lesson and discription.pptx
Cryptography and steganography lesson and discription.pptxCryptography and steganography lesson and discription.pptx
Cryptography and steganography lesson and discription.pptx
 
CH02-CompSec4e.pptx
CH02-CompSec4e.pptxCH02-CompSec4e.pptx
CH02-CompSec4e.pptx
 
Ch08-CryptoConcepts.ppt
Ch08-CryptoConcepts.pptCh08-CryptoConcepts.ppt
Ch08-CryptoConcepts.ppt
 
Cryptography and network security Nit701
Cryptography and network security Nit701Cryptography and network security Nit701
Cryptography and network security Nit701
 
Cryptography & Steganography
Cryptography & SteganographyCryptography & Steganography
Cryptography & Steganography
 
Symmetric encryption
Symmetric encryptionSymmetric encryption
Symmetric encryption
 

Mais de Sam Bowne

Mais de Sam Bowne (20)

Cyberwar
CyberwarCyberwar
Cyberwar
 
3: DNS vulnerabilities
3: DNS vulnerabilities 3: DNS vulnerabilities
3: DNS vulnerabilities
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
 
4 Mapping the Application
4 Mapping the Application4 Mapping the Application
4 Mapping the Application
 
3. Attacking iOS Applications (Part 2)
 3. Attacking iOS Applications (Part 2) 3. Attacking iOS Applications (Part 2)
3. Attacking iOS Applications (Part 2)
 
12 Elliptic Curves
12 Elliptic Curves12 Elliptic Curves
12 Elliptic Curves
 
11. Diffie-Hellman
11. Diffie-Hellman11. Diffie-Hellman
11. Diffie-Hellman
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1
 
9 Writing Secure Android Applications
9 Writing Secure Android Applications9 Writing Secure Android Applications
9 Writing Secure Android Applications
 
12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)
 
10 RSA
10 RSA10 RSA
10 RSA
 
12 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 312 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 3
 
9. Hard Problems
9. Hard Problems9. Hard Problems
9. Hard Problems
 
8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)
 
11 Analysis Methodology
11 Analysis Methodology11 Analysis Methodology
11 Analysis Methodology
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)
 
7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)
 
5. Stream Ciphers
5. Stream Ciphers5. Stream Ciphers
5. Stream Ciphers
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection
 
6 Analyzing Android Applications (Part 2)
6 Analyzing Android Applications (Part 2)6 Analyzing Android Applications (Part 2)
6 Analyzing Android Applications (Part 2)
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 

4. Block Ciphers

  • 1. CNIT 141 Cryptography for Computer Networks 4. Block Ciphers Updated 9-14-2022
  • 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
  • 8. Codebook Attack • Suppose you can encrypt arbitrary plaintext, such as in a Wi-Fi network, but you don't know the key • Encrypt every possible plaintext, place in a codebook • Look up blocks of ciphertext in the codebook
  • 9. Codebook Attack • The codebook size depends on the block size • Blocksize of 32 bits requires 2^32 entries • 4 billion, easily achieved • Blocksize of 64 bits requires 2^64 entries • Impossible to achieve • So blocksize should be 64 or larger
  • 10. How to Construct Block Ciphers
  • 12. 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)))
  • 13. 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
  • 14. The Slide Attack and Round Keys • Consider a block cipher with three rounds, and with all the round keys identical
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. 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. 4a
  • 21. 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
  • 23.
  • 24.
  • 25.
  • 26. AES in Python 3 from Crypto.Cipher import AE S key = b"0000111122223333 " cipher = AES.new(key, AES.MODE_ECB ) a = b"Hello from AES!! " ciphertext = cipher.encrypt(a ) print(ciphertext.hex() ) cipher = AES.new(key, AES.MODE_ECB ) d = cipher.decrypt(ciphertext ) print(d)
  • 28. 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
  • 30. 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
  • 31. Native Instructions • AES-NI • Processor provides dedicated assembly instructions that perform AES • Plaintext in register xmm0 • Round keys in xmm5 to xmm15 • NI makes AES ten times faster
  • 32. 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
  • 34. Electronic Code Book (ECB) • Each plaintext block is encrypted the same way • Identical plaintext blocks produce identical ciphertext blocks
  • 35. AES-ECB • If plaintext repeats, so does ciphertext plaintext = b"DEAD MEN TELL NODEAD MEN TELL NO" ciphertext = cipher.encrypt(plaintext) ciphertext.hex()
  • 38. ECB Mode • Encrypted image retains large blocks of solid color
  • 39. 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
  • 40. CBC Mode • Encrypted image shows no patterns
  • 41. 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
  • 42. 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
  • 43. Message Length • AES requires 16-byte blocks of plaintext • Messages must be padded to make them long enough
  • 44. PKCS#7 Padding • The last byte of the plaintext is always between 'x00' and '10' • Discard that many bytes to get original plaintext
  • 45. 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
  • 46. Ciphertext Stealing • An alternative to padding • Prevents padding oracle attacks • Pad with zeroes • Swap last two blocks of ciphertext • Discard extra bytes at the end • Images on next slides from Wikipedia
  • 48. 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. 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. Nonce Must not be Reused • The first block produces the same bitstream if a nonce and key are re-used
  • 52. 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
  • 53. Parallelizing • CTR is faster than any other mode • Stream can be computed in advance, and in parallel • Before even knowing the plaintext
  • 54. How Things Can Go Wrong
  • 56. Meet-in-the-Middle Attacks • 3DES does three rounds of DES • Why not 2DES?
  • 57. Attacking 2DES • Two 56-bit keys, total 112 bits • End-to-end brute force would take 2^112 calculations
  • 58. Attacking 2DES • Attacker inputs known P and gets C • Wants to find K1, K2
  • 59. 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
  • 60. 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
  • 63. Padding Oracle • Change the last byte in second block • This changes the 17 bytes shown in red
  • 64. 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
  • 65. Padding Oracle • Continue, 256 guesses finds the next orange byte
  • 66. Padding Oracle • Once the orange bytes are known • Attacker can forge plaintext[32:48] to say anything
  • 67. 4b