CIS 5371 Cryptography 3c. Pseudorandom Functions Based on: Jonathan Katz and Yehuda Lindell Introduction to Modern Cryptography 1 Definition • A ๐๐๐ฆ๐๐ ๐๐ข๐๐๐ก๐๐๐ ๐น is a two input function ∗ ∗ ∗ ๐น โถ 0,1 × 0,1 → 0,1 where the first input is called the key, denoted ๐, .and the second is just called input. 2 Definition 3.23 • Let ๐น be an efficient length preserving keyed function. ๐น is a pseudorandom function if ๏ข PPT distinguishers D, ๏ค a negl function such that | Pr ๐ท๐น๐ โ 1๐ = 1 − Pr ๐ท ๐ โ 1๐ = 1 | ≤ negl(๐) ∗ where ๐ ← 0,1 is chosen uniformly at random and f is chosen at random from the set of all functions mapping n-bit strings to n-bit strings. 3 A secure fixed length encryption scheme ๐น๐๐๐ โ ๐๐๐๐๐๐ ๐ ๐ก๐๐๐๐ ๐ ๐๐ ๐๐ข๐๐๐๐๐๐๐๐ ๐๐๐ฆ๐๐ ๐๐ข๐๐๐ก๐๐๐ ๐๐๐ ๐๐๐๐๐๐ก๐๐ฅ๐ก ๐๐๐ ๐๐๐โ๐๐๐ก๐๐ฅ๐ก 4 Existence of pseudorandom functions • We cannot prove that pseudorandom functions exist! • In practice there exist very efficient primitives called block ciphers that are widely believed to behave as pseudorandom functions. 5 CPA secure encryption using PRF Protocol Π = (Gen, Enc, Dec) Let ๐น be a pseudorandom function. Define a private-key encryption scheme for messages of length ๐ as follows: • Gen: on input 1๐ choose ๐ ๏ฌ {0,1}๐ uniformly at random and output ๐ as key. • Enc: on input a key ๐ ๏ {0,1}๐ and a message m๏{0,1}๐ , choose choose ๐ ๏ฌ {0,1}๐ uniformly at random and output the ciphertext ๐ โ ๏ก๐, ๐น๐ ๐ ๏ ๐๏ฑ . • Dec: on input a key ๐ ๏ {0,1}๐ and a ciphertext c = ๏ก๐, ๐ ๏ฑ, output the plaintext ๐ โ ๐น๐ ๐ ๏ ๐ . 6 Theorem 3.25 Let ๐น be a pseudorandom function. Then protocol ๏ is a fixed-length private-key encryption scheme for messages of length n that has indistinguishable encryptions under CPA. 7 A secure fixed length encryption Proof Let Π be an encryption that is exactly the same as Π but that uses a truly random function ๐. Then, ∀ Adversary A (even inefficient) that makes at most ๐ ๐ queries to the oracle, we have Pr PrivK cpa 1 ๐(๐) ๐ด, Π ๐ = 1 = + ๐+1 2 2 8 A secure fixed length encryption Proof We have: Pr PrivK Let cpa ๐ ๐ โ Pr[PrivK cpa ๐ด, Π ๐ = 1 = 1 2 + (๐ด, Π) ๐ = 1] − 1 2 . Then Pr[PrivK cpa (๐ด, Π) ๐ = 1] = 1 2 ๐(๐) . 2๐+1 + ๐(๐). If ๏ฅ is negligible then we should not be able to distinguish these. Otherwise a gap between them would make it possible to distinguish truly random from pseudorandom. 9 A secure fixed length encryption Reduction Distinguisher D with oracle O: {0,1}๐ ๏ฎ {0,1}๐ Adversary A with Protocol Π or Π 1๐ 1๐ , ๐๐๐๐๐๐ O Choose ๐ ๏ฌ {0,1} uniformly at random Query O ๐ to get ๐ ๐ ๐๐๐๐๐ฆ๐๐ก ๐ (๐, ๐ ๏ ๐) Query encryption oracle to get encryptions of chosen plaintexts ๐0 , ๐1 ๐๐กโ๐๐: (๐, ๐ ๏ ๐) 1 if ๐ ′ = ๐ 0 if ๐ ′ ๏น ๐ choose a random bit ๐ Query O ๐′ to get ๐ ′ return ๐๐ = ๏ก๐′, ๐ ′ ๏ ๐๐ ๏ฑ ๐๐ Repeat: Query to get encryptions of chosen plaintexts ๐′ 10 A secure fixed length encryption Proof From, Pr ๐ท ๐น๐ (โ) 1๐ = 1 = Pr[PrivK cpa Pr ๐ท ๐(โ) 1๐ = 1 = Pr[PrivK cpa 1 (๐ด, Π)(๐) = 1] = 2 + ๐ ๐ and ๐ด, Π ๐ = 1] . Then, | Pr[๐ท๐น๐(โ) 1๐ = 1 − Pr[๐ท ๐ (โ) 1๐ = 1]| ≥ ≥ 1 2 + ๐ ๐ − 1 2 ๐ ๐ − ๐+1 2 = ε ๐ ๐(๐) − ๐+1 2 that must be negligible. So ε ๐ is negligible. 11 A secure variable length encryption The messages ๐1 , . . . , ๐๐ can be securely encrypted as ๏ก๐1 , ๐น๐ ๐1 ๏ ๐1 ๏ฑ , . . . , ๏ก๐๐ , ๐น๐ ๐๐ ๏ ๐๐ ๏ฑ. 12 Corollary 3.26 Let ๐น be a pseudorandom function. Then the scheme sketched in the previous slide is an arbitrary length private-key encryption scheme that has indistinguishable encryptions under CPA. 13 Pseudorandom permutations • Let ∗ ∗ ∗ ๐น โถ 0,1 × 0,1 → 0,1 be an efficient, length preserving, keyed function. ๐น is called a ๐๐๐ฆ๐๐ ๐๐๐๐๐ข๐๐ก๐๐ก๐๐๐ if for every ๐, the function ๐น๐ โ is one-to-one ๐ ๐ ๐น ๐๐ a ๐๐๐๐๐๐ก๐๐๐ . • A keyed permutation is efficient if there is a polynomial-time algorithm that will compute function ๐น๐ −1 ๐ฅ given ๐ and ๐ฅ . • A pseudorandom permutation is defined in a manner analogous to Definition 3.23, by replacing the term “function” by “permutation”. 14 Definition 3.28 Strong Pseudorandom permutations • Let F be an efficient keyed permutation. We say that ๐น is a strong pseudorandom permutation if, ๏ข PPT distinguishers D, ๏ค a negl function such that | Pr −1 ๐น โ , ๐น (โ) ๐ ๐ ๐ท 1๐ = 1 − Pr −1 (โ) ๐ โ ,๐ ๐ท 1๐ = 1 | ≤ negl(๐) where ๐ ← {0,1}∗ is chosen uniformly at random and f is chosen at random from the set of all permutations on n-bit strings. • The analogue for strong pseudorandom permutations are block ciphers. 15 Pseudorandom permutations modes of operation 1. Electronic Code Book (ECB) 2. Cipher Block Chaining (CBC) 3. Output Feedback (OFB) 4. Counter(CTR) 16 Pseudorandom permutations ๐1 ๐2 ๐3 ๐น๐ ๐น๐ ๐น๐ ๐1 ๐2 ๐3 Electronic Code Book (ECB) 17 Pseudorandom permutations IV IV ๐1 ๐2 ๐3 ๏ ๏ ๏ ๐น๐ ๐น๐ ๐น๐ ๐1 ๐2 ๐3 Cipher Block Chaining (CBC) 18 Pseudorandom permutations IV ๐น๐ IV ๐1 ๏ ๐1 ๐น๐ ๐2 ๏ ๐2 ๐น๐ ๐3 ๏ ๐3 Output Feedback (OFB) 19 Pseudorandom permutations ctr ๐1 ctr ctr+1 ctr+2 ctr+3 ๐น๐ ๐น๐ ๐น๐ ๏ ๐1 ๐2 ๏ ๐3 ๐2 ๏ ๐3 Counter mode (CTR) 20 Pseudorandom permutations modes of operation Electronic Code Book (ECB) ๐1 , ๐2 , … , ๐๐ ๏ฎ ๐น๐ ๐1 , ๐น๐ ๐2 , … , ๐น๐ ๐๐ Encryption is deterministic : no CPA-security Worse: ECB-mode does not have indistinguishable encryptions in the presence of an eavesdropper: if a block is repeated in the plaintext, the same block will be repeated in the ciphertext. 21 Pseudorandom permutations modes of operation Cipher Block Chaining (CBC) ๐๐ = ๐น๐ (๐๐−1 ๏ ๐๐ ). Encryption is probabilistic . ๐น๐ must be invertible. It has been shown that we get CPA-security if ๐น๐ is a pseudorandom permutation. Drawback: encryption is sequential. [Chained CBC: the last block of the previous ciphertext is the IV of the next ciphertext. Used in SSL 3.0 & TLS 1.0] 22 Pseudorandom permutations modes of operation Output Feedback (OFB) ๐๐ = ๐น๐ (๐๐−1 ), ๐๐ = ๐๐ ๏ ๐๐ . Unsynchronized stream-cipher mode. Encryption is probabilistic. It can been shown that we get CPA-security if ๐น๐ is a pseudorandom permutation. Drawback: both encryption and encryption are sequential. 23 Pseudorandom permutations modes of operation Counter(CTR) -- randomized counter mode ๐๐ = ๐น๐ (ctr + ๐), ๐๐ = ๐๐ ๏ ๐๐ , ๐น๐ need not be invertible. Encryption is probabilistic . It can been shown that we get CPA-security if ๐น is a pseudorandom function. Both encryption and encryption can be fully parallelized. We do not require that ๐น is a permutation (that is, it need not be invertible). 24 Chosen Ciphertext Attacks (CCA) In a CCA the adversary not only can encrypt messages of his choice (CPA) but also can decrypt ciphertexts of his choice (with one exception discussed later). Formally this is captured by giving the adversary access to a decryption oracle (as well as the encryption oracle). Let ๏= (Gen, Enc, Dec) be a private-key encryption scheme, ๐ด an adversary and ๐ the value of the security parameter. 25 CCA indistinguishability experiment cca PrivK (A, Π)(๐) 1. 3. 4. 3. A key ๐ is generated running Gen 1๐ . The adversaryA is given input 1๐ and ๐๐๐๐๐๐ ๐๐๐๐๐ ๐ ๐ก๐ En๐๐ โ ๐๐๐ De๐๐ โ ๐๐๐ outputs a pair of messages ๐0 and ๐1 of the same length. A random bit ๐ ๏ฌ 0,1 is chosen and then a ciphertext ๐๐ ๏ฌ En๐๐ ๐๐ is computed and given to A. The adversary A continues to have ๐๐๐๐๐๐ ๐๐๐๐๐ ๐ ๐ก๐ Enc๐ โ ๐๐๐ De๐๐ โ ๐๐ข๐ก ๐๐ ๐๐๐ก ๐๐๐๐๐ค๐๐ ๐ก๐ ๐๐ข๐๐๐ฆ ๐ท๐๐๐ โ on the challenge ciphertext ๐๐ itself. Eventually A outputs a bit ๐ ′ . The output of the experiment i๐ 1 if ๐ = ๐ ′ and 0 otherwise. 26 Indistinguishable encryptions under CCA --Definition A private-key encryption scheme Π has indistinguishable encryptions under CCA if ∀ PPT adversaries A, ∃ ๐ negl function with: Pr[PrivK cca (A, Π)(๐)=1] ≤ 1 2 + negl(n) where the probabilities is taken over the coins used in the experiment. 27 Insecurity of the encryption schemes that we have studied 1. .All earlier discussed private-key encryption schemes are not CCA-secure. 2. Example. Let ๐ โ ๏ก๐, ๐น๐ ๐ ๏ ๐๏ฑ , and suppose A chose๐ ๐0 = 0๐ and ๐1 = 1๐ , to get the ciphertext ๏ก๐, ๐ ๏ฑ. The adversary flips the first bit of ๐ to get ๐ ′ an asks for the plaintext of ๐ ′ = ๏ก๐, ๐ ′๏ฑ ≠ ๐ . If he gets 10๐−1 then ๐ = 0; if he gets 01๐−1 then ๐ = 1. 4. CCA implies non-malleability : by trying to modify the ciphertext the result is either an invalid ciphertext or one that decrypts to a plaintext that has no relation to the original. 28