Announcements Homework 2 graded. Recitation tomorrow: - - PowerPoint PPT Presentation

announcements
SMART_READER_LITE
LIVE PREVIEW

Announcements Homework 2 graded. Recitation tomorrow: - - PowerPoint PPT Presentation

Announcements Homework 2 graded. Recitation tomorrow: Eigenvalues and SVD. HW solution discussion. No lecture next Tuesday (November 5 th ). Make-up lecture next Friday (November 8 th ). 15-853 Page 1 15-853:Algorithms


slide-1
SLIDE 1

Announcements

  • Homework 2 graded.
  • Recitation tomorrow:
  • Eigenvalues and SVD.
  • HW solution discussion.
  • No lecture next Tuesday (November 5th).
  • Make-up lecture next Friday (November 8th).

15-853 Page 1

slide-2
SLIDE 2

15-853 Page 2

15-853:Algorithms in the Real World

Cryptography #1

slide-3
SLIDE 3

15-853 Page 3

Cryptography Outline

Introduction: terminology, cryptanalysis, security Private-Key Algorithms: Rijndael, DES Number Theory

slide-4
SLIDE 4

15-853 Page 4

Cryptography Outline

Introduction: – terminology – cryptanalytic attacks – security Private-Key Algorithms: Rijndael, DES Number Theory

slide-5
SLIDE 5

15-853 Page 5

Some Terminology

Cryptography – the general term Cryptology – the theory Encryption – encoding (but sometimes used as general term) Cryptanalysis – breaking codes Cipher – a method or algorithm for encrypting or decrypting

slide-6
SLIDE 6

15-853 Page 6

More Definitions

Private Key or Symmetric: Key1 = Key2 Public Key or Asymmetric: Key1 ≠ Key2 Key1 or Key2 is public depending on the protocol Encryption Decryption Key1 Key2 Ciphertext Ek(m) = c Dk(c) = m Original Plaintext Plaintext Key Generator

slide-7
SLIDE 7

Private key encryption

15-853 Page 7

Alice Bob Eve Encrypt Decrypt m c m k k We assume Eve knows everything about the encryption scheme (except the secret key)

slide-8
SLIDE 8

15-853 Page 8

What does it mean to be secure?

Attempt 1: it should be impossible for Eve to get the key. Attempt 2: it should be impossible for Eve to recover m. Attempt 3: impossible for Eve to recover any bit of m. Attempt 4: regardless of any information that Eve has, c should not leak any additional information about m. ✓

slide-9
SLIDE 9

One-time pad

  • Key generation:
  • Input: length n (in unary)
  • Output: uniformly random k ∈ {0,1}n
  • Encryption:
  • Input: m ∈ {0,1}n, k ∈ {0,1}n
  • Output: c = m ⊕ k
  • Decryption:
  • Input: c ∈ {0,1}n, k ∈ {0,1}n
  • Output: m = c ⊕ k

15-853 Page 9

slide-10
SLIDE 10

One-time pad

One-time pad is perfectly secret:

  • Let M, C be r.v.s for the message and ciphertext.
  • For every message m and ciphertext c with Pr[C=c] > 0:

Pr[M = m | C = c] = Pr[M = m]

  • Ciphertext contains no information about message!

15-853 Page 10

slide-11
SLIDE 11

One-time pad

One-time pad is perfectly secret. Proof: Pr[C = c | M = m] = Pr[m ⊕ K = c] = Pr[K = m ⊕ c] = 2-n Pr[C = c] = Σm Pr[C = c | M = m] Pr[M = m] = 2-n Σm Pr[M = m] = 2-n Pr[M = m | C = c] = Pr[C = c | M = m] Pr[M = m] / Pr[C = c] = Pr[M = m]

15-853 Page 11

Can we reuse a one-time pad? No.

slide-12
SLIDE 12

The importance of randomness

  • Previous proof only works if key is truly uniformly random.
  • An adversary can exploit biases in randomness.
  • There are techniques to extract uniformly random bits

from biased sources.

  • E.g: suppose we have a biased coin with probabilities p

and 1 – p for heads and tails.

  • How to obtain uniformly random bits from this coin?
  • Flip twice:
  • If (heads, tails) then output 1.
  • If (tails, heads) then output 0.
  • If (heads, heads) or (tails, tails) then no output.

15-853 Page 12

slide-13
SLIDE 13

Computational secrecy

  • Perfect secrecy requires the key to be at least as long as

