Docsity

CS 387 Applied Cryptography, Exercises of Cryptography and System Security

Partial preview of the text

Download CS 387 Applied Cryptography and more Exercises Cryptography and System Security in PDF only on Docsity!

CS 387

Applied Cryptography

David Evans

written by Daniel Winter special thanks to: Wolfgang Baltes

Contents

1 Symmetric Ciphers

1.1 Cryptology, Symmetric Cryptography & Correctness Property

Definition cryptography, cryptology cryptography comes from Greek with crypto means ”hidden, secret” and graphy means ”writ- ing”. A broader definition is cryptology with Greek ”-logy” means ”science”. Example 1: These actions involve cryptology:

  • Opening a door
  • Playing poker
  • Logging into an internet account

. Definition symmetric Cryptography Symmetric Cryptography means all parties have the same key to do encryption and decryption. The keys may be identical or there may be a simple transformation to go between the two keys. Definition symmetric Cryptosystem, decryption function, encryption function In this paper a symmetric Cryptosystem always looks as follows:

m //E /o c/o^ /o//X /oc/o^ /o//D //m

k

O O

k

O O

where

m is a plaintext message from the set M of all possible messages,

k is the key from the set K of all possible keys and

c is a ciphertext from the set C of all possible Ciphertexts.

E ist the encryption function,

X is a possible eavesdropper of the insecure channel and

D is the decryption function with:

E : M × K → C : (m, k) 7 → c D : C × K → M : (c, k) 7 → m

. Definition correctness property In order we get the same message after decrypting the ciphertext (encrypted message) we need the correctness property: ∀m ∈ M, ∀k ∈ K

Dk(Ek(m)) = m

Example 2: These functions satisfy the correctness property for a symmetric cryptosystem:

  1. Ek(m) = m + k, Dk(c) = c − k with M = K = N because

Dk(Ek(m)) = Dk(m + k) = m + k − k = m

  1. Ek(m) = am + b, Dk = a−^1 (c − b) with M = K = Z/Zm, a ∈ (Z/Zm)×^ because

Dk(Ek(m)) = Dk(m) = m

1.2 Kerchoff’s Principle & xor-function

Theorem 1.2.1 (Kerchoff ’s Principle) The general assumption is that the channel for message transmission is not secure. Even if the encryption function E and decryption function D are public, the message is still secure due to a usage of a secret. Only the key has to be secret. If the key gets public you have to use another key. So the keys must be kept secret in a cryptosystem.

Definition xor function the xor function or exclusive or (symbol: ⊕) is given by it’s truth table:

A B A ⊕ B 0 0 0 1 0 1 0 1 1 1 1 0

Useful properties ∀x, ∀y, ∀z of the xor function are:

  • Distributivity x ⊕ (y ⊕ z) = (x ⊕ y) ⊕ z
  • Commutativity x ⊕ y = y ⊕ x
  • Negation x ⊕ 1 = x
  • Identity x ⊕ x = 0

which are applied in ciphers. It follows x ⊕ y ⊕ x = x ⊕ x ⊕ y = y ⇔ m ⊕ k = c and c ⊕ k = m

that the xor function is kommutative and assoziative and how to compute the ciphertext c with the message m and the key k and decrypt the ciphertext c with the same key k to get m.

∀i ∈ { 0 , 1 ,... , n − 1 }: ci ⊕ ki = mi ⇒ m = 10100101000011

if m is separated in 2 parts of length 7: 1010010 and 1000011, convert each to a decimal number and apply the built-in Python function chr()=ascii charakter the result is ’BS’ instead of the correct string ’CS’. Example 4: Suppose an eavesdropper X knows A is sending B a message m ∈ { 00 , 01 , 10 , 11 } using a one-time pad were the key k is a perfectly random key unknown to X and the distribution of messages is uniform - each message is equally likely. Then the conditional probability

P [m = 01|X intercepts c = 01] = 0. 25

because since m is encrypted using a one-time-pad we gain no information about m from c, therefore: P [m = 01|X intercepts c = 01] = P [m = 01] =

