cryptology course

124
Universit´ e de Marseille II, M1 2nd Semester 2006 Cryptology course By Christophe RITZENTHALER

Upload: phamdiep

Post on 04-Jan-2017

252 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Cryptology course

Universite de Marseille II, M1 2nd Semester 2006

Cryptology course

ByChristophe RITZENTHALER

Page 2: Cryptology course

2

Page 3: Cryptology course

3

These are notes of a course taught at Marseille in Second Semester 2006. They canbe found on www.iml.univ-mrs.fr/∼ritzenth.Please send comments and corrections to me at [email protected].

This course is deeply inspired by the following books :P. Barthelemy, R. Rolland, P. Veron, cryptographie, principes et mises en œuvre,Lavoisier (2005).J. A. Buchman, introduction to cryptography, second edition, Springer-Verlag 2004.

Page 4: Cryptology course

4

Page 5: Cryptology course

Contents

1 Why modern cryptography ? 131.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.2 Classical cryptography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

1.2.1 The shift cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151.2.2 The substitution cipher . . . . . . . . . . . . . . . . . . . . . . . 151.2.3 The Vigenere cipher . . . . . . . . . . . . . . . . . . . . . . . . . 151.2.4 The Hill cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

1.3 . . . and classical cryptanalysis . . . . . . . . . . . . . . . . . . . . . . . . 161.3.1 The substitution cipher . . . . . . . . . . . . . . . . . . . . . . . 171.3.2 The Vigenere cipher . . . . . . . . . . . . . . . . . . . . . . . . . 181.3.3 A known plaintext attack on the Hill cipher . . . . . . . . . . . . 21

1.4 New requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211.4.1 Steganography . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221.4.2 Future perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2 What is cryptography ? 252.1 Transmission of information . . . . . . . . . . . . . . . . . . . . . . . . . 25

2.1.1 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.2 Cryptography technics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

2.2.1 Encryption scheme . . . . . . . . . . . . . . . . . . . . . . . . . . 272.2.2 Secret key cryptosystem . . . . . . . . . . . . . . . . . . . . . . . 282.2.3 Public key cryptography . . . . . . . . . . . . . . . . . . . . . . . 282.2.4 Random functions . . . . . . . . . . . . . . . . . . . . . . . . . . 302.2.5 Hash function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

2.3 Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.3.1 Signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.3.2 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.3.3 Key management . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.3.4 More complex protocols . . . . . . . . . . . . . . . . . . . . . . . 332.3.5 Normalization and standardization . . . . . . . . . . . . . . . . . 33

2.4 Cryptanalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342.4.1 Attacks classification . . . . . . . . . . . . . . . . . . . . . . . . . 352.4.2 Keys length : where size matters . . . . . . . . . . . . . . . . . . 36

5

Page 6: Cryptology course

6 CONTENTS

3 Public key cryptography 373.1 RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3.1.1 Encryption-decryption scheme . . . . . . . . . . . . . . . . . . . 373.1.2 Practical construction . . . . . . . . . . . . . . . . . . . . . . . . 383.1.3 Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393.1.4 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433.1.5 Encryption and decryption scheme . . . . . . . . . . . . . . . . . 45

3.2 ElGammal encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463.2.1 The Diffie-Hellman problem . . . . . . . . . . . . . . . . . . . . . 463.2.2 ElGammal encryption scheme . . . . . . . . . . . . . . . . . . . . 473.2.3 Practical construction . . . . . . . . . . . . . . . . . . . . . . . . 483.2.4 Attacks and security . . . . . . . . . . . . . . . . . . . . . . . . . 48

3.3 Rabin encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493.3.1 Rabin encryption scheme . . . . . . . . . . . . . . . . . . . . . . 493.3.2 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

3.4 Signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503.4.1 RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503.4.2 ElGammal signature . . . . . . . . . . . . . . . . . . . . . . . . . 513.4.3 DSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

3.5 Key exchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533.6 Authentication : zero-knowledge proof . . . . . . . . . . . . . . . . . . . 54

3.6.1 Feige-Fiat-Shamir protocol . . . . . . . . . . . . . . . . . . . . . 553.6.2 Schnorr identification . . . . . . . . . . . . . . . . . . . . . . . . 55

4 Private key cryptography 574.1 Block ciphers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

4.1.1 Electronic Codebook Mode : ECB . . . . . . . . . . . . . . . . . 574.1.2 Cipher Block Chaining Mode : CBC . . . . . . . . . . . . . . . . 584.1.3 Cipher Feedback Mode : CFB . . . . . . . . . . . . . . . . . . . . 584.1.4 Counter Mode : CTR . . . . . . . . . . . . . . . . . . . . . . . . 59

4.2 DES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594.2.1 Feistel ciphers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604.2.2 Plaintext, ciphertext and keyspace . . . . . . . . . . . . . . . . . 604.2.3 General overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 604.2.4 Internal block ciphers . . . . . . . . . . . . . . . . . . . . . . . . 614.2.5 Keys generation . . . . . . . . . . . . . . . . . . . . . . . . . . . 624.2.6 Decryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624.2.7 Double DES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

4.3 AES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644.3.1 Plaintext, ciphertext and keys . . . . . . . . . . . . . . . . . . . . 644.3.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654.3.3 Internal procedures . . . . . . . . . . . . . . . . . . . . . . . . . . 654.3.4 Generation of the round keys . . . . . . . . . . . . . . . . . . . . 67

4.4 Differential cryptanalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Page 7: Cryptology course

CONTENTS 7

4.4.1 Last round detector . . . . . . . . . . . . . . . . . . . . . . . . . 694.4.2 A detector for differential cryptanalysis . . . . . . . . . . . . . . 69

5 Security 735.1 Different notions of security . . . . . . . . . . . . . . . . . . . . . . . . . 73

5.1.1 Formalization of the cryptosystem . . . . . . . . . . . . . . . . . 735.1.2 Formalization of the attacker . . . . . . . . . . . . . . . . . . . . 745.1.3 Formalization of security . . . . . . . . . . . . . . . . . . . . . . . 75

5.2 Security of ElGammal encryption . . . . . . . . . . . . . . . . . . . . . . 775.2.1 The decisional Diffie-Hellman problem . . . . . . . . . . . . . . . 775.2.2 Simple ElGammal algorithms . . . . . . . . . . . . . . . . . . . . 775.2.3 Cramer-Shoup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

6 Reviews and complements 836.1 Integers, congruences, Z/nZ . . . . . . . . . . . . . . . . . . . . . . . . . 83

6.1.1 Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836.1.2 Prime and factorization . . . . . . . . . . . . . . . . . . . . . . . 846.1.3 Representations of integers . . . . . . . . . . . . . . . . . . . . . 866.1.4 Congruences and Z/nZ . . . . . . . . . . . . . . . . . . . . . . . 87

6.2 Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.2.2 Conditional probability . . . . . . . . . . . . . . . . . . . . . . . 926.2.3 Perfect secrecy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936.2.4 Birthday paradox . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

6.3 Comparison of functions, complexity . . . . . . . . . . . . . . . . . . . . 956.3.1 Asymptotic behavior . . . . . . . . . . . . . . . . . . . . . . . . . 966.3.2 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966.3.3 Euclid algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 976.3.4 Probabilistic algorithms . . . . . . . . . . . . . . . . . . . . . . . 1006.3.5 Reduction of a problem . . . . . . . . . . . . . . . . . . . . . . . 101

6.4 Quadratic residues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026.4.1 Legendre, Jacobi symbols . . . . . . . . . . . . . . . . . . . . . . 102

6.5 Continued fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1036.5.1 Finite continued fraction . . . . . . . . . . . . . . . . . . . . . . . 1046.5.2 Infinite continued fraction . . . . . . . . . . . . . . . . . . . . . . 104

6.6 Finite fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056.6.1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056.6.2 Irreducible polynomials . . . . . . . . . . . . . . . . . . . . . . . 1056.6.3 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

7 Tutorial : algorithms 1077.1 Prime numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

7.1.1 Primality test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077.2 Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Page 8: Cryptology course

8 CONTENTS

7.2.1 Trial division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1117.2.2 Pollard p− 1 method . . . . . . . . . . . . . . . . . . . . . . . . 1117.2.3 Quadratic sieve . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

7.3 Square roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1147.3.1 When p = 4k − 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 1147.3.2 When p = 4k + 1 : Shanks algorithm . . . . . . . . . . . . . . . . 114

7.4 Discrete Logarithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1167.4.1 Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1167.4.2 Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

7.5 About Cipher and Signature schemes . . . . . . . . . . . . . . . . . . . . 1247.5.1 RSA scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1247.5.2 Signature ElGammal . . . . . . . . . . . . . . . . . . . . . . . . . 124

7.6 Primality and factorization . . . . . . . . . . . . . . . . . . . . . . . . . 1257.6.1 Primality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1257.6.2 Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

7.7 Square root and DL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1257.7.1 Square root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1257.7.2 DL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

8 Travaux diriges 127

9 Devoirs 1319.1 Devoir 1 (a rendre 24-01) . . . . . . . . . . . . . . . . . . . . . . . . . . 1319.2 Devoir 2 (a rendre 06-02) . . . . . . . . . . . . . . . . . . . . . . . . . . 131

9.2.1 Enonce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1319.2.2 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

9.3 Devoir 3 (a rendre 27-02) . . . . . . . . . . . . . . . . . . . . . . . . . . 1339.3.1 Enonce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1339.3.2 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

9.4 Devoir 4 (a rendre 27-03) . . . . . . . . . . . . . . . . . . . . . . . . . . 1389.4.1 Enonce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1389.4.2 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

10 Devoirs surveilles 14310.1 Partiel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

10.1.1 Cours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14310.1.2 Arithmetique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14310.1.3 Probabilites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

10.2 Correction du partiel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14510.2.1 Cours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14510.2.2 Arithmetique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14510.2.3 Probabilite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

10.3 Examen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14810.3.1 Sujet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

Page 9: Cryptology course

CONTENTS 9

10.3.2 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15110.4 Exercice possible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15410.5 complement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15510.6 Fonction complement et DES . . . . . . . . . . . . . . . . . . . . . . . . 15510.7 Fonction complement et DES :solution . . . . . . . . . . . . . . . . . . . 15510.8 Annexe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

10.8.1 Chiffrement de Feistel . . . . . . . . . . . . . . . . . . . . . . . . 15610.8.2 Plaintext, ciphertext and keyspace . . . . . . . . . . . . . . . . . 15610.8.3 Survol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15710.8.4 Blocs internes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15710.8.5 Generation des cles de tours . . . . . . . . . . . . . . . . . . . . . 158

Page 10: Cryptology course

10 CONTENTS

Page 11: Cryptology course

Preface

This course is aimed at French student in fourth year at university with a mathematicalbackground. On a meta-mathematical point, cryptography is divided into two parts :the maths games based on number theory, algebraic geometry, combinatorics and thereal world, using network, chips, certificate, protocols . . . . Nowadays, these two partsare of equal importance but as a mathematician, my course deals mainly with the firstaspect. Still a few chapters will be devoted to real cryptography.

The mathematics used in this course are elementary, which does not mean that thecourse is easy ! Indeed, cryptography twists most of the use we could make on generalresults and it can be difficult to see at the end why a given scheme gives what we want.It may also be difficult for standard mathematicians which are not accustomed to judgea theorem according to its effectivity or to its efficiency. For instance, we all agree thatthere are infinitely many prime numbers, but can one produce one with 1000-digits ?And if yes, how fast can you do that ? One second or one year ?

11

Page 12: Cryptology course

12 CONTENTS

Page 13: Cryptology course

Chapter 1

Why modern cryptography ?

1.1 Introduction

We have an intuitive idea of what cryptography is : its fundamental objective (butnot unique) is to enable two people, usually referred to as Alice (A) and Bob (B) 1,to communicate over an insecure channel in such a way that an opponent, Oscar (O)(or Eve for Eavesdropper), cannot understand what is being said. This channel can bea telephone line or a computer network for instance. Note that the science of secrecyincludes two different approaches : the design of proper tools to insure secrecy which isstricto sensu cryptography (cryptographie) and the attacks of these tools to find outtheir weaknesses, called cryptanalysis (cryptanalyse). Thus the science that coversthese two parts is nowadays called cryptology (cryptologie).Cryptography has been used for long, mainly for military purposes. Going back to Cae-sar one finds the example of ‘the shaved slave’ : to transmit a message, one shaved theskull of a slave, wrote the message on top of it, waited till hair has grow again (!) andsent the slave. Besides the obvious slowness of the method, another drawback is thatthe secrecy of the information is based on the secrecy of the method : if for instancethe slave speaks, the message is known. This important notion was first written downby Auguste Kerckhoffs (1883). He gave the basic principles of (secret key) cryptography :

‘Il faut bien distinguer entre un systeme d’ecriture chiffre, imagine pour un echangemomentane de lettres entre quelques personnes isolees, et une methode de cryptographiedestinee a regler pour un temps illimite la correspondance des differents chefs d’armeeentre eux. Ceux-ci, en effet, ne peuvent a leur gre et a un moment donne, modifier leursconventions ; [. . . ] Un grand nombre de combinaisons ingenieuses peuvent repondreau but qu’on veut atteindre dans le premier cas ; dans le second, il faut un systemeremplissant certaines conditions exceptionnelles, conditions que je resumerai sous lessix chefs suivants :

1. Le systeme doit etre materiellement, sinon mathematiquement indechiffrable ;

1listen to the song (!) on http://www.iro.umontreal.ca/∼crepeau/CRYPTO/Alice-Bob.html

13

Page 14: Cryptology course

14 CHAPTER 1. WHY MODERN CRYPTOGRAPHY ?

2. Il faut qu’il n’exige pas le secret, et qu’il puisse sans inconvenient tomber entreles mains de l’ennemi; [. . . ]’

Hence, if the secrecy cannot be based on the method (this is still not always under-stood even nowadays by certain companies, see for instance the ‘secret’ A5 algorithm ofthe GSM norm for mobiles which has been reveled on internet), it has to be based onadditional secret information, called keys.

We will see in this chapter classical cryptosystems. Besides introducing the basicterminology, the aim of this chapter is to answer the questions : why this course ?Why do we have to use advanced mathematical tools ? We will see that the classicalcryptosystems are not satisfactory, either due to their mathematical weaknesses or dueto the changes in our needs.

1.2 Classical cryptography . . .

Let us introduce some terminology. The information that Alice wants to send to Bobwill be called plaintext (Message clair). She will cipher or encrypt (chiffrer) theplaintext to obtain a ciphertext (texte chiffre ou cryptogramme) with the help ofa key. Bob who knows the key will then decipher (dechiffrer) the ciphertext, whereasOscar, who does not, can try to decrypt (decrypter) it, in order to obtain the plaintext.

Definition 1.2.1. A (secret key) cryptosystem (cryptosysteme) is a three-tuple (P, C,K)where the following conditions are satisfied :

1. P is a finite set of possible plaintexts;

2. C is a finite set of possible ciphertexts;

3. K is a finite set of possible keys called keyspace (espace des cles);

4. For each K ∈ K, there is an encryption rule (fonction de chiffrement) EK :P → C and a decryption rule (fonction de dechiffrement) DK : C → P suchthat DK ◦ EK = Id.

Remark 1. We see already that the function EK must be injective. Moreover if P = C,EK and DK are bijective : they are permutations, inverse of each other.

Alice and Bob will employ the following protocol to use a specific cryptosystem.First they choose a random key K ∈ K. This is done when they are in the same placeand not being observed by Oscar, or, alternatively, when they do have access to a securechannel. At a later time, suppose Alice wants to communicate a message to Bob overan insecure channel. We suppose that this message is a string

x = x1x2 . . . xn

Page 15: Cryptology course

1.2. CLASSICAL CRYPTOGRAPHY . . . 15

for some integer n > 0, where each plaintext xi ∈ P. Each xi is encrypted using EK asyi = EK(xi). She sends the resulting ciphertext

y = y1y2 . . . yn

to Bob over the channel. When Bob receives y, he deciphers it using DK . If we apply thisprotocol, the privacy is in the difficulty for Oscar to find the key K. Let us present nowsome classical examples. We will first start with mono-alphabetic ciphers (the elementsof P are letters) and then move to more sophisticated poly-alphabetic ciphers.

1.2.1 The shift cipher

Let represent the 26 usual letters by elements in Z/26Z (for instance A 7→ 0, B 7→1, . . . Z 7→ 25). We consider then P = C = K = Z/26Z. If K ∈ K one defines

EK : x 7→ x + K.

The decryption rule is given by

DK : y 7→ y −K.

Remark 2. The case K = 3 is known historically as Caesar cipher. If we apply it tothe plaintext sauna we obtain vdxqd.In spite of its extreme weakness (there are only 26 possibilities for the key, so one cantest all of them till obtaining a coherent plaintext), it was used by South officers duringthe American Civil War and even by the Russian army in 1915.Oddly, this cipher was used again at the beginning of internet, in forums. It was calledROT-13 (with K = 13). The idea was not to cipher texts but to prevent someone toread involuntarily a message (end of a movie,. . . ).

1.2.2 The substitution cipher

The previous method can be seen as a particular case of permutation of letters. Allowinga random permutation is then an easy way to increase dramatically the number of keys: we can obtain 26! ≈ 4 · 1026 of them. Formally we have here P = C = Z/26Z andK = S26. The encryption and decryption rules for σ ∈ K are

Eσ : x → σ(x), Dσ : y → σ−1(y).

1.2.3 The Vigenere cipher

This is our first case of poly-alphabetic ciphers. Let m be some fixed positive integer.Define P = C = K = (Z/26Z)m. For a key K = (k1, . . . , km) ∈ K we define

EK(x1, . . . , xm) = (x1 + k1, . . . , xm + km)

Page 16: Cryptology course

16 CHAPTER 1. WHY MODERN CRYPTOGRAPHY ?

andDK(y1, . . . , ym) = (y1 − k1, . . . , ym − km).

Stricto sensu, the value m should be public. But we can make the system more difficultby assuming that the value m is secret as we will do (formally, it makes the accuratedefinitions of the sets a bit more complicated). Note that the case m = 1 is the shiftcipher.

1.2.4 The Hill cipher

Let m be some fixed positive integer. Define P = C = (Z/26Z)m and K = GLm(Z/26Z).Note that a matrix with coefficients in Z/26Z is invertible if and only if its determinantis coprime to 26. For a key K ∈ K we define

EK(x) = xK and DK(y) = yK−1.

As a special case we obtain the so called permutation cipher by using a permutationmatrix (i.e. matrices with exactly one 1 on a given line and column and 0 elsewhere).

Remark 3. We can notice that the Hill cipher is a generalization of Vigenere cipher.Indeed the Vigenere cipher with key K = (k1, . . . , km) is a Hill cipher with a matrix ofsize m + 1

1 0. . .

...1 0

k1 . . . km 1

and an entry x = (x1, . . . , xm, 0). Note that there will be in the final text a 0 at everym + 1 multiple positions that has to be canceled.

In conclusion, we see that this cryptographic constructions are based on two princi-ples (that we can mix) : substitutions of letters and affine transformations. We will seenow that how to attack them.

1.3 . . . and classical cryptanalysis

We have already seen in 1.2.1 that the shift cipher does not resist to a exhaustiveresearch. Of course, as a set of key is always finite, exhaustive research is always an

Page 17: Cryptology course

1.3. . . . AND CLASSICAL CRYPTANALYSIS 17

option and thus any cryptosystem can be theoretically broken. However, the opponenthas not an infinite power of computation or unlimited time so if the keyspace is too big(which means more than 260 keys) one must have to try clever methods. We presenthere attacks based on statistical properties.

1.3.1 The substitution cipher

A way to decrypt a ciphertext is to use statistical properties of the language. Variouspeople have estimated the relative frequencies of the 26 letters (or of any group of 2 or3 letters). For the case of English and French these probabilities are compiled in Tab.1.3.1, Fig. 1.1 and the most frequent pairs are in the table below.

letter English French letter English FrenchA .082 0.084 N .067 0.071B .015 0.010 O .075 0.052C .028 0.030 P .019 0.03D .043 0.041 Q .001 0.009E .127 0.172 R .060 0.065F .022 0.011 S .063 0.080G .020 0.012 T .091 0.07H .061 0.009 U .028 0.057I .070 0.073 V .010 0.013J .002 0.003 W .023 0.0004K .008 0.0005 X .001 0.004L .040 0.06 Y .020 0.003M .024 0.02 Z .001 0.001

English FrenchTH ESHE DEIN LEER ENAN RERE NTES ONON ERST TENT ELEN ANED SEND ET

Figure 1.1: English / French frequencies

One can use these tables to find the permutation key like we will show on the followingexample.

Example 1. Let us consider the following French ciphertext :wvzjxojukvnapzeikxzjtpkhojxkepfzvntkiktovxikzzaaikjxi kckzvbovaxkbqotk-twvojtzenazixktrkjtwvepkterjoikjn.

Page 18: Cryptology course

18 CHAPTER 1. WHY MODERN CRYPTOGRAPHY ?

The frequency analysis gives the following results : K (16), Z, J, T (9), V (8), O, I (7),X (6), A, E (5).K is likely to be E but then it is difficult to decide between Z, J, T. We use then pairscontaining K.IK (7), KT (4), KJ, XK (3).Among the pairs starting with E the most frequent is ES. So we will assume that T is S.The next one is EN so we will assume that J maps to N. Among the letters with secondfrequency, only Z is unassigned. We can suppose that Z maps to A.Among the pairs finishing with E the most frequent are DE,LE,RE. So I must be D,L orR. Now I is quite frequent as a letter so we will assume that I maps to the most frequentletter among them which is R. We can also think that X maps to D.So far we have

plain A D E N R Scipher Z X K J I T

which gives..and...e......red..s.e..nde.....tseres..dre....rendre.e......de...ses...ns.....rdes.ens...es..n.ren.Analysing the beginning of the sentence one recognize quand and the last letter must bet. It is then easy to complete the key :plain A B C D E F G H I J K L Mcipher Z C B X K F R Q E . . P Hplain N O P Q R S T U V W X Y Zcipher J O A W I T N V U . . Y .

and to decipher :quand on veut plaire dans le monde, il faut se resoudre a apprendre beau-coup de choses qu’on sait par des gens qui les ignorent (Chamfort, Maximeset Pensees).

1.3.2 The Vigenere cipher

The first step is to determine the integer m. A method is the so-called Kasiski test andanother one uses the index of coincidence.The Kasiski test was described by Friedrich Kasiski in 1863 (and by Babbage before him).It is based on the observation that two identical segments of plaintext will be encryptedto the same ciphertext whenever their occurrence in the plaintext is d positions apart,where d ≡ 0 (mod m). Conversely, if we observe two identical segments of ciphertext,each of length at least three, say, then there is a good chance that they do correspondto identical segments of plaintext.The Kasiski test works as follows. We search the ciphertext for pairs of identical segmentsof length at least three, and record the distance between the starting positions of thetwo segments. If we obtain several such distances di then we will conjecture that mdivides the gcd of the di’s.Further evidence for the value of m can be obtained by the index of coincidence. Thisconcept was defined by Wolfe Friedman in 1920, as follows

Page 19: Cryptology course

1.3. . . . AND CLASSICAL CRYPTANALYSIS 19

Definition 1.3.1. Suppose x = x1 . . . , xn is a string of n alphabetic characters. Theindex of coincidence of x, denoted Ic(x), is defined to be the probability that two randomelements of x are identical.

Suppose we denote the frequencies of A, . . . , Z in x by f0, . . . , f25 respectively. Wecan choose two elements of x in

(n2

)ways. For each i, there are

(fi2

)ways of choosing

both elements to be i. Hence we have the formula

Ic(x) =∑25

i=0 fi(fi − 1)n(n− 1)

.

Now suppose that x is a string of a given language text. Denote the expected proba-bilities of occurrence of the letters A, . . . , Z by p0, . . . , p25 respectively. Then we wouldexpect that

Ic ≈25∑

i=0

p2i = 0.065, 0.074 English/French,

since the probability that two random elements both are A is p20, etc. The same rea-

soning applies if x is a ciphertext obtained by means of any monosyllabic cipher (as theprobabilities are shifted).Suppose we start with a ciphertext y = y1 . . . yn that has been constructed by usinga Vigenere cipher. Define m substrings Y1 . . . Ym of y of lengths n/m by writing y incolumns in a m× n/m matrices and by taking the m rows (for instance with m = 5) :

Y1 : y1 y6 . . .Y2 : y2 y7 . . .

Y5 : y5 y10 . . .

If this is done and if m is indeed the key length then each Ic(Yi) should be roughlyequal to 0.065 (English) or 0.074 (French). On the other hand if m is not the key length,then the substrings Yi will look much more random, since they will have been obtainedby shift encryption with different keys. Observe that a complete random string will have

I ′c = 26(1/26)2 = 1/26 ≈ 0.038.

The two values are sufficiently far apart that we will often be able to determine thecorrect key length.

Once the key length obtained, how do we get the key ? It is useful to consider themutual index of coincidence of two strings.

Definition 1.3.2. Suppose that y = y1 . . . yn and y′ = y′1 . . . y′n′ are strings of n and n′

alphabetic characters respectively. The mutual index of coincidence of y and y′, denotedMIc(y, y′) is defined to be the probability that a random element of y is identical to arandom element of y′.

Page 20: Cryptology course

20 CHAPTER 1. WHY MODERN CRYPTOGRAPHY ?

Suppose we denote the frequencies of A, . . . , Z in y by f0, . . . , f25 and by f ′0, . . . , f′25

in y′. Then

MIc(y, y′) =∑25

i=0 fif′i

nn′.

Suppose that K = (k1, . . . , km) is the key. Let us see if we can estimate MIc(Yi, Yj).The probability that both characters are A in Yi, Yj is p−kip−kj , the probability thatboth are B is p1−kip1−kj ,etc. Hence we estimate that

MIc(Yi, Yj) ≈25∑

h=0

ph−kiph−kj =25∑

h=0

phph+ki−kj .