the message. This is impractical!

  • We need to settle for a weaker definition.
  • Any efficient adversary succeeds in breaking the

scheme with at most negligible probability.

  • Efficient = runs in probabilistic polynomial time (PPT).
  • Negligible = goes to zero faster than any inverse poly:

– A positive function f is negligible if for every positive integer c, there exists Nc such that: f(n) < n-c, for all n > Nc – Denoted as f = negl(n).

15-853 Page 13

slide-14
SLIDE 14

15-853 Page 14

Cryptanalytic Attacks

c = ciphertext messages m = plaintext messages Ciphertext Only: Attacker has multiple cs but does not know the corresponding ms Known Plaintext: Attacker knows some number of (c,m) pairs. Chosen Plaintext: Attacker gets to choose ms and generate cs before. Chosen Ciphertext: Attacker gets to choose cs and generate ms before.

slide-15
SLIDE 15

15-853 Page 15

Cryptography Outline

Introduction: terminology, cryptanalysis, security Private-Key Algorithms: – Block ciphers and product ciphers – Rijndael, DES Number Theory

slide-16
SLIDE 16

15-853 Page 16

Private Key Algorithms

Encryption Decryption Key1 Key1 Ciphertext Ek(M) = C Dk(C) = M Original Plaintext Plaintext What granularity of the message does Ek encrypt?

slide-17
SLIDE 17

15-853 Page 17

Private Key Algorithms

Block Ciphers: blocks of bits at a time – DES (Data Encryption Standard) Banks, linux passwords (almost), SSL, kerberos, … – Blowfish (SSL as option) – IDEA (used in PGP, SSL as option) – Rijdael (AES) – the new standard

slide-18
SLIDE 18

15-853 Page 18

Private Key: Block Ciphers

A Block cipher C is a function with:

  • Input: a key k ∈ {0,1}|k|, block x ∈ {0,1}n (with|k| ≤ n)
  • Output: a block y ∈ {0,1}n
  • Objective: should be hard to distinguish from a random

permutation from {0,1}n to {0,1}n.

  • We can chop long messages into blocks.
  • Suppose we encrypt each block as c = C(k, m).
  • What’s the problem with this?
  • Equal messages have equal encryptions!
slide-19
SLIDE 19

15-853 Page 19

Private Key: Block Ciphers

Intuition: generate a “fresh” one-time pad for each block. Counter (CTR) mode: ctr ctr ctr+1 m1 c1

C(k, ⋅)

ctr+2 m2 c2

C(k, ⋅)

ctr+3 m3 c3

C(k, ⋅)

slide-20
SLIDE 20

Block cipher implementations

15-853 Page 20

slide-21
SLIDE 21

15-853 Page 21

Iterated Block Ciphers

Consists of n rounds R = the “round” function si = state after round i ki = the ith round key R R R

s1

. . .

m c

. . .

key

k1 k2 kn s2

slide-22
SLIDE 22

15-853 Page 22

Iterated Block Ciphers: Decryption

Run the rounds in reverse. Requires that R has an inverse. R-1 R-1 R-1

s1

. . .

m c

. . .

key

k2 kn s2 k1

slide-23
SLIDE 23

15-853 Page 23

Feistel Networks

  • Run with round keys in

reverse order to decrypt.

  • Used by DES (the Data

Encryption Standard)

Image: “Feistel cipher diagram” by Amirki CC BY-SA 3.0

slide-24
SLIDE 24

15-853 Page 24

Substitution-Permutation network

Each round has two components: – Substitution (S-box)

  • ne-to-one mapping of

subblocks. – Permutation (P-box) Mix the bits around. Both operations are invertible. Avalanche effect: changing one bit of m affects all of c.

Image: “Substitution-Permutation Network” by GaborPete CC BY-SA 3.0

slide-25
SLIDE 25

15-853 Page 25

Rijndael

Selected by AES (Advanced Encryption Standard, part of NIST) as the new private-key encryption standard. Based on an open “competition”. – Competition started Sept. 1997. – Narrowed to 5 Sept. 1999

  • MARS by IBM, RC6 by RSA, Twofish by

Counterplane, Serpent, and Rijndael – Rijndael selected Oct. 2000. – Official Nov. 2001 (AES page on Rijndael) Designed by Rijmen and Daemen (Dutch)

slide-26
SLIDE 26

15-853 Page 26

Goals of Rijndael