Additionally, suppose X learns that A generated k using a biased random number generator that outputs 0 with 0.52 probability. Then

P [m = 01|X intercepts c = 01] = 0. 2704

for c = 01 to map to m = 01 the key has to be k = 00. It follows

P [k = 00] = 0. 52 · 0 .52 = 0. 2704

1.4 Probability

Definition Probability Space Ω The probability space Ω is the set of all possible outcomes (ωi)i∈I. Example 5:

  • Flipping a coin. The coin can land on Head H, Tail T or Edge E, hence Ω = {H, T, E}
  • Rolling a die. The outcomes are 1, 2 , 3 , 4 , 5 or 6, hence Ω = { 1 , 2 , 3 , 4 , 5 , 6 }

. Definition Bernoulli Trial A Bernoulli Trial is an experiment whose outcome is random and can be either of two possible outcomes:

  • Success (S)
  • Failure (F )

As probabilities, we assign

p as the probability for success

and

1 − p as the probability for failure

. Definition Geometric Distribution As experiment, we perform a Bernoulli trial until success. This meas k −1 trials fail and success at the kth^ trial for k = 1, 2 ,... , ∞. The probability space Ω is never changed by any trial. It follows:

  • Using the symbols S for success, F for failure and F nS :=

n times ︷ ︸︸ ︷ F F... F S then Ω is an infinite set with Ω = {S, F S, F F S, F F F S, F 4 S, F 5 S,.. .}

  • Since successive trials are independent, the probability distribution is given by

P (F nS) = P (F )n^ · P (S) = (1 − p)n^ · p

  • The average number of trails until success is

∑^ ∞

k=

(1 − p)k−^1 · p · k = −p · d dp

k=

(1 − p)k

= −p · d dp

p

p

. Definition Uniform Distribution A uniform distribution has a underlying probability space Ω a finite set, e.g. Ω = {ω 1 , ω 2 ,... , ωr} with r elements, and a probability measure P that has (by definition) the property

P ({ωi}) =

r

Example 6: Assume Ω = {H, T } for Head and Tail (without Edge) then

P (H) = P (T ) =

Example 7: Assume a die with Ω = { 1 , 2 , 3 , 4 , 5 , 6 } then

∀i ∈ Ω : P (i) =

Example 8: Another example is given by a similar, but slightly different experiment to that one described for the geometric distribution which deals with a set Ω 0 := {ω 1 , ω 2 ,... , ωN } of N numbers. Let’s assume that exactly one of the numbers ωi be prime. Again, we perform a draw until success, where success means ’we draw a prime’. Additionally, in case the number drawn is not prime, we don’t place this number back into Ω, what will effect the probability space Ω for the next draw. The probability-distribution of this experiment’s outcomes is the uniform distribution. It follows

Example 11: Let’s assume Ω = {H, T, E} with probabilities

P (H) = 0. 49999 P (T ) = 0. 49999

The probability for edge E is given by

1 = P (Ω) = P (H) + P (T ) + P (E) = 0.49999 + 0.49999 + P (E) ⇒ P (E) = 0. 00002

Theorem 1.4.2: The probability of an event A is given by

P (A) =

ω∈A

P (ω)

Example 12: The probability for a valid coin toss B = {H, T } is

P (B) = P (H) + P (T ) = 0.49999 + 0.49999 = 0. 99998

Definition Conditional Probability Given two events, A and B, in the same probability space Ω, the conditional probability of B, given that A occured is:

P (B|A) =

P (A ∩ B)

P (A)

Example 13: Given that a coin toss is valid, the probability it is heads is given with A = {H, T } is the event that a coin toss is valid and B = {H} is the event that the coin toss is heads. It follows with P (A) = P ({H, T }) = P ({H}) + P ({T }) = 0.49999 + 0.49999 = 0.99998 and P (B) = P ({H}) = 0.49999:

P (B|A) =

P (A ∩ B)

P (A)

P ({H, T } ∩ {H})

P ({H, T })

P ({H})

P ({H, T })

Example 14: The relative frequencies of the vowels in English, as a percentage of all letters in a sample of typical English text:

e: 13%, a: 8%, o: 7%, i: 7%, u: 3%

For the letter x drawn randomly from the text, it is

  • P (x is a vowel):

P (x ∈ {a, e, i, o, u}) = 0.13 + 0.08 + 0.07 + 0.07 + 0.03 = 0. 38

  • P (x is ’e’|x is a vowel) :

P (x = e|x ∈ {a, e, i, o, u}) = P (x = e ∩ x ∈ {a, e, i, o, u}) P (x ∈ {a, e, i, o, u})

= P (x = e) P (x ∈ {a, e, i, o, u})

=

  • P (x is a vowel|x is not a} :

P (x ∈ {a, e, i, o, u}|x 6 = a) = P (x ∈ {a, e, i, o, u} ∩ x 6 = a) P (x 6 = a)

= P (x = e) + P (x = i) + P (x = o) + P (x = u) 1 − P (x = a) =

1.5 Secret Sharing

Definition Secret Sharing A useful property of xor is that it can be used to share a secret (message) amount at least 2 (yourself and 2 others) people as follows:

  1. The secret message of length n is

x = x 0 x 1 x 2... xn− 1

  1. Generate a random key k ∈ { 0 , 1 }n^ :

k = k 0 k 1 k 2... kn− 1

  1. Compute c = k ⊕ x with ∀i ∈ { 0 , 1 , 2 ,... , n − 1 } : ci = ki ⊕ xi
  2. Give c and k to different person and keep x yourself.

The message can only be decryptet by computing c ⊕ k. So the people with the information c and k may not meet. Theorem 1.5.1: To share a n bit long secret x amoung m people it is needed to compute (m − 1) · n key bits (equally: to compute m − 1 keys).

Proof: Show that m − 1 keys are enough to share a secret securely amoung m people with the property that only all m people together can decrypt the message. Compute m − 1 keys: k 1 , k 2 ,... , km− 1

That’s the probability of event B, which is the probability that some message encrypts to some key (computed over all the messages). Then

P (A∩B) = P (m = m∗∩Ek(m) = c) = P (m = m∗)·P (k = k∗) = P (m = m∗)·

|K|

P (m = m∗) |K|

to see this consider k∗^ ∈ K, m∗^ ∈ M and the distribution of M is not uniform (not all messages are equally likely) and every key maps each message to only one ciphertext and the keys are equally likely (the distribution of the keys is uniform), therefore P (k = k∗) = (^) |K|^1. Plugging all together in the conditional probability formula gives

P [m = m∗|Ek(m) = c] = P (m = m∗^ ∩ Ek(m) = c) P (Ek(m) = c)

P (m=m∗) |K| 1 |K|

= P (m = m∗)

Which is the definition of the perfect cipher. It follows that the one-time pad is a perfect cipher  Definition malleable cipher, impractical cipher A cipher is

  • malleable then the encryptet message Ek(m) = c can be modified by an active attacker X, which means m //Ek(m) c/o^ /o /o//X c /o /o′^ /o^ // Ek(c′) //m′

k

O O

k

O O

  • impractical if and only if |K| ≥ |M| The one-time pad is very impractical, because the keys have to be as long as the messages, and a key can never be reused. That means

|K| = |M|

Unfortunately, Claude Shannon proved that finding a practical perfect cipher is impossible.

. Theorem 1.6.2 (Shannon’s Keyspace Theorem) Every perfect cipher is impractical.

Proof: Proof by contradiction: Assume having a perfect cipher that does not satisfy the impractical property. That’s equal to: Suppose E is a perfect cipher where |M| > |K|. Let c 0 ∈ C with P (Ek(m) = c 0 ) > 0. That means there is some key that encrypts some message m to c 0. Decrypt c 0 with all k ∈ K with the decryption function D (not necessarily the same as E). Since the cipher is correct - in order to be perfect it has to both be correct and perfectly secure. That means the decryption function must have the property

Dk(Ek(m)) = m

Let M 0 =

k∈K

Dk(c 0 )

Therefore M 0 is the set of all possible messages decrypting c 0 with every key k ∈ K (brute-force attack). It follows

