An Intensive Introduction to Cryptography
Total Page:16
File Type:pdf, Size:1020Kb
BOAZBARAK ANINTENSIVE INTRODUCTION TOCRYPTOGRAPHY LECTURENOTES. AVAILABLEON HTTPS://INTENSECRYPTO.ORG Text available on https://github.com/boazbk/crypto - please post any issues there - thank you! This version was compiled on Thursday 23rd September, 2021 13:32 Copyright © 2021 Boaz Barak This work is licensed under a Creative Commons “Attribution-NonCommercial- NoDerivatives 4.0 International” license. If you can just get your mind together Then come on across to me We’ll hold hands, and then we’ll watch the sun rise From the bottom of the sea Jimi Hendrix, Are You Experienced? Contents Foreword and Syllabus 9 I Preliminaries 15 0 Mathematical Background 17 1 Introduction 39 II Private key cryptography 59 2 Computational Security 61 3 Pseudorandomness 83 4 Pseudorandom functions 103 5 Pseudorandom functions from pseudorandom generators and CPA security 117 6 Chosen Ciphertext Security 137 7 Hash Functions and Random Oracles 153 8 Key derivation, protecting passwords, slow hashes, Merkle trees 167 9 Private key crypto recap 177 III Public key cryptography 179 10 Public key cryptography 181 11 Concrete candidates for public key crypto 211 12 Chosen ciphertext security for public key encryption 229 Compiled on 9.23.2021 13:32 6 13 Lattice based cryptography 231 14 Establishing secure connections over insecure channels 247 IV Advanced topics 257 15 Zero knowledge proofs 259 16 Fully homomorphic encryption: Introduction and boot- strapping 273 17 Fully homomorphic encryption: Construction 285 18 Multiparty secure computation I: Definition and Honest- But-Curious to Malicious complier 299 19 Multiparty secure computation II: Construction using Fully Homomorphic Encryption 315 20 Quantum computing and cryptography I 325 21 Quantum computing and cryptography II 337 22 Software Obfuscation 347 23 More obfuscation, exotic encryptions 357 24 Anonymous communication 363 V Conclusions 365 25 Ethical, moral, and policy dimensions to cryptography 367 26 Course recap 373 Contents (detailed) Foreword and Syllabus 9 0.1 Syllabus ............................ 10 0.1.1 Prerequisites ..................... 12 0.2 Why is cryptography hard? . 12 I Preliminaries 15 0 Mathematical Background 17 0.1 A quick overview of mathematical prerequisites . 17 0.2 Mathematical Proofs .................... 19 0.2.1 Example: The existence of infinitely many primes. 20 0.3 Probability and Sample spaces . 22 0.3.1 Random variables . 24 0.3.2 Distributions over strings . 26 0.3.3 More general sample spaces. 27 0.4 Correlations and independence . 27 0.4.1 Independent random variables . 29 0.4.2 Collections of independent random variables. 30 0.5 Concentration and tail bounds . 31 0.5.1 Chebyshev’s Inequality . 32 0.5.2 The Chernoff bound . 33 0.6 Exercises ........................... 34 0.7 Exercises ........................... 35 1 Introduction 39 1.1 Some history ......................... 39 1.2 Defining encryptions .................... 41 1.3 Defining security of encryption . 43 1.3.1 Generating randomness in actual cryptographic systems ........................ 44 1.4 Defining the secrecy requirement. 46 1.5 Perfect Secrecy ........................ 49 1.5.1 Achieving perfect secrecy . 52 1.6 Necessity of long keys ................... 54 8 1.6.1 Amplifying success probability . 57 1.7 Bibliographical notes .................... 58 II Private key cryptography 59 2 Computational Security 61 2.0.1 Proof by reduction . 65 2.1 The asymptotic approach . 66 2.1.1 Counting number of operations. 68 2.2 Our first conjecture ..................... 70 2.3 Why care about the cipher conjecture? . 71 2.4 Prelude: Computational Indistinguishability . 71 2.5 The Length Extension Theorem or Stream Ciphers . 76 2.5.1 Appendix: The computational model . 80 3 Pseudorandomness 83 3.0.1 Unpredictability: an alternative approach for proving the length extension theorem . 88 3.1 Stream ciphers ........................ 90 3.2 What do pseudorandom generators actually look like? . 92 3.2.1 Attempt 0: The counter generator . 92 3.2.2 Attempt 1: The linear checksum / linear feed- back shift register (LFSR) . 92 3.2.3 From insecurity to security . 94 3.2.4 Attempt 2: Linear Congruential Generators with dropped bits . 95 3.3 Successful examples ..................... 96 3.3.1 Case Study 1: Subset Sum Generator . 96 3.3.2 Case Study 2: RC4 . 97 3.3.3 Case Study 3: Blum, Blum and Shub . 98 3.4 Non-constructive existence of pseudorandom generators 99 4 Pseudorandom functions 103 4.1 One time passwords (e.g. Google Authenticator, RSA ID, etc.) ............................107 4.1.1 How do pseudorandom functions help in the login problem? . 108 4.1.2 Modifying input and output lengths of PRFs . 111 4.2 Message Authentication Codes . 112 4.3 MACs from PRFs . 114 4.4 Arbitrary input length extension for MACs and PRFs . 115 4.5 Aside: natural proofs . 115 9 5 Pseudorandom functions from pseudorandom generators and CPA security 117 5.1 Securely encrypting many messages - chosen plaintext security ............................122 5.2 Pseudorandom permutations / block ciphers . 125 5.3 Encryption modes . 130 5.4 Optional, Aside: Broadcast Encryption . 131 5.5 Reading comprehension exercises . 134 6 Chosen Ciphertext Security 137 6.1 Short recap . 137 6.2 Going beyond CPA . 138 6.2.1 Example: The Wired Equivalence Privacy (WEP) 138 6.2.2 Chosen ciphertext security . 140 6.3 Constructing CCA secure encryption . 143 6.4 (Simplified) GCM encryption . 148 6.5 Padding, chopping, and their pitfalls: the “buffer overflow” of cryptography . 149 6.6 Chosen ciphertext attack as implementing metaphors . 150 6.7 Reading comprehension exercises . 150 7 Hash Functions and Random Oracles 153 7.1 The “Bitcoin” Problem . 153 7.1.1 The Currency Problem . 153 7.1.2 Bitcoin Architecture . 154 7.2 The Bitcoin Ledger . 155 7.2.1 From Proof of Work to Consensus on Ledger . 158 7.3 Collision Resistance Hash Functions and Creating Short “Unique” Identifiers . 160 7.4 Practical Constructions of Cryptographic Hash Func- tions ..............................161 7.4.1 Practical Random-ish Functions . 162 7.4.2 Some History . 163 7.4.3 The NSA and Hash Functions . 164 7.4.4 Cryptographic vs Non-Cryptographic Hash Functions . 164 7.5 Reading comprehension exercises . 165 8 Key derivation, protecting passwords, slow hashes, Merkle trees 167 8.1 Keys from passwords . 167 8.2 Merkle trees and verifying storage. 170 8.3 Proofs of Retrievability . 171 8.4 Entropy extraction . 172 8.4.1 Forward and backward secrecy . 175 10 9 Private key crypto recap 177 9.0.1 Attacks on private key cryptosystems . 178 III Public key cryptography 179 10 Public key cryptography 181 10.1 Private key crypto recap . 183 10.2 Public Key Encryptions: Definition . 185 10.2.1 The obfuscation paradigm . 186 10.3 Some concrete candidates: . 188 10.3.1 Diffie-Hellman Encryption (aka El-Gamal) . 189 10.3.2 Sampling random primes . 193 10.3.3 A little bit of group theory. 194 10.3.4 Digital Signatures . 195 10.3.5 The Digital Signature Algorithm (DSA) . 196 10.4 Putting everything together - security in practice. 200 10.5 Appendix: An alternative proof of the density of primes 204 10.6 Additional Group Theory Exercises and Proofs . 205 10.6.1 Solved exercises: . 206 11 Concrete candidates for public key crypto 211 11.1 Some number theory. 211 11.1.1 Primaliy testing . 212 11.1.2 Fields . 213 11.1.3 Chinese remainder theorem . 214 11.1.4 The RSA and Rabin functions . 215 11.1.5 Abstraction: trapdoor permutations . 216 11.1.6 Public key encryption from trapdoor permuta- tions . 217 11.1.7 Digital signatures from trapdoor permutations . 220 11.2 Hardcore bits and security without random oracles . 222 11.2.1 Extending to more than one hardcore bit . 226 12 Chosen ciphertext security for public key encryption 229 13 Lattice based cryptography 231 13.0.1 Quick linear algebra recap . 233 13.1 A world without Gaussian elimination . 235 13.2 Security in the real world. 237 13.3 Search to decision . 238 13.4 An LWE based encryption scheme . 239 13.5 But what are lattices? . 244 13.6 Ring based lattices . 245 14 Establishing secure connections over insecure channels 247 11 14.1 Cryptography’s obsession with adjectives. 247 14.2 Basic Key Exchange protocol . 249 14.3 Authenticated key exchange . 250 14.3.1 Bleichenbacher’s attack on RSA PKCS V1.5 and SSL V3.0 . 250 14.4 Chosen ciphertext attack security for public key cryp- tography . 251 14.5 CCA secure public key encryption in the Random Oracle Model . 253 14.5.1 Defining secure authenticated key exchange . 255 14.5.2 The compiler approach for authenticated key exchange . 255 14.6 Password authenticated key exchange. 256 14.7 Client to client key exchange for secure text messaging - ZRTP, OTR, TextSecure . 256 14.8 Heartbleed and logjam attacks . 256 IV Advanced topics 257 15 Zero knowledge proofs 259 15.1 Applications for zero knowledge proofs. 260 15.1.1 Nuclear disarmament . 260 15.1.2 Voting . 261 15.1.3 More applications . 261 15.2 Defining and constructing zero knowledge proofs . 261 15.3 Defining zero knowledge . 265 15.4 Zero knowledge proof for Hamiltonicity. 268 15.4.1 Why is this interesting? . 271 15.5 Parallel repetition and turning zero knowledge proofs to signatures. 271 15.5.1 “Bonus features” of zero knowledge . 272 16 Fully homomorphic encryption: Introduction and boot- strapping 273 16.1 Defining fully homomorphic encryption . 276 16.1.1 Another application: fully homomorphic en- cryption for verifying computation . 277 16.2 Example: An XOR homomorphic encryption . 278 16.2.1 Abstraction: A trapdoor pseudorandom generator.280 16.3 From linear homomorphism to full homomorphism . 282 16.4 Bootstrapping: Fully Homomorphic “escape velocity” . 282 16.4.1 Radioactive legos analogy . 283 16.4.2 Proving the bootstrapping theorem . 283 12 17 Fully homomorphic encryption: Construction 285 17.1 Prelude: from vectors to matrices .