Resistance against known attacks: – Differential cryptanalysis – Linear cryptanalysis – Truncated differentials – Square attacks – Interpolation attacks – Weak and related keys Speed + Memory efficiency across platforms – 32-bit processors – 8-bit processors (e.g smart cards) – Dedicated hardware Design simplicity and clearly stated security goals

slide-27
SLIDE 27

15-853 Page 27

High-level overview

An iterated block cipher with – 10–14 rounds, – 128-256 bit blocks, and – 128-256 bit keys Mathematically reasonably sophisticated

slide-28
SLIDE 28

15-853 Page 28

Blocks and Keys

The blocks and keys are organized as matrices of bytes. For the 128-bit case, it is a 4x4 matrix.              

15 11 7 3 14 10 6 2 13 9 5 1 12 8 4

b b b b b b b b b b b b b b b b              

15 11 7 3 14 10 6 2 13 9 5 1 12 8 4

k k k k k k k k k k k k k k k k Data block Key b0, b1, …, b15 is the order of the bytes in the stream.

slide-29
SLIDE 29

15-853 Page 29

Galois Fields in Rijndael

Uses GF(28) over bytes. The irreducible polynomial is: M(x) = x8 + x4 + x3 + x + 1 or 100011011 or 0x11B Also uses degree 3 polynomials with coefficients from GF(28). These are kept as 4 bytes (used for the columns) The polynomial used as a modulus is: M(x) = 00000001x4 + 00000001 or x4 + 1 Not irreducible, but we only need to find inverses of polynomials that are relatively prime to it.

slide-30
SLIDE 30

15-853 Page 30

Each round

3 1 2

Rotate Rows

. .

Byte substitution Mix columns + Keyi

  • ut

in The inverse runs the steps and rounds backwards. Each step must be reversible!

slide-31
SLIDE 31

15-853 Page 31

Byte Substitution

Non linear: y = b-1 (done over GF(28)) Linear: z = Ay + B (done over GF(2), i.e., binary)

                          =                   = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 B A 

To invert the substitution: y = A-1(z - B) (the matrix A is nonsingular) b = y-1 (over GF(28))

slide-32
SLIDE 32

15-853 Page 32

Mix Columns

For each column a in data block a0 a1 a2 a3 compute b(x) = (a3x3+a2x2+a1x+a0)(3x3+x2+x+2) mod x4+1 where coefficients are taken over GF(28). New column b is b0 b1 b2 b3 where b(x)=b3x3+b2x2+b1x+b0

slide-33
SLIDE 33

15-853 Page 33

Implementation

              = 2 1 1 3 3 2 1 1 1 3 2 1 1 1 3 2 C

Using xj mod (x4 + 1) = x(j mod 4) M(x) is not irreducible, but the rows of C and M(x) are coprime, so the transform can be inverted. (a3x3+a2x2+a1x+a0)(3x3+x2+x+2) mod x4+1 = (2a0+3a1+a2+a3) + (a0+2a1+3a2+a3)x + (a0+a1+2a2+3a3)x2 + (3a0+a1+a2+2a3)x3 Therefore, b = C • a

slide-34
SLIDE 34

15-853 Page 34

Generating the round keys

f + + + + Words corresponding to columns of the key f = b1 b2 b3 b4 b2 b3 b4 b1 + rotate sub byte consti

slide-35
SLIDE 35

15-853 Page 35

Performance

Performance: (64-bit AMD Athlon 2.2Ghz, 2005, Open SSL): Algorithm Bits/key Mbits/sec DES-cbc 56 399 Blowfish-cbc 128 703 Rijndael-cbc 128 917 Hardware implementations go up to 32 Gbits/sec

slide-36
SLIDE 36

15-853 Page 36

Cryptography Outline

Introduction: terminology, cryptanalysis, security Private-Key Algorithms: Rijndael, DES Number Theory – Groups

slide-37
SLIDE 37

15-853 Page 37

Groups

A Group (G,*,I) is a set G with operator * such that:

  • 1. Closure. For all a,b ∈ G, a * b ∈ G
  • 2. Associativity. For all a,b,c ∈ G, a*(b*c) = (a*b)*c
  • 3. Identity. There exists I ∈ G, such that for all

a ∈ G, a*I=I*a=a

  • 4. Inverse. For every a ∈ G, there exist a unique element b

∈ G, such that a*b=b*a=I An Abelian or Commutative Group is a Group with the additional condition

  • 5. Commutativity. For all a,b ∈ G, a*b=b*a
slide-38
SLIDE 38

15-853 Page 38

Examples of groups