(a) |M 0 | ≤ |K| Because of construction of M 0 (union over all keys)

(b) |M 0 | < |M| Because of the assumption |M| > |K| and combined with (a) : |M 0 | ≤ |K|.

(c) ∃m∗^ ∈ M : m∗^ ∈ M/ 0 Follows exactly from (b) : |M 0 | < |M|

Considering the perfect cipher property

P [m = m∗|Ek(m) = c] = P [m = m∗]

Due to (b) : P (m = m∗) = 0 but due to (c) : m∗^ ∈ M ⇒ P (m = m∗) 6 = 0 We have contradicted the requirement for the pefect cipher. Therefore the assumption |M| > |K|. Thus: There exists no perfect ciphers where

|M| > |K|

Therefore every cipher that is perfect must be impractical. 

1.7 Monoalphabetic Substitution Cipher (Toy-Cipher)

Definition Monoalphabetic Substitution Cipher (Toy-Cipher) The Toy-Cipher is a monoalphabetic substitution cipher where each letter in the alphabet is mapped to a substitution letter. The decryption is done by the reversed mapping. The cipher uses M = {A, B, C,... , Z}n^ (words of length n, using letters from the alphabet) and has K = σ 26 (permutation of 26 letters) as keyspace. Example 15: One possible mapping is given by (every letter maps to the next letter and z maps to a)

a 7 → b b 7 → c .. . y 7 → z z 7 → a

Thus the encryption function E encrypts the message m =hello as follows:

h 7 → i e 7 → f l 7 → m l 7 → m o 7 → p

Each letter of the message m would be divided into 5 bits m 0 m 1 m 2 m 3 m 4 , and those would be xor’d with the value coming from the corresponding and different sized k-wheels which had at each position a 0 or a 1. The result would also be xor’d with the value of the s-wheels, which worked similarly. The k-wheels turned every charakter, the s-whells turned conditionally on the result of 2 other wheels, which were the m 1 -wheel (which turned every time) and the m 2 -wheel (which would rotate depending on the value of the m 1 -wheel) and depending on the m 1 ⊕ m 2 either all the s-wheels would rotate by 1 or none of them would. The result of all these xors is the cipher text c = c 0 c 1 c 2 c 3 c 4. The Lorenz Cipher works similarly to an One - Time Pad: xor’ing a message with a key leads to a ciphertext. Knowing the structure of the machine is not enough to break the cipher. It’s necessary to know the initial configuration.

Example 16: Let z = z 0 z 1 z 2 z 3 z 4 z 5 z 6 z 7... zn− 1 be the interceptet message. The ciphertext z is broken into 5 channels c where each bit on position i with i ∈ { 0 , 1 , 2 ,... , n − 1 } is transmitted over channel (i + 1) mod 5. Thus for 5 channels c 1 , c 2 , c 3 , c 4 , c 5 :

c 1 → z 0 z 5 z 10 z 15... c 2 → z 1 z 6 z 11 z 16... c 3 → z 2 z 7 z 12 z 17... c 4 → z 3 z 8 z 13 z 18... c 5 → z 4 z 9 z 14 z 19...

So channel 1 transmit the first part of the first letter z 0 , the first part of the second letter z 5 , channel 2 transmit the second part of the first letter z 1 , the second part of the second letter z 6 , and so on. Now subscripting z by th channel and the letter for that channel zc,i. It follows

z 0 ,i = z 0 , z 5 , z 10 ,... z 1 ,i = z 1 , z 6 , z 11 ,...

The subscripts break up the ciphertext into channels and therefore, with the weakness of the cipher (all s-wheels move in turn). Thus

zc,i = mc,i ⊕ kc,i ⊕ sc,i

and by separating the ciphertext into these 3 pieces, it’s possible to take advantage of properties that they have. The importance is that the s-wheels don’t always turn. Looking at subsequent characters, there is a good chance that the s-wheels have not changed. Let’s define

∆zc,i := zc,i ⊕ zc,i+

notice that zc,i, zc,i+1 are 5 characters apart in the interceptet ciphertext, but they are adjacent for that channel. It follows

