Cryptography Final Exam Review - English Version
Part 1: Symmetric Tools
1. PRG -> Stream Cipher
1.1 Pseudo-Random Generator (PRG)
Exam Focus: Concept Explanation - What is PRG?
A pseudo-random generator (PRG) is a deterministic algorithm that expands a short random seed into a long sequence, such that this sequence is computationally indistinguishable from a truly random sequence. PRG is a fundamental building block in cryptography that solves the core problem of "how to generate a large amount of seemingly random data using a small amount of randomness."
Formal Definition: Let be a function where (expansion requirement). is a secure PRG if for all polynomial-time distinguishers , there exists a negligible function such that: where is a random seed and is a truly random string.
Key Understanding:
- Input: a short random seed (e.g., 128 bits), which is the only source of randomness
- Output: a long pseudo-random sequence (e.g., 1GB), much longer than the input
- Security: the output sequence is computationally indistinguishable from a truly random sequence, meaning no polynomial-time algorithm can distinguish from a truly random string
- Deterministic: the same seed always produces the same output sequence
Why Do We Need PRG? In cryptography, we often need large amounts of random numbers (e.g., encryption key streams), but generating truly random numbers is expensive. PRG allows us to generate large amounts of "seemingly random" data using a small amount of true randomness (the seed), greatly reducing the randomness requirement.
Practical Applications:
- Generating encryption key streams (for stream ciphers)
- Generating session keys
- Generating initialization vectors (IV)
- As building blocks for other cryptographic primitives
Exam Focus: PRG Security Definition A distinguisher is an algorithm that attempts to distinguish PRG output from a truly random string. If outputs 1 to indicate it thinks the input is random, then:
- is the probability that the distinguisher thinks the PRG output is random
- is the probability that the distinguisher thinks a truly random string is random
- If the difference between these probabilities is negligible, it means the PRG output is indistinguishable from a truly random string
1.2 Stream Cipher
Exam Focus: Concept Explanation - How Stream Cipher Works
A stream cipher is a symmetric encryption scheme that uses a key stream generated by a PRG to perform bitwise XOR with the plaintext. The core idea of stream ciphers is: if the key stream is truly random, then the ciphertext is a "one-time pad," which is theoretically unbreakable encryption.
Detailed How It Works:
- Key Generation: Sender and receiver share a key (e.g., 128 bits)
- Initialization Vector: Choose a random or pseudo-random (initialization vector). need not be secret, but should be different for each encryption
- Key Stream Generation: Use PRG to generate key stream , with length equal to plaintext length
- Encryption: Ciphertext is obtained by bitwise XOR:
Mathematical Representation: For the -th bit: where is the -th bit of plaintext, is the -th bit of key stream, and is the -th bit of ciphertext.
Decryption Process: Due to the property of XOR (), decryption simply requires XOR again:
Calculation Problem: Stream Cipher Encryption/Decryption Example: Given plaintext and key stream , calculate ciphertext and decrypted plaintext. Solution:
- Encryption:
- Decryption: ✓
Security Requirements (Exam Focus):
- Key Stream Length: Key stream must be the same length as plaintext, neither shorter nor longer
- Non-Reusability: The same combination of key and IV must never be reused! If reused, an attacker can compute: This reveals the XOR of two plaintexts, leaking information
- PRG Security: The underlying PRG must be cryptographically secure, otherwise the key stream may be predictable
- IV Uniqueness: Each encryption must use a different IV to ensure different key streams
Scheme Design Problem: Why Do We Need IV? Without IV, the same plaintext always produces the same ciphertext, which is insecure. The role of IV is to ensure that even with the same key, each encryption produces a different key stream, thus producing different ciphertexts. IV can be a counter, random number, or timestamp, but must ensure uniqueness.
Advantages:
- Fast encryption (only requires XOR operation)
- Simple implementation (easy to implement in both hardware and software)
- Suitable for real-time communication (can generate key stream while encrypting)
- Errors do not propagate (one bit error only affects one bit)
Disadvantages:
- Key stream cannot be reused (must ensure IV uniqueness)
- Requires synchronized IV (sender and receiver must use the same IV)
- Complex key management (need to securely share and store keys)
Proof Problem: CPA Security of Stream Cipher If PRG is secure, then the stream cipher based on is semantically secure under CPA. Proof Idea:
- Assume there exists an attacker that can break the stream cipher with non-negligible advantage
- Construct a distinguisher to distinguish PRG output from random strings
- If succeeds, then can also succeed in distinguishing, contradicting PRG security
- Therefore, the stream cipher is CPA secure
2. PRF -> Block Cipher
2.1 Pseudo-Random Function (PRF)
Exam Focus: Concept Explanation - Difference Between PRF and PRG
A pseudo-random function (PRF) is a deterministic function that takes a key and an input, producing an output, such that without knowing the key, it is impossible to distinguish this function from a truly random function. A PRF can be thought of as a "queryable random function table," where querying different inputs yields (seemingly) random outputs.
Formal Definition: Let be a function family, where the first parameter is the key and the second parameter is the input. is a secure PRF if for all polynomial-time distinguishers , there exists a negligible function such that: where is a random key and is a randomly chosen function from all functions (a truly random function).
Key Understanding:
- Function Family: For different keys , are different functions
- Deterministic: The same input and key always produce the same output
- Pseudo-randomness: Without knowing the key , the behavior of is indistinguishable from a truly random function
- Queryability: The distinguisher can query the function on arbitrary inputs
Difference Between PRF and PRG (Exam Focus):
| Property | PRG | PRF |
|---|---|---|
| Input | Fixed-length seed | Key + arbitrary input |
| Output | Long sequence | Fixed-length output |
| Query | Generate entire sequence at once | Can query arbitrary inputs on demand |
| Application | Stream cipher | Block cipher, MAC |
Core Properties:
- Deterministic: Same input and key always produce same output, i.e.,
- Pseudo-randomness: Without knowing the key, output appears random
- Efficiency: Fast computation, can be computed in polynomial time
- Reversibility: PRF itself may not be reversible, but can be used to construct reversible block ciphers
Practical Applications:
- Constructing block ciphers (e.g., AES)
- Constructing message authentication codes (MAC)
- Constructing key derivation functions
- As building blocks for other cryptographic primitives
2.2 Block Cipher
Exam Focus: Concept Explanation - What is Block Cipher?
A block cipher is a symmetric encryption scheme that encrypts a fixed-length plaintext block (e.g., 128 bits) into a ciphertext block of the same length. Block ciphers are one of the most fundamental and widely used cryptographic primitives.
Basic Structure: Block ciphers are typically constructed based on PRF, with AES (Advanced Encryption Standard) being the most famous example. The core of a block cipher is designing a reversible, pseudo-random permutation, i.e., for each key, the encryption function is a bijection from all possible plaintext blocks to all possible ciphertext blocks.
How AES Works (Detailed): AES treats a 128-bit plaintext block as a byte matrix (each byte is 8 bits, total 16 bytes = 128 bits).
- Input: 128-bit plaintext block and 128/192/256-bit key
- Key Expansion: Expand the key into multiple round keys
- Initial Round Key Addition (AddRoundKey): XOR plaintext with first round key
- Multiple Rounds (depending on key length: 10 rounds for 128-bit key, 12 for 192-bit, 14 for 256-bit):
- SubBytes (Byte Substitution): Use S-box (Substitution Box) to perform nonlinear substitution on each byte, providing confusion
- ShiftRows (Row Shifting): Cyclically shift each row of the matrix by different amounts, providing diffusion
- MixColumns (Column Mixing): Perform linear transformation on each column (omitted in last round), further providing diffusion
- AddRoundKey (Round Key Addition): XOR with current round key
- Last Round: Omit MixColumns operation
- Output: 128-bit ciphertext block
Mathematical Representation: where is the plaintext block, is the key, is the encryption function, and is the ciphertext block.
Decryption Process: where is the decryption function, the inverse of the encryption function. AES decryption uses inverse operations: InvSubBytes, InvShiftRows, InvMixColumns.
Calculation Problem: AES Encryption Calculation Example: Given AES-128 key and plaintext block , describe the encryption process (no need for specific values, but explain each step). Solution Points:
- Key expansion: Generate 11 round keys (1 initial + 10 round keys)
- Initial round key addition:
- 10 rounds of transformation: Each round includes SubBytes, ShiftRows, MixColumns (except round 10), AddRoundKey
- Output ciphertext block
Security Analysis (Exam Focus):
- Single Block Security: Block ciphers themselves only provide encryption for a single block. If the plaintext is exactly one block, encryption is secure
- Multiple Blocks Problem: Directly using block ciphers to encrypt multiple blocks is insecure! Identical plaintext blocks produce identical ciphertext blocks, which leaks information
- Encryption Modes Needed: Must use encryption modes (such as CBC, CTR) to securely encrypt multiple blocks
Proof Problem: Why Directly Using Block Cipher to Encrypt Multiple Blocks is Insecure? Proof Idea: Assume directly using to encrypt multiple blocks: If (), then An attacker observing can infer , which leaks plaintext information. Therefore, directly using block ciphers to encrypt multiple blocks is not semantically secure.
3. How to Use Block Cipher? -> Encryption Modes
Scheme Design Problem: Why Do We Need Encryption Modes?
Directly using block ciphers to encrypt multiple blocks is insecure because identical plaintext blocks produce identical ciphertext blocks, which leaks information. Encryption modes define how to use block ciphers to securely encrypt messages of arbitrary length (which may contain multiple blocks).
Core Problem: Block cipher can only encrypt fixed-length blocks (e.g., 128 bits). To encrypt longer messages, we need:
- Split the message into multiple blocks
- Use some method to combine the encryption of these blocks
- Ensure the combination method does not leak information
3.1 ECB Mode (Electronic Codebook Mode)
Exam Focus: Concept Explanation - How ECB Mode Works and Its Security
ECB (Electronic Codebook) mode is the simplest encryption mode, where each plaintext block is encrypted independently without affecting others.
How It Works:
- Split plaintext into blocks: (each block length equals the block cipher block length)
- Encrypt each block independently:
- Ciphertext is:
Decryption:
Calculation Problem: ECB Mode Encryption Calculation Example: Encrypt message using AES-128 (block length 128 bits) in ECB mode (assume padded to block length multiple). If , , , write the encryption process. Solution:
- Split: , , $P_3 = "D..."`
- Encrypt: , ,
- Ciphertext:
Security Analysis (Exam Focus): ECB mode has serious security problems:
- Identical plaintext blocks produce identical ciphertext blocks: If , then
- Does not hide patterns: Repetitive patterns in plaintext are reflected in ciphertext
- Not CPA secure: Attackers can observe which blocks are identical, inferring plaintext information
Proof Problem: Prove ECB Mode is Not CPA Secure Proof Idea: Construct attacker :
- chooses two plaintexts (two identical blocks) and (two different blocks, )
- queries encryption oracle, receives challenge ciphertext
- If the first two blocks of are identical, outputs ; otherwise outputs
- 's success probability is 1 (perfect distinguishing), therefore ECB is not CPA secure
Practical Example: If an image is encrypted using ECB mode, even after encryption, the general outline of the image remains visible because identical pixel blocks produce identical ciphertext blocks.
Conclusion: ECB mode should not be used in practical applications!
3.2 CBC Mode (Cipher Block Chaining Mode)
Exam Focus: Concept Explanation - How CBC Mode Solves ECB's Problems
CBC (Cipher Block Chaining) mode solves the problem of identical plaintext blocks producing identical ciphertext blocks by XORing each plaintext block with the previous ciphertext block.
How It Works:
- Choose IV: Choose a random initialization vector (length equals block length, e.g., 128 bits)
- First Block: First plaintext block XORed with then encrypted
- Subsequent Blocks: Each plaintext block XORed with previous ciphertext block then encrypted
Complete Encryption Formula:
Decryption Process:
- Decrypt first block:
- Decrypt subsequent blocks:
Calculation Problem: CBC Mode Encryption/Decryption Calculation Example: In CBC mode, given , , , key , assuming , , calculate and , then verify decryption. Solution:
- Encryption:
- (need to know value of )
- Assume , then
- Assume , then
- Decryption Verification:
- ✓
- ✓
Key Characteristics (Exam Focus):
- Requires IV: Must have an initialization vector, usually transmitted together with the first ciphertext block
- Properties of IV:
- should be random (or pseudo-random)
- need not be secret, can be transmitted in plaintext
- Each encryption should use a different (to ensure semantic security)
- Different Ciphertexts for Same Plaintext: Even if , if , then
- Parallelism:
- Encryption is sequential: Must wait for previous block encryption to complete before encrypting next block (cannot parallelize)
- Decryption can be parallelized: All blocks can be decrypted simultaneously because is already known
Scheme Design Problem: Why Does IV Not Need to Be Secret? Even if the attacker knows , as long as is random, CBC mode is still CPA secure. The role of is to ensure each encryption produces different ciphertexts, not to provide confidentiality. Confidentiality is provided by the encryption function .
Security: CBC mode is semantically secure under CPA (Chosen Plaintext Attack), provided:
- The underlying block cipher is a pseudo-random permutation (PRP)
- is randomly chosen (different for each encryption)
Proof Problem: CPA Security of CBC Mode (Simplified Proof Idea) Proof Idea:
- Assume the underlying block cipher is a pseudo-random permutation
- If is random, then each block's input () appears random
- Since is pseudo-random, output also appears random
- Therefore, the entire ciphertext appears random, cannot distinguish encryptions of two plaintexts
- Therefore, CBC mode is CPA secure
3.3 CTR Mode (Counter Mode)
Exam Focus: Concept Explanation - Relationship Between CTR Mode and Stream Cipher
CTR (Counter) mode uses a counter to generate a key stream, then XORs with plaintext. CTR mode essentially converts a block cipher into a stream cipher.
How It Works:
- Choose IV: Choose an initial value (usually a random number or counter starting value)
- Generate Key Stream: Apply block cipher to each counter value () to generate key stream blocks:
- Encryption: Plaintext block XORed with corresponding key stream block:
- Decryption: XOR ciphertext with same key stream block:
Mathematical Representation:
Calculation Problem: CTR Mode Encryption Calculation Example: In CTR mode, given , , , key , assuming , , calculate and . Solution:
Key Characteristics (Exam Focus):
- Encryption and Decryption Are Identical: Both encryption and decryption use XOR operation, exactly the same operation
- Fully Parallelizable: Can encrypt/decrypt all blocks simultaneously because each can be computed independently
- No Padding Needed: Can handle arbitrary length data without padding to block length multiples
- Similar to Stream Cipher: CTR mode behaves similarly to stream cipher but based on block cipher rather than PRG
- Random Access: Can decrypt arbitrary block without decrypting previous blocks (just need to know and block index)
Scheme Design Problem: CTR Mode vs CBC Mode
| Property | CBC Mode | CTR Mode |
|---|---|---|
| Parallel Encryption | ❌ Sequential | ✅ Fully parallel |
| Parallel Decryption | ✅ Can parallelize | ✅ Fully parallel |
| Random Access | ❌ Need previous blocks | ✅ Can directly access |
| Padding | ✅ Required | ❌ Not needed |
| Error Propagation | ✅ One bit error affects subsequent blocks | ❌ Errors do not propagate |
| Implementation Complexity | Medium | Simple |
Security: CTR mode is semantically secure under CPA, provided:
- The underlying block cipher is a pseudo-random permutation (PRP)
- is randomly chosen, and values do not repeat (counter does not wrap around)
Proof Problem: CPA Security of CTR Mode Proof Idea:
- If is a pseudo-random permutation, then output appears random
- Key stream appears to be a truly random string
- Therefore, appears to be "one-time pad" encryption
- "One-time pad" is theoretically unbreakable, therefore CTR mode is CPA secure
Practical Applications: CTR mode is widely used in modern cryptography because it supports parallel processing, suitable for high-speed encryption scenarios.
3.4 CPA Secure Semantic Security
Exam Focus: Concept Explanation - Complete Definition of CPA Security
Chosen Plaintext Attack (CPA): In a chosen plaintext attack, the attacker can choose arbitrary plaintexts and obtain corresponding ciphertexts. This models real-world scenarios where attackers can observe encrypted communications.
Semantic Security: Semantic security means that even if the attacker knows some information about the plaintext (such as length, format, etc.), they cannot obtain additional information from the ciphertext. In other words, the ciphertext does not leak any information about the plaintext (except public information like length).
Formal Definition: An encryption scheme is CPA secure if for all polynomial-time attackers , there exists a negligible function such that: where is the CPA game, outputting 1 when attacker wins.
CPA Game (Detailed Steps):
- Initialization: Challenger generates key , where is the security parameter
- Learning Phase 1: Attacker can query encryption oracle arbitrarily many polynomial times, obtaining pairs
- Challenge Phase:
- Attacker chooses two equal-length plaintexts ()
- Challenger randomly chooses (uniformly random)
- Challenger computes and returns challenge ciphertext
- Learning Phase 2: Attacker can continue to query encryption oracle arbitrarily many polynomial times (but cannot query decryption of )
- Guess Phase: Attacker outputs
- Decision: If , attacker wins, game outputs 1; otherwise outputs 0
Attacker's Advantage: Attacker's advantage is defined as: If (negligible function), then the encryption scheme is CPA secure.
Proof Problem: Prove ECB Mode is Not CPA Secure Proof: Construct attacker :
- chooses (two identical blocks) and (two different blocks, )
- queries encryption oracle, receives challenge ciphertext
- checks: if , output ; otherwise output
Analysis:
- If (encrypt ), then , , so
- If (encrypt ), then , , since and is a permutation, so
- Therefore, can always correctly guess with success probability 1
- , which is non-negligible
- Therefore, ECB mode is not CPA secure
Proof Problem: Prove CBC Mode is CPA Secure (Simplified Idea) Proof Idea (based on ideal cipher model):
- Assume the underlying block cipher is a pseudo-random permutation (PRP)
- In ideal case, if is random, then each block's input appears random
- Since is pseudo-random, output also appears random
- Therefore, the entire ciphertext appears random, cannot distinguish encryptions of and
- Any attacker's advantage is negligible
- Therefore, CBC mode is CPA secure
Important Conclusions (Exam Focus):
- ✅ CBC Mode: Semantically secure under CPA (if is random)
- ✅ CTR Mode: Semantically secure under CPA (if is random)
- ❌ ECB Mode: Not CPA secure, should not be used
- CPA security is a fundamental security requirement in modern cryptography: Any practical encryption scheme must be CPA secure
4. Hash Function
Exam Focus: Concept Explanation - Three Security Properties and Their Relationships
A hash function maps inputs of arbitrary length to fixed-length outputs. Hash functions are fundamental tools in cryptography, used for data integrity verification, digital signatures, password storage, etc.
Formal Definition: Let be a function, where represents binary strings of arbitrary length and represents binary strings of fixed length .
Basic Properties:
- Compression: Fixed output length (e.g., SHA-256 outputs 256 bits), regardless of input length
- Efficiency: Fast computation, can be computed in polynomial time
- Deterministic: Same input always produces same output, i.e.,
Security Requirements (Exam Focus):
1. Preimage Resistance (One-Wayness) Definition: Given hash value , finding such that is computationally infeasible. Formal: For all polynomial-time attackers , there exists a negligible function such that: Intuitive Understanding: Given a hash value, computing the preimage is difficult (one-way function property).
2. Second Preimage Resistance Definition: Given , finding such that is computationally infeasible. Formal: For all polynomial-time attackers , there exists a negligible function such that: Intuitive Understanding: Given an input, finding another input that produces the same hash value is difficult.
3. Collision Resistance Definition: Finding any such that but is computationally infeasible. Formal: For all polynomial-time attackers , there exists a negligible function such that: Intuitive Understanding: Finding any pair of collisions is difficult.
Proof Problem: Relationships Between Three Security Properties Theorem:
- Collision Resistance Second Preimage Resistance
- Second Preimage Resistance Preimage Resistance (under random oracle model)
- But Preimage Resistance Second Preimage Resistance
- Second Preimage Resistance Collision Resistance
Proof Idea 1: Collision Resistance Second Preimage Resistance
- Assume there exists attacker that can find second preimage with non-negligible probability
- Construct attacker to find collision:
- Randomly choose
- Call to get such that
- Output as collision
- If succeeds, then also succeeds, contradiction
Calculation Problem: Birthday Attack (Collision Finding) Birthday Paradox: In a room with people, what is the probability that at least two people share the same birthday?
- When , probability is about 50%
Birthday Attack: For a hash function with output length bits, finding a collision requires approximately hash computations. Example: SHA-256 outputs 256 bits, how many hash computations are needed to find a collision using birthday attack? Solution: hash computations (still computationally infeasible)
Practical Applications:
- Digital Signatures: Hash message before signing, rather than signing entire message directly (efficient)
- Message Authentication Codes: As building block for MAC (e.g., HMAC)
- Password Storage: Store hash of password rather than plaintext password
- Blockchain: Merkle trees, proof of work (PoW)
- Data Integrity Verification: Verify whether files have been tampered with
Common Hash Functions:
- SHA-256: 256-bit output, currently secure, widely used
- SHA-512: 512-bit output, more secure but slightly slower
- SHA-3: Based on Keccak, different design from SHA-2
- MD5: 128-bit output, insecure, should not be used (collisions found)
- SHA-1: 160-bit output, insecure, should not be used (collisions found)
Scheme Design Problem: How to Use Hash Function to Verify File Integrity? Scheme:
- Sender computes file hash value
- Sender sends through secure channel (e.g., digital signature)
- Receiver computes after receiving
- If , file is intact; otherwise file has been tampered with
Why This Design?
- If attacker modifies file, hash value changes
- Due to preimage resistance, attacker cannot find different file producing same hash value
- Therefore, any tampering can be detected
5. Message Authentication Code (MAC)
Exam Focus: Concept Explanation - Difference Between MAC and Digital Signature
Message authentication codes (MAC) are used to ensure message integrity and authenticity. MAC uses symmetric keys, so sender and receiver must share the same key.
Basic Idea:
- Key Sharing: Sender and receiver pre-share a key (through secure channel)
- Generate Tag: Sender computes and sends
- Verify Tag: Receiver computes and checks if
- Decision: If , message is intact and from sender; otherwise reject message
Formal Definition: A MAC scheme consists of three algorithms:
- Key Generation: , generates key
- Tag Generation: , computes tag for message
- Verification: , verifies tag, outputs 1 (valid) or 0 (invalid)
Usually if and only if .
Security Requirements (Exam Focus):
Unforgeability MAC must be unforgeable, meaning even if the attacker sees many pairs, they cannot generate a valid tag for a new message .
Formal Security Definition: For all polynomial-time attackers , there exists a negligible function such that: where is not a message that has queried (i.e., , where is the number of queries).
MAC Security Game:
- Challenger generates key
- Attacker can query MAC oracle arbitrarily many polynomial times, obtaining pairs
- Attacker outputs , where is not a queried message
- If , attacker wins
Proof Problem: Why Is Simple Possibly Insecure? Problem: If attacker knows , they may be able to construct new valid tags. Attack Example (Length Extension Attack):
- If , attacker can compute without knowing
- Attacker queries to get
- Then attacker can compute (in some hash functions, this equals )
- Therefore attacker can generate valid tag for without knowing
Common MAC Constructions:
1. HMAC (MAC Based on Hash Function) where:
- = 0x5c5c5c... (outer padding)
- = 0x363636... (inner padding)
- represents concatenation
Calculation Problem: HMAC Calculation Example: Given key and message , describe HMAC computation steps. Solution:
- If block length, then
- If block length, then right-pad with 0s
- Compute
- Compute
2. CBC-MAC (MAC Based on Block Cipher) Encrypt message using CBC mode, use the last ciphertext block as MAC.
How It Works:
- Split message into blocks:
- Encrypt using CBC mode (usually ):
- MAC is the last ciphertext block:
Note: CBC-MAC is only secure for fixed-length messages. For variable-length messages, other techniques are needed (e.g., encrypt the length of the last block).
MAC vs Digital Signature (Exam Focus):
| Property | MAC | Digital Signature |
|---|---|---|
| Key Type | Symmetric key (shared key) | Asymmetric key (public/private key pair) |
| Key Management | Need to securely share key | Public key can be public |
| Non-repudiation | ❌ Both parties can generate tags | ✅ Only private key holder can sign |
| Verifier | Must know key | Only needs public key |
| Efficiency | Fast | Slower |
| Application | Two-party communication | Public verification, non-repudiation |
Scheme Design Problem: Design a Secure MAC Scheme Requirements: Ensure message integrity and authenticity. Scheme:
- Choose secure hash function (e.g., SHA-256)
- Use HMAC:
- Send
- Receiver verifies: Compute , check if
Why This Design?
- HMAC resists length extension attacks
- Based on secure hash function, provides unforgeability
- Computationally efficient
6. Authenticated Encryption
Exam Focus: Concept Explanation - Why Do We Need Authenticated Encryption?
Authenticated encryption provides both confidentiality and integrity/authenticity. This is one of the most important security goals in modern cryptography.
Two Security Goals:
- Confidentiality (Confidentiality): Attacker cannot obtain any information about plaintext, even when seeing ciphertext
- Integrity/Authenticity (Integrity/Authenticity): Attacker cannot forge or modify messages without being detected
Why Authenticated Encryption is Needed: Encryption alone (such as CBC, CTR) only provides confidentiality, not integrity. This leads to serious security problems:
Attack Example:
- Attacker intercepts ciphertext
- Attacker modifies ciphertext to get (e.g., flip some bits)
- Receiver decrypts to get
- Receiver cannot detect that is not the original message (because decryption may produce valid plaintext, but not the original message)
Practical Attack Scenarios:
- Padding Oracle Attack: Attacker gains information by observing whether decryption succeeds
- Ciphertext Modification Attack: Attacker modifies ciphertext, may cause predictable plaintext changes
Construction Methods (Exam Focus):
1. Encrypt-then-MAC (Recommended) Steps:
- Encrypt first:
- Compute MAC:
- Send
Verification:
- Verify MAC: Check if
- If MAC is valid, decrypt:
Advantages:
- Best security (under standard assumptions)
- MAC protects entire ciphertext, including integrity of encryption scheme
2. MAC-then-Encrypt Steps:
- Compute MAC first:
- Encrypt:
- Send
Verification:
- Decrypt:
- Verify MAC: Check if
Disadvantages:
- May be insecure if encryption scheme has vulnerabilities (e.g., padding oracle)
- Not recommended
3. Encrypt-and-MAC Steps:
- Encrypt and compute MAC simultaneously: ,
- Send
Verification:
- Verify MAC: Check if (need to decrypt first to get )
- If MAC is valid, accept
Disadvantages:
- MAC protects plaintext, not ciphertext
- May be insecure if encryption and MAC use the same key
Scheme Design Problem: Design an Authenticated Encryption Scheme Requirements: Provide both confidentiality and integrity. Recommended Scheme (Encrypt-then-MAC):
- Choose CPA-secure encryption scheme (e.g., AES-CTR)
- Choose secure MAC scheme (e.g., HMAC-SHA256)
- Use two independent keys: (encryption) and (MAC)
- Encrypt:
- Compute MAC:
- Send
- Receiver verifies: First verify , if valid then decrypt
Why Use Two Independent Keys?
- If using the same key, may lead to security problems
- Key separation is a best practice in cryptography
CCA Secure Semantic Security
Exam Focus: Concept Explanation - Difference Between CCA Security and CPA Security
Chosen Ciphertext Attack (CCA): In a chosen ciphertext attack, the attacker can choose arbitrary ciphertexts and obtain corresponding plaintexts (or verification failure). This models real-world scenarios where attackers can send modified ciphertexts and observe decryption results.
CCA Security: An encryption scheme is CCA secure if the attacker cannot distinguish encryptions of two plaintexts even when they can query a decryption oracle.
Formal Definition: For all polynomial-time attackers , there exists a negligible function such that:
CCA Game (Detailed Steps):
- Initialization: Challenger generates key
- Learning Phase 1: Attacker can query:
- Encryption oracle : Obtain
- Decryption oracle : Obtain
- Challenge Phase:
- Attacker chooses two equal-length plaintexts
- Challenger randomly chooses
- Challenger returns challenge ciphertext
- Learning Phase 2: Attacker can continue to query encryption and decryption oracles, but cannot query decryption of
- Guess Phase: Attacker outputs
- Decision: If , attacker wins
Proof Problem: Why Are Encryption Modes Alone (Such as CBC, CTR) Not CCA Secure? Proof Idea (using CBC as example): Construct attacker :
- chooses and (two blocks)
- queries encryption oracle, receives challenge ciphertext
- constructs new ciphertext (add a random block)
- queries decryption oracle , obtains
- Due to CBC mode properties, can infer information about from
- Therefore can distinguish encryptions of and
Important Conclusions (Exam Focus):
- ✅ Authenticated Encryption: Typically provides CCA security (e.g., Encrypt-then-MAC)
- ❌ Encryption Modes Alone (CBC, CTR): Not CCA secure
- CCA security is stronger than CPA security: CCA security implies CPA security, but not vice versa
- Modern applications must use authenticated encryption: Encryption alone is insufficient to provide complete security
Practical Applications:
- TLS/SSL Protocols: Use authenticated encryption to protect Web communications
- SSH Protocol: Use authenticated encryption to protect remote login
- Modern Encrypted Communication: All secure communication protocols use authenticated encryption
Calculation Problem: Complete Flow of Authenticated Encryption Example: Implement Encrypt-then-MAC using AES-128-CTR and HMAC-SHA256. Given: Key (128 bits), (256 bits), message Solution Steps:
- Encryption:
- Choose random
- Generate key stream:
- Encrypt:
- Compute MAC:
- Send:
- Receiver verifies:
- Verify
- If valid, decrypt
Part 2: Public Key Cryptography
1. Public Key Encryption from Trapdoor Permutations
1.1 RSA Encryption Scheme
Exam Focus: Concept Explanation - What is a Trapdoor Permutation?
A trapdoor permutation is a family of functions with the following properties:
- Forward computation is easy: Given public key and input , computing is easy
- Reverse computation is hard: Without trapdoor information, computing from is hard
- Reverse computation is easy (with trapdoor): Given private key (trapdoor) , computing from is easy
RSA is a classic example of a trapdoor permutation.
RSA Key Generation Algorithm:
- Choose two large primes and (typically 1024 bits or larger each)
- Compute (modulus)
- Compute Euler's totient function
- Choose integer such that and ( is public exponent, often 65537)
- Compute such that ( is private exponent)
- Public key:
- Private key: (or )
RSA Encryption (Textbook Version): Given public key and plaintext (), ciphertext is:
RSA Decryption: Given private key and ciphertext , plaintext is:
Correctness Proof: Since , there exists integer such that . By Euler's theorem, if , then . Therefore:
Calculation Problem: Complete RSA Encryption/Decryption Calculation
Problem 1: Given RSA parameters: , , , plaintext . (1) Compute public and private keys (2) Compute ciphertext (3) Verify decryption process
Detailed Solution:
Step 1: Compute modulus and Euler's totient function
Step 2: Verify is coprime with
- ✓ (since 7 is prime and 7 does not divide 120)
Step 3: Compute private exponent Need to find such that , i.e., for some integer .
Using extended Euclidean algorithm:
Back substitution:
- Therefore
Verify: ✓
Step 4: Determine keys
- Public key:
- Private key:
Step 5: Encryption
- Plaintext:
- Ciphertext:
Compute :
Compute :
- Therefore
Step 6: Decryption verification
- Ciphertext:
- Plaintext:
Since is large, use modular exponentiation:
Compute :
Now compute :
Compute step by step:
Therefore , matching the original plaintext ✓
Problem 2: Given RSA public key , encrypt message , compute ciphertext.
Detailed Solution:
- Plaintext:
- Check: , so ✓
- Ciphertext:
Compute :
Compute :
- (since )
- Therefore
So
Note: In this example , which is due to special properties of . This generally does not occur.
1.2 RSA Textbook Version vs CPA Secure Version
Exam Focus: Concept Explanation - Why is RSA Textbook Version Insecure?
RSA textbook version has the following security problems:
- Deterministic encryption: Same plaintext always produces same ciphertext, attackers can observe patterns
- Not CPA secure: Attackers can query encryption oracle, obtaining pairs, potentially inferring information
- Small plaintext attack: If plaintext is small (), then (no modular reduction), attackers can directly compute
- Common modulus attack: If multiple users use same but different , may be attacked
- Low encryption exponent attack: If is small and plaintexts are same, may be attacked
Proof Problem: Prove RSA Textbook Version is Not CPA Secure
Proof: Construct attacker :
- chooses two plaintexts and
- queries encryption oracle, receives challenge ciphertext
- If , outputs ; if , outputs ; otherwise outputs random guess
Analysis:
- If (encrypt ), then
- If (encrypt ), then
- Therefore can perfectly distinguish with success probability 1
- Therefore RSA textbook version is not CPA secure
CPA Secure RSA (RSA-OAEP):
To achieve CPA security, padding schemes are needed, most commonly OAEP (Optimal Asymmetric Encryption Padding).
RSA-OAEP Encryption Process:
- Use OAEP padding to convert plaintext to (padded message)
- Encrypt:
OAEP Padding (Simplified Description):
- Use random number and hash functions
- Ensures same plaintext produces different ciphertexts each encryption
- Provides semantic security
Scheme Design Problem: Design a CPA Secure RSA Encryption Scheme
Scheme: Use RSA-OAEP
Detailed Steps:
- Key Generation: Use standard RSA key generation, obtain
- Encryption:
- Choose random number ( is security parameter)
- Use hash functions and (e.g., SHA-256)
- Compute ( is zeros padding)
- Compute
- Set
- If , reselect and repeat
- Encrypt:
- Decryption:
- Decrypt:
- Split:
- Recover:
- Recover:
- Verify padding and extract
Why is this design CPA secure?
- Random number ensures same plaintext produces different ciphertexts
- Hash functions provide randomness
- Under random oracle model, RSA-OAEP can be proven CPA secure