– Integers, Reals or Rationals with Addition – The nonzero Reals or Rationals with Multiplication – Non-singular n x n real matrices with Matrix Multiplication – Permutations over n elements with composition

[0→1, 1→2, 2→0] o [0→1, 1→0, 2→2] = [0→0, 1→2, 2→1]

We will only be concerned with finite groups, I.e., ones with a finite number of elements.

slide-39
SLIDE 39

15-853 Page 39

Key properties of finite groups

Notation: aj ≡ a * a * a * … j times Definition: the order of g ∈ G is the smallest positive integer m such that gm = I Definition: a group G is cyclic if there is a g ∈ G such that

  • rder(g) = |G|

Definition: an element g ∈ G of order |G| is called a generator or primitive element of G.

slide-40
SLIDE 40

15-853 Page 40

Groups based on modular arithmetic

The group of positive integers modulo a prime p Zp

* ≡ {1, 2, 3, …, p-1}

*p ≡ multiplication modulo p Denoted as: (Zp

*, *p)

Required properties

  • 1. Closure. Yes.
  • 2. Associativity. Yes.
  • 3. Identity. 1.
  • 4. Inverse. Yes.

Example: Z7

*= {1,2,3,4,5,6}

1-1 = 1, 2-1 = 4, 3-1 = 5, 6-1 = 6

slide-41
SLIDE 41

15-853 Page 41

Other properties

|Zp

*| = (p-1)

By Fermat’s little theorem: a(p-1)= 1 (mod p) Example of Z7

*

x x2 x3 x4 x5 x6 1 1 1 1 1 1 2 4 1 2 4 1 3 2 6 4 5 1 4 2 1 4 2 1 5 4 6 2 3 1 6 1 6 1 6 1

For all p the group is cyclic. Generators

slide-42
SLIDE 42

15-853 Page 42

What if n is not a prime?

The group of positive integers modulo a non-prime n Zn ≡ {1, 2, 3, …, n-1}, n not prime *p ≡ multiplication modulo n Required properties?

  • 1. Closure. ?
  • 2. Associativity. ?
  • 3. Identity. ?
  • 4. Inverse. ?

How do we fix this?

slide-43
SLIDE 43

15-853 Page 43

Groups based on modular arithmetic

The multiplicative group modulo n Zn

* ≡ {m : 1 ≤ m < n, gcd(n,m) = 1}

* ≡ multiplication modulo n Denoted as (Zn

*, *n)

Required properties:

  • Closure. Yes.
  • Associativity. Yes.
  • Identity. 1.
  • Inverse. Yes.

Example: Z15

* = {1,2,4,7,8,11,13,14}

1-1 = 1, 2-1 = 8, 4-1 = 4, 7-1 = 13, 11-1 = 11, 14-1 = 14

slide-44
SLIDE 44

15-853 Page 44

The Euler Phi Function

If n is a product of two primes p and q, then

) / 1 1 ( ) (

| *

p n n

n p n

− ∏ = Ζ = φ ) 1 )( 1 ( ) / 1 1 )( / 1 1 ( ) ( − − = − − = q p q p pq n φ

Fermat-Euler Theorem:

* ) (

for ) (mod 1

n n

a n a Ζ ∈ =

φ

Or for n = pq

* ) 1 )( 1 (

for ) (mod 1

pq q p

a n a Ζ ∈ =

− −

This will be very important in RSA!

slide-45
SLIDE 45

15-853 Page 45

Generators

Example of Z10

*: {1, 3, 7, 9}

x x2 x3 x4 1 1 1 1 3 9 7 1 7 9 3 1 9 1 9 1

For n = (2, 4, pe, 2pe), p an odd prime, Zn is cyclic Generators

slide-46
SLIDE 46

15-853 Page 46

Operations we will need

Multiplication: a*b (mod n) – Can be done in O(log2 n) bit operations, or better Power: ak (mod n) – The power method O(log n) steps, O(log3 n) bit ops

fun pow(a,k) = if (k = 0) then 1 else if (k mod 2 = 1) then a * (pow(a,k/2))2 else (pow(a, k/2))2

Inverse: a-1 (mod n) – Euclids algorithm O(log n) steps, O(log3 n) bit ops

slide-47
SLIDE 47

15-853 Page 47

Discrete Logarithms

If g is a generator of Zn

*, then for all y there is a unique x

(mod φ(n)) such that – y = gx mod n This is called the discrete logarithm of y and we use the notation – x = logg(y) In general finding the discrete logarithm is conjectured to be hard…as hard as factoring.