∆z 0 ,i ⊕ ∆z 1 ,i = z 0 ,i ⊕ z 0 ,i+1 ⊕ z 1 ,i ⊕ z 1 ,i+

= m 0 ,i ⊕ k 0 ,i ⊕ s 0 ,i ⊕ m 0 ,i+1 ⊕ k 0 ,i+1 ⊕ s 0 ,i+1 ⊕ m 1 ,i ⊕ k 1 ,i ⊕ s 1 ,i ⊕ m 1 ,i+1 ⊕ k 1 ,i+1 ⊕ s 1 ,i+ = m 0 ,i ⊕ m 0 ,i+1 ⊕ m 1 ,i ⊕ m 1 ,i+ ︸ ︷︷ ︸ =:∆m

⊕ k 0 ,i ⊕ k 0 ,i+1 ⊕ k 1 ,i ⊕ k 1 ,i+ ︸ ︷︷ ︸ =:∆k

⊕ s 0 ,i ⊕ s 0 ,i+1 ⊕ s 1 ,i ⊕ s 1 ,i+ ︸ ︷︷ ︸ =:∆s = ∆m ⊕ ∆k ⊕ ∆s

Theorem 1.8.2: With the example above follows

(a) P (∆m = 0) > (^12)

(b) P (∆s = 0) > (^12)

Proof:

(a) P (∆m = 0) > 12 depends on subsequent message letters: If adjacent letters in the message are the same, that ensures that ∆m = 0 (repeated letter: ’wheels’, ’letters’, for German 0.61)

(b) P (∆s = 0) > 12 follows by the structure of the machine: When the s-wheel advance this probability is about 12 but when they don’t advance, ∆s is always 0. This means, the probability that ∆s = 0 is significanlty greater than 12 (for the structure of the Lorenz Cipher Maschine it’s about 0.73)

 Example 17: Assume P (∆k = 0) = 12 and P (∆m = 0) > 12 and P (∆s = 0) > 12 with ∆zc,i = ∆mc,i ⊕ ∆kc,i ⊕ ∆sc,i. It’s possible to break the cipher knowing more about the key k. If key is uniformly distributed, whatever patterns m and s have are lost when they get xor’ed with k in ∆zc,i = ∆mc,i ⊕∆kc,i ⊕∆sc,i. The k-wheels in the Lorenz Cipher machine produce key. Looking at ∆z for two channels, i.e. only at the first two k-wheels (size 41 and size 31). Then there are 41 · 31 = 1271 different configurations for k 0 and k 1. That means that every 1271 letters those wheels woult repeat, and there are only 1271 different possible settings for the k-wheels. Trying all 1271 possible setting and for 1 of those possible settings we are goint to know all the key bits and if we guess the right setting then ∆k = 0. If we guess right then P (∆k = 0) = 1 otherwise (false guess) P (∆k = 0) = 12. With ∆z = ∆m ⊕ ∆k ⊕ ∆s it follws P (∆z = 0) = 0. 55 because:

∆z = ∆m ⊕ (^) ︸︷︷︸∆k

⊕∆s ⇒ P (∆z = 0) = P (∆m = 0) ∧ P (∆s = 0) + P (∆m = 1) ∧ P (∆s = 1)

= 0. 61 · 0 .73 + (1 − 0 .63) · (1 − 0 .73) = 0. 55

Computing the sum of all ∆z. If the output is nearly |z 2 | is was a bad guess otherwise if the result is about 0. 55 · |z| is was a good guess. Assume having a 5000 letters message with all 1271 configurations of k 0 and k 1 and for all configuration its necessary to compute the summation of the ∆z. Guessing that the ∆s = 0 therefore

∆z 0 ,i ⊕∆z 1 ,i = m 0 ,i ⊕m 0 ,i+1 ⊕m 1 ,i ⊕m 1 ,i+1 ⊕k 0 ,i ⊕k 0 ,i+1 ⊕k 1 ,i ⊕k 1 ,i+1 ⊕s 0 ,i ⊕ s 0 ,i+1 ⊕ s 1 ,i ⊕ s 1 ,i+ ︸ ︷︷ ︸ =:∆s=

