Chapter1 Introduction 1.1.1 WhatisCryptography?
“The study of principles and techniques by which information can be concealed in ciphers and later revealed by legitimate users employing a secret key (i.e., a piece of information known only to them), but in which it is either impossible or computationally infeasible for an unauthorized person to do so”. (Encyclopedia Britannica)
• The word comes from Greek kryptós – “hidden”, and gráphein – “to write”.
• A more inclusive term is cryptology, from Greek kryptós and lógos – “word”.
“The science of secure (generally secret) communications”. (Encyclopedia Britannica)
• Apart from Cryptography, the term Cryptology includes Cryptanalysis: From Greek
kryptós and anal ̋ein – “to loosen, to untie”.
“The science (and art) of recovering information from ciphers without knowledge of the key”. (Encyclopedia Britannica)
1.1.2 Thedi erencebetweenciphersandcodes
Cipher: From French chi re and Arabic sifr (“nothing” – also related to zero).
“1. Any system of secret writing that uses a prearranged scheme or key. — 2. A message
in cipher, also, its key.” (Funk & Wagnall’s Standard Desk Dictionary).
Code: From Latin codex – “writing tablet”.
“A set of signals, characters, or symbols used in communication”. (Funk & Wagnall’s)
The main topic of this course will be ciphers rather than codes. Some examples of codes: • Morse code
• ASCII (American Standard Code for Information Interchange) • The “pigpen cipher” (really a code)
• Sherlock Holmes’ “Dancing Men”
1.1.3 Aboutthiscourse
The main purpose of this course:
• To give the mathematical foundations of modern cryptography and of the most important
cryptosystems.
• To give means to judge the security of a cryptosystem.
1.1 Generalities
1.2 More Terminology, Classification
What this course does not cover (or only in passing):
• Implementations, protocols, etc.
• Related to this: Network security, e-commerce, etc.
• Political and social issues (“escrow systems”, the CLIPPER chip, etc.)
• Ethical and human-rights issues
• Steganography (covert secret writing; from Greek steganos – “covered”)
1.2 MoreTerminology,Classification 1.2.1 Terminology
• Cryptosystem (or cryptographic system: A more “technical” term for cipher.
• Plaintext: An English (French, German, . . . ) text, numerical data, other information; may
already have been encoded (for instance, in ASCII).
• Encryption: Performed by the sender; intended to render the message unintelligible to any
eavesdropper.
• Ciphertext: The result of an encryption; usually a string of symbols, digits, bits, . . .
• Decryption: Performed by the intended receiver; the recovering of plaintext from cipher-
text.
1.2.2 Kerckho s’principle
“It is assumed that the cryptosystem in use, and the workings of this system, are public knowledge, or at least known to the potential eavesdropper”.
(Auguste Kerckho s, 1883)
Reasons:
• It is unreasonable to depend on the secrecy of the cryptosystem.
• Adherence to this principle makes standardization of algorithms and large-scale commu-
nication easier.
Thus, the only secret is the key. Therefore, key distribution and key management are fundamental issues in cryptography.
1.2.3 Classification
Cryptosystems can be (roughly) classified according to three di erent criteria:
1. The types of operations used for encryption:
• Substitution: Each element in the plaintext (bit, letter, group of bits or letters) is mapped
to another element.
• Transposition: Elements in the plaintext are rearranged.
2
1.3 Basic Concepts of Cryptanalysis
Most cryptosystems employ multiple stages of substitutions and transpositions (“product sys- tems”).
2. The number of keys used:
• Symmetric (or single-key, secret-key, conventional) encryption:
Both sender and receiver use the same key.
• Asymmetric (or two-key, or public key) encryption:
Sender and receiver each uses a di erent key.
3. The way in which the plaintext is processed:
• Block cipher: Input is processed one block of elements at a time, producing an output
block for each input block.
• Stream cipher: Input elements are processed continuously, producing an output of one
element at a time, as it goes along.
1.2.4 Modelofconventionalcryptosystems
The basic communications scenario can be depicted as follows:
There are two parties, usually called Alice and Bob (for A and B) who wish to communicate securely over an insecure channel. We assume that a third party has access to the insecure channel and thus to the ciphertext and, in certain scenarios, will also have access to the corre- sponding plaintext and might even be able to alter the ciphertext and/or impersonate Alice or Bob. In accordance with Kerckho s’ principle, we also assume that this party will know which cryptosystem is used and will know its inner workings. This party is often called Oscar (for “opponent” or “observer”), or Eve (for “eavesdropper”).
3
1.3 BasicConceptsofCryptanalysis
Cryptanalysis is as much an art as it is a science. Although some ciphers may be compu- tationally intractable, human ingenuity and intuition may help to crack them. (There are many examples of this throughout history).
1.3.1 Meansofcryptographicattacks
1. Mathematical:
• Statistics (frequency distributions, etc.). • Number theory.
• Group theory.
• Combinatorics and graph theory, etc.
2. Side information:
• Linguistic (human language is full of redundancy). • Formatting (such as “Dear Dr. Dilcher”).
• Subject.
• Known words or phrases (such as military ranks).
3. “Cloak & Dagger” methods:
• Theft, bribery, blackmail, sex, violence.
1.3.2 Typesofcryptographicattacks
1. Ciphertext only:
• The cryptanalyst has only the ciphertext to work with. • Easiest type to defend against.
• Example of this type of attack: “exhaustive search”.
2. Known plaintext:
• Often the cryptanalyst has one or more plaintext messages along with corresponding
encryptions.
• Closely related: “Probable word attack”.
3. Chosen ciphertext:
• The cryptanalyst can cause a ciphertext of his choice to be decoded.
• Both ciphertext and corresponding plaintext segments are then known. • Similar: “Chosen plaintext attack”.
4
1.3 Basic Concepts of Cryptanalysis
1.4 SomeHistory
This is a selective list of some key dates (pun intended) and events in the history of cryptography.
• Ancient Egyptians, Hebrews, Babylonians, Assyrians used protocryptographic systems.
• ca. 400 BC: Spartans used the scytale for communications between military commanders.
– First transposition cipher.
• 4th century BC: Chapter on cryptography in a book by Aeneas. – Earliest treatise on the
subject.
• Same time: Polybios encoded letters into pairs of symbols. – First biliteral substitution.
• ca. 50 BC: “Caesar cipher”: simple shift cipher.
• Arab culture: First clear understanding of the principles of cryptology. 1412: Treatment
of several cryptosystems in an encyclopedia by al-Kalkashandi. First use of frequency
analysis.
• 1379: First European manual on cryptography, by Gabriele de Lavinde of Parma.
• 1470: First cipher disk, by Leon Battista Alberti.
• 1586: Blaise de Vigenère – The “Vigenère table”.
• 17th – 19th centuries: Rapid development of techniques.
• 1920s: Electromechanical devices used by most powers.
• Both world wars: Cryptanalytical successes of greatest importance to (mostly) the Allied
forces.
• 1950s on: Use of electronic computers.
• 1976: Public key cryptography described by Di e and Hellman.
• 1977: Data Encryption Standard (DES) adopted.
• 1978: RSA (Rivest, Shamir, Adleman).
• 1980s: Elliptic curve cryptosystems.
• 2000/2001: Replacement of DES by the Rijndael algorithm as new “Advanced Encryption
Standard” (AES).
5
1.4 Some History
Chapter2 ClassicalCryptography
In this chapter we are going to study some basic principles of cryptography, along with several historical and insecure cryptosystems as examples. We will also consider modern block ciphers and stream ciphers, and two sections contain mathematical background that will be required in this chapter and throughout the course.
2.1 Cryptosystems 2.1.1 Basics
Definition 2.1.
A cryptosystem is a 5-tuple (P, C, K, E, D) with the following properties:
1. P is a set, called the plaintext space. Its elements are called plaintexts.
2. C is a set, called the ciphertext space. Its elements are called ciphertexts.
3. K is a set, called the key space. Its elements are called keys.
4. E = {Ek : k 2 K } is a family of functions Ek : P ! C. Its elements are called
encryption functions.
5. D = {Dk : k 2 K } is a family of functions Dk : C ! P. Its elements are called
decryption functions.
6. Foreache2K thereisad2K suchthat Dd(Ee(p))=p forallp2P.
|
Example 1. Shift ciphers.
LetP=C=K ={A,B,C,…,Z}.Weidentifythissetwith⌃={0,1,2,…,25}according
to the table
Notation: Zm is the set {0,1,2,…,m 1} along with the two operations + and ⇥ which are carried out as in N, except that we “reduce modulo 26”. (More about this in the next section).
For e 2 Z26 we define the encryption function Ee by
Ee :⌃!⌃, x7!(x+e) (mod26).
For d 2 Z26 the decryption function Dd is defined by
Dd :⌃!⌃, x7!(x d) (mod26).
The decryption key belonging to the encryption key e is d = e.
Example: Apply the shift cipher with key e = 5 to the word cryptography. We get
HWDUYTLWFUMD.
A
B
C
…
Z
0
1
2
…
25
2.2 Mathematical Background I
Remarks:
1. When the key is e = 3, this is called the Caesar cipher.
2. The key space has only 26 elements. To cryptanalyze, we need only try all keys on a
segment of the ciphertext, until it “makes sense”.
3. Shift ciphers can be modified as follows: Let P and C be the set of all sequences
w = (w1,w2,…,wn), with wi 2 ⌃, 1 i n. Again K = Z26. Now the function Ee replaces each wi with wi + e (mod 26), 1 i n.
4. The symbol ⌃ is the capital Greek letter “Sigma”, and is pronounced this way.
5. Obviously, all this can be done with Zm, for any m 2.
6. Recall that d = e. We can use this as an alternative definition of a symmetric, resp. an
asymmetric cryptosystem: A cryptosystem is called
– symmetric if d = e,
– asymmetric if d , e, and the computation of d from e is not feasible.
2.1.2 Requirementsfora“good”cryptosystem
A. “Classical” requirements (Claude Shannon, 1940): A good cryptosystem should
1. be highly secure against its designer, that is, the designer of the system should not have
any advantage in decryption;
2. use short, easily-changed key;
3. require only simple encryption/decryption;
4. not introduce error propagation;
5. not entail message expansion.
Remark: Requirements 2 – 5 reflect the fact that encryption/decryption used to be done manually by error-prone cipher clerks. They are less important with the use of computers.
B. Modern requirements:
1. As before.
2. As before – keys must be small (but “small” is a relative term; keys can be many digits
long).
3. As before – operations must be relatively simple (what computers do best), but we can do
many of them.
4. Some error propagation may even be desirable.
5. Moderate message expansion is now acceptable.
7
2.2 MathematicalBackgroundI 2.2.1 Congruences
Modular arithmetic and the basics of (abstract) algebra are of fundamental importance for cryptographic algorithms.
Definition 2.2.
Givena,b2Z,wesaythataiscongruenttobmodulom(writtena⌘b (modm))ifm divides b a (written m | b a).
Examples: 2 ⌘ 19 (mod 21), 10 ⌘ 0 (mod 2).
2.2 Mathematical Background I
Remark: Congruence modulo m is an equivalence relation, that is, it satisfies the following relations:
1. a ⌘ a (mod m) (“reflexivity”),
2. a ⌘ b (mod m) implies b ⌘ a (mod m) (“symmetry”);
3. a ⌘ b (mod m) and b ⌘ c (mod m) implies a ⌘ c (mod m)
The following characterization is also useful.
Lemma 2.1.
The following statements are equivalent:
1. a ⌘ b (mod m).
2. Thereisak2Zwitha=b+km.
3. When divided by m, both a and b leave the same remainder.
(“transitivity”).
|
We are now ready to define a basic concept in modular arithmetic:
Definition 2.3.
~
|
The equivalence class of a 2 Z is the set of all integers obtained from a by adding integer multiples of m, that is,
{b2Z|b⌘a (modm)}=a+mZ. This is called the residue class of a (mod m).
Examples:1.Theresidueclassof1 (mod4)is{1,1±4,1±2·4,…}={1, 3,5, 7,9,…}. 2. The residue class of 0 (mod 2) is the set of all even integers; the residue class of 1
(mod 2) is the set of all odd integers.
3.Theresidueclasses (mod4)are0+4Z,1+4Z,2+4Z,3+4Z.
Notation: The set of residue classes (mod m) is denoted by Z/mZ. It has m elements since 0, 1, 2, . . . , m 1 are all the possible remainders upon division by m.
A set of representatives is a set of integers that contains exactly one element of each residue class (mod m).
8
2.2 Mathematical Background I
Examples: 1. {0, 1, 2}, {3, 2, 5}, and {9, 16, 14} are di erent sets of representatives of Z/3Z.
2. Foranym2N,theset{0,1,2,…,m 1}isasetofrepresentatives (modm),called
the least nonnegative residues (mod m), denoted by Zm.
3. {1, 2, . . . , m} is a set of representatives, the least positive residues
Proposition 2.1.
Supposethata⌘b (modm)andc⌘d (modm).Then (a) a ⌘ b (mod m),
(b) a+c⌘b+d (modm),
(c) ac ⌘ bd (mod m).
(mod m).
Proof (a) Since m divides a b, it also divides a + b, and therefore a ⌘ b (mod m).
(b), (c): exercise. ⇤
Example: The integer F = 22n + 1 is called a Fermat number. Pierre de Fermat (1601–1665) n
observed that F0 = 3, F1 = 5, F2 = 17, F3 = 257, and F4 = 65 537 are all prime. He conjectured that all Fn are prime.
However, Leonhard Euler (1707–1786) showed that 641 | F5.
Proof Itisclearthat641=640+1=5·27+1,so5·27⌘ 1(mod641).ByProposition2.1(c)
we get by multiplying both sides of this congruence with itself 4-times over,
54 · 228 ⌘ 1 (mod 641). (2.1)
Ontheotherhand,641=625+16=54 +24,so
54 ⌘ 24 (mod 641).
Substituting this into (2.1), we get
24 · 228 ⌘ 1 (mod 641),
or 232 ⌘1 (mod641),i.e.,225 +1⌘0 (mod641). 2.2.2 Someabstractalgebra
Definition 2.4.
If X is a set, a map : X ⇥ X ! X which sends a pair (x1, x2) of elements from X to the element x1 x2 is called an operation on X.
⇤
|
|
Example: Addition and multiplication are operations on X = R. Definition 2.5.
Given the residue classes a + mZ and b + mZ,
(i) their sum is (a + mZ) + (b + mZ) = (a + b) + mZ; (ii) their product is (a + mZ) · (b + mZ) = (a · b) + mZ.
9
2.2 Mathematical Background I
Remark: This definition uses representatives; however, by Proposition 2.1 sum and product are independent of representatives, that is, they are well defined.
Example: Let m = 5. Then
(3 + 5Z) + (2 + 5Z) = 5 + 5Z = 5Z;
(3 + 5Z) · (2 + 5Z) = 6 + 5Z = 1 + 5Z.
Or: 3+2⌘0 (mod5); 3·2⌘1 (mod5). Definition 2.6.
A pair (H, ) consisting of a set H and an operation that satisfies (a b) c=a (b c) forall a,b,c2H
(i.e., the operation is associative,) is called a semigroup. If, in addition,
a b=b a forall a,b2H,
the semigroup is called commutative or abelian.
A neutral element of the semigroup (H, ) is an element e 2 H which satisfies e a = a e = a for all a 2 H. A semigroup with a neutral element is called a monoid.
|
Example: (Z, +), (Z, ·), (Z/mZ, +), and (Z/mZ, ·) are commutative semigroups. In fact, they are monoids.
Some properties: Let (H, ) be a semigroup, and set a1 = a and an+1 = a an for a 2 H and
n 2 N. Then
an am = an+m, (an)m = anm
for a 2 H and n, m 2 N. If a, b 2 H and a b = b a, then (a b)n = an bn. (This is true in general if the semigroup is commutative).
Definition 2.7.
Let (H, ) be a semigroup and e its neutral element. Given an a 2 H, an element b 2 H is called an inverse of a if a b = e = b a. An element a is called invertible in H if it has an inverse.
Remarks:
(a) A semigroup has at most one neutral element.
(b) In a monoid each element has at most one inverse.
Examples:
(Z, +): Neutral element is 0. Inverse of a is a.
(Z, ·): Neutral element is 1. The only invertible elements are 1 and 1.
(Z/mZ, +): Neutral element is the residue class mZ. Inverse of a + mZ is a + mZ.
|
10
(Z/mZ, ·): Neutral element is the residue class 1 + mZ. For the invertible elements, see the next subsection.
Definition 2.8.
A group is a monoid in which every element is invertible. A group is called commutative or abelian if the monoid is commutative.
2.2 Mathematical Background I
|
Examples: (Z, +) and (Z/mZ, +) are abelian groups. (Z, ·) is not a group because not every element is invertible.
Some properties: Let (G, ·) be a group. Denote by a 1 the inverse of a 2 G, and set a n = (a 1)n
for all n 2 N. Then
holds for all a 2 G and n,m 2 Z. If the group is abelian, then
an · am = an+m, (an)m = anm (a · b)n = an · bn
holds for all n 2 Z.
An important property of a group is that we can “cancel”:
Proposition 2.2.
Let (G, ·) be a group and a, b, c 2 G. Then ca = cb implies a = b, and
ac = bc implies a = b.
Definition 2.9.
The order of a group is the number of its elements.
Examples:
(a) The additive group Z has infinite order. (b) The additive group Z/mZ has order m.
Definition 2.10.
A ring is a triplet (R, +, ·) such that (a) (R, +) is an abelian group,
(b) (R, ·) is a semigroup,
(c) For all x, y, z 2 R we have
x · (y + z) = (x · y) + (x · z),
|
(x + y) · z = (x · z) + (y · z).
The ring is called commutative if the semigroup (R, ·) is commutative. An identity (or unit element) of the ring is a neutral element of the semigroup (R, ·). The property in (c) is called distributivity.
|
Examples:
11
2.2 Mathematical Background I
(1) (Z, +, ·) is a commutative ring with identity 1. This implies: (2) (Z/mZ, +, ·) is a commutative ring with identity 1 + mZ;
it is called the residue class ring modulo m.
Remark: If it is clear which operations are meant, we often write simply R for (R,+,·); for
instance, we write Z/mZ for the residue class ring (mod m). Definition 2.11.
Let R be a ring with identity. An element a 2 R is called invertible, or a unit, if it is invertible in the multiplicative semigroup of R. An element a 2 R is called a zero divisor if a , 0 and there is a b , 0, b 2 R, with ab = 0 or ba = 0.
|
Remark: The units of a commutative ring form a group, the group of units of R, denoted by R⇤.
Examples: (1) Z⇤ = { 1, 1}.
(2) Z has no zero divisors.
(3) Claim: The zero divisors of the residue class ring Z/mZ are the residue classes a + mZ
with 1 < gcd (a, m) < m.
Proof (i)Ifa+mZisazerodivisorofZ/mZ,thenthereisab2Zwithab⌘0 (modm),but a . 0 (mod m) and b . 0 (mod m). Hence m | ab, but m - a and m - b. So gcd (a, m) must lie strictly between 1 and m.
(ii) Suppose that 1 < gcd(a,m) < m, and set b := m/gcd(a,m). Then a . 0 (mod m), ab=(a/gcd(a,m))·m⌘0 (modm),andb.0 (modm).Hencea+mZisazerodivisorof Z/mZ. ⇤
Examples:Whenm=6,then2·3⌘0 (mod6);hence2+6Zisazerodivisor. Consequence: If m is a prime, then Z/mZ has no zero divisors.
Definition 2.12.
A field is a commutative ring in which every nonzero element is invertible. Examples: Q, R, C are fields. Z is not a field.
2.2.3 Divisionintheresidueclassring
Divisibility in rings is defined as in Z: Definition 2.13.
|
Let R be a ring and a, n 2 R. We say that a divides n if there is an element b 2 R such thatn=a·b. Inthiscaseaiscalledadivisorofn,andnamultipleofa,andwewrite a | n (otherwise, a - n).
|
We will now restrict our attention to R = Z/mZ. Which elements in Z/mZ are invertible? Recall: The class a + mZ is invertible if and only if the congruence
ax ⌘ 1 (mod m) (2.2) 12
is solvable. When is this the case?
Proposition 2.3.
The residue class a + mZ is invertible in Z/mZ (i.e., the congruence (2.2) is solvable) if and only if gcd(a, m) = 1. If gcd(a, m) = 1, then the inverse of a + mZ is uniquely determined (i.e., the solution of (2.2) is is uniquely determined modulo m.)
Proof Later.
Remarks: (a) A residue class a + mZ with gcd(a, m) = 1 is called an invertible residue class modulo m. By Proposition 2.3, a residue class a + mZ, 1 a < m, is either a zero divisor or an invertible residue class (i.e., a unit in the residue class ring Z/mZ).
(b) The solution of (2.2), and thus the inverse of a + mZ (when gcd(a, m) = 1), can be computed e ciently with the “Euclidean algorithm” (see later).
Example: Let m = 10. The class a + 10Z is invertible if and only if gcd(a, 10) = 1, i.e., when a = 1, 3, 7, 9. To obtain the inverses, note that
3·7⌘1 (mod10), 7·3⌘1 (mod10), 9·9⌘1 (mod10). Proposition 2.4.
Z/mZ is a field if and only if m is a prime number.
Proof By Proposition 2.3, Z/mZ is a field if and only if gcd(k,m) = 1 for all k, 1 k < m.
But this is the case if and only if m is a prime. ⇤
Corollary 2.1.
The set of all invertible residue classes modulo m is a finite abelian group with respect to multiplication.
~
Remark: This group is called the multiplicative group of residues modulo m, denoted by (Z/mZ)⇤.
Definition 2.14.
The Euler '-function ' : N ! N is defined as follows: If m 2 N, then '(m) is the order of (Z/mZ)⇤. In other words: '(m) is the number of integers a 2 {1, 2, . . . , m} with gcd(a, m) = 1.
|
Remarks: (a) In place of “'-function” you will sometimes see “phi-function”; in either case, it is pronounced like “fee”-function. The name Euler is pronounced like “oiler”.
(b) The first few values of the '-function are
In particular: If p is prime, then '(p) = p 1. 13
2.2 Mathematical Background I
m
1
2
3
4
5
6
7
8
9
10
11
...
'(m)
1
1
2
2
4
2
6
4
6
4
10
...
2.3 The A ne Cipher
The Euler '-function will be studied in greater detail later. For now, here are two formulas
for calculating '(n); they will have been derived in most !Discrete Mathematics courses: '(n)=nY 1 1 ,
(2.3)
p where the product is taken over all primes dividing n.
p|n Ifn=pe1 ·...·pek,(thecanonicalform),then
1k
'(n)=(pe1 pe1 1)·...·(pek pek 1). 11 kk
(2.4) Examples: (a) Let n = 2000. The only prime divisors of n are 2 and 5. so by (2.3) we have
For both formulas it is essential that n be completely factored. '(2000)=2000 1 1! 1 1!=2000·1·4=800.
2525
(b) Let n = 4116. The factorization is 4116 = 22 · 3 · 73. This time we use (2.4) to obtain
'(4116) = (22 2)(3 1)(73 72) = 1176.
We close this section with one last result on division in modular arithmetic. We have seen that addition, subtraction and multiplication modulo m are no problem. Also, when m is prime, we can “cancel” modulo m. But what happens when m is not prime?
Example: Starting with the congruence 3 · 8 ⌘ 3 · 4 (mod 12), we see that 8 ⌘ 4 (mod 12) is certainly wrong. However, we do have 8 ⌘ 4 (mod 4). This is explained by the following result.
Proposition 2.5.
xa⌘xb (modm)ifandonlyifa⌘b (mod m ). gcd(x,m)
Proof Two directions need to be shown:
(a) “)”: The first congruence can be rewritten as m | (xa xb), and then m | x(a b).
Now denote d := gcd(x, m) and divide the last relation by d. Then m | x (a b), and since dd
gcd( m, x ) = 1, we have m | (a b), which is equivalent to the second congruence. ddd
(b) “(”: The second congruence is equivalent to m | (a b), which implies m | d(a b) d
and also m | x(a b) since x is a multiple of d. This last relation is the same as m | (xa xb), and this is equivalent to the first congruence. ⇤
2.3 TheA neCipher
In this section we present a cipher that is easily broken using the methods from the previous sections. It is also the basis of some historical ciphers which we will consider later, in Section 2.8.
14
congruence for x. First,
ax+b⌘y (modm) ax⌘y b (modm).
Now, since gcd(a,m) = 1, there is a multiplicative inverse a 1 2 Zm such that a 1a ⌘ 1 (mod m). So
or
a 1ax ⌘ a 1(y b) (mod m), x⌘a 1(y b) (modm).
Therefore, given the encryption key k = (a, b), the decryption function is Dk(y)=a 1(y b) (modm).
Example: Let m = 26. Alice wants to encipher the word bald with the key k = (a, b) = (7, 3). Note that gcd(7, 26) = 1. We use the translation table from Section 2.1; the steps are summarized in the following table:
2.3 The A ne Cipher
2.3.1 Descriptionofthecipher
In Section 2.1 we considered the shift cipher as a special example of a substitution cipher. Its encryption function was
Ek (x) = x + b (mod m), x 2 Zm,
with key k = b 2 Zm.
We now define the more general a ne cipher by the encryption function
Ek (x) = ax + b (mod m), x 2 Zm, with key k = (a, b) 2 Z2m, and gcd(a, m) = 1.
Why do we have this last condition?
Suppose that gcd(a, m) = d > 1. We have seen (see Example (3) after Definition 11) that a + mZ is a zero divisor in Z/mZ, so the congruence ax ⌘ 0 (mod m) has at least two solutions, namely x = 0 and x = m/d. Hence we would have
Ek (0) = b = Ek (m/d),
so the encryption function is not injective, which is not allowed.
Suppose now that we do have gcd(a, m) = 1. What is the decryption function? Solve the
plaintext
b
a
l
d
x
1
0
11
3
y⌘7x+3 (mod26)
10
3
2
24
ciphertext
K
D
C
Y
15
2.4 Block Ciphers
To decipher, Bob has to find a 1. By inspection: 15 · 7 = 105 ⌘ 1 (mod 26) (later we will meetanalgorithmfordoingthis).Soa 1 =15,andthedecryptionfunctionisDk(y)=15(y 3) (mod 26). The steps are now:
2.3.2 Cryptanalysisofthea necipher
1. Ciphertext only:
Consider an a ne cipher with m = 26. Given a key k = (a, b), b can take on any value
b 2 Z26, while for a we require gcd(a, 26) = 1, so there are ‘(26) = 12 possibilities. In total: the key space has only 12 · 26 = 312 elements; an exhaustive search is easily possible.
A di erent kind of ciphertext only attack can be found in the assignments.
2. Known plaintext or known ciphertext:
Example: Suppose that the eavesdropper Oscar knows that the a ne cipher (with m = 26)
with key k = (a, b) maps e to R and s to H. Then he obtains the following congruences 4a+b ⌘ 17 (mod26) (frome7!R),
18a+b ⌘ 7 (mod26) (froms7!H). Subtract the first congruence from the second one:
14a ⌘ 10 ⌘ 16 (mod 26), or, upon dividing by 2 (using Proposition 2.5),
7a ⌘ 8 (mod 13).
If we now multiply by 2 and note that 14 ⌘ 1 (mod 13), we get
a⌘16⌘3 (mod13).
This means that either a ⌘ 3 (mod 26), or a ⌘ 16 (mod 26). The second case is not possible since gcd(16, 26) = 2, while the first case is allowable and leads to b ⌘ 17 4a = 5 (mod 26). So, finally, the encryption key was k = (3, 5), and Oscar has broken the cipher.
2.4 BlockCiphers
Recall from the introduction: One criterion for classifying cryptosystems was “block ci- phers” versus “stream ciphers”. Here we are going to discuss block ciphers in general. First we need some more background material.
ciphertext
K
D
C
Y
y
10
3
2
24
x=15(y 3) (mod26)
1
0
11
3
plaintext
b
a
l
d
16
2.4.1 Alphabetsandwords
Definition 2.15.
An alphabet is a finite nonempty set ⌃. The length of ⌃ is the number of elements in ⌃. The elements of ⌃ are called symbols or letters.
|
2.4 Block Ciphers
Examples:
(1) ⌃ = { A, B, . . . , Z }; length 26. (2) ⌃ = {0, 1}; length 2.
(3) The ASCII symbols; length 128.
Ifanalphabethaslengthm,wecan(andoftenwill)identifyitwithZm ={0,1,…,m 1}. Definition 2.16.
A finite sequence is a finite ordered set (a1, a2, . . . , an ); its elements (some of which may be identical) are called components. Sometimes we also write a1a2 . . . an. The empty sequence () has no components.
Example: (2, 3, 1, 2, 3), or 23123. Definition 2.17.
|
|
Example: Let X = {0, 1, . . . , 5}. An element in the first row of the following matrix is mapped to the number below:
*.0 1 2 3 4 5+/ ,1 2 4 3 5 0-
Example: Let ⌃ = { A, B, . . . , Z }, v = DAL, w = HOUSIE. Then v w = DALHOUSIE. 2.4.2 Permutations
Definition 2.18.
Let X be a set. A permutation of X is a bijective map f : X ! X. The set of all permutations of X is denoted by S(X).
|
Let ⌃ be an alphabet.
(1) A word or string over ⌃ is a finite sequence of symbols from ⌃ including the empty sequence, which is denoted by ” and called the empty string.
(2) The length of a word w over ⌃ is the number of its components, and is denoted by |w|. Also, |”| = 0.
(3) The set of all words over ⌃ including the empty string is denoted by ⌃⇤.
(4) If v, w 2 ⌃⇤, then vw = v w is the string that is obtained by concatenating v and w; it is called the concatenation of v and w. In particular, v ” = ” v = v.
(5) For n 2 N, ⌃n denotes the set of all words of length n over ⌃.
17
2.4 Block Ciphers
Permutations can always be represented like this.
Remark: The set S(X), together with composition, forms a group (in general non-commutative).
Proof By induction on n. (Usually covered in Abstract Algebra and Discrete Mathematics courses.) ⇤
Example: Let X = {0, 1}n, the set of all bitstrings of length n. A bit permutation is a permutation on X in which just the positions of the bits are permuted. Choose a permutation ⇡ 2 Sn. Then put
f : {0,1}n ! {0,1}n, b1b2 …bn 7! b⇡(1)b⇡(2) …b⇡(n).
Every bit permutation can be uniquely written in this way. Hence there are n! bit permutations
of bitstrings of length n.
Example: “Circular leftshift of i positions”: The bitstring (b0, b1 . . . bn 1) is mapped to
(bi (mod n), bi+1 (mod n), . . . , bi+n 1 (mod n) ). “Circular rightshifts” are defined analogously. 2.4.3 Blockciphers
Definition 2.19.
A cryptosystem is called a block cipher if its plaintext space and ciphertext space are ⌃n (n 2 N), the words of a fixed length n over an alphabet ⌃. The integer n is called the block length.
|
Example: A shift cipher is a block cipher of length 1. In general, block ciphers of length 1 are called substitution ciphers.
Ifn2N,Sn denotesthegroupofpermutationsoftheset{1,2,…,n}. Example: S2 consists of the two elements ⇣ 1 2 ⌘, ⇣ 1 2 ⌘.
12 21 ThegroupSn hasordern!=1·2·…·n.
Proposition 2.6.
Proposition 2.7.
The encryption functions of a block cipher are permutations.
Proof We know that encryption functions are injective (Assignment 1). But an injective map from a finite set A ! A (here A = ⌃n) must be bijective, i.e., a permutation. ⇤
The most general block cipher can be described as follows:
• Fix block length n and alphabet ⌃.
• UseP=C=⌃n.
• Key space is K = S(⌃n).
• Encryption function for a key ⇡ 2 S(⌃n): E⇡ :⌃n !⌃n, v7!⇡(v).
18
• Decryption function:
D⇡ :⌃n !⌃n, v7!⇡ 1(v).
The key space is very large; it contains (|⌃|n)! elements. The problem with this is that it is very ine cient to use; it is not clear how to represent and evaluate a permutation ⇡ 2 S(⌃n) e ciently. In practice, therefore, only a subset of all possible permutations of ⌃n is used; it is chosen
such that the permutations are easy to represent and to evaluate.
Example: The permutation cipher. We use only permutations that permute positions of the
symbols. For ⇡ 2 Sn, set
E⇡ : ⌃n ! ⌃n, (v1,…,vn) 7! (v⇡(1),…,v⇡(n));
so the key space is the group of permutations Sn. Decryption function:
D⇡ :⌃n !⌃n, (x1,…,xn)7!(x⇡ 1(1),…,x⇡ 1(n)). Remarks: (a) If ⌃ = {0, 1}, these are the bit permutations.
(b) The key space has n! elements.
2.5 ModesofBlockCipherOperation
2.5.1 ECBmode
We use a block cipher with alphabet ⌃ and block length n. Let K be the key space and Ek, Dk the encryption and decryption functions for k 2 K .
The electronic codebook mode (ECB mode) is used as follows:
• An arbitrarily long plaintext is decomposed into blocks of length n; if necessary, supple-
ment plaintext (for instance, by randomly chosen symbols) such that its length is divisible by n.
2.5 Modes of Block Cipher Operation
19
2.5 Modes of Block Cipher Operation
• Each block of length n is encrypted using the encryption function Ee.
• The ciphertext is decrypted by applying the decryption function Dd to the blocks of length
n, where the decryption key d corresponds to the encryption key e.
• In short, this mode amounts to each block being “looked up in a codebook”.
ECB mode is illustrated in the diagram above
Example: Take ⌃ = {0, 1}, block length n = 4, and the permutation cipher. So K = S4, and for
⇡ 2 S4,
E⇡ : {0,1}4 ! {0,1}4, b1b2b3b4 7! b⇡(1)b⇡(2)b⇡(3)b⇡(4).
Suppose we have the plaintext
m = 101100010100101.
Decompose it into blocks of length 4. The last block has length 3, so we add a random bit, say
0. So we have the blocks
m1 = 1011, m2 = 0001, m3 = 0100,m4 = 1010.
We use the key ⇡ = ⇣ 1 2 3 4 ⌘, so b1b2b3b4 7! b2b3b4b1. The blocks are encrypted separately, 2341
and we get the ciphertext blocks
c1 = E⇡(m1) = 0111, c2 = E⇡(m2) = 0010,
c3 = E⇡(m3) = 1000, c4 = E⇡(m4) = 0101. So the ciphertext is c = 0111001010000101.
The main weaknesses of ECB mode are as follows:
• The same plaintext blocks give rise to the same ciphertext blocks. Di erences in frequen-
cies may therefore be apparent, and be exploited by the eavesdropper Oscar.
• Oscar can also change the ciphertext and not be detected.
2.5.2 CBCmode
The cipherblock chaining (CBC) mode avoids the weaknesses of ECB mode. Here: en- cryption of a block depends not only on the key, but also on the previous block. In other words: Encryption is “context dependent”, in the sense that equal texts in di erent contexts are enciphered di erently. The ciphertext can therefore not be manipulated; manipulations will be detected.
We need the following fundamental operation:
Definition 2.20.
(a) The map : {0,1}2 ! {0,1}, (b,c) 7! b c, called the exclusive or of two bits, or XOR, is defined by the following table:
20
2.5 Modes of Block Cipher Operation
bcb c 000 101 011 110
(b) If k 2 N, b = (b1,b2,…,bk), c = (c1,c2,…ck) 2 {0,1}k, then we set b c = (b1 c1,b2 c2,…,bk ck).
Remark: If {0, 1} is a system of representatives of Z/2Z, then is the same as addition in Z/2Z.
Example: Ifb=0100andc=1101;thenb c=1001.
CBC mode works as follows:
As before, use a block cipher with alphabet ⌃ = {0, 1}, block length n, key space K , and
encryption and decryption functions Ek and Dk for k 2 K .
• Use a fixed initialization vector IV 2 ⌃n which need not be kept secret.
• Theplaintextisdecomposedintoblocksoflengthn(asinECBmode),saym1,m2,…,mt.
• Alice obtains the ciphertext by setting
c0=IV, and cj=Ee(cj 1 mj) for 1jt;
the ciphertext is then c = c1c2 . . . ct .
• To decipher, Bob uses the decryption key d that satisfies Dd (Ee (w)) = w for all plaintext
blocks w. Then he computes
c0=IV, and mj=cj 1 Dd(cj) for 1jt. (2.5)
CBC mode can be illustrated as follows:
|
21
2.5 Modes of Block Cipher Operation
Remark: Why does this work? For 1 j t, set
cj 1 Dd(cj) = cj 1 Dd(Ee(cj 1 mj))
= cj 1 (cj 1 mj)=(cj 1 cj 1) mj = 0 mj=mj.
Example: Use the same block cipher, same plaintext, and same key as in the previous example, namely plaintext blocks m1 = 1011, m2 = 0001, m3 = 0100, m4 = 1010, and key ⇡ = ⇣ 1 2 3 4 ⌘.
We choose the initialization vector IV = 1010. Then
c1= E⇡(c0 m1)=E⇡(0001)=0010,
c2= E⇡(c1 m2)=E⇡(0011)=0110,
c3= E⇡(c2 m3)=E⇡(0010)=0100,
c4= E⇡(c3 m4)=E⇡(1110)=1101.
So the ciphertext is c = 0010011001001101.
The decryption works as follows (note that here we have D = E 1, the inverse in the group
of permutations):
d⇡
m = c E 1(c)=1010 0001=1011, 10⇡1
m = c E 1(c)=0010 0011=0001, 21⇡2
m = c E 1(c)=0110 0010=0100, 32⇡3
m = c E 1(c)=0100 1110=1010, 43⇡4
and we (i.e., Bob) have recovered the plaintext.
Remark: What are the e ects of transmission errors? Consider the decryption process (2.5). If the ciphertext block cj is transmitted incorrectly, then mj and mj+1 may be incorrect, but everything after that will not be influenced.
2.5.3 CFBmode
A disadvantage of the CBC mode is that encryption and decryption of blocks are done sequentially. Encryption and decryption functions may be expensive to compute, which may lead to time lags. For some applications, however, (for instance, secure telephone communications), real-time encryption and decryption are necessary. This time-lag problem is reduced in cipher feedback mode (or CFB mode). The main di erence to CBC mode is that the encryption function is
– not used directly for encrypting plaintext blocks, but – used for generating a sequence of key blocks.
CFB mode works as follows:
• As before, we use a block cipher with alphabet ⌃ = {0, 1}, block length n, key space K ,
and encryption function Ek for k 2 K .
22
2341
2.5 Modes of Block Cipher Operation
• Use a fixed initialization vector IV 2 ⌃n.
• Choose an integer r, 1 r n, and decompose the plaintext into blocks of length r.
• To encrypt the sequence m1, m2, . . . , mu of plaintext blocks, Alice sets
I1 = IV, and for 1 j u:
(1) Oj =Ek(Ij),
(2) tj is the string consisting of the first r bits of Oj,
(3) cj =mj tj,
(4) Ij+1 = 2r Ij + cj (mod 2n), i.e., Ij+1 is obtained by deleting the first r bits in Ij and
appending cj .
• Theciphertextisthesequencec1,c2,…,cn.
• To decrypt, Bob sets I1 = IV, and for 1 j u:
(1) Oj =Ek(Ij),
(2) tj is the string consisting of the first r bits of Oj, (3) mj =cj tj,
(4) Ij+1 = 2r Ij + cj (mod 2n) (as before).
CFB mode can be illustrated as follows:
Remarks:
(1) Why does this work? We have
cj tj =(mj tj) tj =mj (tj tj)=mj.
(2) Both Alice and Bob compute the string tj+1 as soon as they know the ciphertext block cj.
(3) Only the XORs are computed sequentially; this is fast.
(4) CFBmodecannotbeusedwithpublic-keycryptographysincebothAliceandBobusethe
same key.
(5) Transmission errors: Decryption is spoiled as long as parts of the wrong ciphertext block
are in the vector Ij.
23
2.6 Stream Ciphers
2.5.4 OFBmode
The output feedback mode (OFB mode) is very similar to the CFB mode. Everything is the same up to
For 1 j u:
(1) Oj =Ek(Ij),
(2) tj is the string consisting of the first r bits of Oj, (3) cj =mj tj,
(4) Ij+1 =Oj.
Decryption works analogously again, with Step (3) replaced by mj = cj tj. OFB mode can be illustrated as follows:
Remarks:
(1) The key block tj depends only on IV and the key k; it can be computed simultaneously by Alice and Bob. (This is even more e cient than in CFB mode).
(2) Weakness: While encryption of a plaintext block does depend on its position, it does not depend on the previous plaintext blocks. This makes ciphertext manipulation easier than in CFB mode.
(3) Ifabitofciphertextisincorrectlytransmitted,onlythisonebitofplaintextwillbea ected.
2.6
StreamCiphers
A general theory of stream ciphers is described in the textbook (1) by Stinson. Here I will present only a particular example.
With the alphabet ⌃ = {0, 1}, let the plaintext and ciphertext spaces be P = C = ⌃⇤. The key space is K = ⌃n for some n 2 N. Words in ⌃⇤ are encrypted bit by bit as follows:
24
2.7 Mathematical Background II: Linear Algebra
(1) Letk=(k1,k2,…,kn)2K.
(2) Letw= 1 1…