Observe that the value of this estimate depends only on the difference ki − kj . Forki = kj , this value is 0.065 (English) or 0.078 (French) whereas for a non zero differencethis value is less than 0.045. The idea is now to fix an Yi (with frequencies (fh), to shiftit by any of the 26 letters g (let us call Y g

i the result), then to compute for each Yj (withfrequencies (f ′h))

MIc(Yj , Ygi ) =

∑25h=1 fh−gf

′h

nn′=

∑25h=1 fhf ′h+g

nn′≈

25∑

h=1

ph−kiph−kj+g =25∑

h=1

phph+ki−kj+g.

When g = kj −ki the value of MIc should be close to 0.065 (English) or 0.078 (French).We obtain in this way (by varying also Yi) a set of differences and we can express allthe ki in terms of one of them. It is then enough to make another 26 attempts.

Remark 4. The Yi have been obtained by a shift cipher which is a particular case ofsubstitution. An alternative is then to apply the usual statistical methods of 1.3.1.

Example 2. Let us consider the French ciphertextbtcrijkietasxyjxaibwclcgemraiebbgxcckmatbxyijqutmpdwmhwmrkgemwvkieaqttvrbmcgmpnxpkbxxtsnudbasxupka.We must first determine the length of the key : between two xy we have an intervalof length 27 and between two kie we have 54. We can then suppose that the key is oflength 3. Let us compute the coincidence index :Y1 =BRKTXXBLEABXKTYQMWWKMKATBGNKXNBXK gives Ic(Y1) ≈ 0.079;Y2 =TIIAYAWCMIBCMBIUPMMGWIQVMMXBTUAUA gives Ic(Y2) ≈ 0.075;Y3 =CJESJICGREGCAXJTDHREVETRCPPXSDSP gives Ic(Y3) ≈ 0.050.Even if the last result is quite bad, we can believe that the value of m is correct.

We apply now the remark above :

• For Y1, the most frequent letter is k which should correspond to e. But then bwhich is also quite frequent should correspond to v which is not so likely. How-ever if we assume that x (which is also quite frequent) corresponds to e then bcorresponds to i. So we say that the first letter of the key is t.

Page 21: Cryptology course

1.4. NEW REQUESTS 21

• For Y2, the most common letter is m which we assume corresponds to e. So thesecond letter should be i.

• For Y3 we observe the sequence of the frequencies :

1, 0, 4, 2, 4, 0, 2, 1, 1, 3, 0, 0, 0, 0, 0, 3, 0, 3, 3, 2, 0, 1, 0, 2, 0, 0.

The gap 0, 0, 0, 0, 0 is characteristic of the letters v,w,x,y,z so the letter corre-sponding to p must be a.

The key is then tip and the plaintext:il n y aura pas de question sur le chapitre un relatif aux methodes decryptographie ancienne au partiel du mois de mars.

1.3.3 A known plaintext attack on the Hill cipher

So far we have considered only attacks on a single ciphertext. But let assume that theopponent knows several plaintexts and their ciphers. More exactly let us assume thathe knows m plaintexts Xi and corresponding ciphertexts Yi. Writing

Y1...

Ym

=

X1...

Xm

K

one sees easily that one can find in general the key K (if the matrix of the Xi’s isinvertible).

1.4 New requests

We have seen that the previous cryptosystems were quite sensitive to different kinds ofattacks, mainly statistical attacks. A good cryptosystem should avoid these attacks.Can we imagine a good mono-alphabetic cryptosystem ? As we have seen the size ofthe keyspace is bound by 26! which starts being a bit small according to the currentcomputation power. But these cryptosystems are also weak for another reason. Thesystems being open (like on internet) it is not rare to find protocols were the attackercan know pairs of plaintexts and their ciphers. Of course in this context mono-alphabeticcryptography is not possible. Neither is poly-alphabetic cryptography based on linearsystems as we have seen in 1.3.3. Thus modern cryptosystem must include a non-linearbehavior (see Chap. 4).Another important fact is that symmetric key cryptography is not sufficient anymore.With internet, it is not possible to assume that people can meet somewhere to exchangethe key. New cryptosystems have then to be designed. They belong to a new familycalled public key cryptography (cryptographie a cle publique) (see Chap. 3). Notealso that we want these cryptosystems to be as fast as possible. Thus the size of the keyis going to be a constraint.

Page 22: Cryptology course

22 CHAPTER 1. WHY MODERN CRYPTOGRAPHY ?

Besides the encryption of the text we have to deal with issues on the protocol : howto be sure that Alice is the sender ? How to be sure that the message has not beenmodified ? Encryption is not enough for that and we will need to introduce new notions(signature for instance). See Chap. 2.Our cryptography techniques are based on mathematical tools which are convenient forcomputers applications. However cryptography is not limited to the present content andwe will briefly mention below other directions in cryptography.

1.4.1 Steganography

Unlike cryptography which ciphers text to make them incomprehensible, steganography(steganographie) hides texts in a support which can be a casual text or a picture. Thecase of Caesar’s slave may be seen as an example of steganography. Special invisible inksare another one and were used during second World War. A more recent example is thefive messages published in Liberation newspaper by the mysterious group AZF in March2004. We refer to http://www.apprendre-en-ligne.net/crypto/menu/index.htmlfor beautiful examples, among other :

• La dame de la Lune.

• Les lettres de Georges Sand.

• Les images numeriques.

Note that the last one arouses a lot of interests nowadays in relation with the problemof copyright. This application is known under the name of watermarking (tatouageelectronique). The idea is to mark an image in such a way that one cannot removedthis mark. This has a lot of constrains :

• To respect the quality of the picture, i.e. it has to be invisible for the user.

• To be resistant to transformations (compressions, filters, partial selection, or print/scan).

• To be resistant to direct attacks.

The most promising methods rely on frequency analysis (via Fourier transformation),in order to write the information in medium frequency (invisible for the eye but whichcannot be modified by compression).

1.4.2 Future perspectives

Can we imagine perfect secrecy ? The perfect cryptography exists : it is called Vernamone-time-pad (masque jetable) and was used to secure the red line between Washing-ton and Moscow. It is simply a Vigenere cipher whose key is as long as the plaintextand used only once (see 6.2.3) ! Of course, this is not the perfect solution : the problemis the transport of the key and this is not suitable for large internet protocols.Quantum cryptography may solve this issue. The principle is to use the quantum be-havior of photon to make impossible the reading of the message by an opponent without

Page 23: Cryptology course

1.4. NEW REQUESTS 23

destroying it. For technical details see http://www.bibmath.net/crypto/moderne/quantique.php3 or http://www.apprendre-en-ligne.net/crypto/menu/index.html.At the same time, quantum physic may announce the end of current cryptography : in-deed, existence of quantum computers may solve factorization problems (and breakRSA) in polynomial time !Let us mention that cryptography has also looted other areas of mathematics : braids(completely broken since, see [CJ03]), chaos, algebraic geometry,. . . See a nice presen-tation in Dossier Pour la Science, l’art du secret - La cryptographie, 36, Juillet 2002.

Page 24: Cryptology course

24 CHAPTER 1. WHY MODERN CRYPTOGRAPHY ?

Page 25: Cryptology course

Chapter 2

What is cryptography ?

2.1 Transmission of information

Transmission of information raises at least three categories of issues :

• Representation of information, how to code it, how to compress it. We studyhow to use words in a given alphabet to represent different information (text,image,etc.). As underlying problem, one wants to represent this data with theminimal space. This is the problem of data compression.

• Integrity of data, detection and correction of errors. Note that in the secondproblem, the errors come from noise on the channel and are not errors made onpurpose.

• Security of information, confidentiality.

The third point is the aim of this course.

Several mathematical tools are used to solve these problems :

• logic, complexity theory ;

• combinatorics, probability, statistics, entropy ;

• arithmetic ;

• commutative algebra, algebraic geometry.

2.1.1 Security

The following list gathers a short description of the main problems we are going to dealwith, some of them are strongly related :

• secrecy, confidentiality, cipher. The data have to be understandable only by theauthorized persons. More precisely : the confidentiality (confidentialite) is the

25

Page 26: Cryptology course

26 CHAPTER 2. WHAT IS CRYPTOGRAPHY ?

property that an information is not available or disclosed to unauthorized persons,entities or processes (Norm ISO 7498-2). In particular, during a communication,the purpose is to prevent a third party to get information contained in a messagetransmitted on a non secure channel.

• data integrity. One wants to avoid that transmitted data may be modified orforged by an opponent. More precisely, integrity (integrite) is the way to preventan unauthorized modification of the data. Attacks against integrity are calledsubstitutions.

• authentication. Authentication (authentification) consists of checking the iden-tity of the different elements involved in a communication. It can be a person(in that case one speaks also about identification) or a machine (in a open net-work -web- or in a close network -cash machine-). In the case of a message onewants to prove its origin. Attacks against authentication are called masquerade(mascarades).

• non-repudiation. Non-repudiation is a mechanism to prevent to deny a contract.One wants for instance to prove that a message was well sent or well received. Theauthor cannot deny that he wrote it.

• signature. Signature is a mechanism to prove authentication of the sender, in-tegrity of data and non-repudiation. Attacks again signatures are called forgery(falsification).

• certification. Certification is the way, a trusted entity validates a certain informa-tion.

• key management. key management (gestion des cles) is the difficult problem ofdistribution, integrity,. . . of the keys.

• proof. In general, an entity (prover, P) wants to prove to another one (verifier,V) that it is in possession of a secret (password for instance). In some cases, onerequests that this proof (preuve) is done without giving any information on theinitial data. One speaks then about zero-knowledge proof (preuve a divulgationnulle).

In this course we are going to focus on elementary bricks with which we will buildmore complex systems :

• Cipher ;

• Signature ;

• Authentication ;

• Key exchange.

Page 27: Cryptology course

2.2. CRYPTOGRAPHY TECHNICS 27

2.2 Cryptography technics

2.2.1 Encryption scheme

We have already seen a definition in Def. 1.2.1. Here we will extend the latter in orderto include asymmetric cryptosystems.

Definition 2.2.1. A cryptosystem (cryptosysteme) is a three-uplet (P, C,K) suchthat :

1. P is a finite set of possible plaintexts ;

2. C is a finite set of possible ciphertexts ;

3. K is a finite set of possible keys ;

4. for each e ∈ K, there exists a d ∈ K such that there exists an encryption functionEe : P → C and a decryption function Dd : C → P satisfying Dd ◦ Ee = Id.

In the case where e = d, one speaks about symmetric or secret key cryptosystems.Obviously, the key e must be secret. We have seen that the secure key exchange is thenan important issue.If e and d are distinct, one speaks about asymmetric or public key cryptosystems. Insuch system the encryption key can be made public, so e is called the public key and dis called the private key.

Figure 2.1: symmetric vs asymmetric systems

One can wonder why secret key cryptography has no completely disappeared withthe introduction of public key cryptography. Indeed the latter offers a solution to theproblem of key exchange and moreover in a open system with n entities, it is easy to seethat the number of keys to communicate is 2n with asymmetric when it is n(n− 1) forsymmetric cryptography. The reason is simple : asymmetric cryptography is about 1000slower than symmetric cryptography. Most of the present systems work then with bothencryption : first the entity exchanges via an asymmetric protocol a message which isthen used as a key to establish a symmetric protocol between the two entities.

Page 28: Cryptology course

28 CHAPTER 2. WHAT IS CRYPTOGRAPHY ?

2.2.2 Secret key cryptosystem

Important construction principles are confusion and diffusion. They were introduced byShannon who studied the security of cryptosystem in the context of information theory.The confusion of a block cipher is high, if the statistical distribution of the ciphertextsdepends in a complicated way on the distribution of the plaintexts. So an attackercannot extract information on the plaintexts from the distribution on the ciphertexts.For instance shift cipher has a very low confusion and more generally linear ciphers arebad. For this reason, modern ciphers always include a non linear operation.The diffusion of a block cipher is high if each bit of the plaintext and each bit of the keyhave an influence on many bits of the ciphertext.

Example 3. Here is a list of examples, some of them will be studied in the course.

• DES (Data Encryption Standard, see 4.2). It is ANSU X3.92 standard suggestedin 1974, published in the Federal Register in 1975 and accepted as standard in1977. It uses 56 bits keys (completed with 8 bits of parity checking) and plain-texts/ciphertexts are coded on 64 bits. This system is considered now as weakbecause of the small size of the keys. It is still used in 3-DES.

• 3-DES. One composes three circuits in the following way : one uses two DES keysk1, k2. One ciphers the plaintext with k1, deciphers with k2 and ciphers again withk1. See in 4.2.7 why one cannot use a double DES.

• AES (Advanced Encryption Standard, see 4.3). The new American standard sug-gested to replace DES. Build in 1998 by J. Daemen and V. Rijmen under the nameRijndael (pronunce ‘Rhine dahl’), it became the standard FIPS-197 in 2001. Thereis a choice for the key : 128, 192 or 256 bits. Although Rijndael proposes a choicefor the size of blocks, the standard AES has kept only the size 128 bits.

• MISTY1, Camellia, SCHACAL-2 are other cryptosystems which have been selectedby the European project NESSIE (New European Schemes for Signatures, Integrityand Encryption).

2.2.3 Public key cryptography

To Construct a secure symmetric cryptosystems is mathematically equivalent to find agood one-way function (fonction a sens unique). It is a function f which is easyto compute but difficult to inverse (i.e. f−1(y) is difficult to compute for almost ally). See 6.3.4 for a precise definition. Intuitively, we will say that something is easy tocompute if one can do it in polynomial time and something is difficult if it is not. Goodcandidates seems to be problems in the class NP. However this is not completely true asan NP-problem can be hard in bad cases but easy for a big number of other examples.Moreover we do not know if P 6= NP. The question is difficult. Actually, nobody knowsif there exists one-way functions but a lot of functions seems to play this role in practice.Note also that one can distinguish between exponential and sub-exponential algorithms.

Page 29: Cryptology course

2.2. CRYPTOGRAPHY TECHNICS 29

This distinction has direct consequences on the size of the keys (160 or 1024 bits). Thus,good cryptosystems are the one for which no subexponential attack is known.To obtain an efficient cryptosystem, one has to require a last condition : the functionf must become easy to inverse if one knows a secrete value : such functions are calledtrapdoor one-way functions (fonction a sens unique avec trappe).

We give here the most used problems :

Factorization. Given a number n which is the product of two big prime numbersn = pq, determine p and q. There are several (non-polynomial algorithms) to attackthis problem, see 7.2 :

• Eratosthenes sieve : trying all prime numbers up to√

n is of course an exponentialmethod.

• Pollard ρ-method ;

• Pollard p− 1 method : It is an exponential method but very efficient when p− 1has only small prime factors ;

• continued fractions ;

• elliptic curves methods ;

• multiple polynomial quadratic sieve ;

• number field sieve.

These last four are subexponential. This problem is used in RSA, RSA signature (see3.1, 3.4.1).Square roots. Let p be a prime number greater than 2 and x a square in Z/pZ. It ispossible to compute square roots. If p ≡ 3 (mod 4), x

p+14 is a solution. If p ≡ 1 (mod 4),

Shanks algorithm is used (see 7.3.2). If n = pq is the product of 2 big prime numbersdistinct and if p and q are known, the square root can be computed using the Chineseremainder theorem (theoreme du reste chinois). But if p and q are unknown, theproblem is difficult (in some sense as difficult as factorization). This is used in Rabinencryption, see 3.3.Discrete logarithm problem (DLP). Let G be a commutative group and H a finitecyclic subgroup generated by an element a. Given an find n is called the discretelogarithm problem (probleme du logarithme discret). In some groups this problemis difficult, for instance the multiplicative group of Z/pZ (or more generally of a finitefield). There are also several way to attack the problem, see 7.4.2 :

• Pollard ρ method ;

• giant step, baby step (Shanks) ;

• Pohlig and Hellman method ;

Page 30: Cryptology course

30 CHAPTER 2. WHAT IS CRYPTOGRAPHY ?

• Index calculus : Adleman, Coppersmith.

Index calculus methods leads to sub-exponential algorithms for finite fields. Howeverfor other groups (elliptic curves) it is not the case. This problem is used in 3.2 and 3.4.2and 3.4.

Remark 5. Shoup [SHO97], generalizing a result of Nechaev has shown that if p isthe largest prime dividing the group order, a generic algorithm to solve the DLP with aprobability bounded away from zero has to perform O(

√p) operations.

Example 4. Some asymmetric cryptosystems:

• Diffie-Hellman. This was the first protocol using public key cryptography. It isused for key exchange (see 3.5).

• RSA (Rivest-Shamir-Adleman). This system is based on the difficulty of factoriza-tion of a product of two prime numbers. Associated with KEM (Key encapsulationMechanism) (encodage) it has been selected by NESSIE.

• ElGammal. This system is based on the difficulty of the Discrete Logarithm prob-lem in some groups.

• PSEC (Provable Secure Elliptic Curve Encryption). It is based on computationon the group of points of an elliptic curve. Associated with KEM, it belongs toNESSIE.

• Rabin. This system is based on the difficulty to compute the square root modulo aproduct n of two unknown prime numbers.

• McEliece. This system is based on the difficulty to decode in the error-codingtheory.

2.2.4 Random functions

Cryptographic protocols often use random elements. A difficult question is how to pro-duce these elements. On one hand, ‘nature’ supplies hardware-based generators like theradioactive decay or the time between two keyboard strokes.However it is often too time-consuming to generate true random numbers, then pseudo-random numbers are used. Intuitively a pseudorandom generator can be described asan algorithm that, given a short sequence of bits, produces a long sequence of bits thatlooks random. Of course since the algorithm is deterministic, this explains the ‘pseudo’.M. Blum and S. Micali formalized this notion.

Definition 2.2.2. If D, D′ are two distributions, a distinguer (distingueur) of Dand D′ is a probabilistic polynomial algorithm A such that there exists a polynomial Psatisfying

|Pr(A(y) = 1)− Pr(A(y′) = 1)| > 1P (n)

for all y ∈ D, y′ ∈ D′ of length less than n.

Page 31: Cryptology course

2.2. CRYPTOGRAPHY TECHNICS 31

Definition 2.2.3. Two distributions D, D′ are called undistinguishable (indistinguables)if for all probabilistic polynomial algorithm A and for n big enough, A is not a distinguerof D and D′. If D′ is the uniform distribution, D is called a pseudorandom (pseudo-aleatoire) distribution.

We assume now that D′ is a uniform distribution.

Definition 2.2.4. If D is a distribution of bits, a predicator (predicateur) of D is aprobabilistic polynomial algorithm A such that there exists a polynomial P satisfying

Pr(A(y1 . . . yi) = yi+1) >12

+1

P (n)

for all y ∈ D of length n and i < n.D is called unpredictable (impredictible) if such an A does not exist.

Theorem 2.2.1. A distribution D is pseudorandom if and only if it unpredictable.

Definition 2.2.5. A pseudorandom generator (generateur pseudo-aleatoire) is adeterministic polynomial algorithm G such that for all input x of G, one has |G(x)|2 >|x|2 and G(x) is pseudorandom when |x|2 7→ ∞.

A pseudorandom generator has been constructed by L. Blum, M. Blum and M. Shub.Let p, q be two big prime numbers congruent to 3 modulo 4. Let x0 be a quadratic residuemodulo n = pq. The distribution D = y1 . . . yn is defined by xi ≡ x2

i−1 (mod n) andyi = xi (mod 2). This generator has been proved secure. Unfortunately it is too slowfor several applications.

2.2.5 Hash function

Definition 2.2.6. Let Σ be an alphabet. Let denote by Σ∗ the set of all words. A hashfunction (fonction de hachage) is a map h : Σ∗ → Σn for some n.

Example 5. The map that sends b1 . . . bk in {0, 1}∗ to b1 ⊕ . . .⊕ bk is a hash function.

For cryptographic purposes, we add two conditions :

• it must be hard to determine a pre-image of an element.

• it must be resistant to collisions which means that it is practically impossible tofind two messages x1, x2 such that h(x1) = h(x2).

As h is never injective, these two properties can be realized only because of the inex-tricability of the computations. Due to the birthday paradox (paradoxe des anniver-saires), the second condition requires a size of n which is nowadays 128 bits at least(see 6.2.4).

Example 6. Among the current hast functions, let us mention : SHA0, SHA1 (SecureHash Algorithm) on 128, 160, 224, 256, 384, 512 bits, MD5 (Message Digest) on 128 bits,Whirlpool on 512 bits (this one has been selected by NESSIE).Note that some of these functions have been recently successfully attacked (i.e. findingcollisions): SHA0 and MD5 have been broken.

Page 32: Cryptology course

32 CHAPTER 2. WHAT IS CRYPTOGRAPHY ?

2.3 Protocols

Besides the classical encryption-decryption scheme, we will describe the following pro-tocols.

2.3.1 Signature

Signature algorithms are made of several parts and can be schematized by:{

Message + Alice’s private key = SignatureMessage + Signature + Alice’s public key = Yes/No

Let us assume that A wants to sign an already ciphered message y. The user A has apublic key eA and a secret key dA. A digest m of the message y is computed with a hashfunction h, m = h(y). There is then a signature function S with which one computess = S(dA,m) called the appendix of the signature. A transmits then the couple (y, s).To verify the signature, the system produces also a verification function V such thatV(eA, y, s) is ‘true’ (or 1) if and only if the message y is signed by A. We will denote bySA the signature function of A, i.e. the function SA(y) = (y,S(dA, h(y))), and

VA(y, s) =

{0 if (y, s) 6= SA(y),1 if (y, s) = SA(y).

Notice that this process implies non-repudiation. Indeed, since everybody knows thekey eA and since only A can produce SA(y), everybody can check that the signature isA’s one.

Example 7. Here are some examples of signature with appendix.

• RSA, see 3.4.1. It is a ‘reverse’ RSA : the one who signs does it with its privatekey. Everybody can check with the public key of A that it is the right signature.Associated with the encapsulation PSS (Probabilistic Signature scheme), this wasselected by NESSIE.

• DSS (Digital Signature Standard, see 3.4). Use DSA (Digital Signature Algorithm)based on the discrete logarithm in (Z/pZ)∗ or ECDSA (Elliptic Curve Digital Sig-nature Algorithm) based on the discrete logarithm in an elliptic curve. ECDSAhas been selected by NESSIE.

2.3.2 Authentication

One can think about using signature to obtain authentication. But the requirements area bit different. For instance, authentication does not require non-repudiation. Moreoverwith signature everybody can verify the signature. However, authentication may requireto prevent re-play (rejeu), i.e. prevent that data can be reused (for instance that a checkis shown twice). This can be achieved by a dating (datation) system.

Page 33: Cryptology course

2.3. PROTOCOLS 33

Example 8. Here are some of the most well known authentication systems:

• Feige-Fiat-Shamir authentication system based on the difficulty to extract a squareroot modulo n = pq, see 3.6.1.

• It is possible to construct MAC (Message Authentication Code) by using secretciphers (DES, AES).

• UMAC (accepted by NESSIE) which uses a interesting family of hash functions(see [BHKKR99]).

2.3.3 Key management

All these protocols assume at some points that one can trust that the couple (dA, eA)really belongs to A and is valid. These problems are part of the PKI (Public keyinfrastructure (Infrastructure de gestion des cles)). The key creation can be donelocally or through a Key Distribution Center (centre de distribution des cles).Then the public key is registered by a certifying authority (autorite de certification)which gives a certificate (certificat) to the user. It contains the public key, the name ofthe user, the name of the certifying authority and a deadline. Eventually this certificateis signed by the certifying authority with its own private key. The other users know thepublic key and can check the certificate.

2.3.4 More complex protocols

Here are some concrete applications of the previous tools :

• PGP (Pretty Good Privacy) : this system provides encryption and signature. Itcan be used for emails or commercial transactions.

• Kerberos : a complete system with which the clients get from a key distributioncenter a session key to communicate with a server.

• Station to station protocol : this system uses symmetric and asymmetric encryp-tion and also authentication procedure.

• SSH : protocol for networks to get a secure connection with a machine.

2.3.5 Normalization and standardization

These questions are always important in computer science. Recall that standards aredefined de facto when the norms are defined de jure by an organism :

• NIST (National Institute of Standards and Technology) which publishes FIPS(Federal Information Processing Standards), for instance FIPS 140-1 and 140-2;

• ISO (International Standards Organization); Concerning information security, letus mention the norms ISO 17799 and ISO 15408;

Page 34: Cryptology course

34 CHAPTER 2. WHAT IS CRYPTOGRAPHY ?

Figure 2.2: How PGP encryption work

• ANSI (American National Standards Institute);

• ITU (International Telecommunication Union);

• ECMA (European Computer Manufacturers Association);

• IEEE (Institute of Electrical and Electronics Ingineers);

• AFNOR (Association Francaise pour la NORmalisation).

In the case of internet, standards are called RFC (Requests For Comments). One canaccess them on http://www.rfc-editor.org. There are two noteworthy subcategories: the STD which are the official standards and the FYI (For Your Information) whichare tutorials.

2.4 Cryptanalysis

Cryptanalysis is the part of cryptology that deals with attacking cryptosystem. It is ofcourse a way to make them more secure by finding their weaknesses. The main aim isof course to break the cryptosystem, i.e. to determine the plaintext or the secret key.One can also ask to find parts of the text. If the ciphertext does not allow to find anypartial information on the text, it is said semantically sure (semantiquement sur).But one can also see other purposes : forge a signature or modify a message withoutbeing spotted. We then have to define the level of security we want (see 5).To developed a security theory one has also to define the power of the opponent. Thesecurity is then based on the difficulty to manage some computations.Currently an average computer can realize during a human time 250 − 260 elementaryoperations. Thus the size of the keyspace has to be adapted according to the best attackknown (see 2.4.2).

Page 35: Cryptology course

2.4. CRYPTANALYSIS 35

Remark 6. Let us emphasize that there is no absolute proof of security. But undersome assumptions and attacks, one can prove that breaking a system is as hard as tosolve a problem, known to be hard. This game is the based of provable security.

2.4.1 Attacks classification

One has first to distinguish the level of the attack : directly against the core functions,against the protocol (mathematical or logical), or even against its implementation.

Example 9. For RSA, we have mentioned the attack against factorization (core functionattack). We will see other types (see 3.1.3) : protocol attacks, common module, smallprivate exponent, small public exponent or against the implementation (timing or poweranalysis attack).For classical cryptography we have seen in Chap. 1 several types of statistical attacks.We will add in 4.4 : differential or linear cryptanalysis (cryptographie differentielleou lineaire).

Furthermore, one has also to decide what kind of information the opponent canget. Following Kerckhoffs’ principle, the basic hypothesis is that the opponent knowseverything about the system except the secret key. One distinguishes several types :

• ciphertext-only attack (attaque a chiffre seul). The opponent knows only theciphertext.

• known plaintext attack (attaque a textes clairs connus). The opponent knowspairs of plaintext and ciphertext.

• chosen plaintext attack (attaque a textes clairs choisis) (CPA). The opponentcan get ciphers of chosen plaintexts but only before the plaintext to attack (calledchallenge.)

• adaptive chosen plaintext attack (attaque adaptative a textes clairs choisis).The opponent can get ciphers of chosen plaintexts before and after the challenge.

• chosen ciphertext attack (attaque a textes chiffres choisis) (CCA1). The op-ponent can decipher chosen ciphertexts before the challenge. For instance such anattack is possible if a cryptosystem is used for identification. This works as follows.Alice wants to make sure that she is connected to Bob. She sends an encryptedrandom number to Bob for which only Bob knows the decryption key. Bob decryptthe message and sends it back to Alice. An attacker can try to impersonate Alice.Instead of sending random numbers he sends messages of his choice.

• adaptative chosen ciphertext attack (attaque adaptative a textes chiffres choi-sis) (CCA2). The opponent can decipher chosen ciphertexts before and after thechallenge (apart from this latter).

Page 36: Cryptology course

36 CHAPTER 2. WHAT IS CRYPTOGRAPHY ?

In public cryptography, as everybody is allowed to cipher, CCA2 is the most powerfulattack. CCA attacks are called active attacks in contrast with the first three which are‘passive’ attacks (or CPA attacks). Nowadays security level for public key cryptographyis to ask that a system is semantically secure against CCA2 attacks.

2.4.2 Keys length : where size matters

Let us take the example of DES. To find the key, require on average #K/2 attempts.As the secret key is 56 bits long, one has 255 ≈ 1017 keys to try. So it would take :

• 39 days on 10000 Pentium (done in 1997).

• 2.5 days on a $250000 machine (1998).

• 35 minutes for $1000000.

The next results are extracted from a table created by K. Lenstra and E.R. Verheul.Considering that DES was in 1982 sufficiently secure for commercial applications, thistable gives an estimation of the size of keys in the future for an equivalent security. Fora symmetric system with a key of size b, the attack we consider is the one which runover 2b−1 elements (on average). For asymmetric systems, computations are based onthe best factorization or discret logarithm algorithms. To complete the table one appliesMoore law (the computer power doubles every 18 months).

symmetric RSA module size of the elliptic Number ofcryptosystems or DL in (Z/pZ)∗ group for curves years on a

year general DL PII 450 Mhz1982 56 417 102 105 1.11× 103

2005 74 1149 131 139 2.26× 108

2010 78 1369 138 146 3.22× 109

2015 82 1613 145 154 4.59× 1010

2020 86 1881 151 188 6.54× 1011

2025 89 2174 158 169 9.33× 1012

2030 93 2493 165 176 1.33× 1014

2040 101 3214 179 191 2.7× 1016

Page 37: Cryptology course

Chapter 3

Public key cryptography

In this chapter we will study with more details different asymmetric cryptosystems. Theidea was first presented in the seminal paper of Diffie and Hellman entitled New direc-tions in Cryptography. Although Diffie and Hellman invented the concept of public keycryptography in 1976 it was until a year or so later that the first system, namely RSA,was invented.The previous paragraph is how the ‘official’ history of public key cryptography goes.However in the late 1990s an unofficial history came to light. It turned out that in 1969,a cryptographer called James Ellis, working for the British government’s communicationheadquarters GCHQ, invented the concept of public key cryptography (or non-secret en-cryption as he called it). Ellis did not however have a system.The problem of finding such a public key encryption system was given to an new recruitto GCHQ called Clifford Cocks in 1973. Within a day Cocks invented what was essen-tially the RSA algorithm . In 1974 another employee at GCHQ, Malcolm Williamsoninvented the concept the concept of Diffie-Hellman key exchange. Hence by 1974 theBritish security services has already discovered the man techniques in public key cryp-tography.

3.1 RSA

3.1.1 Encryption-decryption scheme

Let n = pq be the product of two distinct big prime numbers. If φ denotes Euler function(see 6.1.4), one has

φ(n) = (p− 1)(q − 1).

Let e be a number coprime with φ(n). By Bezout theorem, there exists d such that

ed ≡ 1 (mod φ(n)).

Lemma 3.1.1. Let Ee(x) ≡ xe (mod n). This function defines a permutation of (Z/nZ)∗

with inverse Dd(y) ≡ yd (mod n).

37

Page 38: Cryptology course

38 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

Proof. By Fermat’s little theorem (see Cor. 6.1.3), one has

Dd ◦ Ee(x) ≡ xde (mod n) ≡ xkφ(n)+1 (mod n) ≡ x (mod n)

so the function Ee is injective, thus bijective and Dd is its inverse.

The cryptosystem RSA is given by

• P = C = (Z/nZ)∗;

• K is a subset of Z/nZ given by the elements e prime to φ(n).

• For e ∈ K one denotes by d an element such that ed ≡ 1 (mod φ(n)). ThenEe(x) ≡ xe (mod n) and Dd(y) ≡ yd (mod n).

A priori the security of RSA relies on the computation of φ(n). Clearly, if thefactorization of n is known, φ(n) also.

3.1.2 Practical construction

We have to find big prime numbers p, q. In general this is done by random choice of aninteger and then by a primality test. The fact that this procedure is efficient rely on thetwo following facts :

• The density of primes is high enough, see 6.1.2;

• There are fast algorithms to test primality. Usually one uses a probabilistic poly-nomial algorithm. Recently, a deterministic polynomial algorithm has been found.However its constants are still not as good as the probabilistic one. One picks aodd number and test if it is prime. If it is not one increases iteratively by 2 untilone finds one. See 7.1.1.

How does man find the encryption key e ? A way to do it is also to pick e randomlyand to test if gcd(e, φ(n)) = 1. If it is not the case, one picks another one. The numberm of distinct primes dividing φ(n) is less than log2(φ(n)) since

φ(n) ≥∏

p|φ(n)

p ≥ 2m.

By 6.1.2 we know that the number of primes less than φ(n) is equivalent to φ(n)/ log(φ(n))so the probability to find an integer 1 < e < φ(n) and coprime with φ(n) is greater than

φ(n)/ log(φ(n))−m

φ(n)∼ 1

log(φ(n)).

Such a number e can then be find in log(φ(n)) attempts.

Page 39: Cryptology course

3.1. RSA 39

Another solution is to construct a prime number strictly bigger than p and q andsmaller than φ(n). Or one may fix e from the beginning (for instance e = 3). Oneconstructs then p, q such that e does not divides p− 1 or q − 1. All these methods arefeasible in a good time.The computation of the exponent d is done by Euclid algorithm (see 6.3.3).The computation of xe (mod n), ye (mod n) can be done by the fast exponentiationmethod. One can make it even faster using the factorization of n and the Chineseremainder theorem. One gains a factor 4 but one has to be careful (see 3.1.3).

3.1.3 Attacks

As we have seen, attacks can be made at different levels.On the level of the function itself, a first question is of course, can we break RSAwithout factorizing n ? If not, it means that the difficulty of the problem depends onthe best known factorization algorithms, which are so far subexponential. The bestcurrent record is 200 digits (RSA200) which has 624 bits. Thus n must have 1024 bits.Unfortunately, the answer to this question is not known and one can give only somerelated results.

Proposition 3.1.1. Knowing φ(n) is equivalent to the factorization of n.

Proof. If p, q are known, one has φ(n) = (p− 1)(q − 1).Conversely, one has

(p− 1)(

n

p− 1

)= φ(n)

p2 − (n + 1− φ(n))p + n = 0

This equation can be solved in polynomial time.

Theorem 3.1.1. There is a Las Vegas algorithm taking the module n and e and usingan oracle which gives d and having for output the factorization of n.

Proof. Let us note that the equation

x2 ≡ 1 (mod n)

is equivalent to

x2 ≡ 1 (mod p)x2 ≡ 1 (mod q).

So the first equation admits 4 solutions, two of them are the trivial solutions ±1.If x is a non-trivial solution, n divides (x + 1)(x− 1) but none of the factors. Thus

gcd(x + 1, n) = p or q,

gcd(x− 1, n) = q or p.

Page 40: Cryptology course

40 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

Hence, if we know a non-trivial square root of 1 modulo n we can factorize n in polyno-mial time. How to compute such a root ?Let us pick a random element 1 < ω ≤ n− 1. If gcd(ω, n) > 1 we have a factor of n.Otherwise, using the oracle, we write ed− 1 = 2sr where s ≥ 1 and r odd. We have

ω2sr = ωed−1 = ωkφ(n)

soω2sr ≡ 1 (mod n).

Let t0 be the smallest integer such that

ω2t0r ≡ 1 (mod n).

If t0 > 0, we definev0 = ω2t0−1r.

Hence v0 6≡ 1 (mod n) but v20 ≡ 1 (mod n). Now if v0 6≡ −1 (mod n) we have a non-

trivial root of 1 modulo n.The algorithm fails if t0 = 0 or if there exists 0 ≤ t ≤ s−1 such that ω2tr = −1 (mod n).The number of such ω is less than φ(n)/4 according to Rabin’s theorem (see 7.1.1). Sothe probability at each round to get a good ω is bigger than 3/4. As each round needsa polynomial time we can conclude.

Note that this seems to be a good argument for the difficulty of RSA. But we havenot proved that it is not possible to decrypt without knowing d !We move now to attacks on the protocol.

• common module. It is a very simple attack. Let us assume that A1 and A2 aretwo users with the same RSA module n. Let eA1 (resp. eA2) the public key of A1

(resp. A2). First, A1 and A2 can know each other private key. But there is worst.Let us assume now that eAi are coprime. One can find x1, x2 such that

x1eA1 + x2eA2 = 1.

If B sends a message x to A1, A2 one has

yAi ≡ xeAi (mod n)

so O can compute x byx ≡ yx1

A1yx2

A2(mod n).

So two different users cannot use the same RSA module.

• small private exponent. In order to speed up the computations, in particular onsmall devices like smart card, one may want to choose a small exponent d. However

Page 41: Cryptology course

3.1. RSA 41

it is not a good choice as there exists an attack due to Wiener, based on continuedfractions (see 6.5). Consider

ed ≡ 1 (mod φ(n)),

this relation can be rewritten

ed = 1 + k

(n + 1

2− p + q

2

)

where k is an integer. So dividing by nd

∣∣∣∣2e

n− k

d

∣∣∣∣ =|2 + k(1− (p + q))|

nd,

so, if|2 + k(1− (p + q))|

n<

12d

then ∣∣∣∣2e

n− k

d

∣∣∣∣ <1

2d2.

This inequality shows that k/d is a reduction of the continued fractions develop-ment of 2e/n (see 6.5). If p, q have the same size p + q = O(

√n). Moreover since

|k| ∼ de/φ(n), we conclude that if d = O(n0.25) this attack works. It is enough tomake the continued fraction development of 2e/n and to check for each reductionif the denominator is a good candidate for d (by trying to factorize n). There existimprovements of this method, in particular Boneh-Durfee attack which works withd < n0.292.

• small public exponent, broadcast attack. Let us first look at a simple case. LetA1, A2, A3 be three users having for public keys (ni, 3). If B sends a message x toAis such that x < inf(n1, n2, n3) then Oscar gets by eavesdropping

y1 ≡ x3 (mod n1),y2 ≡ x3 (mod n2),y3 ≡ x3 (mod n3).

Using the Chinese remainder theorem, we get y ≡ x3 (mod n1n2n3). But asx3 < n1n2n3, one has y = x3 in N, Oscar can find x by taking a cubic root in N.Let us consider now the case of k users Ai with public keys (ni, ei) where the nis arecoprime. Let us assume that B sends a message x < inf(ni) to the Ai’s. In orderto avoid the previous attack, he adds noise with certain monic public polynomialsfi (which induces bijections on Z/niZ, called permutation polynomials), i.e

yi ≡ (fi(x))ei (mod ni).

Page 42: Cryptology course

42 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

Let gi = feii − yi. If k ≥ max(ei deg(fi)), Oscar can find m. In order to do so,

Oscar uses the Chinese remainder theorem and construct the polynomial function

g(u) =k∑

i=1

uigi(u),

where

ui ≡{

1 (mod ni)0 (mod nj) if j 6= i.

By multiplying each gi by an appropriate power of x, we can assume that deg(gi) =deg(gj) for i 6= j. As

∑ui may be taken equal to 1 (with ui = αi

∏j 6=i nj and αi

defined by∑

αi(∏

j 6=i nj) = 1) so g is monic.If n = n1 · · ·nk, x is the unique solution of

g(u) ≡ 0 (mod n)

such thatx < inf(ni) < n1/k ≤ n1/deg(g).

Oscar uses then the following theorem due to Coppersmith:

Theorem 3.1.2. Let n be an integer and g ∈ Z[x] a monic polynomial. LetX = n1/ deg(g)−ε for a certain ε > 0. It is then possible to compute in an efficientway the integers x such that g(x) = 0 and |x| < X. The computation time is boundby the time of the LLL algorithm on a lattice of dimension O(min(1/ε, log2(n))).

We move now to the last category of attacks.

• timing or power analysis, see [KJJ99]. If RSA is implemented on a smart card, onecan use an attack due to Kocher to find the key. The attack takes into accountthe usual multiplication and power d algorithms modulo n (for instance, a fastexponentiation algorithm). The difference of timing between these operations canbe used to estimate the bits of d. Actually, the attack is not so easy to perform.Kocher has also invented an attack based on the power consummation called powercryptanalysis (analyse de courant).

• default attack (attaque par defaut) . Let assume that to speed up the encryp-tion, the device uses the following method :

– Let ep ≡ e (mod p− 1), eq ≡ e (mod q − 1),– one has epd ≡ 1 (mod p − 1) and eqd ≡ 1 (mod q − 1) so y ≡ xep (mod p)

and y ≡ xeq (mod q),– one computes y (mod pq) with the Chinese remainder theorem.

If it happens that during the computation of y, one compute y′ ≡ xep (mod p) andy′ 6≡ xeq (mod q), one has gcd((y′)d−x, n) = p and one has factorized n. One canforce this mistake on a device (smart card) by applying a short electric impulse atthe right time for instance. Of course, modern cards intertwine the computationof the two elements in order to prevent this attack.

Page 43: Cryptology course

3.1. RSA 43

3.1.4 Security

What is the security of RSA ? Recall that intuitively semantic security means that itis not possible to get any information from the ciphertext. It can be proved that adeterministic encryption cannot be semantically secure. For instance, if e is odd, onehas for the Jacobi symbol (see 6.4.1):

(xe

n

)=

(xe

p

)(xe

q

)=

(x

p

)(x

q

)=

(x

n

).

Thus RSA is not semantically secure against passive attacks. On the other hand eventhis basic RSA does not give away some important information, as the parity.

Theorem 3.1.3. Let f be the function defined by

f(y) =

{0 if Dd(y) is even,1 if Dd(y) is odd.

If f can be computed practically, it is possible to decrypt every message.

Proof. First let us show that to compute f is equivalent to compute g defined by

g(y) =

{0 if Dd(y) ≤ n/21 if Dd(y) > n/2.

To do so, let 0 ≤ x < n such that y ≡ xe (mod n). Denote by y1 ≡ 2ey (mod n) andx1 ≡ 2x (mod n). We have

Ee(x1) ≡ (2x)e (mod n)≡ 2ey (mod n)≡ y1 (mod n)

If 0 ≤ x ≤ n/2 then x1 = 2x and x1 is even. If n/2 < x < n then x1 = 2x− n so x1 isodd and reciprocally. So

f(2ey) = f(y1) = g(y).

Nowg(2−ey) = f(2e2−ey) = f(y).

Thus, a polynomial algorithm to compute g gives a polynomial algorithm to compute fand reciprocally.Let us define now a polynomial algorithm in the size of n which uses the function g asan oracle. For all k ≥ 1, let denote

xk ≡ 2kx (mod n),yk ≡ Ee(2kx) (mod n)

Ik =2k−1−1⋃

q=0

[2qn

2k,(2q + 1)n

2k

[.

Page 44: Cryptology course

44 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

Figure 3.1: The Ik

I1

I2

0 n

We haveyk ≡ (2kx)e (mod n) ≡ 2kexe (mod n) = 2key (mod n).

If x ∈ Ik+1 then there exists q such that

2qn

2k+1≤ x <

(2q + 1)n2k+1

,

qn ≤ 2kx < qn +n

2,

so 0 ≤ 2kx (mod n) < n2 , 0 ≤ xk < n

2 and g(yk) = 0. Reciprocally, if g(yk) = 0 thenx ∈ Ik+1.In the same way, if x /∈ Ik+1, then there exists q such that

(2q + 1)n2k+1

< x <2(q + 1)n

2k+1,

qn +n

2≤ 2kx < (q + 1)n,

so n2 ≤ 2kx (mod n) < n, n

2 ≤ xk < n and g(yk) = 1. Reciprocally, if g(yk) = 1 thenx /∈ Ik+1.If y is given one can then compute in polynomial time for each value of k the value yk

and g(yk). One can then know if x ∈ Ik+1 or not. Denote

AN = ∩Nk=1χk

where χk = Ik (resp. {Ik) if x ∈ Ik (resp. x /∈ Ik). The set AN is an interval of lengthn/2N , so for N > log2(n), the length of the interval is less than 1 and it contains atmost one integer, x.

Remark 7. A bit of the plaintext which is as difficult to compute as the whole plaintextis called a hard-core bit (hard-core bit). We have shown that the last bit is a hard-corebit.

On the contrary if the adversary is more powerful, RSA falls completely.

Proposition 3.1.2. RSA is not secure against a CCA2 attack.

Proof. Suppose the message Oscar wants to break is y = xe (mod n). Oscar createsy′ = 2ey and asks the oracle to decrypt y′ and get x′. Now Eve can compute x′/2 =(2ex)d/2 = x.

Page 45: Cryptology course

3.1. RSA 45

3.1.5 Encryption and decryption scheme

The previous section showed us the necessity to perform RSA with a specific scheme toget security. Given a plaintext as a block of characters, how do we cipher it with RSA? The difficulty of inversion of RSA is not enough to ensure the security of the system.For instance if we decide to apply RSA on blocks of length 1 then a simple statisticalanalysis is enough to decrypt the ciphertext.We show here the RSAES-OAEP scheme (RSA Encryption Scheme- Optimal Asymmet-ric Encryption Padding), recommended in the directive PKCS#1v2.1 by RSA society.We start with M a message given by a sequence of octets. To encode we use the followingfunctions:

MEME-OAEP−→ m

OS2IP−→ xEe−→ y

I2OSP−→ C,

and to decode

COS2IP−→ y

Dd−→ xI2OSP−→ m

EME-OAEP−→ M.

Let us describe the missing procedures.The procedure OS2IP (Octet String to Integer Primitive) is very easy. If m = m1 . . .ml

where mi are octets (i.e. numbers between 0 and 28 = 255), one constructs

x =l−1∑

i=0

ml−i256i.

The value of |m|256 depends on the size of the module n, for instance |m|256 = |n|256−1.The procedure I2OSP is the inverse, i.e. it corresponds to the decomposition in base256 (see 6.1.3).The procedure EME-OAEP for encryption and decryption requires a hash function h(which gives a sequence of octets of length |h|256 > 16 i.e. which is without collisions),a public parameter P (which is a sequence of octets) and a pseudo-random function g(which takes a sequence of octets and an integer l and gives a sequence of octets of lengthl). One computes then a sequence PS of null octets of length |m|256−|M |256−2|h|256−1which is also bigger than 16. We concatenate

DB = h(P )||PS||00001111||M (|DB|256 = |m|256 − |h|256).

Now one picks randomly a sequence s of length |h|256 and one computes

DBmask = g(s, |m|256 − |h|256)maskedDB = DB ⊕DBmask

smask = g(maskedDB, |h|256)maskeds = s⊕ smask

m = maskeds||maskedDB

Page 46: Cryptology course

46 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

For decoding, one starts with m. The first |h|256 octets of m give us maskeds, the othersare maskedDB. One compute then

smask = g(maskedDB, |h|256)s = smask ⊕maskeds

DBmask = g(s, |m|256 − |h|256)DB = DBmask ⊕maskedDB

Is is now easy to reconstitute M .It has been shown that RSA-OAEP is semantically secure against a CCA2 attack (thisrelies on the hardness of the partial one-wayness of RSA, see [FOPS01]). This is notice-able as OAEP combined with another trapdoor one-way function is sure against CCA1but may not be against CCA2.

Remark 8. Originally it was believed that RSA-OAEP was plaintext-aware, i.e. that itis difficult to construct a valid ciphertext without being given the corresponding plaintextto start with. This implies that one cannot mount a CCA attack. Since to write down aciphertext requires you to know the plaintext, so why would you ask the decryption oracleto decrypt the ciphertext ? It is then a very strong notion of security but this propertyis not valid.

3.2 ElGammal encryption

Let p be a prime number. We know (see Prop. 6.1.9) that the multiplicative group(Z/pZ)∗ is cyclic. Let α be a generator and define

Eα(x) ≡ αx (mod p).

The inverse of Eα is called the discrete logarithm (logarithme discret), DL. The dis-crete logarithm problem, denote DLP, is finding the discrete logarithm of αx knowingp, α. This problem is NP and known to be difficult. The function Eα is a one-wayfunction and no trapdoor is known so far. Its use in a public cryptosystem will not bedirect.

3.2.1 The Diffie-Hellman problem

There are two types, the computational and decisional one. The computational Diffie-Hellman problem (probleme de Diffie-Hellman calculatoire), called CDH, is :

• Input : p is a prime number, α a generator of (Z/pZ)∗, αa (mod p), αb

(mod p);

• Output : compute αab (mod p).

Page 47: Cryptology course

3.2. ELGAMMAL ENCRYPTION 47

If one can solve the DLP in feasible time, we can clearly solve the CDH problem.The reciprocal is not known but one does not know examples where CDH is easy and notDLP. For some prime numbers, it has been proved that the two problems are equivalent.More precisely, if p− 1 is not divisible by the square of a big prime number, then CDHis not easier than DLP (see [MW99]).The decisional Diffie-Hellman problem (probleme de decision de Diffie-Hellman) is:

• Input : p is a prime number, α a generator of (Z/pZ)∗, αa (mod p), αb

(mod p) and y an integer;

• Output : Is y = αab (mod p) ?

If one can solve the computational Diffie-Hellman problem, one can solve the deci-sional one. The converse is generally not known. However, one knows groups where thedecisional problem is easy but where one does not know simple algorithm to solve thecomputational one (for instance a supersingular elliptic curve).

3.2.2 ElGammal encryption scheme

Let p be a big prime number such that p − 1 has a big prime factor q. Let α be anelement of order q in (Z/pZ)∗ (such an element exists because of Rem. 23). One callsH the subgroup generated by α.

P = (Z/pZ)∗;C = H × (Z/pZ)∗;Public key : p, α a generator of H of order q, β ≡ αa (mod p);Secret key : a ∈ [0, q − 2];Ee(x) ≡ (y1, y2) ≡ (αk (mod p), xβk (mod p) for a k ∈ [0, q − 2] which changes forevery x;Dd((y1, y2)) ≡ y2y

−a1 (mod p).

Note that the encryption is not deterministic : the parameter k is chosen randomly.This function has a trapdoor : if someone knows the DL a of β, he can easily constructx knowing the relation y2 = xya

1 but he cannot find k. There are some variants :

• It is possible to work on the entire (Z/pZ)∗ by taking α a primitive element. Pohlig-Hellman algorithm (7.4.2) shows that this does not provide a better security andone has to work with bigger exponents. Moreover the determination of a primitiveelement requires in any case the construction of a prime number q dividing p− 1(see 7.4.1).

• The modified ElGammal encryption is to restrict the plaintext space to H.

• A last variant works with an hash function h. One has for instance

y1 = αk (mod p), y2 = h(βk (mod p))⊕ x.

Page 48: Cryptology course

48 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

3.2.3 Practical construction

We have to construct p, q, α.

• Generate q. We pick a random number of a given size and apply a primality test.

• Construct p. We look for a prime number p of the given size in the arithmeticalprogression aq + 1. If it does not work, we modify the value of q. This procedurecan be carried out in average time of the size of p.

• Find α. We have p − 1 = sq. Pick randomly 0 < β < p until βs 6≡ 1 (mod p).Write α = βs.

3.2.4 Attacks and security

What are the size of p and q ? For any cyclic group G of order n, there exist two attacks: one is in O(

√n) (Shanks) and the other in O(

√t) (Pohlig-Hellman) where t is the

biggest prime factor of n (see 7.4.2). For this reason, q has 160 bits. In the particularcase where G = (Z/pZ)∗, there exists also a subexponential algorithm in the size of pcalled index calculus attack (methode de l’index) that we can apply also in a cyclicsubgroup H of order q. But one does not know how to apply it directly on H. So onehas to balance the values of p and q, for instance p of size 1024 and q of size 160 bits.What can we say about semantical security ? First note that the Legendre symbol of αis 1 (see 6.4.1). Indeed as q is big it is not 2, so q divides (p− 1)/2 and

p

)≡ α(p−1)/2 ≡ (αq)(p−1)/(2q) ≡ 1 (mod p).

So the Legendre symbol of y2 equal the Legendre symbol of x and the system is notsemantically secure.However the modify version (with x ∈ H) has always Legendre symbol equal to 1 (asx is a power of α). More precisely one can show that the semantical security againstknown plaintext attack is equivalent to the decisional Diffie-Hellman problem. But ifthe attacker is more powerful (CCA2), then the system is not semantically secure (forCCA1 it is not known), see ??. Moreover, another issue is to translate a plaintext inan element of H. This is inextricable apart from the case of Sophie Germain primesp = 2q + 1 : indeed the elements of H are the quadratic residues modulo p. So if0 ≤ x < q is a quadratic residue we keep it. Otherwise we change it in p− x. One hasthen : (

p− x

p

)=

(−1p

)·(

x

p

)= 1

because −1 is not a quadratic residue ((p − 1)/2 is odd). But this case is not reallyinteresting because the exponents are big.What happens if the messages are short ? D. Boneh, A. Joux and P. Nguyen have shownin [BJN00] that the version with hash function is not secure.

Page 49: Cryptology course

3.3. RABIN ENCRYPTION 49

Remark 9. One can think about other groups for the DL problem for which there is nosubexponential algorithm known. It is the case with an elliptic curve and the key size isthen less than 200 bits. The operations are a bit more difficult and all elliptic curves arenot secure (see [FL05]).

3.3 Rabin encryption

Given a prime number p it is easy to know if a number x is a quadratic residue, i.e. asquare modulo p and to find its roots if it is so (see 6.4). It is not the same if one workswith n = pq for p, q two big secret prime numbers. Indeed

Proposition 3.3.1. For every n = pq with p, q prime numbers and for every x which isa square modulo n, there exists a Las Vegas algorithm which computes the square rootsof x if the factorization of n is known.

Proof. One can compute the square roots of x modulo p and q (if necessary with Shanksalgorithm) and find the result with the Chinese remainder theorem.

And conversely:

Proposition 3.3.2. For every n = pq with p, q prime numbers there is a Las Vegasalgorithm which computes p and q if one uses an oracle giving a square root modulo nof any given square.

Proof. One picks randomly u and let a ≡ u2 (mod n). The oracle gives a square rootv of a. There is half a chance that u 6≡ ±v (mod n) and in this case one knows thatu2− v2 = kn, i.e. n divides (u + v)(u− v) but any of the factor. Thus gcd(n, u + v) = por q and the same for the other one.

Remark 10. On the contrary, nobody knows if to know if x (mod n) is a square or notis equivalent to the factorization of n. Note that the Jacobi symbol can be computed inpolynomial time but if it is equal to 1 one cannot conclude.

3.3.1 Rabin encryption scheme

Let n = pq for p, q two big prime numbers congruent to 3 modulo 4.

P = (Z/nZ);C = H × {−1, 0, 1} × {0, 1} where H is the subset of quadratic residues;Public key : n;Secret key : p, q;Ee(x) = (y, J, b) = (x2 (mod n), J, b) where J is the Jacobi symbol of x and b = 1 ifx ≥ n/2 and 0 otherwise;Compute the four roots of y : x1,−x1, x2,−x2. With J determine if x ∈ {−x1, x1}or in {−x2, x2}. Once the right pair determined, use b to determine the sign.

The decipher process relies on the following lemma:

Page 50: Cryptology course

50 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

Lemma 3.3.1. If p, q are prime numbers congruent to 3 modulo 4 then y, J, b as abovedetermine a unique root of y modulo n.

Proof. y has four roots ±xi modulo n. If u, v are such that u2 ≡ y (mod p) andv2 ≡ y (mod q) then one can assume that ±x1 ≡ ±u (mod p) (resp. ±v (mod q)) and±x2 ≡ ±u (mod p) (resp. ±x2 ≡ ∓v (mod q)). Thus

(±x1

n

)=

(±x1

p

)(±x1

q

)=

(x1

p

)(x1

q

)=

(u

p

)(v

q

)

because of the congruences of p and q modulo 4. Also(±x2

n

)= −

(u

p

)(v

q

)

so J allows us to choose between ±x1 and ±x2. Now b allows us to determine thesign.

3.3.2 Security

As the Rabin problem is as difficult as the factorization problem, the cryptosystem issure against a chosen plaintexts attack. In the contrary it is not secure against a chosenciphertext attack as we can use the decryption oracle to factorize n.

3.4 Signature

NIST has defined in FIPS 186-2 the signature standard DSS (Digital Signature Stan-dard). This standard is based on three types of signatures : RSA or ECDSA (EllipticCurve Digital Signature Algorithm), DSA (Digital Signature Algorithm).We will recall also the initial ElGammal signature algorithm.

3.4.1 RSA

Any public cryptosystem for which there exists a hash function with value in C can betransform into a signature scheme (such a function can be difficult to build for instanceif C = (Z/nZ)∗. It is the case for RSA.

Public key : e;Private key : d;Signature : y → (y, s) = (y,Dd(h(y))) ;Verification : check that Ee(s) = h(y).

Of course one has to follow a protocol (almost identical to RSA) for the signature(called RSASSA-PSS) in order to obtain sufficient security.It is also obvious that any attack against RSA is an attack against this signature.

Page 51: Cryptology course

3.4. SIGNATURE 51

Note that the hash function plays an important role. If it is not a one-way function,Oscar can realize the following attack: he computes h′ = re (mod n) for some random r.He can then compute a pre-image of h′, i.e. h′ = h(y′). He can then pretend that Alicesigned y′ since (y′, r). Of course y′ has probably no meaning but in certain protocolsthat does not play a role. Such a forgery is called an existential forgery (falsificationexistentielle).

If it is not collision resistant, Alice can break the repudiation condition: she findstwo messages y, y′ such that h(y) = h(y′) and sign (y, s). Later, she can say that shesigned (y′, s).

3.4.2 ElGammal signature

Let p be a big prime number and h a hash function with values in [0, p− 2]. We will usethe full multiplicative group G = (Z/pZ)∗. Let g be a primitive element.

Public key : (p, g, b) with b ≡ ga (mod p) ;Secret key : a ∈ [0, p− 2];Signature : y → (y, r, s) with r ≡ gk (mod p), s ≡ k−1(m − ra) (mod p − 1) withm = h(y) and k ∈ [1, p− 2] different for each signature;Verification : check that 0 ≤ r ≤ p − 1. If not reject the signature ; computem = h(y) ; compute v ≡ gm (mod p) and w ≡ brrs (mod p) ; Check that v = w.

To find the secret key is equivalent to solve a case of the DLP. Also it is not difficultto see that if a message y and r are fixed, finding a valid s if also a case of the DLP(from v ≡ brrs (mod p)). Last, if one fixes a message y and s one has to solve

gm ≡ brrs (mod p)

for which no algorithm is known.

It is important to check that 0 ≤ r ≤ p− 1. Otherwise, Oscar may create signaturesof meaningful documents starting from an old signature (this is call selective forgery(falsification selective)). Let (y, r, s) a valid signature and y′ a new message. To signy′, Oscar compute

u ≡ h(y′)h(y)−1 (mod p− 1).

Here we assume h(y) coprime to p− 1. Oscar also computes

s′ ≡ su (mod p− 1)

and using the Chinese remainder theorem, he determines r′ with

r′ ≡ ru (mod p− 1), r′ ≡ r (mod p).

The signature (y′, r′, s′) is valid. Indeed

br′(r′)s′ ≡ brursu ≡ gu(ar+ks) ≡ gh(y′) (mod p).

Page 52: Cryptology course

52 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

Moreover r′ ≡ r (mod p) but r′ ≡ ru 6≡ r (mod p − 1) (otherwise h is not withoutcollisions) implies r′ 6= r so r′ > p.

It is important to change the value of k. Suppose that y1 and y2 are signed bys1, s2 with the same k. Then the number r ≡ gk (mod p) is the same. Therefores1− s2 ≡ k−1(h(y1)−h(y2)) (mod p− 1). From this congruence k can be determined ifh(y1)− h(y2) is invertible modulo p− 1. Then the adversary can find the secret key a.

This signature may be attacked if g is a small divisor of p − 1. More precisely, oneassumes now that p = 4u + 1 and that p − 1 = gt. gt is a primitive element of acyclic subgroup H of order g and bt belongs to H. We suppose g small enough suchthat the DL in H is easy. We can then compute z such that gtz = bt. As g ∈ G isprimitive g(p−1)/2 ≡ −1 (mod p). Since gt ≡ −1 (mod p), (gt)(p−3)/2 ≡ (−1)(p−3)/2 ≡−1 (mod p). Then

g−1g(p−1)/2t(p−3)/2 ≡ −1 (mod p),

so t(p−3)/2 ≡ g (mod p).An attacker who wants to imitate the signature of A compute m = h(y), takes r = tand s ≡ (p− 3)(m− tz)/2 (mod p− 1). Under these conditions

ω ≡ bt(t(p−3)/2)(m−tz) (mod p)≡ btgm−tz (mod p),≡ btgmb−t (mod p),

so ω = v. This forged signature is then accepted as a signature from A.

Remark 11. If no hash function is used, there exist two other types of attacks duringwhich the attacker chooses particular couples (r, s) and makes a existential forgery. Letus present the first one. Let i, j be two integers such that 0 ≤ i ≤ p−2 and 0 ≤ j ≤ p−2.We look for r ≡ gibj (mod p). We want to satisfy

gy ≡ br(gibj)s (mod p)

which is equivalent to gy−is ≡ br+js (mod p). This is the case for instance if

{y − is ≡ 0 (mod p− 1)r + js ≡ 0 (mod p− 1)

.

These equations can be solved if gcd(j, p− 1) = 1. We obtain

r ≡ gibj (mod p)s ≡ −rj−1 (mod p− 1)y ≡ −rij−1 (mod p− 1).

Page 53: Cryptology course

3.5. KEY EXCHANGE 53

The second case is an existential forgery with known signature. Let assume that (r, s)is a signature for the text y. Oscar can then sign other texts. Let h, i, j integers with0 ≤ h, i, j ≤ p− 2 and gcd(hr − js, p− 1) = 1. We compute

λ ≡ rhgibj (mod p)µ ≡ sλ(hr − js)−1 (mod p− 1)y′ ≡ λ(hy + is)(hr − js)−1 (mod p− 1).

It is tedious but easy to check that (y′, λ, µ) is valid.

3.4.3 DSA

DSA is based on the DLP. It is an improvement of the ElGammal scheme. Indeed inthe previous one, the size of the appendices is about twice the size of p (i.e. 2048 bits).We want to work with shorter elements.Let 512 ≤ t ≤ 1024 be a multiple of 64. Let 2t−1 < p < 2t be a prime number. Let2159 < q < 2160 be a prime divisor of p− 1.

Public key : (p, q, α, β) with α an element of order q of (Z/pZ)∗ and β ≡ αa (mod p);Secret key : a ∈ [0, q − 2];Signature : y → (y, r, s) with r ≡ αk (mod p), s ≡ k−1(m + ar) (mod q) withm = h(y) and k ∈ [1, q − 2] different for each signature;Verification : check that (r, s) ∈ [0, p − 1] × [0, q − 1]. If not reject the signature ;compute m = h(y) ; compute ω ≡ s−1 (mod q), u1 ≡ mω (mod q) and u2 ≡ rω(mod q) ; compute v ≡ αu1βu2 (mod p) and check that v = r.

Unfortunately there is no proof of security for DSA (i.e. against an existential forgerywith passive attacker).

3.5 Key exchange

As we said, encryption of long messages is done generally by secret key systems, muchfaster than public ones. The secret key systems are used to exchange the symmetric keybetween the users. RSA or ElGammal can be used in this direction. We describe herethe elementary Diffie-Hellman key exchange protocol.A and B want to construct a symmetric 128 bits key k. They take a prime number of1024 bits, a primitive elements g ∈ (Z/pZ)∗ and a hash function h which output has128 bits.

A chooses 0 < n < p− 1 which is kept secret;B chooses 0 < m < p− 1 which is kept secret;A sends gn to B and B sends gm to A ;A and B computes k = h(gmn).

Page 54: Cryptology course

54 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

The difficulty of the Diffie-Hellman problem insures the security of the system. How-ever for a general i the problem of the ith bit is not solved : it is not known which arethe bits of gmn which are as difficult to find as the whole gmn. One knows that the firstbits are easy to compute. One knows also that to compute more than

√log2(p) last bits

is as difficult as to compute gmn. Using the hash function h allows to walk round thisissue.The middle-man attack (attaque de l’homme du milieu) (see Fig. 3.2) is an attackwhich can be made on this protocol by an active attacker : the attacker O intercepts theexchanges between A and B. He constructs then a common key with A and a commonkey with B. He can then recreate for A,B the impression of a secure communicationwhereas he can of course decipher all the messages.

Figure 3.2: Middle-man attack

3.6 Authentication : zero-knowledge proof

In various applications (email, bank exchanges) it may be necessary that the sender cancheck the identity of the receiver before starting the transaction. This is of course anauthentication problem. An authentication scheme must allow the verifier V to checkthe identity of the prover P in polynomial time, as often as he wants without beingable to steal his identity. This cannot be achieved by the standard methods (password,access code) but in 1985 S. Goldwasser, S. Micali and C. Rackoff introduced the notion ofzero-knowledge interactive proof. They showed that the minimal amount of informationthat an user must reveal to prove (with a huge probability) that he knows a secret can

Page 55: Cryptology course

3.6. AUTHENTICATION : ZERO-KNOWLEDGE PROOF 55

be zero. In 1986, A. Fiat and A. Shamir showed how this can be use in the context ofauthentication by giving a scheme based on the factorization problem (see [QG90] foran educative introduction).The general principle is the following : each user has a secret s which satisfies a predicateP (I, s) for a case I of a difficult problem. The verifier asks the provers a series ofquestions. If the last one knows the secret s he can answer all the questions correctly.Otherwise, he can answer only randomly with a probability 0 < q < 1 of success. Iteringthe process, one can make the probability of cheating as small as desired.

3.6.1 Feige-Fiat-Shamir protocol

Let n = pq with p, q two big prime numbers. We will use the difficulty of the square rootproblem in G = Z/nZ. P has a public key v ≡ a2 (mod n) for 1 ≤ a ≤ n − 1 coprimeto n. P and V use the following protocol.

Public key of P : v ≡ a2 (mod n) ;Private key of P : a ∈ [1, n− 1] ;P chooses a random r ∈ [1, n[ and sends x ≡ r2 (mod n) to V ; V sends a randombit b to P ; if b = 0, P sends r to V and V checks that x ≡ r2 (mod n) ; if b = 1then P sends y ≡ ra (mod n) to V and V checks that x ≡ y2v−1 (mod n).

If the user P does not know the value a, he cannot satisfies both cases. At eachtrial, he has 1/2 chance to be unmasked. By itering again one sees that a proof madeby a fair prover is always accepted, the system is said consistent (consistant). A proofmade by an unfair prover has a tiny chance to be accepted, the system is said meaningful(significatif). It can be shown that this proof is zero-knowledge : r being random, raand x are also and no information on a is divulged.

Remark 12. We can mention a variant of this protocol for the so called coin-flippingby telephone. Suppose Alice and Bob want to make some decision based on a randomcoin flip but they are not at the same place. It can be done by a bit commitment scheme.Alice chooses a random bit x and computes a blob y which is sent to Bob. This blob musthave two properties : a concealing property which means that it is impossible for Bobto find x ; a binding property which means that Alice cannot change her mind. Moreexplicitly, Bob sends n = pq to Alice with p, q two big prime numbers congruent to 1modulo 4. Alice chooses x and compute the coin flip

(xn

). She sends y ≡ x2 (mod n)

to Bob. Bob guesses the result ±1 and sends its answer to Alice. Alice sends then x toBob and Bob sends (p, q) to Alice.

3.6.2 Schnorr identification

This system uses a multiplicative group G = (Z/pZ)∗ where p is a 1024 bits primenumber and H a subgroup of order q at least 160 bits. Let α be a generator of H.

Page 56: Cryptology course

56 CHAPTER 3. PUBLIC KEY CRYPTOGRAPHY

Public key of P : v ≡ α−s (mod n);Private key of P : s ∈ Z/qZ ;P chooses a random r ∈ Z/qZ and sends x ≡ αr (mod p) to V ; V sends a challengee ∈ [0, 2k[ to P ; P sends y ≡ r+es (mod q) to V ; V checks that x ≡ αyve (mod p).

If the prover can answer two different cases e, e′ then he knows s (and he is able tocompute the DL of v). Indeed

x ≡ αyve ≡ αy′ve′ (mod p),ve′−e ≡ αy−y′ (mod p),

αs(e−e′) ≡ αy−y′ (mod p),

s ≡ y − y′

e− e′(mod q).

So the prover cannot answer more than one of the 2k different questions. He can cheatsuccessfully with a probability less than 1/2k. If k = 20 the system is meaningful.Moreover it can be shown that it is zero-knowledge.

Page 57: Cryptology course

Chapter 4

Private key cryptography

Secret key cryptography can be divided into two categories : block ciphers (chiffrementpar blocs) and stream cipher (chiffrement a flot). The first one uses a fixed trans-formation on fixed size plaintext blocks and returns fixed size ciphertext blocks. Thesecond operates on individual symbols of the plaintext by a transformation dependingon the key and the position of the symbol in the stream. It is possible to decipherdirectly (without waiting for a block).We will present two different block ciphers : DES and AES.

4.1 Block ciphers

Given a plaintext x divided into blocks x1, . . . , xk how is the system use to cipher ?There are several possibilities.

4.1.1 Electronic Codebook Mode : ECB

Each xi has the size te of the encryption system. The ciphertext is then y = y1 . . . yk =EK(x1) . . . EK(xk).To decipher, one has x = DK(y1) . . .DK(yk).This mode has a drawback : if in the text two blocks are the same, they will be cipheredidentically. It is then necessary that the blocks are big enough to avoid a statisticalanalysis. However this is an advantage if one wants to access a specific part of the text.This mode is considered as low secure.

57

Page 58: Cryptology course

58 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

4.1.2 Cipher Block Chaining Mode : CBC

Each xi has the size te of the encryption system. One needs also a random initial blocky0 of the same size. One computes

y1 = EK(y0 ⊕ x1),y2 = EK(y1 ⊕ x2),. . . = . . . ,

yk = EK(yk−1 ⊕ xk)

The ciphertext is y = y0 . . . yk.To decipher one computes :

x1 = DK(y1)⊕ y0,

x2 = DK(y2)⊕ y1,

. . . = . . . ,

xk = DK(yk)⊕ yk−1

In CBC mode, two identical blocks give two different ciphertexts. The ciphertext is abit longer than the plaintext. The initial block should be transfer secretly; indeed

x(i)1 = y

(i)0 ⊕DK(y1)(i)

(where (i) denotes the ith bit). So the modification of the ith bit of y0 induces the samemodification on the ith bit of x1.

4.1.3 Cipher Feedback Mode : CFB

We need the following notations : if B is a block of size n and if 0 ≤ u ≤ n thenMSBu(B) (resp. LSBu(B)) is the u most (resp. less) significative bits of B, i.e. the ubits of B the most on the left (resp. right).The text is split into blocks xi of size s where 1 ≤ s ≤ te. One needs also an initialrandom block I1 of size te. One computes

z1 = EK(I1) y1 = x1 ⊕MSBs(z1),I2 = LSBte−s(I1)||x1,

z2 = EK(I2) y2 = x2 ⊕MSBs(z2),. . . = . . . . . . = . . . ,

Ik = LSBte−s(Ik−1)||xk−1,

zk = EK(Ik) yk = xk ⊕MSBs(zk)

Page 59: Cryptology course

4.2. DES 59

The ciphertext is y = I1y1 . . . yk.To decipher one computes

z1 = EK(I1) x1 = y1 ⊕MSBs(z1),I2 = LSBte−s(I1)||x1,

z2 = EK(I2) y2 = x2 ⊕MSBs(z2),. . . = . . . . . . = . . . ,

Ik = LSBte−s(Ik−1)||xk−1,

zk = EK(Ik) yk = xk ⊕MSBs(zk)

Remark 13. If s = te then for j ≥ 2, Ij = xj−1. So if we denote y0 = I1, one has forj ≥ 1, Zk = EK(yj−1) and yj = xj ⊕ zj.

This mode can be transformed into a stream cipher for any data of size 1 ≤ s ≤ te. Inthis mode the function DK is not used. This can be an advantage for some cryptosystemwhich are faster in encryption than in decryption (like some implementations of AES).The modification of a block in the plain or ciphertext has consequences on the followingblocks. It is not possible to make a random access but it allows to detect modificationsduring a communication.

4.1.4 Counter Mode : CTR

Each xi has the size te of the encryption system. One needs a counter of size te. Anrandom initial value I1 is picked. One computes then

z1 = EK(I1) y1 = x1 ⊕ z1,

I2 ≡ I1 + 1 (mod 2te),z2 = EK(I2) y2 = x2 ⊕ z2,

. . . = . . . . . . = . . . ,

Ik ≡ Ik−1 + 1 (mod 2te),zk = EK(Ik) yk = xk ⊕ zk

The ciphertext is y = I1y1 . . . yk.To decipher one computes Zi = EK(Ii) and xi = yi ⊕ Zi, Ii+1 ≡ Ii + 1 (mod 2te).This mode is really easy to implement, is secure and does not use the decipher function.One can also make random access to the text.

4.2 DES

We present the Data Encryption System (DES). For many years, this cryptosystem wasthe encryption standard in the U.S. and was used worldwide. Today, simple DES is nolonger secure. Nevertheless, there are secure variant of DES that are widely use. Also,DES remains an important model for the construction of secure block ciphers.

Page 60: Cryptology course

60 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

Table 4.1: The initial permutation IP

58 50 42 34 26 18 10 260 52 44 36 28 20 12 462 54 46 38 30 22 14 664 56 48 40 32 24 16 857 49 41 33 25 17 9 159 51 43 35 27 19 11 361 53 45 37 29 21 13 563 55 47 39 31 23 15 7

4.2.1 Feistel ciphers

The DES algorithm is built on Feistel ciphers. In this section, we explain Feistel cipher.Let t = 2n be the size of the block. If k ∈ K is the secrete key, there is a way to produceround keys (cles de tour) Ki from it. If the plaintext is written x = (L0, R0) where L0

is the left half and R0 the right half, then we produce a sequence by iterations

(Li, Ri) = (Ri−1, Li−1 ⊕ fKi(Ri−1))

where fKi is a non-linear function which depends on the round key Ki. In the case ofDES this function is built on the so-called S-boxes.The decryption is immediately obtained:

(Li−1, Ri−1) = (Ri ⊕ fKi(Li), Li).

4.2.2 Plaintext, ciphertext and keyspace

The plaintext and ciphertext spaces of DES are P = C = {0, 1}64. The DES keys arebitstrings of length 64 with parity checks. More precisely

K = {(b1, . . . , b64) ∈ {0, 1}64 :8∑

i=1

b8k+i ≡ 1 (mod 2), 0 ≤ k ≤ 7}.

Thus the number of DES key is 256. The length of the round keys is 48 bits. Theirgeneration is explained in 10.8.5.

4.2.3 General overview

Given a plaintext x, DES works in three steps.

1. DES applies an initial permutation IP to x. If x = x1x2 . . . x64 then (L0, R0) =IP (x) = x58x50x42 . . . x7 given by Tab. 10.1.

Page 61: Cryptology course

4.2. DES 61

Table 4.2: The functions E and P

32 1 2 3 4 54 5 6 7 8 98 9 10 11 12 1312 13 14 15 16 1716 17 18 19 20 2120 21 22 23 24 2524 25 26 27 28 2928 29 30 31 32 1

16 7 10 2129 12 28 171 15 23 265 18 31 202 8 24 1432 27 3 919 13 30 622 11 4 25

2. A 16-round Feistel cipher is applied to the permuted plaintext (Li, Ri) = (Ri−1, Li−1⊕fKi(Ri−1)) for i = 1, . . . , 16. We describe in 10.8.4 the functions fKi .

3. Finally the ciphertext is constructed using the inverse permutation

y = IP−1((R16, L16)).

4.2.4 Internal block ciphers

Let us assume that (L,R) is the input of the ith round (for 0 ≤ i ≤ 15) and thatK ∈ {0, 1}48 is the round key (the generation of the round key is explained in 10.8.5).DES applies a Feistel cipher with the function fK : {0, 1}32 → {0, 1}32, R 7→ D whichwe describe now.

1. The argument R ∈ {0, 1}32 is expanded by the expansion function E : {0, 1}32 →{0, 1}48. This function is shown in Tab. 10.2. If R = R1 . . . R32 then E(R) =R32R1R2 . . . R32R1.

2. Next E(R)⊕K is computed and the result is divided into eight blocks Bi of length6, namely

E(R)⊕K = B1B2 . . . B8.

3. With the help of the S-boxes Si : {0, 1}6 → {0, 1}4, one builds a string of length32

C = S1(B1)S2(B2) . . . S8(B8).

The S-boxes (see Tab. 10.3) are the heart of DES because they are highly non-linear. Each S-box is represented by a table with 4 rows and 16 columns. Foreach string Bj = b1 . . . b6 the value Sj(Bj) is computed as follow. The integerwith binary expansion b1b6 is used as the row index and the integer with binaryexpansion b2b3b4b5 is used as the column index. The entry of this row and columnis written in binary expansion. This expansion is padded with leading zeros suchthat its length is four. The result is Sj(Bj). For instance S1(001011) = 0010because the (01 = 1, 0101 = 5) elements of S1 is 2 = 10.

Page 62: Cryptology course

62 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

4. The permutation P (see Tab. 10.2) is applied on C. The output is D = P (C).

4.2.5 Keys generation

Finally we explain how the round keys are computed. Let k ∈ {0, 1}64 be a DES key.We generate the round keys Ki, i = 1, . . . , 16 of length 48. We define the values vi fori = 1, . . . , 16 as follows.

vi =

{1 for i = 1, 2, 9, 162 otherwise.

The round keys are computed by the following algorithm using the functions

PC1 : {0, 1}64 → {0, 1}28 × {0, 1}28, PC2 : {0, 1}28 × {0, 1}28 → {0, 1}48

which are described in Tab. 10.4.

1. Set (C0, D0) = PC1(k). If k = k1 . . . k64 then C0 = k57k49 . . . k36 and D0 =k63k55 . . . k4.

2. For 1 ≤ i ≤ 16 do the following:

(a) Let Ci be the string that is obtained from Ci−1 by a circular left shift of vi

positions.

(b) Let Di be the string that is obtained from Di−1 by a circular left shift of vi

positions.

(c) Ki = PC2(Ci, Di). If (Ci, Di) = b1 . . . b56 then Ki = b14b17 . . . b32.

4.2.6 Decryption

We apply to y the same algorithm but with the round keys K ′i = K17−i for i = 1, . . . , 16.

First we compute

IP (y) = IP (IP−1((R16, L16)) = (R16, L16).

Then if L′0 = R16 and R′0 = L16 then

L′1 = R′0 = L16 = R15,

R′1 = L′0 ⊕ fK′

1(R′

0) = R16 ⊕ fK16(L16) = R16 ⊕ fK16(R15) = L15

i.e. (L′1, R′1) = (R15, L15).

By iteration, we obtain L′16 = R0 and R′16 = L0 and by applying IP−1((L0, R0)) = x.

Page 63: Cryptology course

4.2. DES 63

Table 4.3: The S-boxesS1

14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 70 15 7 4 14 2 13 1 10 6 12 11 9 5 3 84 1 14 8 13 6 2 11 15 12 9 7 3 10 5 015 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13

S2

15 1 8 14 6 11 3 4 9 7 2 13 12 0 5 103 13 4 7 15 2 8 14 12 0 1 10 6 9 11 50 14 7 11 10 4 13 1 5 8 12 6 9 3 2 1513 8 10 1 3 15 4 2 11 6 7 12 0 5 14 9

S3

10 0 9 14 6 3 15 5 1 13 12 7 11 4 2 813 7 0 9 3 4 6 10 2 8 5 14 12 11 15 113 6 4 9 8 15 3 0 11 1 2 12 5 10 14 71 10 13 0 6 9 8 7 4 15 14 3 11 5 2 12

S4

7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 1513 8 11 5 6 15 0 3 4 7 2 12 1 10 14 910 6 9 0 12 11 7 13 15 1 3 14 5 2 8 43 15 0 6 10 1 13 8 9 4 5 11 12 7 2 14

S5

2 12 4 1 7 10 11 6 8 5 3 15 13 0 14 914 11 2 12 4 7 13 1 5 0 15 10 3 9 8 64 2 1 11 10 13 7 8 15 9 12 5 6 3 0 1411 8 12 7 1 14 2 13 6 15 0 9 10 4 5 3

S6

12 1 10 15 9 2 6 8 0 13 3 4 14 7 5 1110 15 4 2 7 12 9 5 6 1 13 14 0 11 3 89 14 15 5 2 8 12 3 7 0 4 10 1 13 11 64 3 2 12 9 5 15 10 11 14 1 7 6 0 8 13

S7

4 11 2 14 15 0 8 13 3 12 9 7 5 10 6 113 0 11 7 4 9 1 10 14 3 5 12 2 15 8 61 4 11 13 12 3 7 14 10 15 6 8 0 5 9 26 11 13 8 1 4 10 7 9 5 0 15 14 2 3 12

S8

13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 71 15 13 8 10 3 7 4 12 5 6 11 0 14 9 27 11 4 1 9 12 14 2 0 6 10 13 15 3 5 82 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11

Page 64: Cryptology course

64 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

Table 4.4: The functions PC1 and PC2

57 49 41 33 25 17 91 58 50 42 34 26 1810 2 59 51 43 35 2719 11 3 60 52 44 3663 55 47 39 31 23 157 62 54 46 38 30 2214 6 61 53 45 37 2921 13 5 28 20 12 4

14 17 11 24 1 53 28 15 6 21 1023 19 12 4 26 816 7 27 20 13 241 52 31 37 47 5530 40 51 45 33 4844 49 39 56 34 5346 42 50 36 29 32

4.2.7 Double DES

The key size of DES is too short. Currently triple DES (see 2.2.2) is used. A naturalquestion is then : why not a double DES ?This cryptosystem would work as follows: the key would be k = (k1, k2) and y =DES(DES(x, k1), k2). This principle could be applied to any cryptosystem as long asthere is no key k3 such that Ek1 ◦ Ek2 = Ek3 .However this mechanism can be attacked by meet in the middle (meet in the middle).This attack is based on the equality

∀(x, y) ∈ P × C, Ek1(x) = Dk2(y).

Then, if a pair of plaintext-ciphertext is known it is enough to compute all left-hand andright-hand members, i.e. 2 · 256 computations. So for keys twice longer, the complexityis on the same order as for the simple DES. Actually this attack is theoretical becauseof the size of the storage.

4.3 AES

This system is based on the work of Joan Daemen and Vincent Rijmen who created asystem called Rijndael after the invitation to tender of NIST in 1997 to replace DES. Itis important to notice that, unlike DES, the selection of AES was completely open andimplicate the whole cryptographic community through three international conferences.

4.3.1 Plaintext, ciphertext and keys

The size of the secret keys are 128 bits (16 octets), 192 bits (24 octets) or 256 bits (32octets).For AES, the basic element is octet so we will cut our plaintext and our keys in octetsand place them in arrays. The input is therefore a 4× 4 array of octets p0, . . . , p15 andthe key a 4 × NK table with NK = 4, 6 or 8. The number of round keys depends on

Page 65: Cryptology course

4.3. AES 65

Table 4.5: Input and key (case NK = 8)

x0 x4 x8 x12

x1 x5 x9 x13

x2 x6 x10 x14

x3 x7 x11 x15

k0 k4 k8 k12 k16 k20 k24 k28

k1 k5 k9 k13 k17 k21 k25 k29

k2 k6 k10 k14 k18 k22 k26 k30

k3 k7 k11 k15 k19 k23 k27 k31

NK : for NK = 4, 6, 8, this number is respectively nr = 10, 12, 14 plus one for an initialround. The round keys (of length 16 octets) will be then denoted K0, . . . , Knr . Theirgeneration is explained in 4.3.4.

4.3.2 Overview

Given an input x of length 16 octets, we make the following operations.

1. x⊕K0 (as bits).

2. we apply recursively for i = 1 to nr−1 the procedures SubBytes, ShiftRows, MixColumnsand ⊕Ki which will be described in 4.3.3.

3. we apply finally SubBytes, ShiftRows and ⊕Knr .

4.3.3 Internal procedures

Procedure SubBytes

It is the only procedure which is non linear. It is therefore the core of AES. It is basedon computations in F256 (see 6.6).We consider the polynomial

P (X) = X8 + X4 + X3 + X + 1.

This polynomial is irreducible over F2 and generates then the field F28 .The elements of this field can be seen as octet. Indeed one can represent the octetb7b6b5b4b3b2b1b0 as the element

b(X) = b7X7 + b6X

6 + b5X5 + b4X

4 + b3X3 + b2X

2 + b1X + b0.

The addition and multiplication laws in the field F256 give addition and multiplicationlaws on the octets by :

c(X) = a(X) + b(X) c(X) = a(X)b(X) (mod P (X)).

We denote by g : F256 → F256 the map

g(x) =

{0 if x = 0x−1 otherwise.

.

Page 66: Cryptology course

66 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

We introduce also an affine function f(a) = b by the matrix

b7

b6

b5

b4

b3

b2

b1

b0

=

1 1 1 1 1 0 0 00 1 1 1 1 1 0 00 0 1 1 1 1 1 00 0 0 1 1 1 1 11 0 0 0 1 1 1 11 1 0 0 0 1 1 11 1 1 0 0 0 1 11 1 1 1 0 0 0 1

a7

a6

a5

a4

a3

a2

a1

a0

01100011

.

This circulant matrix corresponds to a polynomial multiplication modulo X8 + 1 :

b(X) = ((X4 + X3 + X2 + 1)a(X) (mod X8 + 1) + (X6 + X5 + X + 1).

The procedure Subbytes := f ◦ g is then applied on each octet.

Procedure ShifRows

We apply this procedure on the 4× 4 array given by the input : each row i is shifted tothe left from i cases.

Table 4.6: Procedure ShiftRows

x0 x4 x8 x12

x1 x5 x9 x13

x2 x6 x10 x14

x3 x7 x11 x15

Ã

x0 x4 x8 x12

x5 x9 x13 x1

x10 x14 x2 x6

x15 x3 x7 x11

Procedure MixColumns

This procedure works on the columns of the input array.

Table 4.7: Procedure MixColumns

c0 c1 c2 c3 Ã d0 d1 d2 d3

The transformation is linear and given by a matrix with coefficients in F256 written

Page 67: Cryptology course

4.3. AES 67

in hexadecimal pairs (for instance A1 represents the elements 1010, 0001 or X7+X5+1).

d0

d1

d2

d3

=

02 03 01 0101 02 03 0101 01 02 0303 01 01 02

c0

c1

c2

c3

.

This is again a circular matrix. It corresponds to the multiplication by the polynomialA(X) = 03X3 + 01X2 + 01X + 02 modulo 1 + X4 :

d0 + d1X + d2X2 + d3X

3 = A(X)(c0 + c1X + c2X2 + c3X

3) (mod X4 + 1).

The polynomial A(X) is prime with X4 + 1. Its inverse is B(X) = 0BX3 + 0DX2 +09X + 0E.

4.3.4 Generation of the round keys

The secret key K, which is given in a 4×NK-array is extended into a 4×4(NK +1)-arrayW . The round key Ki is given by the four columns 4i, 4i + 1, 4i + 2, 4i + 3 of W .The construction of W is slightly different whether NK = 4, 6 or 8. It requires alsoconstants Ci = Xi as elements of F256. We present successively the case NK = 4, 6 andNK = 8.

for j = 0 to NK − 1 dofor i = 0 to 3 do

W [i, j] = K[i, j];end for;

end for;for j = NK to 4(NK + 1)− 1 do

if j (mod NK) = 0 thenW [0, j] = W [0, j −NK ]⊕ SubBytes(W [1, j − 1])⊕ Cj/NK

;for i = 1 to 3 do

W [i, j] = W [i, j−NK ]⊕SubBytes(W [i+1 (mod 4), j−1]);end for;

elsefor i = 0 to 3 do

W [i, j] = W [i, j −NK ]⊕W [i, j − 1];end for;

end if;end for;

Page 68: Cryptology course

68 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

for j = 0 to NK − 1 dofor i = 0 to 3 do

W [i, j] = K[i, j];end for;

end for;for j = NK to 4(NK + 1)− 1 do

if j (mod NK) = 0 thenW [0, j] = W [0, j −NK ]⊕ SubBytes(W [1, j − 1])⊕ Cj/NK

;for i = 1 to 3 do

W [i, j] = W [i, j−NK ]⊕SubBytes(W [i+1 (mod 4), j−1]);end for;

elseif j (mod NK) = 4 then

for i = 0 to 3 doW [i, j] = W [i, j −NK ]⊕ s(W [i, j − 1]);end for;

elsefor i = 0 to 3 doW [i, j] = W [i, j −NK ]⊕W [i, j − 1];end for;

end if;end if;

end for;

Remark 14. The polynomial P (X) = X8 + X4 + X3 + X + 1 does not give a primitiveelements in F256, i.e. the element is of order 51 and not 255. But this is the simplestirreducible polynomial of order 8.All the constants Ci are distinct.The decryption is realized by the succession of the previous operations in reverse order.Note that, since the operations SubBytes and ShiftRows commute, we can use theencryption algorithm for decryption by changing the values of the round keys.

4.4 Differential cryptanalysis

Brute force attacks are realized by an exhaustive research of the key. This gives thedefinition of what a good attack is : it requires signficantly less operations. However,these attacks often are theoretical in account of their memory requests. For instance, itis more the increase of computer power than these methods that has killed DES.

Anyway, we will study differential cryptanalysis. It was introduced by E. Bihamand A. Shamir in 1990. Note that other powerful cryptanalysis methods exist : linearcryptanalysis, by interpolation,. . . . They are all based on the following remarks:

• they apply on systems that iterates a function which is cryptographically weak.

Page 69: Cryptology course

4.4. DIFFERENTIAL CRYPTANALYSIS 69

• they are chosen plaintext attacks.

• they are statistical attacks on the last round. They use the notion of last rounddetector.

4.4.1 Last round detector

We assume that plaintexts and ciphertexts are elements of E = P = C = {0, 1}td andthat the round keys are in F = {0, 1}tr and that the round function is

F : E × F → E.

To cipher a plaintext, we iterate the function F nr times

y = FKnr◦ FKnr−1

◦ · · · ◦ FK1(x).

Let us denote F = FKnr−1◦ · · · ◦FK1(x). A last round detector (detecteur au dernier

tour) is an algorithm A which, given n couples (xi, zi) ∈ E×E, can detect if zi = F(xi)with a good probability. If it exists such a fast algorithm A we can apply it in thefollowing way :

• let T be a possible Knr , we compute n couples (xi, yi) and then (xi, zi) withzi = F−1

T (yi).

• we apply A to the couples (xi, zi).

• if the detector is positive, then T is a good candidate for Knr otherwise we startagain with another value.

• once the last round key found, we apply the algorithm recursively.

A priori, we need to apply this algorithm approximately 2tr−1 times (for each T ∈ F ).If tr is smaller than the size of the key, this is already an improvment. Moreover,sometimes the round function is cryptographically weak and revels some information onthe round key that can be exploited.

4.4.2 A detector for differential cryptanalysis

Let u ∈ E, T ∈ F and define for x ∈ E,

δu,T (x) = F(x, T )⊕F(x⊕ u, T ).

If v ∈ E, we denote Au,v,T = {x ∈ E|δu,T (x) = v}.We have the following hypothesis (H) : we assume that #Au,v,T does not depend on

T . We can make two remarks :

Page 70: Cryptology course

70 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

• if F(x, T ) = f(x⊕ T ), we have

δu,T (x) = f(x⊕ T )⊕ f(x⊕ u⊕ T ) = f(x⊕ T )⊕ f(x⊕ T ⊕ u),

so (H) is satisfied in this case. In the same way, if F(x, T ) = g(x)⊕ T , we have

δu,T (x) = g(x)⊕ T ⊕ g(x⊕ u)⊕ T = g(x)⊕ g(x⊕ u)

so (H) is satisfied in this case too.

• If the plaintexts have the same probability, the inputs of F at each round have thesame probability (it is a bijection). The hypothesis (H) claims that the probabilityPr(v|u) that the difference z ⊕ z′ between two outputs z, z′ equal v knowing thatthe difference x⊕x′ between the inputs x, x′ equal u does not depend of the roundkey.

We can check that (H) is satisfied for DES and AES.

We can then iterate the hypothesis (H) and apply it to the function F . A couple(u, v) such that for x ⊕ x′ = u the difference z ⊕ z′ = v where z = F(x), z′ = F(x′)is relatively in majority is called a good differential on nr − 1 rounds (une bonnedifferentielle sur nr − 1 tours).

Let us assume that the probability Pr(v|u) is not uniform in v (see for instance Tab.4.8 in the case of DES) and so that a good differential (u, v) exists. This unbalancedsituation is the heart of differential cryptanalysis. Assume we have an algorithm A′ suchthat given v = z ⊕ z′ and y = FT (z), y′ = FT (z′) produces T . Such an algorithm mightbe naive, i.e. runs over the whole F .Given x, x′ two plaintexts, if we knew for sure the difference z⊕z′, then we could obtainKnr by applying A′. This is not the case, but according to what has been said, if wechoose a good differential (u, v) on nr − 1 rounds, then by ciphering enough (x, x′) withx ⊕ x′ = u we are likely to get a relative majority of v. Applying A′ on y, y′ with thedifferential v and taking the most common result, we are likely to get the good Knr .

Remark 15. In the case of DES, this attack requires 247 pairs plaintext/ciphertext.Although this attack is better than brute force attack, it remains theoretical since itdemands 221 Go of memory.AES is resistant to differential analysis.

Page 71: Cryptology course

4.4. DIFFERENTIAL CRYPTANALYSIS 71

Table 4.8: Distribution of v for the S-box S1 when u = 110100

0000 0 1000 60001 8 1001 00010 16 1010 00011 6 1011 00100 2 1100 00101 0 1101 80110 0 1110 00111 12 1111 6

Page 72: Cryptology course

72 CHAPTER 4. PRIVATE KEY CRYPTOGRAPHY

Page 73: Cryptology course

Chapter 5

Security

Apart from Shannon perfect secrecy notion which is far too much restricting, we willformalize another notion : provable security -in the context of public key cryptography-which can have several levels : total break of the system, semantic security, non-malleability. We will study them on some of the cryptosystems we have introduced.Note that this formalism can be modified for signature schemes for instance.

5.1 Different notions of security

5.1.1 Formalization of the cryptosystem

To control the different parameters of the cryptosystem, we will use a unique parametercalled security parameter (parametre de securite). In the case of RSA for instance,it is the size of the module n. Then we say that the size t(k) of an object whichdepends from k is polynomially bound (borne polynomialement) by k if there existsa polynomial P such that t(k) ≤ P (k). We formalize a cryptosystem as :

• The key generator. It is a public probabilistic algorithm K which has for inputa security parameter k and gets a coherent couple (e, d) of keys. This algorithmruns in maximal polynomial time in k. So the size of e and d are polynomiallybound in k.

• The plaintext space. It is a subset P ⊂ {0, 1}∗ whose words are polynomiallybound in k.

• The cipher algorithm. It is a public probabilistic algorithm E which has for inpute, x ∈ P and gets a ciphertext y. This algorithm runs in maximal polynomial timein k, so the ciphertext y is polynomially bound in k.

• The decipher algorithm. It is a public deterministic algorithm D which has forinput a private key d and a word y ∈ {0, 1}∗ and gets either an error message if y isnot valid or a valid plaintext x. It satisfies for any valid couple (e, d), Dd ◦Ee = Id.

73

Page 74: Cryptology course

74 CHAPTER 5. SECURITY

5.1.2 Formalization of the attacker

We assumed that the power of an adversary (an algorithm) is polynomial (or probabilis-tic polynomial). Note that this might be not precise enough if we are really interestedin concrete applications as it might be important to have a look at the different constants.

We have also to assume that some problems are difficult : factorization, DL, squareroots. We apply then a reduction argument (in the sense of 6.3.5) and we prove thatto break a cryptosystem or to get some information would give a solution to a difficultproblem. Again it might be important in the real world to study the constants of thereduction. For instance a secure algorithm based on factorization but with a reductioncost of 4 would need keys of size 4096 bits. It appears that reduction in the so calledstandard model (modele standard) –which reflects the ‘real’ world– have usually toohigh costs. This may be solved in the following ways.

1. We assume the existence of perfectly random hash functions. This is the so calledRandom oracle model (modele de l’oracle aleatoire). This oracle is a randomfunction f which can be called by the users to produce random numbers i.e. eachbits of f(x) is uniformly random. In the real world, such an oracle is usuallyreplaced by a pseudo-random generator. Thus in the real world, the adversarycan take advantage of the algebraic structure of the hash function to attack thesystem. In conclusion, the proof of security in this model does not imply securityin the real world, but the known counter-examples are not natural (see [CGH04])and the advantage is that we have localized the attacks on the hash functions. Itis then a good indication of security.

2. We can introduce new hard problems which are assume to be difficult. For instancethe flexible RSA problem : given n = pq and a random y find an e > 1 and a xsuch that xe ≡ y (mod n).

We will mostly work in the random oracle model.We have seen that the adversary can have different degrees of power in his attack

(see 2.4.1). As we are dealing with public key cryptosystems, we are going to considerthe three categories : CPA < CCA1 < CCA2. Note that CCA2 attack may look im-possible in real life. It could happen for instance in a system where authentication andcipher would be realized with the same key.

The (polynomial) adversary A will be formalized by a couple (A1, A2) of probabilisticpolynomial algorithms. The input of A1 is the public key and can call an oracle O1. It isperformed before the challenge. The input of A2 is the output of A1 and the challenge.It may call an oracle O2. Its output is an answer to the problem asked. The attackis said efficient (efficace) if the probability of success is bigger than the probability ofsuccess of an answer given without knowing the challenge or using a decipher oracle byguessing the most likely answer. The power of the oracles is the following :

• CPA. O1,O2 have no output.

Page 75: Cryptology course

5.1. DIFFERENT NOTIONS OF SECURITY 75

• CCA1. O1 deciphers texts. It can be used at any moment of A1 and increase thenumber of computations by 1. O2 has no output.

• CCA2. O1 and O2 can decipher ciphertexts. They can be called at any momentof A1 and A2.

5.1.3 Formalization of security

The last parameter is to ask what the adversary wants to get from the system or byopposition how much the cryptosystem reveals.

• Indistinguibility (indistinguabilite). This is roughly the following idea : giventwo plaintexts of the same length and the ciphertext of one of them, it cannot becompute in polynomial time with a probability better than 1/2 from which plain-text it is the cipher. To formalize this notion, let Π = (K, E ,D) be a cryptosystemdepending on k and A = (A1, A2) an adversary. We describe two experiences :EInd−ATK

Π (A, k) and EInd−ATKΠ (A, k). Here, Ind stands for Indistinguibility and

ATK is the level of the attack (CPA,CCA1,CCA2).Let us describe EInd−ATK

Π (A, k).

1. The algorithm K supplies (e, d).

2. A1 takes e and outputs (x0, x1) two plaintexts of the same lengths and swhich contains information on the state of the system. In particular s couldbe e.

3. A random bit b0 is picked and y = Ee(xb0).

4. y is the challenge given to A2. The output is a bit b.

The experience EInd−ATKΠ (A, k) is a simple coin flipping. This gives the following

definition.

Definition 5.1.1. The cryptosystem Π is secure for indistinguibility against anattack of type ATK (ATK=CPA or CCA1, CCA2) if and only if for any attackerA of type ATK following the previous scheme, the function of k

Pr(EInd−ATKΠ (A, k) = b0)− 1

2

is negligible (in the sense of 6.3.1).

• non-malleability (non-malleabilite). Roughly speaking, this notion is the im-possibility to construct from a ciphertext y a ciphertext y′ whose plaintext issignificantly related to the plaintext of y. We describe again two experiences: ECNM−ATK

Π (A, k) (resp. ECNM−ATKΠ (A, k)). In the notations, CNM stands

for Comparison non-malleability (a slightly different definition is Simulation non-malleability but they are in fact equivalent).

Page 76: Cryptology course

76 CHAPTER 5. SECURITY

1. The algorithm K supplies (e, d).2. A1 takes e and outputs the description of a set M of plaintexts of the same

length with a uniform distribution law, an element x ∈ M (resp. x, x′ ∈ M)and a state s.

3. y is the ciphertext of x.4. A2 takes (M, s, y) and outputs a relation R taking m inputs and m − 1

ciphertexts yi = Ee(xi) distinct from y for an arbitrary m ≥ 2.5. If R(x, x1, . . . , xm−1) (resp. R(x′, x1, . . . , xm−1)) then 1 else 0.

Definition 5.1.2. The cryptosystem Π is secure for non-malleability against anattack of type ATK if and only if for any attacker of type ATK, the function of k

Pr(ECNM−ATKΠ (A, k) = 1)− Pr(ECNM−ATK

Π (A, k) = 1)

is negligible.

• Semantically secure (semantiquement sur). This notion means that it is notpossible to get any information from the plaintext knowing the ciphertext in poly-nomial time, apart from its length. It is the natural weakening of Shannon security.This can be formalize by the following couple of experiences ESS−ATK

Π (A, k) (resp.ECNM−ATK

Π (A, k)).

1. The algorithm K provides (e, d).2. A1 takes e and outputs the description of a set M , an element x ∈ M (resp.

x, x′ ∈ M) and a state s.3. y is the ciphertext of x.4. A2 takes (M, s, y) and outputs a value z and the description of a function f

on P.5. if z = f(x) (resp. z = f(x′)) then 1 else 0.

Definition 5.1.3. The cryptosystem Π is semantically secure against an attackof type ATK if and only if for any attacker of type ATK, the function of k

Pr(ESS−ATKΠ (A, k) = 1)− Pr(ESS−ATK

Π (A, k) = 1)

is negligible.

Theorem 5.1.1. The semantic security and indistiguibility are equivalent notions.Non-malleability and indistinguibility are linked by the following diagram (an arrowmeans ‘implies’ a not-arrow means ‘not imply’).

NM − CPA

²²

/

))

NM − CCA1

²²

oo / //NM − CCA2oo

²²IND − CPA IND − CCA1oo

/

ii

IND − CCA2oo

OO

Page 77: Cryptology course

5.2. SECURITY OF ELGAMMAL ENCRYPTION 77

5.2 Security of ElGammal encryption

We want to illustrate the previous notions on ElGammal encryption. We have to precisethe algorithm first. Let k be the security paramater. We want to build an algorithm Gfor ElGammal encryption scheme which provides a subgroup H of order q of (Z/pZ)∗.To do so, we have two increasing functions with integer values l(k), L(k) such thatl(k) ≤ L(k) ≤ kc where c > 0 is a constant. The prime p is of size L(k) and q is ofsize l(k) and can be constructed as in 3.2.3. We construct also a generator α of H asexplained in 7.4.1. We denote Γ = (G,H,α).

5.2.1 The decisional Diffie-Hellman problem

We have already introduced this problem in 3.2.1. We want to find a equivalent set-theoretic formulation. Let

Tk,Γ = {αx, αy, αxy), x, y ∈ Z/qZ}, Nk,Γ = H3 Mk,Γ = Nk,Γ \ Tk,Γ.

The first set will be called the set of Diffie-Hellman triplets.We define two experiences Edisc

G (A, k) (resp. EdiscG (A, k)).

1. Run G with input k and produce Γ = (G,H,α).

2. Pick a t in Tk,Γ (resp. in Nk,Γ).

3. A(k, Γ, t) returns a bit b.

Definition 5.2.1. We say that the DDH problem is hard if Pr(EdiscG (A, k) = 1) −

Pr(EdiscG (A, k) = 1) is negligible. We say that the sets Nk,Γ and Tk,Γ are polynomially

indicernable (polynomialement indiscernables).

It can be shown by elementary manipulations that this equivalent to the followingdefinitions.

Proposition 5.2.1. The DDH problem is hard if and only if the sets Mk,Γ and Tk,Γ arepolynomially indicernable.Let C be a subset of H which does not contain 1. Let

MCk,Γ = {(αx, αy, cαxy), x, y ∈ Z/qZ, c ∈ C}.

The DDh problem is hard if and only if Tk,Γ and MCk,Γ are polynomially indicernable.

5.2.2 Simple ElGammal algorithms

We have seen in 3.2.4 that when P = G, the cryptosystem is not semantically secure.However

Proposition 5.2.2. The modified ElGammal encryption scheme (when P = H) is INP-CPA if and only if the DDH problem is hard.

Page 78: Cryptology course

78 CHAPTER 5. SECURITY

Proof. If the DDH problem is easy then it is not hard to break the ElGammal encryp-tion scheme. Conversely suppose that the DDH problem is hard. The attacker hasconstructed two plaintexts xb and one of them has been ciphered. So the attacked gety = (y1, y2) with y2 = xbβ

k. By computing y2/x0, he gets triplets (y1, β, y2/x0) so either(αk, αa, αak) or (αk, αa, cαak) with c = x1/x0 and y1, β random. By using Prop. 5.2.1with C = {x1/x0}, we conclude that the attacker cannot determine with a non-negligibleprobability of success if (y1, β, y2/x0) is a Diffie-Hellman triplet or not. So he cannotknow which xb has been ciphered.

On the contrary

Proposition 5.2.3. The modified ElGammal encryption scheme is not NM-CPA, so isnot NM-CCA1 or IND-CCA2.

Proof. Let us consider the following attacker A : A1(e) return M = {x, xz} and s = z.The algorithm A2(M, s, y) returns Y = zβk and the relation R(x,X) : x/X − z 6= 0with X = D(Y ) = z. We can check now that if x = x then the relation is true and ifx = xz then the relation is false. Thus the probability that the experience E returns 1is 1, when the probability that the experience E returns 1 is 1/2. So the advantage isnot negligible.

Remark 16. As already pointed out, one does not know for IND-CCA1.

5.2.3 Cramer-Shoup

To make ElGammal IND-CCA2 secure, several methods were suggested. Fujisaki-Okamoto transformation (see [FO99]) gives a secure ElGammal encryption in the Oraclemodel under the assumption that DDH is hard. Moreover the reduction cost is quitegood.We will present here another variant, called Cramer-Shoup encryption which is IND-CCA2 in the standard model.

Encryption scheme

Let p be a prime number which size depends on a security parameter k and H a subgroupof order q, prime, of G = (Z/pZ)∗. Two elements α1, α2 are picked randomly in H. Wedenote Γ = (G,H, α1, α2). We pick randomly five integers a1, a2, b1, b2, z ∈ [0, q− 1] andwe compute

c = αa11 αa2

2 , d = αb11 αb2

2 , h = αz1.

We have also a hash function F : G3 → [0, q − 1], build thanks to a probabilistic algo-rithm H which pick randomly, for any value of the security parameter k, a hash functionF in a set Hk of hash functions.

Page 79: Cryptology course

5.2. SECURITY OF ELGAMMAL ENCRYPTION 79

P = H;C = H;Public key : (α1, α2, c, d, h, F );Private key : (a1, a2, b1, b2, z);Ee(x) = (u1, u2, e, v) = (αr

1, αr2, h

rx, crdru) with u = F (u1, u2, e) and r ∈ [0, q− 1] aninteger picked randomly;To decipher : compute u = F (u1, u2, e) ; if v = ua1+b1u

1 ua2+b2u2 then x = e/uz

1

otherwise reject the ciphertext.

The theorem

Theorem 5.2.1. Cramer-Shoup encryption scheme is IND-CCA2 in the standard modelif and only if the DDH problem is hard and if there exists a universal family of one-wayhash functions.

To prove the theorem, we suppose that there exists an attacker A = (A1, A2) oftype CCA2 with an efficient attack against indistinguibility. We show that A solvesDDH. Instead of working directly with the cryptosystem, we work with an attackerA′ = (A′1, A

′2) on a simulator S which we will prove equivalent for the problem. Let us

describe S = (K′, E ′,D′) and compare it with Π = (K, E ,D).

Algorithm K(k) (resp. K′(α1, α2))Γ = (G,H,α1, α2) ← k (resp. nothing)a1, a2, b1, b2 et z (resp. z1, z2) ← [0, q − 1]c ← αa1

1 αa22

d ← αb11 αb2

2

h ← αz1 (resp. h ← αz1

1 αz22 )

F ← Hk

return (pk, sk) = ((α1, α2, c, d, h, F ), (a1, a2, b1, b2, z))(resp. (pk′, sk′) = ((α1, α2, c, d, h, F ), (a1, a2, b1, b2, z1, z2));

Algorithm Epk(x) (resp. E ′sk′(u1, u2, x))r ← [0, q − 1] (resp. nothing)u1 ← αr

1 (resp. nothing)u2 ← αr

2 (resp. nothing)e ← hrx (resp. e ← uz1

1 uz22 x)

u ← F (u1, u2, e)v ← crdru (resp. v ← ua1+b1u

1 ua2+b2u2 )

return y = (u1, u2, e, v) (resp. y′ =(u1, u2, e, v))

Algorithm Dsk(y) (resp. D′sk′(y′))u ← F (u1, u2, e)if v = ua1+b1u

1 ua2+b2u2 then

x = e/uz1 (resp. x = e/(uz1

1 uz22 ))

else non-validreturn x

Be aware that E ′ works with the secret key sk′.

The algorithms A1, A2 (resp. A′1, A′2) on Π (resp. on the simulator S) work in the

same way but they use respectively K, E ,D and K′, E ′,D′.

Page 80: Cryptology course

80 CHAPTER 5. SECURITY

EIND−CCA2Π (A, k)

(pk, sk) ← K(k)(x0, x1, s) ← A1(pk)x0, x1 distinct, same lengthb0 ← {0, 1}y ← Epk(xb0)b ← A2(x0, x1, s, y)if b = b0 then 1else 0.

EIND−CCA2S (A′, α1, α2, u1, u2)

(pk′, sk′) ← K′(α1, α2)(x0, x1, s) ← A′1(pk′)x0, x1 distinct, same lengthb0 ← {0, 1}y′ ← E ′sk′(u1, u2, xb0)b ← A′2(x0, x1, s, y

′)if b = b0 then 1else 0.

Let (α1, α2, u1, u2) for which we want to decide if it is of DH type or not, i.e. withα2 = αω

1 , u1 = αr1 we want to see if u2 = αr

2 = αωr1 . We denote D the subset of H4 of

quadruple of Diffie-Hellman type.Let (u1, u2, e, v) ∈ H4 and V ⊂ H4 the subset of these elements for which there existr ∈ [0, q − 1] such that u1 = αr

1, u2 = αr2, i.e. such that (α1, α2, u1, u2) ∈ D.

The strategy is the following : first we compare the answer of S and Π when(α1, α2, u1, u2) ∈ D then when it is not.

Comparison of S and Π when the input is in D

Note that the dismiss test for D,D′ is the same. We assume here that (α1, α2, u1, u2) ∈D.

Lemma 5.2.1. A quadruple which is not in V has a negligible probability not to berejected by the decipher algorithm (of Π and S).

Proof. Let P = (a1, a2, b1, b2) seen as a point of H4. Let ω = logα1(α2). The expo-

nents a1, a2, b1, b2 are secret. The opponent knows c, d and the element v (part of thechallenge). This can be formalized in the following equation

logα1(c) = a1 + ωa2 (5.1)

logα1(d) = b1 + ωb2 (5.2)

logα1(v) = ra1 + rωa2 + rub1 + ruωb2. (5.3)

If P belongs to the affine plane defined by the first two equations, then the last one isautomatically true (because (α1, α2, u1, u2) ∈ D).Let now (u′1, u

′2, v

′, e′) not in V , then logα1(u′1) = r′1 and logα1

(u′2) = ωr′2 with r′1 6= r′2.This quadruple will be rejected unless

logα1(v′) = r′1a1 + r′2ωa2 + r′1u

′b1 + r′2u′ωb2 (5.4)

is satisfied. This implies that the point P which is in the plane defined by (5.2) and (5.3)is also in the hyperplane defined by (5.4). These equations are linearly independent, theydefine a line. The cipher will be rejected with a probability greater than 1−q/q2 = 1−1/q(as a plane as q2 points and a line q points).

Page 81: Cryptology course

5.2. SECURITY OF ELGAMMAL ENCRYPTION 81

To be completely accurate, one should take in account the fact that one does not deciphertwice the same text. In this case it is easy to see that the probability that a ciphertextis rejected is at least 1 − 1/(q − i + 1) ≤ 1 − 1/(q − n + 1) where i is the number ofdeciphers already rejected and n the number of requested deciphers. As q is exponentialin k and n polynomial (the number of ciphertexts submitted to the oracle is polynomialin k), we get the result.

Proposition 5.2.4. If (α1, α2, u1, u2) ∈ D, the probability of success of the attackagainst S is indistinguable from the probability of success against Π.

Proof. The outputs of E and E ′ have the same distribution. Indeed, in both casesua1

1 ua22 = cr ub1

1 ub22 = dr, h can be considered as uniformly random. The same for

uz11 uz2

2 . So e = xb0λ with λ random, u = F (u1, u2, e) and v = crdru.The output of D,D′ have also indistinguable distributions. Indeed, if u′1 = αr′

1 andu′2 = αr′

2 then in both cases, deciphering gives e/hr′ and if u′1 = αr′11 and u′2 = α

r′22 with

r′1 6= r′2 then in both cases, the ciphertext is rejected except in some negligible cases.

Comparison of S and Π when the input is not in D

We suppose now that (α1, α2, u1, u2) /∈ D, i.e. u1 = αr11 , u2 = αωr2

1 with r1 6= r2 (andω = logα1

(α2)).

Lemma 5.2.2. A quadruple which is not in V has a negligible probability not to berejected by D′.Proof. We resume the notations of Lem. 5.2.1. Here again P is defined by three hyper-planes, namely (5.2),(5.3) and

logα1(v) = r1a1 + r2ωa2 + r1ub1 + r2uωb2. (5.5)

Assume that the opponent submits (u′1, u′2, e

′, v′) /∈ V to D′ and different from thechallenge (u1, u2, e, v). Let logα1

(u′1) = r′1, logα1(u′2) = ωr′2 with r′1 6= r′2 and u′ =

F (u′1, u′2, e

′). We consider

1. if (u′1, u′2, e

′) = (u1, u2, e) then u′ = u but

v′ 6= v = ua1+b1u1 ua2+b2u

2 = ua1+b1u′1 ua2+b2u′

2

and the quadruple is rejected.

2. if (u′1, u′2, e

′) 6= (u1, u2, e) and u′ 6= u. The algorithm D′ rejects (u′1, u′2, e

′, v′) unlessequation (5.4) is satisfied. But (5.2),(5.3),(5.4),(5.5) are linearly independent as adeterminant computation can show. So there is only one point satisfying all theconditions. This concludes the case.

3. if (u′1, u′2, e

′) 6= (u1, u2, e) and u′ = u. This happens with a negligible probabilityif the function F is resistant to collisions.

Page 82: Cryptology course

82 CHAPTER 5. SECURITY

Remark 17. In fact, it would be enough that F comes from an universal family of one-way hash functions. For such a family, an opponent cannot choose an x, pick randomlyan F in the family and constructs in polynomial time a y 6= x such that F (y) = F (x).With this hypothesis, the last case can be handled with a slight modification.

Lemma 5.2.3. If D′ rejects all (except a negligible part of) the ciphertexts which arenot in V then the public information (α1, α2, c, d, h, F ) and the information delivered bythe decipher oracle do not supply information on the bit b0.

Proof. Consider in the plane (Z/qZ)2 the point Q = (z1, z2). The single piece of infor-mation on Q known by the opponent which attacks S comes from h, i.e.

logα1(h) = z1 + ωz2 (5.6)

Thus Q is on a line determined by (5.6) with an uniform distribution. There is no otherinformation since the decipher algorithm rejects (almost) all ciphertexts which are notin V and which in the other cases answers

r′ logα1(h) = r′z1 + r′ωz2

which is the same as equation (5.6).Let us consider now the challenge (u1, u2, e, v) and denote K = uz1

1 uz22 . We have

logα1(K) = r1z1 + ωr2z2.

As the distribution of Q is uniform on the line (5.6) and r1 6= r2, the distribution oflogα1

(K) is uniform in Z/qZ and K is uniform in H. Let us write now e = Kxb0 . Asthe distribution of K is uniform, knowing e does not give information on the ciphertextxb0 or on b0.

Proposition 5.2.5. If (α1, α2, u1, u2) /∈ D, the distribution of the bit b0 in the simula-tion S is independent (up to a negligible constant) from (α1, α2, c, d, h, F ).

Proof. It is a consequence of Lem. 5.2.2, 5.2.3.

The proof of Th.5.2.1

Prop. 5.2.4 and 5.2.5 suggests the following approach. Run at the same time the attackon S and Π. If the input is in D, both A and A′ have a non-negligible advantage. If theinput is not in D, then A, by assumption, still has a non-negligible advantage but notA′. Then we return 1 if the two algorithms A, A′ return the same result and 0 otherwise.This allows us to distinguish D from its complementary and then to solve DDH.

Page 83: Cryptology course

Chapter 6

Reviews and complements

6.1 Integers, congruences, Z/nZ

6.1.1 Divisibility

Definition 6.1.1. We say that a divides n if there is an integer b with n = ab.

Proposition 6.1.1. 1. if a|b and b|c then a|c.

2. if a|b then ac|bc for all c.

3. if c|a and c|b then c|da + eb for all d and e.

4. if a|b and b|a then |a| = |b|.

Proof. Let us show the last one. a = 0 if and only if b = 0, so the proposition is provedin this case. If a 6= 0, there exists a′ 6= 0 such that aa′ = b so |aa′| = |a||a′| = |b|. Since|a′| ≥ 1, |a| ≤ |b|. By symmetry, |b| ≤ |a| and we have the equality.

The following result is very important. It shows that division with remainder ofintegers is possible (Z is euclidian).

Proposition 6.1.2. If a and b are integers, b > 0, then there are uniquely determinedintegers q and r such that a = qb + r and 0 ≤ r < b.

Proof. One can check that q = bab c and r = a− bq satisfy the hypothesis.

We define the greatest common divisor of two integers.

Definition 6.1.2. Among all the common divisors of two integers a, b which are not bothzero, there is exactly one greatest divisor (with respect to ≤). It is called the greatestcommon divisor (plus grand multiple commun) of a and b and denoted gcd(a, b) (orsometimes (a, b)).

For completeness we set gcd(0, 0) = 0.

83

Page 84: Cryptology course

84 CHAPTER 6. REVIEWS AND COMPLEMENTS

Proposition 6.1.3. The set of all integer linear combinations of a and b is the set ofall integer multiples of gcd(a, b), i.e.

aZ+ bZ = gcd(a, b)Z.

Proof. We can assume a or b different from 0. Set I = aZ + bZ. Let g be the smallestpositive integer in I. We claim that I = gZ. To see this, choose a non-zero elementc ∈ I. By Prop. 6.1.2 there are q, r such that c = qg + r and 0 ≤ r < g. Thereforer = c− qg belongs to I. But since g is the smallest positive integer in I, we must haver = 0 and c = qg.It remains to show that g = gcd(a, b). Since a, b ∈ I it follows from I = gZ that g is acommon divisor of a, b. Moreover since g ∈ I there are x, y with g = ax + by. Thereforeif d is a common divisor of a and b then d divides g. Then |d| ≤ |g| and g is the greatestcommon divisor of a, b.

Corollary 6.1.1 (Bezout). For all a, b, n the equation ax+by = n is solvable in integersx, y if and only if gcd(a, b)|n.

Proof. If there are x, y with n = ax + by then n ∈ aZ+ bZ and by Prop. 6.1.3 we haven ∈ gcd(a, b)Z.Conversely, if n is a multiple of gcd(a, b) then n ∈ gcd(a, b)Z = aZ+ bZ.

If the gcd(a, b) = 1 one says that a, b are coprime (premiers entre eux).One will introduce also the least common multiple (plus petit commun multiple)lcm(a, b) = ab/ gcd(a, b). One can check that this number is the smallest commonmultiple of a and b and that any multiple of a and b is a multiple of lcm(a, b).

Remark 18. Euclid algorithm, which gives a fast method to compute the gcd, will bepresented in 6.3.3.

6.1.2 Prime and factorization

Definition 6.1.3. An integer p > 1 is called a prime number (nombre premier) if ithas only 1 and p as divisors.

Example 10. There are infinitely many prime numbers. The biggest generic one is

(((((((((23 + 3)3 + 30)3 + 6)3 + 80)3 + 12)3 + 450)3 + 894)3 + 3636)3 + 70756)3 + 97220

Interested readers may read http: // www. cs. uwaterloo. ca/ journals/ JIS/ VOL8/

Caldwell/ caldwell78. html for the origin of this number. It has 20,562 decimal digitsand the proof was built using fastECPP on several networks of workstations.

We will write P the set of prime numbers. To estimate the efficiency of some algo-rithms, we need results on density of primes.

Page 85: Cryptology course

6.1. INTEGERS, CONGRUENCES, Z/NZ 85

Theorem 6.1.1. Let π(x) = #{p ≤ x prime}. One has

π(x) ∼ x

log x.

Let n ≥ 2 be an integer and c an integer prime to n. Let πn,c(x) = #{p ≤ x prime, p =kn + c}. One has

πn,c(x) ∼ 1φ(n)

x

log x.

Remark 19. For x ≥ 17, one has π(x) > x/ log x and for x > 1 one has π(x) <1.25506(x/ log x).

• To find a prime number, the number of attempts is then of the size of x. Indeed,the probability to fail in k attempts is (1−1/ log(x))k so the probability to succeed

1− (1− 1/ log(x))k ∼ 1− e−k/ log(x)

which is closed to 1 for any k = log(x)1+ε.

• To construct a couple (p, q) of prime numbers such that q divides p − 1, one canapply the previous lemma in the case n = q and c = 1. There are less than p/2qvalues of k for which p = kq + 1 may be prime (since we exclude k odd). Inthe series kq + 1 there are πq,1(p) values which give a prime number p, so theproportion of good k among the p/2q possible is

πq,1(p)p/2q

=2q

q − 11

log p.

Here again one finds a number of attempts of the size of p.

• To construct a couple (p, q) of prime numbers such that p = 2q + 1. It is notknown if there exists infinitely many (Sophie Germain) primes p. However it isconjectured that the number of Sophie Germain primes less than n is equivalentto

2Cn

(log(n))2,

where C ≈ .66.

Let us finish with the fundamental result.

Theorem 6.1.2. Every integer a > 1 can be written as the product of prime numbers

a =∏

p∈Ppe(p)

with e(p) ≥ 0 and e(p) = 0 except for finitely many primes p. Up to permutation, thefactors in this product are uniquely determined.

Page 86: Cryptology course

86 CHAPTER 6. REVIEWS AND COMPLEMENTS

6.1.3 Representations of integers

In books, integers are written in decimal expansion. On computers, binary expansion isused. More generally, integers can be represented using the so-called g-adic expansion.

Proposition 6.1.4. Let g > 1 be an integer. For each positive integer a, there is auniquely determined positive integer k and a uniquely determined sequence

(a1, . . . , ak) ∈ [0, . . . , g − 1]k

with a1 6= 0 and

a =k∑

i=1

aigk−i. (6.1)

In addition k = blogg ac+ 1.

Proof. Let a be a positive integer. If a can be represented as in (6.1) then gk−1 ≤ a ≤gk − 1 < gk. Hence k is unique. We prove the existence and uniqueness of the sequence(a1, . . . , ak) by induction on k.For k = 1, set a1 = a.For k > 1. We first prove the uniqueness. If there is a representation as in (6.1), then0 ≤ a− a1g

k−1 < gk−1 and therefore 0 ≤ a/gk−1 − a1 < 1. Therefore a1 is the integralquotient of a divided by gk−1 and is hence unique. Set a′ = a− a1g

k−1. If a′ = 0 thenai = 0, 2 ≤ i ≤ n or a′ =

∑ki=2 aig

k−i is the uniquely determined representation of a′

by the induction hypothesis.

Definition 6.1.4. The sequence (a1, . . . , ak)is called the g-adic expansion of a (representationen base g). Its length is |a|g = blogg ac+ 1.

Example 11. The sequence 10110 is the binary expansion of 24 + 22 + 2 = 22.Let us compute the binary expansion of 105 : 26 < 105 < 27 so it is of length 7. Wehave a1 = b105/64c = 1. Now 105 − 64 = 41 so a2 = b41/32c = 1. 41 − 32 = 9,a3 = b9/16c = 0, a4 = b9/8c = 1 ; 9 − 8 = 1 so a5 = a6 = 0 and a7 = 1. Hence thebinary expansion of 105 is 1101001.Another way to compute this representation is to use the division algorithm, which weillustrate here :

105 = 2 · 52 +152 = 2 · 26 +026 = 2 · 13 +013 = 2 · 6 +16 = 2 · 3 +03 = 2 · 1 +11 = 2 · 0 +1

Page 87: Cryptology course

6.1. INTEGERS, CONGRUENCES, Z/NZ 87

The result can now be read from bottom to top.Another important representation in computer science is the hexadecimal representa-tion, with g = 16. When writing the hexadecimal expansion, we use instead of thedigits 10, 11, . . . , 15 the letters A,B, C,D, E, F so A1C is the hexadecimal expansion of10 · 162 + 16 + 12 = 2588.

6.1.4 Congruences and Z/nZ

Definition 6.1.5. We say that a is congruent to b modulo n and we write a ≡ b(mod n) if n|(b− a).

This relation is a equivalence relation between the integers. We can consider theclass of Z (as a set) modulo this relation (for a fixed n). It is easy to see that if a is aelement, the class of a is a + nZ so representative elements are 0, 1, . . . , n− 1.On the other hand we can consider the commutative ring (Z, +,×). The set nZ is anideal in Z, we can consider the quotient Z/nZ which is also a ring denoted Z/nZ. It isnot difficult to see that the set we constructed before is in natural bijection with the ringwe obtained here (by definition !), thus we can consider that the elements of Z/nZ areclasses of the representative elements 0, 1, . . . , n − 1. The addition and multiplicationin Z/nZ are done using the usual addition and multiplication on the representativeelements and reducing the result modulo n.

Example 12. Let n = 6. If a, b ∈ Z/nZ with a the class of 3 and b the class of 5,one can write a + b = class(3 + 5) = class(8) = class(2) and ab = class(15) = class(3).The sign = is legitim as we are working in the ring. However we can perform directlythe same operations on the integers and use the congruence notations : 3 + 5 = 8 ≡ 2(mod 6) and 3 · 5 = 15 ≡ 3 (mod 6). We will often work with the elements and use thecongruence relation. Moreover by abuse of notations we will confuse the element and itsclass modulo n if the context is clear.

Example 13. What are the last two digits of 32005 (Use a fast exponentiation algorithm)?In base 2, 2005 = 11111010101 so the exponentiation can be realize according to thefollowing scheme:

1 1 1 1 1 0 1 0 1 0 181 41 21 61 81 41 21 61 81 9 343 3 83 23 43 3 3 43 43 3 3

Prove that if a number is written in base 10 as abcabc then it is divisible by 13.

We will now study the ring R = Z/nZ. The neutral element for addition is (theclass) of 0 and the neutral element for multiplication is (the class) of 1. As in anycommutative ring, we can study the invertible elements (elements inversibles) in R :a ∈ R is invertible if and only if there is b ∈ R such that ab = 1.

Proposition 6.1.5. An element a ∈ R is invertible if and only if a is coprime to n.

Page 88: Cryptology course

88 CHAPTER 6. REVIEWS AND COMPLEMENTS

Proof. a ∈ R is invertible if and only if there exists b such that ab = 1 i.e. ab ≡ 1(mod n). So there exists k ∈ Z such that ab− kn = 1. By Cor. 6.1.1, this is equivalentto gcd(a, n) = 1.

Example 14. A matrix M ∈ Mm(R) is invertible if and only if det(M) is invertible inR.

Corollary 6.1.2. The ring R is a field (i.e. all the element different from 0 are invert-ible) if and only if n is prime.

We denote this field Fp. It is not difficult to see that the invertible elements form agroup with respect to the multiplication. This group is denoted R∗ = (Z/nZ)∗ and itsorder φ(n), the Euler function . We will study this group in more details later.

Proposition 6.1.6. (Z/nZ,+) is a cyclic group (groupe cyclique), i.e. it is generatedby a unique element. Any finite cyclic group is isomorphic to (Z/nZ,+). The numberof generators of (Z/nZ,+) is φ(n).

Proof. Let G =< a > be a finite cyclic group of order n generated by a. Any element bof G can be written ra with a unique 0 ≤ r < n. We define ψ : G → Z/nZ, b 7→ r. It iseasy to see that ψ is an isomorphism of group.The element 1 is a generator of G = Z/nZ. So any invertible element is a generator ofG. Conversely, if a is a generator of G there exists n ∈ Z such that na = 1, i.e. a isinvertible in G. So the number of generators is φ(n).

Remark 20. The generators of (Z/nZ, +) are the invertible elements. So the invertibleelements are the elements of order n.Any cyclic ring is isomorphic (as a ring) to (Z/nZ, +,×).

We will study the decomposition of cyclic groups.

Lemma 6.1.1. If m,n are coprime the condition{

a ≡ b (mod n)a ≡ b (mod m)

is equivalent toa ≡ b (mod mn).

Proof. If a ≡ b (mod mn) then the two conditions hold. Conversely, there exist k1, k2

such that a − b = k1m = k2n. As m,n are coprime m|k2 and so there exists k3 suchthat a− b = k3mn, i.e. a ≡ b (mod mn).

Theorem 6.1.3 (Chinese Remainder Theorem). Let m,n coprime. The solutions{

x ≡ a (mod m)x ≡ b (mod n)

are of the following form : let u, v such that um + vn = 1 then a solution is x0 =bum + avn and all the other solutions are of the form x0 + kmn for k ∈ Z.

Page 89: Cryptology course

6.1. INTEGERS, CONGRUENCES, Z/NZ 89

Proof. One can check that x0 is a solution. Now if x1 is another solution then x1 ≡ x0

(mod m) and x1 ≡ x0 (mod n) so the previous lemma allows to conclude.

This can be reformulated in the following proposition.

Proposition 6.1.7. If m, n are coprime, the ring Z/mnZ is isomorphic to Z/mZ ×Z/nZ.

Proof. By applying Th. 6.1.3, one can check that the map T : x (mod mn) 7→ (x(mod m), x (mod n)) is an isomorphism of rings.

Example 15. Solve the equation 2x ≡ 3 (mod 45) using the Chinese Remainder The-orem.We can prove the following result : if n =

∏ki=1 p

e(pi)i is an odd integer, then the num-

ber of solutions of x2 ≡ 1 (mod n) is 2k. By the Chinese Remainder Theorem, it isenough to prove that x2 ≡ 1 (mod pe) for any p odd prime and e ≥ 1 if and only ifx ≡ ±1 (mod pe). It is true if e = 1 since ZpZ is a field. Let assume that it is truefor e and let us prove it for e + 1. If x2 ≡ 1 (mod pe+1) then it is true also modulope and by hypothesis one has x ≡ ±1 (mod pe), i.e x ≡ ±1 + kpe (mod pe+1). Now(±1 + kpe)2 ≡ 1± 2kpe (mod pe+1) so p|k and x ≡ ±1 (mod pe+1).

We will see now some properties of the Euler function.

Lemma 6.1.2. 1. φ(p) = p− 1;

2. φ(pα) = (p− 1)pα−1.

3. if m and n are coprime then φ(mn) = φ(m)φ(n).

4. for all n > 1,

φ(n) = n∏

(1− 1pi

)

where pi are the prime factors of n.

Proof. By Cor. 6.1.2, the number of invertible elements in Z/pZ is p−1, so φ(p) = p−1.In the same way, the elements of Z/pαZ which are not coprime to p are the multiple ofp, thus p elements. So the number of invertible elements is (p− 1)pα−1.By Prop. 6.1.7, one has (Z/mnZ)∗ ' (Z/mZ)∗ × (Z/nZ)∗ which gives the result.

Remark 21. [HW79] One has

limφ(n) log log n

n= e−γ

where γ is the Euler constant.

Page 90: Cryptology course

90 CHAPTER 6. REVIEWS AND COMPLEMENTS

Corollary 6.1.3 (Fermat’s little theorem). For all a ∈ (Z/nZ)∗ one has

aφ(n) ≡ 1 (mod n).

In particular if n = p prime, one has

ap−1 ≡ 1 (mod p).

Proof. By definition, the order of the group (Z/nZ)∗ is φ(n), which gives in the groupaφ(n) = 1.

Remark 22. Another form of Fermat’s little theorem is the following : for any a onehas ap ≡ a (mod p).Here is another proof of Fermat’s little theorem : prove first that

(pk

) ≡ 0 (mod p) forall 1 ≤ k ≤ p− 1. Develop (a + 1)p (mod p). Then by induction on a.

Let us show a last property of the function φ.

Proposition 6.1.8. For all n ≥ 1, one can write

n =∑

d|nφ(d).

Proof. Let us denote

D = { 1n

,2n

, . . . ,n

n}.

For all d|n define

Dd = {k

d, gcd(k, d) = 1, 1 ≤ k ≤ d}.

By the unicity of the irreducible form of a fraction, one sees that the Dds form a partitionof D. Now the proposition follows, noting that #Dd = φ(d).

The structure of (Z/pZ)∗ is particulary simple.

Proposition 6.1.9. The group G = ((Z/pZ)∗,×) is cyclic. The generators of this groupare called primitive elements (elements primitifs).

Proof. Let d be a divisor of p− 1. If there exists an element x of order d, it generates asubgroup H of order d of G. For all y ∈ H, yd − 1 = 0. As the polynomial Y d − 1 hasat most d roots in Z/pZ, all the elements of order d are in H. Thus the number N(d) ofelements of order d is 0 or φ(d), in both cases N(d) ≤ φ(d). Using Prop. 6.1.8, one seesthat N(d) = φ(d) for all d, in particular N(p− 1) = φ(p− 1) > 0 and G has an elementof order p− 1, i.e. a primitive element.

Remark 23. The proof shows also that for any divisor q of p − 1 there is an elementin G of order q.

Page 91: Cryptology course

6.2. PROBABILITY 91

Proposition 6.1.10. Let p be a odd prime and e ≥ 2. Then

(Z/peZ)∗ ' Z/(p− 1)Z× Z/pe−1Z.

Proof. First we prove by induction that if k ∈ N∗ then (1+p)pk= 1+λpk+1 with λ ∈ N∗

prime to p.From this result we deduce that 1 + p is an element of order pe−1 in (Z/peZ)∗.Now, we consider the surjective morphism ψ : (Z/peZ)∗ → (Z/pZ)∗. Let x ∈ (Z/peZ)∗

an element such that ψ(x) generated (Z/pZ)∗. The order of x is a multiple of (p − 1)so there is an element y of order p − 1. As the orders of y and 1 + p are coprime, theelement y(1 + p) is of order pe−1(p − 1). So the group (Z/pZ)∗ is cyclic and by theChinese Remainder Theorem, we can write it as the proposition claims.

Example 16. Find the structure of (Z/16Z)∗ and the primitive elements of (Z/13Z)∗.

Remark 24. For p = 2 and e ≥ 3 the groups (Z/peZ)∗ are not cyclic. More precisely(Z/peZ)∗ ' Z/2Z× Z/2e−2Z.

6.2 Probability

6.2.1 Introduction

Let S be a finite nonempty set. We call it the sample space (espace des evenements).Its elements are called elementary events (evenement elementaires).

Example 17. If we flip a coin, we either obtain heads H or tails T. The sample spaceis S = {H, T}.

An event (evenement) is a subset of S. The certain event is S. The null event is∅. Two events U, V are mutually exclusive (disjoint) if U ∩ V = ∅.Definition 6.2.1. A probability distribution on S is a map Pr that sends an event toa real number such that

1. 0 ≤ Pr(A) ≤ 1 for all event A;

2. Pr(S) = 1;

3. Pr(A ∪B) = Pr(A) + Pr(B) for two mutually exclusive events.

Pr(A) is called the probability of A.

One can show that Pr(∅) = 0 and if A ⊂ B then Pr(A) ≤ Pr(B).

Example 18. The probability distribution on the set {1, 2, 3, 4, 5, 6} which models a diemaps each elementary event to 1/6.

The probability distribution that maps each elementary event a ∈ S to the proba-bility 1/|S| is called the uniform distribution (distribution uniforme).

Page 92: Cryptology course

92 CHAPTER 6. REVIEWS AND COMPLEMENTS

6.2.2 Conditional probability

Let (S, Pr) be a finite set with a probability distribution.

Definition 6.2.2. Let A,B be events with Pr(B) > 0. The conditional probability(probabilite conditionnelle) of A given B is defined to be

Pr(A|B) =Pr(A ∩B)

Pr(B).

Two events are called independent (independants) if

Pr(A ∩B) = Pr(A) · Pr(B).

This is equivalent to Pr(A|B) = Pr(A).

Proposition 6.2.1 (Bayes theorem). If A,B are two events such that Pr(A) > 0 andPr(B) > 0 then

Pr(B)Pr(A|B) = Pr(A)Pr(B|A).

Example 19. We throw two dice. Determine the probability that they both show dif-ferent numbers under the condition that the sum of both numbers is even (answer :2/3).

Remark 25. Conditional probabilities are subtle and may lead to paradoxes. Let quotethe following introduce by Leslie and Carter. Let A be the event : apocalypse will happenbefore 2050 and B the event the apocalypse will happen after 2050. Let Z the event, I wasthere in 2005. In case A one can say that 1/10 humans would have lived in 2005. In thecase B this number will be smaller than 1/1000. What is the probability of A knowing thatI’m alive in 2005 ? One has Pr(A) = .01, P r(B) = .99, Pr(Z|A) = 0.1, P r(Z|B) = .001so

Pr(Z) =Pr(Z|A)Pr(A)

Pr(A|Z)=

Pr(Z|B)Pr(B)1− Pr(Z|A)

.

So we get Pr(A|Z) > 1/2 ! For a a possible explaination of this paradox see [Del03].Another interesting problem is the problem of the 3 boxes : in a TV game there are 3boxes, one of them containing a treasure. You can pick a box. The presenter, who knowswhere is the treasure, opens one of the two remaining box he knows empty. He asks youthen if you want to reconsider your choice. Do you ?A last example is the following : in a casino, you’re asked to play the following game: you can choose a sequence of three colors (red, red, black for instance). Then youropponent chooses one also. The roulette is launched. The first sequence to appear wins.Is it a fair game ? It can be shown that whatever the sequence you choose, the opponentcan make a better choice in proportions from 2 to 1 till 7 to 1 ! Here is the list and theprobability of the opponent to win.

Page 93: Cryptology course

6.2. PROBABILITY 93

Your choice Opponent’s choice probabilityRRR NRR 7/8RRN NRR 3/4RNR RRN 2/3RNN RRN 2/3NRR NNR 2/3NRN NNR 2/3NNR RNN 3/4NNN RNN 7/8

6.2.3 Perfect secrecy

We will study Shannon security for symmetric cryptosystems. We assume that the setsP and K are given with probability distributions PrP and PrK. One denotes also Prthe product probability on P × K. To simplify notations, we write Pr(x) for x ∈ Pmeaning Pr({x} × K) = PrP({x}) and the same for k ∈ K. Last, if y ∈ C, one denotesPr(y) the probability of the event {(x, k), Ek(x) = y}.Note that

{(x, k), Ek(x) = y} =⋃

k∈Ky∈Ek(P)

{(Dk(y), k)}.

SoPr(y) =

k∈Ky∈Ek(P)

Pr(k)Pr(Dk(y)).

Let us point out that we assume here that a new key k is chosen randomly for each newmessage x.

Definition 6.2.3. Such a cryptosystem is perfectly secure (parfaitement sur) if

∀x ∈ P,∀y ∈ C, P r(x|y) = Pr(x).

Proposition 6.2.2. If for any y ∈ C, Pr(y) > 0 and if the system is perfectly securethen

#K ≥ #C ≥ #P.

Proof. Let x ∈ P such that Pr(x) > 0. For any y ∈ C, one has Pr(x|y) = Pr(x). ByProp. 6.2.1 Pr(y), P r(x|y) = Pr(y|x)Pr(x) so Pr(y|x) > 0 which means that there is atleast one key k ∈ K such that Ek(x) = y. So #K ≥ #C. As Ek is injective #C ≥ #P.

Proposition 6.2.3. Assume that the cryptosystem satisfies #K = #C = #P and thatPr(y) > 0 for any y ∈ C. It is perfectly secure if and only if

• all the keys have the same probability;

• for all x ∈ P and all y ∈ C there exists a unique key k satisfying Ek(x) = y.

Page 94: Cryptology course

94 CHAPTER 6. REVIEWS AND COMPLEMENTS

Proof. If the conditions are satisfied, let us compute

Pr(y) =∑

k∈Ky∈Ek(P)

Pr(k)Pr(Dk(y)),

=1

#K∑

k∈KPr(Dk(y)),

=1

#K∑

x∈PPr(x) =

1#K .

On the other hand, for x ∈ P and y ∈ C, as there is only one key k such that Ek(x) = y,one has

Pr(y|x) =∑

k| Ek(x)=y

Pr(k) =1

#K .

NowPr(x|y) =

Pr(x)Pr(y|x)Pr(y)

= Pr(x).

Conversely, assume that the security is perfect. As in the previous proposition, oneshows that for all (x, y) ∈ P × C there exists a key k such that Ek(x) = y. If x is fixedone has

{Ek(x), k ∈ K} = C.As K = C, the key k has to be unique.Let k1, k2 be two different keys. Let y ∈ C and xi ∈ P be the unique elements such thatEki

(xi) = y. One has

P (y) = P (y|xi) =∑

k| Ek(xi)=y

Pr(k) = Pr(ki)

so Pr(k1) = Pr(k2).

Example 20. The one-time-pad of Vernam (see 1.4.2) satisfies of course the conditionsof the proposition. It is then perfectly secure.On the contrary, if x is of length n > 1 and A a invertible binary matrix of size n × n(picked randomly) then y = Ax is not perfectly secure ! Indeed, Pr(x = O) = 1/2n whenPr(x = 0|y = 0) = 1.

6.2.4 Birthday paradox

The problem is the following. Suppose a group of people are in a room. What is theprobability that two of them have the same birthday ? This probability is astonishinglylarge.We will make a slightly more general analysis. Suppose that there are n birthdays andk people. An elementary event is a tuple (b1, . . . , bk) ∈ {1, 2, . . . , n}k. So we have nk

elementary events which are equally probable. Then the probability of an elementary

Page 95: Cryptology course

6.3. COMPARISON OF FUNCTIONS, COMPLEXITY 95

event is 1/nk.We want to compute the probability p that two people in the room have the samebirthday. In order to do that, one evaluates the probability 1− p that any two peoplehave different birthdays. The event we are interested is the set E of all sequences(g1, . . . , gk) whose entries are pairwise distinct. The order of E can be computed asfollow : the first entry can be any of the n possibilities. If the first entry is fixed thenthere are n− 1 possibilities for the second entry and so on. Hence we obtain

|E| =k−1∏

i=0

(n− i)

and

1− p = |E|/nk =k−1∏

i=1

(1− i

n

).

Now 1 + x ≤ ex for all real number so

1− p ≤ e−k(k−1)/(2n).

If k ≥ (1 +√

1 + 8n log 2)/2 then p ≥ 1/2. For n = 365 one can choose k = 23.

Example 21. Suppose that four-digit PINs are randomly distributed. How many peoplemust be in a room such that the probability that two of them have the same PIN is atleast 1/2 ?

We can see now why we need at least 128 bits for hash functions : indeed k ≈ 260 son must be at least quadratic with respect to k, so n > 2120 in order to avoid collisions.

6.3 Comparison of functions, complexity

To define complexity in a proper way, one should introduce Turing machines. Howeverwe will assume an intuitive understanding of an algorithm by a program on a computer.We will not consider operations at the level of the symbols of the alphabet of the machine.Instead we will consider elementary operations as addition, multiplications, etc.It can be shown that the class of complexity (polynomial, exponential or subexponential)does not depend on the model we choose. Thus we will express the size (taille) of theinput in terms of their length in bits. For instance if the input is an integer n, its sizewill be |n|2 = blog2(n)c+ 1.We want to analyze the complexity of algorithms which will be essentially their runningtime. Indeed we want to

• evaluate the resources we need (CPU time).

• compare two different algorithms solving the same problem.

• give a upper bound on the size of the input for which the running time is feasiblein practice.

Page 96: Cryptology course

96 CHAPTER 6. REVIEWS AND COMPLEMENTS

We recall the following definitions.

Definition 6.3.1. Let (Dn, P r) the set of all input of size n of an algorithm A withprobability distribution Pr. Let Cn(d) be the number of elementary operations done byA on the input d ∈ Dn.The best cases (cas favorables) are the inputs d0 such that Cn(d0) = min{Cn(d), d ∈Dn}.The worst cases (cas defavorables) are the inputs d0 such that Cn(d0) = max{Cn(d), d ∈Dn}.The average running time (temps moyen d’execution) of A is given by

∑d Cn(d)Pr(d).

To analyze an algorithm is to try to compare the average cost with usual functionslog2(n), n, n2, 2n, . . ..

6.3.1 Asymptotic behavior

Let f, g be two positive functions. One says that f is dominated by (dominee par) g(near +∞) if there exists a constant c > 0 and x0 such that for all x > x0, f(x) ≤ cg(x).One denotes f = O(g).One says that f is negligible (negligeable) with respect to g if for all ε there exists x0

such that for x > x0 f(x) ≤ εg(x). One denotes f = o(g). Also if g is not given, we saythat f is negligible if for any integer n, f(x) = o(x−n).f and g are said equivalent if f − g = o(g). One denotes f ∼ g.

Example 22. x2 + 5x = O(x2), x log(x) = o(x2), x3 + x + log(x)5 ∼ x3.

Sometimes, we use also O(g(n)) to mean O(g(n) log(g(n))k) for some k.

6.3.2 Complexity

Let n be the maximal size of the input.

Definition 6.3.2. An algorithm is said exponential (exponentiel) if its average run-ning time is O(ecn) for a constant c > 0.An algorithm is said polynomial (polynomial) if its average running time is O(nd) fora constant d ≥ 1. The set of problems that can be solve by a polynomial algorithm isdenoted P.An algorithm is said subexponential (sous-exponentiel) id its average running timeis O(Ln(u, v)) where

Ln(α, c) = ecnα(log n)1−α

for some 0 < α < 1 and c > 0.

Some classical running-times :

• addition of two integers of size n : O(n).

• multiplication of two integers of size n : O(n2).

Page 97: Cryptology course

6.3. COMPARISON OF FUNCTIONS, COMPLEXITY 97

• reduction of an integer of size 2n modulo an integer of size n : O(n2).

• multiplication of two integers of size n modulo an integer of size n : O(n2).

• Euclid algorithm for two integers of size at most n : O(n2).

• computation of xc (mod m) where x, c, m are of size at most n : O(n3).

• computation of a−1 (mod m) where a, m are of size n : O(n3).

• application of Gauss triangulation algorithm on a k × n matrix with binary coef-ficients O(nk2).

Remark 26. These running-times do not take in account the optimizations which maybe dramatic. For instance, the product of two integers of size n can be realize usingFast-Fourier-Transform in O(n(log n)3), see [Knu98].

6.3.3 Euclid algorithm

Euclidian division

We present two algorithms to do the euclidian division of two integers a > b.

B := b;R := a;Q := 0;while R ≥ B do

R := R−B;Q := Q + 1;

end while;

It is easy to check that at each step a = Qb + R and that R decreases.We have now a binary version. First one computes the smaller integer n such that2nb > a.

Page 98: Cryptology course

98 CHAPTER 6. REVIEWS AND COMPLEMENTS

B := b;R := a;Q := 0;N := n;Aux := 2NB;while N > 0 do

Aux := Aux/2;N := N − 1;if R < Aux then

Q := 2 ∗Q;else

Q := 2Q + 1;R := R−Aux;

end if;end while;

It is easy to check that at each step a = AuxQ + R and that 0 ≤ R < Aux and thatwhen N = 0 one has Aux = B.

Remark 27. The algorithms have not the same complexity. If b is fixed, the first oneruns in maximal time of the order of a, so it is exponential in the size of a. For thesecond one, one has to determine n which can be done in polynomial time in the size ofa. Then the number of loops is of the order of |a|2 so linear in the size of a. Note thatthe loops contain in both cases only elementary operations.

Euclid algorithm

R0 := |a|;R1 := |b|; (b 6= 0)while R1 > 0 do

R := DivisionRemainder(R0, R1);R0 := R1;R1 := R;

end while;

The output is R1 := 0 and R0 := gcd(a, b). This is clear because the set of commondivisors of a and b is the set of common divisors of R0 and R1. Moreover if R1 = 0then gcd(R1, R0) = R0. Before analyzing the complexity of this algorithm, we give anextended form which has the same complexity.

Page 99: Cryptology course

6.3. COMPARISON OF FUNCTIONS, COMPLEXITY 99

R0 := a, a ≥ 0;R1 := b; (b > 0);U0 := 1; U1 := 0;V 0 := 0; V 1 := 1;while R1 > 0 do

Q := DivisionQuotient(R0, R1);R := DivisionRemainder(R0, R1);U := U0−Q ∗ U1;V := V 0−Q ∗ V 1;R0 := R1; R1 := R;U0 := U1; U1 := U ;V 0 := V 1;V 1 := V ;

end while;

As previously at the end, R1 := 0, R0 := gcd(a, b) and one has

U0a + V 0b = R0.

As previously this can be shown by recursion on the equalities :

U0a + V 0b = R0U1a + V 1b = R1

R1 ≥ 0

Example 23. Use the extended euclidian algorithm to compute a solution of 42x ≡ 1(mod 67) (answer : 8).

We have seen that (if we use the binary euclidian division) all the operations arepolynomial. So to prove that Euclid algorithms are polynomial it is enough to provethat the number of loops is at worst polynomial in the size of a.

Proposition 6.3.1. Let a > b > 0 and Φ := (1+√

5)/2. Then the number of iterationsin the euclidian algorithm is at most log(a)/ log(Φ) < 1.441 log2(a).

Proof. Denote by R0k (resp. R1k, Rk, Qk) the value of R0 (resp. R1, R, Q) at the kthround of the loop for 0 ≤ k ≤ n (so R00 = a and R0n = gcd(a, b), Rn = R1n = 0 etR0k = R1kQk + Rk). We will prove by inverse induction that

R0k ≥ R0nΦn−k.

This is true for k = n. For k = n− 1 one has

R0n−1 = R1n−1Qn−1 + Rn = R1n−1Qn−1 = R0nQn−1 > 2R0n > R0nΦ1.

Indeed Qn−1 6= 1 since otherwise we would have R0n−1 = R1n−1 which implies Rn−2 =R1n−1 (impossible : the remainder must be smaller than the divider).For n− 2 ≥ k ≥ 0 one has

R0k = R0k+2 + Qk+1R0k+1 ≥ R0k+2 + R0k+1 ≥ R0nΦn−k−1

(1 +

)= R0nΦn−k.

Page 100: Cryptology course

100 CHAPTER 6. REVIEWS AND COMPLEMENTS

This proves the proposition since

log(R00) = log(a) ≥ n log(Φ) + log(gcd(a, b)).

Remark 28. The presence of the golden number is not a mystery : it is associated tothe growing of the Fibonacci sequence which is the worst case for the euclidian algorithm.

6.3.4 Probabilistic algorithms

All complexity notions can be extended to probabilistic algorithms, i.e. algorithms forwhich some decisions may be taken randomly. It might seem paradoxal but often thesealgorithms give faster answers than deterministic algorithms, the problem is that theirrunning time is less easy to evaluate and that sometimes they do not stop. More preciselyone distinguishes the following categories :

• a Las Vegas algorithm is a probabilistic polynomial algorithm which may runendlessly but if it stops it gives the right answer.

• a Monte Carlo algorithm is a probabilistic algorithm which worst running time ispolynomial. Then it always stops but if it answers yes the answer is sure but itmay answer no when it is yes.

• an Atlantic city algorithm is a probabilistic algorithm which worst running timeis polynomial. Then it always stops but can be wrong if the answer if yes or no.Of course the probability of a wrong answer is smaller than the correct one.

Note that we have defined the different algorithms for decision problems. By dichotomyargument it is possible to reduce in linear time the problem of the value of a functionf : N→ N to a decision problem.

Remark 29. We can always simulate a probabilistic algorithm (running on a non-deterministic Turing machine) by a standard algorithm on a standard Turing machine.However the reduction time may be exponential.Caution : probabilistic algorithms are a different notion from non deterministic algo-rithms. For instance Monte Carlo algorithms are the algorithms to solve a problem inthe class RP (Randomized problem) when non deterministic solve problem in a largerone denoted NP. Intuitively a NP (decision) problem is a problem for which we cancheck the positive answers in polynomial time using an oracle which delivers a specificcertificate. For instance the problem ‘IsComposite?’ is clearly in NP: indeed to checkthat an integer is composite it’s enough to give two factors and to make the product.The problem ‘IsPrime?’ is also in NP (even in P). RP is included in NP because atleast half of the certificates must be valid.

Example 24. We will give the precise definition of a one-way function. A functionf : {0, 1}∗ → {0, 1}∗ is a one-way function if

Page 101: Cryptology course

6.3. COMPARISON OF FUNCTIONS, COMPLEXITY 101

• there is an Atlantic City algorithm which computes f ;

• for all probabilistic algorithm (A,Pr) which runs in polynomial maximal time thereexists a function ν satisfying limk→∞(ν(k)km) = 0 for all m, and k0 such that forall k > k0 and for all x ∈ {0, 1}k

Pr(f(A(1k, f(x))) = f(x)) ≤ ν(k).

The word 1k is an artificial input to impose that the input is at length at least k evenif f(x) is smaller than x. To understand the interest of this constraint, let us give thefollowing example. Let us define

f(x) = f(x1 . . . xk) = (x1 . . . xt)

for t = blog2(k)c+1. It is very easy to find an algorithm giving a preimage of f . Howeveras the input of A is f(x), of length t, the writing of such a solution is exponential in t.So we would have an ‘easy exponential’ algorithm. To avoid this paradox, one imposesthe input of A to be of length k and then we have an easy linear algorithm.

Remark 30. An alternative definition is to ask that f is computable in polynomialtime but that f−1 is not. Then it is clear that to find such an f would prove P 6= NP .However this definition which is convenient for theoretical studies is not accurate forcryptography.Complexity theory helps us to delimit problems which might be useful to build cryp-tosystem. However, complexity theory deals with difficulty in the worst case, whereascryptography deals with difficulty in the average case. For instance knapsack problemsthat are on a complexity point of view the most difficult (NP-complete) were crypto-graphically broken (by lattice attacks, see [Odl90]).To see that RSA for instance is not ’hard in worst case’ and ’easy on average’, there isa technique called random self reduction. Suppose that we are given y and are asked tosolve y ≡ xe (mod N) where the idea is that this is a worst case instance. We reducethis to an average problem by choosing s ∈ (Z/NZ)∗ at random and setting y′ = sey.Then we try to solve y′ ≡ x′e (mod N). If the average case is easy, we can solve thehard case also since x = x′/s.

6.3.5 Reduction of a problem

Definition 6.3.3. Solving a problem P1, we say that we call a P2-oracle if the algorithmwe use transforms the input of the problem P1 in an input of P2.

Definition 6.3.4. If P1 and P2 are two problems, we say that P1 reduces (se reduit)to P2 (in polynomial time) if there exists a polynomial algorithm for P1 which uses aP2-oracle at most a polynomial times.

Example 25. See the proof of Th. 3.1.3.

Page 102: Cryptology course

102 CHAPTER 6. REVIEWS AND COMPLEMENTS

6.4 Quadratic residues

Definition 6.4.1. Let a, n be two coprime integers. We say that a is a quadratic residue(residu quadratique) modulo n if there is an integer x such that x2 ≡ a (mod n).

We will deal with two problems : find out if a number is a quadratic residue; if it isso, find out a square root.

6.4.1 Legendre, Jacobi symbols

Let n = p be an odd prime (the case p = 2 is trivial). We know (Prop. 6.1.9) that(Z/pZ)∗ is cyclic. Let α be a primitive element.

Lemma 6.4.1. The element α is not a quadratic residue. Moreover

α(p−1)/2 = −1.

Proof. By Fermat’s little theorem αp−1 = 1, so α(p−1)/2 = ±1. But as α is of order p−1one has α(p−1)/2 = −1. So α is not a quadratic residue. Otherwise there would exist βsuch that β2 = α and α(p−1)/2 = βp−1 = 1.

Lemma 6.4.2. Let n = p be an odd prime. The quadratic residue are the even powersof α and 0. Thus, half of the p− 1 elements of (Z/pZ)∗ are quadratic residue.

Proof. It is enough to prove that α2k+1 is not a quadratic residue. Otherwise therewould be u such that u2 = α2k+1, so α = u2/α2k would be a square.

Definition 6.4.2. Let n = p be an odd prime number and a an integer. We define theLegendre symbol of a by:

(a

p

)=

0 if a is divisible by p,

1 if a is a quadratic residue modulo p,−1 if a is not a quadratic residue modulo p.

Lemma 6.4.3. If a is prime to p, then(

a

p

)≡ a(p−1)/2 (mod p).

Proof. Let α be a primitive element of (Z/pZ)∗. One can write a ≡ αk (mod p). Now

a(p−1)/2 ≡ (α(p−1)/2)k ≡ (−1)k (mod p).

Lem. 6.4.2 leads to the conclusion.

The Legendre symbol of a is equal to 1 if and only if a is a quadratic residue. By theexpression of the previous lemma, this property can be computed in polynomial time.

Page 103: Cryptology course

6.5. CONTINUED FRACTIONS 103

Definition 6.4.3. Let n ≥ 3 be an odd integer. We write n = p1 · · · ps where the pi areprime numbers (not necessarily distinct). Let a be an integer. The Jacobi symbol of ais defined by (a

n

)=

(a

p1

)· · ·

(a

ps

).

This symbol is multiplicative in both arguments:(

ab

n

)=

(a

n

)(b

n

),

( a

mn

)=

( a

m

)(a

n

).

Remark 31. The Jacobi symbol only depends on the class of a modulo n.The definition can be extended to even numbers n by multiplicativity.

The Jacobi symbol can be computed efficiently even if the factorization of n is notknown.

Theorem 6.4.1. Let n > 3 be an odd integer. Then(−1

n

)= (−1)(n−1)/2,

(2n

)= (−1)(n

2−1)/8.

Theorem 6.4.2 (quadratic reciprocity law). Let m, n ≥ 3 be odd coprime integers.Then (m

n

)= (−1)

(n−1)(m−1)4

( n

m

).

Example 26. Compute(

5370

)=

(5335

)=

(1835

)

=(

235

)(935

)= −1 · 1 ·

(359

)

= −1 ·(−1

9

)= −1.

Remark 32. The Jacobi symbol does not characterize quadratic residues modulo n.Clearly if the Jacobi symbol of a is −1 then a is not a quadratic residue but if it is 1 wecannot say more.

6.5 Continued fractions

Continuous fractions are important in many branches of mathematics and particularlyin the theory of approximation to real numbers by rational. We shall refer to [HW79,Chap.X] for the proofs.

Page 104: Cryptology course

104 CHAPTER 6. REVIEWS AND COMPLEMENTS

6.5.1 Finite continued fraction

We shall describe the expression

a0 +1

a1 + 1a2+ 1

a3+ . . .+ 1

aN

which we shall denote [a0, a1, a2, . . . , aN ] and call a continued fraction (fraction con-tinue). We will restrict to the case where

the ai are positive integers (for i > 0 ) and a0 is an integer. (6.2)

Theorem 6.5.1. [HW79, Th.149] If pn and qn are defined by

p0 = a0 p1 = a1a0 + 1 pn = anpn−1 + pn−2

q0 = 1 q1 = a1 qn = anqn−1 + qn−2

then[a0, a1, . . . , an] =

pn

qn.

Theorem 6.5.2. [HW79, Th.150] The functions pn and qn satisfy

pnqn−1 − pn−1qn = (−1)n−1.

6.5.2 Infinite continued fraction

We start by ‘taking the limit’ of the previous process and call it an infinite continuedfraction.

Theorem 6.5.3. [HW79, Th.165] If (ai) is a sequence of integers satisfying (6.2) thenthe sequence [a0, a1, . . . , ai] converges and we denote its limit by [a0, a1, . . .].

We can now inverse the process. Let x be a real number and let a0 = bxc. We havethen x = a0 + ξ0 with 0 ≤ ξ0 < 1. We define now a1 = b1/ξ0c. We have a1 > 0 and wedefine 1/ξ0 = a1 + ξ1 with 0 ≤ ξ1 < 1. Iterating, we define in this way a sequence (ai)satisfying (6.2).

Theorem 6.5.4. The number [a0, a1, . . .] is equal to x. Moreover if x is irrational, itcan be represented in a unique way as an infinite continued fraction.

Example 27. The continued fraction development of a rational number is finite. Theperiodicity of the development is equivalent to x being an irrational root of a quadraticequation with integral coefficients.e = [2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, . . .].π = [3, 7, 15, 1, 292, 1, 1, . . .]. This sequence is much more mysterious. For instancenobody knows if the upper limit of the coefficients is +∞ or not. It can be shown thatthis problem is equivalent to the density in R of the sequence (n sinn).

Page 105: Cryptology course

6.6. FINITE FIELDS 105

Continued fractions are good approximations of numbers as the following theoremshows.

Theorem 6.5.5. [HW79, Th.171,183,184] One has

|x− pn

qn| < 1

q2n

and either p/q = pn/qn or p/q = pn+1/qn+1 satisfies

|x− p

q| < 1

2q2

Conversely if p/q is a fraction which satisfies

|x− p

q| < 1

2q2

then there is an n such that p/q = pn/qn.

6.6 Finite fields

In this section we describe a method for constructing finite fields.

6.6.1 Definitions

Definition 6.6.1. Let p be a prime and n a positive integer n. We call the finite field(corps fini) over Z/pZ of degree n the decomposition field of the polynomial Xpn −X.We denote this field Fpn

.

It can be shown (see [Goz97, chap.VII]) that Fpn is the only field with pn elementsup to isomorphism. In particular, if f be an irreducible polynomial of degree n over Fp,it defines an extension of Fp of degree n, Fp[X]/f , which can be identified to Fpn .

Example 28. The polynomial X2 + X + 1 is irreducible over F2 (otherwise it wouldhave a root in F2). It defines then the extension F4.

Proposition 6.6.1. The extension Fpn/Fp is Galois with Galois group isomorphic toZ/nZ. A generator of this group is the automorphism x 7→ xp.

6.6.2 Irreducible polynomials

Rabin’s test relies on the following theorem.

Proposition 6.6.2. If f is of degree n and irreducible then f |Xpn −X.

Proof. Let F be the extension of Fp defined by f . As F is Galois, f has all its rootsin F . As f is irreducible, these roots have multiplicity one and we know that they arezeros of Xpn −X. So f |Xpn −X.

Page 106: Cryptology course

106 CHAPTER 6. REVIEWS AND COMPLEMENTS

So we can apply the following algorithm :

1. Test if f |Xpn −X. If not f is not irreducible.

2. for each prime q dividing n compute gcd(f,Xpn/q − X). f is irreducible if andonly if all these numbers are equal to 1.

Example 29. Let p = 2 and f(X) = X8 + X4 + X3 + X + 1. We can check thatf |X28 −X and gcd(f,X24 −X) = 1.

6.6.3 Operations

The elements of the field are residue classes modulo f . The construction of those residueclasses corresponds to the construction of residue classes in Z. By euclidian division,a representative of the class is a polynomial of degree less than deg(f). Addition andmultiplication can be done imitating the process in Z/nZ.

Example 30. Representatves of the residue classes in F2[X]/X2 +X +1 are 0, 1, X, 1+X. We obtain the following addition and multiplication tables.

+ 0 1 X X + 10 0 1 X X + 11 1 0 X + 1 X

X X X + 1 0 1X + 1 X + 1 X 1 0

× 1 X X + 11 1 X X + 1X X X + 1 1

X + 1 X + 1 1 X

We can also compute the inverse of an element using Bezout theorem. Indeed, sincef is irreducible, for any g ∈ Fp[X] of degree less than deg(f), f and g are coprime.There exist then (u, v) such that uf + vg = 1. Thus v is the inverse of g modulo f .

Example 31. Let p = 2 and f(X) = X8 +X4 +X3 +X +1. We determine the inverseof X + 1 modulo f . We have

f(X) = (X + 1)(X7 + X6 + X5 + X4 + X2 + X) + 1

so the class of X7 + X6 + X5 + X4 + X2 + X is an inverse of X + 1 modulo f .

Page 107: Cryptology course

Chapter 7

Tutorial : algorithms

7.1 Prime numbers

To Produce big prime numbers is very important for cryptographic applications. For agiven n, there is no generic algorithm which can compute a random prime number lessthan n. However a result by Hadamard and de la Vallee Poussin shows that #{p ≤n prime} ∼ n

log n (see 6.1.2). So the usual method is to pick random numbers and to testif they are prime or not. This requests that we have fast algorithms to test primality.

7.1.1 Primality test

Trial division

The simplest algorithm is based on the following result.

Proposition 7.1.1. n is a composite number if and only if it has a prime divisor psuch that p ≤ √

n.

Proof. Since n is composite, n = ab and either a or b is smaller than√

n.

This proposition suggests that one can try all prime numbers less or equal to√

n usingEratosthenes sieve. Following the estimate density of prime (see 6.1.2), it means that wemake up to

√n/ log

√n divisions, leading to an exponential algorithm in O(e( 1

2−ε) log n).

Fermat test and Carmichael numbers

By Fermat little theorem 6.1.3, one knows that if n is a prime number then an−1 ≡ 1(mod n) for all a ∈ Z coprime with n. If the theorem was an equivalence, we wouldhave an easy polynomial algorithm to test if a number is a prime. Unfortunately

Example 32. Consider n = 341 = 11 ·31. One has 2340 ≡ 1 (mod 341). Such a numberis called pseudo-prime (pseudo-premier) in base 2.We can prove that there is infinitely many pseudo-prime in base 2 by showing that if n

107

Page 108: Cryptology course

108 CHAPTER 7. TUTORIAL : ALGORITHMS

is such a number then 2n−1 also. Indeed because n is a pseudo-prime in base 2 one hasn|2n−1 − 1, i.e. there is c such that nc = 2n−1 − 1. Now

22n−1−1 − 1 = 22(2n−1−1) − 1 = 22nc − 1.

The last expression is divisible by 2n − 1 so

22n−1−1 ≡ 1 (mod 2n − 1).

To finish the proof, one has to show that 2n − 1 is not a prime. Since n = ab, 2n − 1 isdivisible by 2a − 1.

An idea is then to change the value of a : for instance 3340 ≡ 56 (mod 341). Un-fortunately, there are numbers that are pseudo-prime in any base. Such numbers arecalled Carmichael numbers (for instance 561 = 3 · 11 · 17). It has been shown by Alford,Granville and Pomerance in 1994 that there are infinitely many Carmichael numbers soFermat test cannot be completely sure. Let us show some properties of these numbers.

Proposition 7.1.2. An (odd) composite number n ≥ 3 is a Carmichael number if andonly if it is square free and for each prime divisor p of n, p− 1 divides n− 1.

Proof. First it is easy to see that a Carmichael number is odd : indeed (−1)n−1 ≡ 1(mod n) if and only if n is odd.Let a be a Carmichael number, for any a prime to n one has

an−1 ≡ 1 (mod n).

Let p be a prime divisor of n. There exists a primitive element modulo p that is primeto n. Indeed, let a a primitive element modulo p and n = pr · m with m coprime top. There exists an element (still denoted a) in Z/prZ lifting the initial a (because themorphism Z/prZ → Z/pZ est surjectif). We find s ∈ Z/mZ coprime to m and sinceZ/nZ ' Z/prZ × Z/mZ we construct the element a ∈ Z/nZ image of (a, s). Such anelement satisfies the properties for a. Now, one has of course an−1 ≡ 1 (mod p) but asa is primitive p− 1 divides n− 1.Now suppose that n = p2m and write a = 1 + pm. One has

ap ≡ 1 + p2m + . . . ≡ 1 (mod n)

So the order of a is p. But p does not divide n− 1 (p|n) so we get a contradiction.Conversely, let n be a square-free integer such that p − 1 divides n − 1 for all primedivisors p of n. Let a be prime to n one has

ap−1 ≡ 1 (mod p)

and because n− 1 is a multiple of p− 1,

an−1 ≡ 1 (mod p).

Using the Chinese Remainder theorem for all the factors p, one gets

an−1 ≡ 1 (mod n).

Page 109: Cryptology course

7.1. PRIME NUMBERS 109

Corollary 7.1.1. Any Carmichael number is the product of at least 3 distinct oddprimes.

Proof. Because a Carmichael number is without square factor and is not prime it hasat least two prime factors. Let us assume that n = pq with p < q. Then q − 1 dividespq − 1 = p(q − 1) + p− 1 so q − 1 divides p− 1. Absurd.

Example 33. Show that if 6m + 1, 12m + 1 and 18m + 1 are primes then n = (6m +1)(12m+1)(18m+1) is a Carmichael number. First by the Chinese Remainder theorem,one can see that if n = ab with a, b coprime then for any x prime to n one has

xlcm(φ(a),φ(b)) ≡ 1 (mod n).

Now lcm(φ(6m+1), φ(12m+1), φ(18m+1)) = 36m and also 36m|n−1. One can checkthat 1729 is such a number.

Lucas test

Let n > 1 be an integer. We will show that if there exists an a such that an−1 ≡ 1(mod n) and aq 6≡ 1 (mod n) for all q|n − 1 then n is prime. This is a very good testfor Fermat numbers Fm, i.e. numbers of the form n = 22m

+ 1 (For m = 0 . . . 32 onlythe first five are prime. F33 is so big that it may be many years before we can decideits nature). But obviously this test is not good for a generic prime since we know thefactorization of n− 1.Let assume that such an a exists and let d be the order of a in (Z/nZ)∗. Since an−1 ≡ 1(mod n), d|(n− 1). More exactly as no proper divisor of n− 1 is the order of a, one hasd = n− 1. Now n− 1 = d|φ(n). This is possible only if n is prime.

Rabin-Miller test

Contrary to the Fermat test, the Miller-Rabin test can prove the compositeness of anycomposite number (i.e. there is no analog of Carmichael numbers for this test). ButRabin-Miller test is a Monte-Carlo algorithm : it always stops ; if it answers yes, thenumber is composite and if it answers no then the answer is correct with a probabilitygreater than 3/4.

Let n be an odd positive integer and s = max{r ∈ N, 2r|n− 1}. Let d = (n− 1)/2s.

Lemma 7.1.1 (Miller). If n is a prime and if a is an integer prime to n then we haveeither ad ≡ 1 (mod n) or there exists r ∈ {0, . . . , s− 1} such that a2rd ≡ −1 (mod n).

Proof. The order of a is a divisor of n − 1. It can be d and then ad ≡ 1 (mod n). Ifit is not then its order is 2rd for r ∈ {1, . . . , s}. So a2rd ≡ 1 (mod n) and a2r−1d is anon-trivial square root of 1 so a2r−1d ≡ −1 (mod n).

If we find an a which is prime to n and that satisfies neither of the conditions, thenn is composite. Such an integer a is called a witness (temoin) for the compositeness ofn.

Page 110: Cryptology course

110 CHAPTER 7. TUTORIAL : ALGORITHMS

Example 34. Let n = 561. a = 2 is a witness for n. Indeed here s = 4, d = 35and 235 ≡ 263 (mod 561), 22·35 ≡ 166 (mod 561), 24·35 ≡ 67 (mod 561), 28·35 ≡ 1(mod 561).

For the efficiency of the Rabin-Miller test, it is important that there are sufficientlymany witnesses for the compositeness of a composite number.

Theorem 7.1.1 (Rabin). If n ≥ 3 is an odd composite number, then the set {1, . . . , n−1} contains at most (n − 1)/4 numbers that are prime to n and not witnesses for thecompositeness of n.

Proof. We want to estimate the numbers of a ∈ {1, . . . , n − 1} prime to n such thatad ≡ 1 (mod n) or a2rd ≡ −1 (mod n) for some r ∈ {0, . . . , s − 1}. Suppose such anon-witness a exists. We can assume that it satisfies the second condition (indeed ifad ≡ 1 (mod n) then (−a)2

0d ≡ −1 (mod n)).Let k be the maximum value of r for which there is an integer a prime to n that satisfiesthe second identity. We set m = 2kd. Let n =

∏p pe(p) be the prime factorization of n.

Let

J = {a + nZ : gcd(a, n) = 1, an−1 ≡ 1 (mod n)}K = {a + nZ : gcd(a, n) = 1, am ≡ ±1 (mod pe(p)) for all p|n}L = {a + nZ : gcd(a, n) = 1, am ≡ ±1 (mod n)}

M = {a + nZ : gcd(a, n) = 1, am ≡ 1 (mod n)}.

We have M ⊂ L ⊂ K ⊂ J ⊂ (Z/nZ)∗. For each a which is not a witness for thecompositeness of n, the residue class a + nZ belongs to L. We will prove that the indexof L in (Z/nZ)∗ is at least four.The index of M in K is a power of 2 because the square of each element of K belongsto M (see Ex. 15). Therefore the index of L in K is also a power of 2, say 2j . If j ≥ 2then we are finished.If j = 1 (i.e. [L : K] = 2) then n has two prime divisors. It follows from Cor. 7.1.1 thatn is not a Carmichael number. This implies that J is a proper subgroup of (Z/nZ)∗ andthe index of J in (Z/nZ)∗ is at least 2. Therefore the index of L in (Z/nZ)∗ is at least4.Finally, let j = 0. Then n is a prime power, say n = pe with e > 1. But φ : (Z/nZ)∗ →Z/(p − 1)Z × Z/pe−1Z is an isomorphism (see Prop. 6.1.10). As n − 1 is prime to pan−1 ≡ 1 (mod n) if and only if φ(a) = (µ, 0). So [(Z/nZ)∗ : J ] = #Z/pe−1Z = pe−1.This is bigger than 4 except for n = 9 which can be checked by hand.

To apply the Rabin-Miller test, we choose a random number a ∈ {2, . . . , n − 1}. Ifgcd(a, n) > 1 then n is composite. Otherwise we compute ad, a2d, . . . , a2s−1d. If we finda witness for the compositeness of n, then we have proved that n is composite. By Th.7.1.1, the probability that n is composite and that a is not a witness is less than 1/4. Soif we repeat the test t times we can make this probability less than (1/4)t. For t = 10this probability is less than 10−6.

Page 111: Cryptology course

7.2. FACTORIZATION 111

Remark 33. Under the Generalized Riemann hypothesis (which is conjectural but be-lieved true), it can be proved that there is always a witness for the compositeness of nwith a ≤ O((log n)2).If we want a absolute test, Adleman, Pomerance, Rumely, Cohen and Lenstra have givenan algorithm (APRCL) which is slower but still feasible on numbers of 1000 digits (itruns in O(|n|C log log |n|2

2 )).In 2002, M. Agrawal, N. Kayal and N. Saxena have found a deterministic polynomialalgorithm to solve the problem of primality.

7.2 Factorization

Now given an n that is known to be composite, how can we find its decomposition inprime factors ? We are going to present algorithms to obtain a non-trivial factor. Byrepeating inductively the algorithm, we can then factorize the number.

7.2.1 Trial division

To find small prime factors of n, a precomputed table of all prime numbers below afixed bound B is computed. This can be done using the sieve of Eratosthenes. A typicalbound is B = 106.

Example 35. We want to factor n = 321 + 1. Trial division with primes less than 50yields the factors 22, 72, 43. If we divide n by those factors, we obtain m = 1241143.Since 2m−1 ≡ 793958 (mod m), this number is still composite.

7.2.2 Pollard p− 1 method

This algorithm is efficient when n has a prime factor p such that p − 1 has only smallprime divisors. Indeed, by Fermat’s little theorem, one has

ak ≡ 1 (mod p)

for all multiple k of p− 1. If p− 1 has only small prime divisors, one can try

k =∏

q∈P,qe≤B

qe

where B is a given bound. Now if ak − 1 is not divisible by n, then gcd(ak − 1, n) is anon-trivial factor of n.

Example 36. Let n = 1241143 of the previous example. We set B = 13. Thenk = 8 · 9 · 5 · 7 · 11 · 13 and gcd(2k − 1, n) = 547. So n = 547 · 2269 which are both primenumbers.

Page 112: Cryptology course

112 CHAPTER 7. TUTORIAL : ALGORITHMS

7.2.3 Quadratic sieve

Idea

The quadratic sieve finds integer x, y such that

x2 ≡ y2 (mod n)

andx 6≡ ±y (mod n).

Then n is a divisor of x2 − y2 = (x − y)(x + y) but of neither x − y or x + y. Henceg = gcd(x− y, n) is a proper divisor of n.

Example 37. Let n = 7429, x = 227, y = 210. Then x2 − y2 = n, x− y = 17 so 17|n.

Determination of x and y

The idea from the previous section is also used in other factoring algorithms, such asthe number field sieve (NFS), but those algorithms have different ways of finding x, y.We describe how x, y are found in the quadratic sieve.Let m = b√nc and

f(X) = (X + m)2 − n.

We first explain the procedure on an example.

Example 38. Let n = 7429. Then m = 86. One has

f(−3) = 832 − 7429 = −540 = −1 · 22 · 33 · 5,

f(1) = 872 − 7429 = 140 = 22 · 5 · 7,

f(2) = 882 − 7429 = 315 = 32 · 5 · 7.

This implies

832 ≡ −1 · 22 · 33 · 5 (mod 7429),872 ≡ 22 · 5 · 7 (mod 7429),882 ≡ 32 · 5 · 7 (mod 7429).

If the last two congruences are multiplied then we obtain

(87 · 88)2 ≡ (2 · 3 · 5 · 7)2 (mod n).

Therefore we can set x ≡ 87 · 88 (mod n) ≡ 227 and y ≡ 2 · 3 · 5 · 7 (mod n) ≡ 210.

In the example we have presented number s for which the value f(s) has only smallprime factors. Then we use the congruence

(s + m)2 ≡ f(s) (mod n).

From those congruences, we select a subset whose products yields squares on the left-and the right-hand sides. The left-hand side of each congruence is a square anyway.Also we know the prime factorization of each right-hand side. The product of a numberof right-hand sides is a square if the exponents −1 and all prime factors are even. Inthe next section, we explain how an appropriate subset of congruences is chosen.

Page 113: Cryptology course

7.2. FACTORIZATION 113

Table 7.1: Factor base and sieving

# decimal digits of n 50 60 70 80 90 100 110 120# factor base in thousand 3 4 7 15 30 51 120 245

# sieving interval in million .2 2 5 6 8 14 16 26

Choosing appropriate congruences

The selection process is controlled by coefficients λi ∈ {0, 1}. If λi = 1 the congruencei is chosen; otherwise it is not. The product of the right hand sides of the chosencongruences is

(−1 · 22 · 33 · 5)λ1 · (22 · 5 · 7)λ2 · (32 · 5 · 7)λ3 =(−1)λ1 · 22λ1+2λ2 · 33λ1+2λ3 · 5λ1+λ2+λ3 · 7λ2+λ3 .

We want this number to be a square, so we have to solve the following linear system:

λ1 ≡ 0 (mod 2)2λ1 + 2λ2 ≡ 0 (mod 2)3λ1 + 2λ3 ≡ 0 (mod 2)

λ1 + λ2 + λ3 ≡ 0 (mod 2)λ2 + λ3 ≡ 0 (mod 2).

A solution is λ1 = 0, λ2 = λ3 = 1.In general we choose a positive integer B. Then we look for integers s such that f(s)has only prime factors that belong to the factor base

F (B) = {p ∈ P, p ≤ B} ∪ {−1}.

Such values f(s) are called B-smooth. If we have found as many values for s as thefactor base has elements, then we try to solve the corresponding linear system overZ/2Z. Faster algorithms than Gauss algorithm exist in this case.

Sieving

It remains to be shown how the values of s are found for which f(s) is B-smooth. Onepossibility is to compute the value f(s) for s = 0,±1,±2, . . . and to test by trial divisionwhether f(s) is B-smooth. Unfortunately, those values typically are not B-smooth. Thisis very inefficient as the factor base is large for large n (see Tab. 7.1). A more efficientmethod is to use sieving techniques, which are described as follows.We explain a simplified version that shows the main idea. We fix a sieving interval

S = {−C,−C+1, . . . , 0, 1, . . . , C}. We want to find all s ∈ S such that f(s) is B-smooth.

Page 114: Cryptology course

114 CHAPTER 7. TUTORIAL : ALGORITHMS

To find out which of the values f(s) is divisible by a prime number p in the factor base,we start from the end. We fix a prime p. The equation f(s) ≡ 0 (mod p) has twosolutions si,p which can be computed quickly. Then we try to find values si,p + kp ∈ S.After each step, we divide the corresponding f(s) by p. Prime powers can be treatedsimilarly.

Example 39. Let n = 7429, m = 86. The factor base is the set {2, 3, 5, 7} ∪ {−1}. Assieve interval, we use the set S = {−3, . . . , 3}.

s −3 −2 −1 0 1 2 3(s + m)2 − n −540 −373 −204 −33 140 315 492Sieve with 2 −135 −51 35 123Sieve with 3 −5 −17 −11 35 41Sieve with 5 −1 7 7Sieve with 7 1 1

Remark 34. The optimum size of the factor base is roughly

B =(e√

log n log(log n))√2/4

and the sieving interval is in C = B3. The heuristic running time is Ln(1/2, 1). Thefastest current algorithm is NFS which is in Ln(1/3, (64/9)1/3).

7.3 Square roots

We will restrict to the case where n = p prime. Recall that if the factorization of n = pqis not known, then it is a difficult problem, equivalent to the factorization problem.However, if the factorization is known, then we can solve it by the Chinese RemainderTheorem.

7.3.1 When p = 4k − 1

In this case let a ≡ x2 (mod p). Let us check that ap+14 is a square root of a :

(ap+14 )2 ≡ a(p−1)/2 · a ≡ xp−1 · a ≡ a (mod p).

7.3.2 When p = 4k + 1 : Shanks algorithm

Let us write p − 1 = 2st with t odd and s ≥ 2. Let a ≡ x2 (mod p). Let assume thatwe know a b which is not a quadratic residue modulo p. Let us write z = bt.Set B = at, X = a(t+1)/2, Y = z and R = s− 1 and run the following algorithm.

Page 115: Cryptology course

7.3. SQUARE ROOTS 115

while R ≥ 1 doif B2R−1 ≡ 1 (mod p) then

Y := Y 2;else

B := BY 2;X := XY ;Y := Y 2;

end if;R := R− 1;

end while;

One can check that the output X is a square root of a. To do so, we check that thefollowing conditions are loop invariants :

aB = X2

Y 2R ≡ −1 (mod p)B2R ≡ 1 (mod p)R ≥ 0

As initial conditions

aB = aat = at+1 = (a(t+1)/2)2

Y 2R ≡ z2s−1 ≡ b(p−1)/2 ≡ −1 (mod p)B2R ≡ at2s−1 ≡ a(p−1)/2 ≡ 1 (mod p)R = s− 1 ≥ 0

After a loop, let us denote B′, X ′, Y ′, R′ the new values.

• if B2R−1 ≡ 1 (mod p), then

aB′ = aB = at+1 = (a(t+1)/2)2

(Y ′)2R′= Y 2R ≡ −1 (mod p)

(B′)2R′ ≡ B2R−1 ≡ 1 (mod p)R′ = R− 1 ≥ 0

• if B2R−1 ≡ −1 (mod p), then

aB′ = aBY 2 = X2Y 2 = X ′2

(Y ′)2R′= Y 2R ≡ −1 (mod p)

(B′)2R′ ≡ B2R−1Y 2R ≡ 1 (mod p)

R′ = R− 1 ≥ 0

Let us point out that this algorithm gives the correct answer as long as we have pickeda non quadratic residue b. It is then a Las Vegas algorithm.

Page 116: Cryptology course

116 CHAPTER 7. TUTORIAL : ALGORITHMS

7.4 Discrete Logarithms

Let (G,×) be a finite cyclic group of order n, α a generator. We recall that the DLP isto find x in the equation αx = y.

7.4.1 Generator

We present a way to find a primitive element in (Z/pZ)∗ knowing the decompositionof p − 1 =

∏qαii . We pick a a and for each i we compute a(p−1)/qi . If this element

is different from 1 this means that qαii divides the order of a. As these numbers are

coprime, if all a(p−1)/qi are different from 1 then a is a primitive element, otherwise wepick another a. The probability of success is φ(p−1)/(p−1) which is greater (accordingto Rem. 21) than e−γ/ log log(p− 1) for p big enough.

If we want to find a subgroup H of order q prime in a cyclic group of order n, withn = qr and (q, r) = 1, we pick randomly a and test if ar 6= 1. If so ar generates asubgroup of order q. Elements for which ar = 1 are the ones whose order divides r,there are r such elements. Thus the probability of a bad case is r/n = 1/q.

7.4.2 Attacks

We will present several attacks on the DLP. The first four are exponential. The last oneis subexponential. Note that the biggest DLP which has been solved was in the groupF6553725 of size 400 bits.

Enumeration

The simplest method for computing the DL x from αx = y in G is to test whetherx = 0, 1, 2, . . . satisfies the equation. Of course, as soon as the size of the group isimportant (60 bits), this method is not possible anymore.

Shanks Baby-Step Giant-Step

We set m = d√ne and write x = qm + r with 0 ≤ r, q < m. We have

αqm+r = y ⇒ (αm)q = yα−r.

First we compute the set of baby-steps (pas de bebe)

B = {(yα−r, r), 0 ≤ r < m}.If we find a pair (1, r) then y = αr. If we do not find such a pair, we determine δ = αm.Then we test for q = 1, 2, . . . , m whether the element δq is the first component of anelement of B. As soon as it is true we have a solution for the DLP. The elements δq arecalled giant steps (pas de geant).It is easy to see that this algorithm is in O(

√#G). Note that it requires also a storage

for O(√

#G) elements.

Page 117: Cryptology course

7.4. DISCRETE LOGARITHMS 117

The Pollart ρ-algorithm

This algorithm has the same running time as the previous one but it only requiresconstant storage.We need a partition G1 qG2 qG3 = G. Let f : G → G be defined by

f(β) =

αβ if β ∈ G1,

β2 if β ∈ G2,

yβ if β ∈ G3.

We choose a random x0 ∈ {1, . . . , n} and compute β0 = αx0 . Then we compute thesequence

βi+1 = f(βi).

The elements of this sequence can be written as

βi = αxiyδi

where δ0 = 0 and

xi+1 =

xi + 1 (mod n) if βi ∈ G1,

2xi (mod n) if βi ∈ G2,

xi if βi ∈ G3,

and

δi+1 =

δi (mod n) if βi ∈ G1,

2δi (mod n) if βi ∈ G2,

δi + 1 if βi ∈ G3.

At some points, two elements in the sequence (βi) must be equal, say βi+k = βi. Thisimplies

αxiyδi = αxi+kyδi+k

and thereforeαxi−xi+k = yδi+k−δi .

We obtain a congruence

xi − xi+k ≡ x(δi+k − δi) (mod n).

The solution is unique if δi+k − δi is invertible modulo n. If the solution is not uniquethen the discrete logarithm can be found by testing the different possibilities modulo n.If there are too many possibilities then the algorithm is applied with a different x0.We estimate the number of βi that must be computed before a match is found. By thebirthday paradox (see 6.2.4) if we compute O(

√#G) elements then a match is found

with a probability greater than 1/2.Thus far, our algorithm is less good than the previous one. The advantage is that we donot need to store as many elements. Initially (β1, x1, δ1) is stored. Now suppose that at

Page 118: Cryptology course

118 CHAPTER 7. TUTORIAL : ALGORITHMS

a certain point in the algorithm (βi, xi, δi) is stored. Then (βj , xj , δj) is computed forj = i+1, i+2, . . . until either a match is found or j = 2i. In the latter case we delete βi

and store β2i. Hence we only store the triplets with i = 2k. This works for the followingreason : the sequence (βi) is periodic after a certain number s of iterations (with thefirst match as end point). If l is the length of the period then if 2j ≥ max(s, l) then aperiod is contained in the interval [2j , . . . , 2j+1] and a match can be found.

The Pohlig-Hellman algorithm

We now show that the DLP can be reduced to DLPs in cyclic groups of prime order ifwe know the factorization

n = #G =∏p

pe(p).

1. Reduction to prime powers. For each prime divisor p of n, we set

np = n/pe(p), αp = αnp , yp = ynp .

Then the order of αp is exactly pe(p) and

αxp = yp.

Assume we can solve the DLP in the prime powers subgroups and call x(p) theresults. Then the Chinese Remainder Theorem shows that x is the unique solutionof the congruences

x ≡ x(p) (mod pe(p)).

2. Reduction to prime order. Let now assume that #G = pe for a prime p. We wantto solve the DLP in this group. We have x < pe so let us write (in base p)

x = x0 + x1p + . . . xe−1pe−1, 0 ≤ xi < p, 0 ≤ i ≤ e− 1.

We show that the xi are DLP in a group of order p. Indeed, one has

pe−1x = x0pe−1 + pe(x1 + x2p + . . . + xe−1p

e−2).

Now(αpe−1

)x0 = ype−1.

This equation shows that x0 is the DL in a group of order p. The other coefficientsare determined recursively. Suppose that x0, . . . , xi−1 have been determined. Then

αxipi+...+xe−1pe−1

= yx−(x0+x1p+...+xi−1pi−1).

Denote the right-hand side by yi, one has by raising to the power pe−i−1

(αpe−1)xi = ype−i−1

i .

We have then reduce the problem of the DLP in G to e DLPs in a group of primeorder.

Page 119: Cryptology course

7.4. DISCRETE LOGARITHMS 119

3. Prime order. One applies one of the two previous algorithms (i.e. 7.4.2 or 7.4.2).

We see easily that the running time is dominated by the square root of the largest primedivisor of #G.

Example 40. Let us solve 5x ≡ 3 (mod 2017). The order of the multiplicative groupis n = 2016 = 25 · 32 · 7. First we determine x(2) ≡ x (mod 25). We obtain x(2) as asolution of the congruence

(532·7)x(2) ≡ 332·7 (mod 2017).

To solve this congruence, we write

x(2) = x0(2) + . . . + x4(2) · 24.

The coefficient x0(2) is solution of

2016x0(2) ≡ 1 (mod 2017).

We obtain x0(2) = 0. Now y1 = y. Then x1(2) is solution of

2016x1(2) ≡ 2016 (mod 2017).

We obtain x1(2) = 1 and y2 ≡ 1579 (mod 2017). Hence x2(2) is solution of

2016x2(2) ≡ 2016 (mod 2017).

We obtain x2(2) = 1 and y3 ≡ 1 (mod 2017) so x3(2) = x4(2) = 0. Concluding thosecomputations, we obtain x(2) = 6.Now we compute

x(3) = x0(3) + x1(3) · 3.

We obtain x0(3) as the solution of

294x0(3) ≡ 294 (mod 2017),

so x0(3) = 1 and y1 ≡ 294 (mod 2017). Hence x1(3) = 1 and x(3) = 4.Finally we compute x(7) as the solution of the congruence

1879x(7) ≡ 1879 (mod 2017),

so x(7) = 1. We obtain x as the solution of the simultaneous congruence

x ≡ 6 (mod 32), x ≡ 4 (mod 9), x ≡ 1 (mod 7).

The solution is x = 1030.

Page 120: Cryptology course

120 CHAPTER 7. TUTORIAL : ALGORITHMS

Index calculus

When G = (Z/nZ)∗ or more generally the unit group of a finite field, there are moreefficient DL algorithms, the so called index calculus algorithms ( methode de l’index).They are closely related to integer factoring algorithms such as the quadratic sieve. Wedescribe a simple index calculus algorithm.

The idea. Let p be a prime number, α a primitive element modulo p and y ∈{1, . . . , p− 1}. We want to solve αx ≡ y (mod p). We choose a bound B and determinethe set

F (B) = {q ∈ P, q ≤ B}.This is the factor base. An integer b is called B-smooth if it has only prime factor inF (B). We proceed in two steps. First we compute the discrete logarithm of the factorbase elements, i.e. we solve

αx(q) ≡ q (mod p)

for all q ∈ F (B). Then we determine an exponent δ ∈ {1, . . . , p − 1} such that yαδ

(mod p) is B-smooth. We obtain

yαδ ≡∏

q∈F (B)

qe(q) (mod p).

Together

yαδ ≡∏

q∈F (B)

qe(q) ≡∏

q∈F (B)

αx(q)e(q) ≡ αP

q∈F (B) x(q)e(q) (mod p),

and hencey = α

Pq∈F (B) x(q)e(q)−δ (mod p).

Therefore,x ≡

q∈F (B)

x(q)e(q)− δ (mod p− 1). (7.1)

Discrete logarithms of the factor base elements. To compute the discrete logarithmsof the factor base elements, we choose random numbers z ∈ {1, . . . , p− 1} and computeαz (mod p). We check whether those numbers are B-smooth. If they are, we computethe decomposition

αz (mod p) =∏

q∈F (B)

qf(q,z).

Each exponent vector (f(q, z))q∈F (B) is called a relation. If we find as many relations asthere are factor base elements, then we try to find the discrete logarithms by solving alinear system. We obtain

αz ≡∏

q∈F (B)

qf(q,z) ≡∏

q∈F (B)

αx(q)f(q,z) ≡ αP

q∈F (B) x(q)f(q,z) (mod p).

Page 121: Cryptology course

7.4. DISCRETE LOGARITHMS 121

This impliesz ≡

q∈F (B)

x(q)f(q, z) (mod p− 1)

for all z, so each relation yields one linear congruence. The system is solved with stan-dards methods.

Individual logarithms. If the discrete logarithm of the factor base elements are com-puted, then the discrete logarithm of y to the base α is determined. We choose a randomδ ∈ {1, . . . , p− 1}. If yαδ is B-smooth, then 7.1 is applied. Otherwise, we choose a newδ.

Remark 35. It can be shown that the running time is Lp(1/2, C) for some constantC. In principle the index calculus algorithm works in any group. However the factorbase must be chosen such that relations can be found efficiently. (Un)fortunetaly, forsome groups, such that elliptic curves over finite fields, it is not known how to choosethe factor base and how to compute relations.

Page 122: Cryptology course

122 CHAPTER 7. TUTORIAL : ALGORITHMS

Page 123: Cryptology course

Bibliography

[BHKKR99] J. Black, S. Halevi, H. Krawczyk, T. Krovetz, P. Rogaway, UMAC: fastand secure massage authnetication, Advances in cryptology - crypto ’99, LectureNotes in Computer Science 1666, Springer-Verlag, (1999), 216-233.

[BJN00] D. Boneh, A. Joux, P. Nguyen, Why textbook ElGamma and RSA encryp-tion are insecure, Advances in Cryptology-Asiacrypt ‘00, 1976 in Lecture Notes inComputer Science, Springer-Verlag, (2000), 30-43.

[CGH04] R. Canetti, O. Goldreich, S. Halevi, the random oracle methodology revisited,Journal of ACM, 51, (2004), 557-594.

[CJ03] J.H. Cheon, B. Jun, a polynomial time algorithm for the braid Diffie-Hellmanconjugacy problem, Advances in cryptology- Crypto 2003, lecture notes in computerscience 2729, Springer-Verlag, (2003), 212-225.

[Del03] J.-P. Delahaye, la Belle au bois dormant, la fin du monde et les extraterrestres,Pour la Science 309, Juillet 2003, 98-103.

[FO99] Fujisaki E., Okamoto T., how to enhance the security of public key encryptionat minimum cost, Public Key cryptography PKC ’99, Lecture notes in computerscience 1560, Springer-Verlag, (1999), 53-68.

[FOPS01] E. Fujisaki, T. Okamoto, D. Pointcheval, J. Stern, RSA-OAEP is secure underthe RSA assumption, In advances in Cryptology, Crypto 2001, 2139, Springer-Verlag, 2001, 260-274.

[Goz97] I. Gozard, Theorie de Galois, Mathematiques 2ieme cycle, Ellipses, 1997.

[HW79] G.H. Hardy, E.M. Wright, an introduction to the theory of numbers, OxforfScience Publications, fifth edition 1979.

[Knu98] D.E. Knuth, the art of computer programming, vol. II, seminumericalalorithms, Addison-Wesley, 1998.

[KJJ99] P. Kocher, J. Jaffe, B. Jun, differential power analysis, advances in cryptology-crypto ’99, lectures notes in computer sciences 1666, Sprinver-Verlag, 1999.

123

Page 124: Cryptology course

124 BIBLIOGRAPHY

[MW99] U. Maurer, S. Wolf, The relationship between breaking the Diffie-Hellmanprotocol and computing the dicrete logarithm, SIAM Journal on Computing, 28,(1999), 1689-1721.

[Odl90] A. Odlyzko, The rise and fall of knapsack cryptosystems, in Cryptology andComputational Number theory, Proc. Symposia in Applied Maths 42, 1990.

[QG90] J.-J. Quisquater, L. Guillou, How to explain Zero-knowledge protocols to yourchildren, advances in cryptology-crypto ’89, lectures notes in computer science 435,Springer-Verlag, 1990, 628-631.

[SHO97] V. Shoup, lower bounds for discrete logarithms and related problem, Eurocrypt1997, Lecture Notes in computer science 1233, Springer-Verlag, 1997, 256-266.

[FL05] Frey, Lange, crypto elliptique