Thus computin 7 xors for each character and counting the number of times that’s equal to 0. It follows the number of xors are 5000 · 1272 · 7 = 44485000 whats the maximum number of xors we have to do (expect about half of 44485000 operations to find the correct configuration of k 0 and k 1 and then do similar thinks with the other k-wheels and then we can decrypt the whole

  • speed: implementing it both in hardware and in software and
  • simplicity which is usually against security.

The winner of the AES competition was a cipher known as Rijndael (developed by two belgian cryptographers). A brute force attack with a 128 bit key would require on average 2 128 2 = 2

127

attempts. The best known attack needs 2^126 attempts. The AES works with xor and has two main operations

  • shift (permuting bits - moving bits around)
  • s-boxes (non-linearity: mixes up data in way that is not linear): This is done by lookup-tables: A s-box takes 8 bits and have a lookup table (with 256 entries) mapping each set of 8 bits to some other set of 8 bits. Designing the lookup table is a challenge. The lookup table has to be as nonlinear as possible and make sure there is no patterns in the data in this table.

The way AES works is combining shifts and s-boxes with xor to scramble up the data and do this multiple rounds and put them back through a series of shifts and s-boxes with xor. The number of rounds depens on the key size: for the smallest key size for AES (128 bits) we would do 10 rounds going through the cycle, getting the output cipher text for that block.

2 Application of Symmetric Ciphers

2.1 Application of Symmetric Ciphers

Ciphers provide 2 main functions:

  • Encryption: Takes a message m from some message space M and a key k from some key space K.
  • Decryption: Is the inverse of encryption. It takes a ciphertext and if it takes the corresponding key k′ it will produce the same message that we got.

The correctness property (as mentioned earlier):

Dk(Ek(m)) = m

All of our assumptions about security depend on the key. There are 2 main key properties:

  • k is selected randomly and uniformly from K. This means each key is equally likely to be selected and there is no predictability about what the key is.
  • k can be kept secret (but shared). That means that the adversary can’t learn the key but it can be shared between the 2 endpoints.

2.2 Generating Random Keys

Definition (Kolomogorov) Randomness A string of bits is random if and only if it is shorter than any computer program that can produce that string (Kolmogorov Randomness). This means that random strings are those that cannot be compressed. Example 18: k ∈ K for K := { 0 , 1 }n^ with some n ∈ N. If there are no visible patterns (e.g. 100100100.. .) and enough repititions (e.g. 100000101111101011111.. .), then it is likely that the key is random. Definition Complexity of a Sequence (Kolomogorov Complexity) How random a certain string is, is a way of measuring the complexity K of some sequence s. This is defined as the length of the shortest possible description of that sequence:

K(s) = length of the shortest possible describtion of s

where a description is e.g. a Turing-Maschine, a python program or wathever we select as description language and as long as that description language is powerful enough to describe any algorithm, which it’s a reasonable way to define complexity. Definition Random Sequence A sequence s is random if and only if

K(s) = |s| + C

That means, making the sequence longer the description gets longer at the same rate with the constant C. Therefore a short program that can produce the sequence is not random as there is a structure in the program and the program shows what is that structure. If there isn’t a short program that can describe that sequence, that’s an indication that the sequence is random (there is no simpler way to understand that sequence other than to see the whole sequence). Theorem 2.2.1: For a given sequence s it is theoretically impossible to compute K(s).

Proof: If s is truly random then K(s) = |s| + C

would be correct. But if s is not truly random, there might be some shorter way to compute K(s). So K(s) gives the maximum value of the Kolomogorov complexity of a sequence s e.g. ’’print ’’ + s which prints out s. It’s length would be the length of s plus the 5 characters (4 for print plus 1 for the space). But that doesn’t proof that there is a shorter program that can produce s.  Example 19: The Berry Paradoxon gives an idea of the proof of the former theorem:

’What is the smallest natural number that cannot be described in eleven words?’

Which has 2 properties:

  • Set of natural numbers that cannot be described in eleven words (a set).
  • Any set of natural numbers has a smallest element.

The answer: