Secret Key: stream ciphers & block ciphers Stream Ciphers - - PowerPoint PPT Presentation

secret key stream ciphers block ciphers stream ciphers
SMART_READER_LITE
LIVE PREVIEW

Secret Key: stream ciphers & block ciphers Stream Ciphers - - PowerPoint PPT Presentation

Secret Key: stream ciphers & block ciphers Stream Ciphers Idea: try to simulate one-time pad define a secret key (seed) Using the seed generates a byte stream ( Keystream): i-th byte is function only of the key


slide-1
SLIDE 1

Secret Key: stream ciphers & block ciphers

slide-2
SLIDE 2

Stream Ciphers

Idea: try to simulate one-time pad

  • define a secret key (“seed”)
  • Using the seed generates a byte stream

(Keystream): i-th byte is function

– only of the key (synchronous Stream cypher)

  • r

– Of the key and first i-1 bytes of ciphertext (asynchronous Stream cypher).

  • obtain ciphertext by using XOR of

textplain and keystream (bi-wise)

slide-3
SLIDE 3

= ⊕

Synchronous Stream Cipher

Key Ciphertext Stream Plaintext

encryption

slide-4
SLIDE 4

Synchronous Stream Cipher

= ⊕ Key Plaintext Stream Ciphertext

decryption

slide-5
SLIDE 5

Cipher Streams in practice

  • Many codes before 1940
  • Enigma - II world war (Germany)
  • A5 – GSM (encryption cell phone-

base station)

  • WEP - used in ethernet 802.11

(wireless)

  • RC-4 (Ron’s Code)
slide-6
SLIDE 6

Example: RC-4

  • RC: code proposed by Ron (Ron’s Code,

Ron=Ronald Rivest)

  • Considered safe: 1987 - 1994 kept secret,

after ‘94 extensively studied

  • Good for exporting (complain US

restrictions)

  • Easy to program, fast
  • Very popular: Lotus Notes, SSL, Wep etc.
slide-7
SLIDE 7

RC4: properties

  • variable key lenght (byte)
  • synchronous
  • starting from the key it generates a

apparently random permutation:

  • Eventually the sequence will repeat
  • However long period > 10100 [in this way it

simulates one-time-pad]

  • very fast: 1 byte of output requires 8-16

instruction

slide-8
SLIDE 8

RC-4 initialization

1. j=0 2. S0=0, S1=1, …, S255=255 3. Assume a key of 255 (bytes) k0,…,k255 (if the key is shorter repeat) 4. For i=0 to 255 j = (j + Si+ ki) mod 256 exchange Si and Sj In this way we obtain a permutation of 0, 1, …,255, the resulting permutation is a function of the key

slide-9
SLIDE 9

RC-4 Key-stream generation

Input: i,j, permutation of 0,1,…255 1. i = (i+1) mod 256 2. j = (j +Si) mod 256 3. exchange Si and Sj 4. t = (Si + Sj) mod 256 5. B = St Output: B Recall: ciphertext EXOR of 1 byte of plaintext and 1 byte of ciphertext

slide-10
SLIDE 10

Real World Block Ciphers

  • DES, 3-DES - (64 bit block, 56 bit key)
  • AES (Rijndael) (128-256 block)
  • RC-2
  • RC-5
  • IDEA ((64 bit block, 128 bit key)
  • Blowfish, Cast
  • Gost
slide-11
SLIDE 11

ECB Mode Encryption

(Electronic Code Book)

P1 Ek C1 P2 Ek C2 P3 Ek C3 encrypt each plaintext block separately

slide-12
SLIDE 12

Properties of ECB

  • Simple and efficient
  • Parallel implementation possible
  • Does not conceal plaintext patterns
  • Active attacks are possible (plaintext can be

easily manipulated by removing, repeating,

  • r interchanging blocks).
slide-13
SLIDE 13

ECB: plaintext repetitions

plaintext ciphertext ECB good cyphertext

slide-14
SLIDE 14

CBC (Cipher Block Chaining) mode

m1 Ek C1 m2 Ek C2 m3 Ek C3 seed Previous ciphertext is XORed with current plaintext before encrypting current block.

  • Seed is used to start the process; it can be sent without encryption
  • Seed =0 safe in most but NOT all cases (eg assume the file with

salaries is sent once a month, with the same seed we can detect changes in the salaries) therefore a random seed is better

slide-15
SLIDE 15

CBC (Cipher Block Chaining): decryption

m1 Dk C1 m2 Dk C2 m3 Dk C3 seed

Problem IF a transmission error changes one bit of C(i-1) - THEN block mi changes in a predicatble way BUT there are unpredictable changes in m (i-1); Solution: always use error detecting codes (for example CRC) to check quality of transmissione

slide-16
SLIDE 16

Properties of CBC

  • Asynchronous stream cipher
  • Errors in one ciphertext block propagate
  • Conceals plaintext patterns
  • No parallel implementation known
  • Plaintext cannot be easily manipulated.
  • Standard in most systems: SSL, IPSec

etc.

slide-17
SLIDE 17

OFB Mode

(Output FeedBack)

An initialization vector s0 is use as a ``seed'’ for a sequence of data blocks si s0= seed

slide-18
SLIDE 18

OFB mode

Discussion

  • If f is public (known to the adversary) then initial seed s0

must be encrypted (why?)

  • If f is a cryptographic funnction that depends on a secret

key then initial sees can be sent in the clear (why?)

  • Initial seed must be modified for EVERY new message -

even if is protected and unknown to the adversary (in fact if the adv knows a pair message, initial seed then he can encode every message - why?)

  • Extension: it can be modified in such a way that only k bits

are used to compute the ciphertext (k-OFB)

slide-19
SLIDE 19

Properties of OFB

  • Synchronous stream cipher
  • Errors in ciphertext do not propagate
  • Pre-processing is possible
  • Conceals plaintext patterns
  • No parallel implementation known
  • Active attacks by manipulating plaintext

are possible

slide-20
SLIDE 20

CTR (Counter Mode)

seed Ek C1 seed +1 Ek C2 seed +2 Ek C3

Similar to OFB

  • There are problems in repeated use of same seed (like OFB)
  • CTR vs OFB: using CTR you can decrypt the message starting from

block i for any i (i.e. You do not need to decrypt from the first block as in OFB)

m1 m2 m3

slide-21
SLIDE 21

AES Proposed Modes

  • CTR (Counter) mode (OFB modification):

Parallel implementation, offline pre- processing, provable security, simple and efficient

  • OCB (Offset Codebook) mode - parallel

implementation, offline preprocessing, provable security (under specific assumptions), authenticity

slide-22
SLIDE 22

Strengthening a Given Cipher

  • Design multiple key lengths – AES
  • Whitening - the DESX idea
  • Iterated ciphers – Triple DES (3-

DES), triple IDEA and so on

slide-23
SLIDE 23

Triple Cipher - Diagram

P Ek1 C Ek2 Ek3

slide-24
SLIDE 24

Iterated Ciphers

  • Plaintext undergoes encryption repeatedly

by underlying cipher

  • Ideally, each stage uses a different key
  • In practice triple cipher is usually

C= Ek1(Ek2(Ek1(P))) [EEE mode] or C= Ek1(Dk2(Ek1(P))) [EDE mode] EDE is more common in practice

slide-25
SLIDE 25

Two or Three Keys

  • Sometimes only two keys are used in 3-DES
  • Identical key must be at beginning and end
  • Legal advantage (export license) due to

smaller overall key size

  • Used as a KEK in the BPI protocol which

secures the DOCSIS cable modem standard

slide-26
SLIDE 26

Adverary’s goal

  • Final goal: find the secret key
  • Partial goals:

– Reduee the no of possible keys – Detect patterns in the text – Decode part of the text – Modify the cipertext obtaining a plausible text (even without breaking the cipher; even without knowing which modifications)

slide-27
SLIDE 27

Repeated coding

  • To increase the robustness perform

multiple encryption. How many times? 2,3, 678?

  • In practice triple cipher

C= Ek1(Ek2(Ek1(P))) [EEE mode ] or C= Ek1(Dk2(Ek1(P))) [EDE mode] EDE more used

slide-28
SLIDE 28

Double DES: man in the middle attack

Cipher twice with two different keys? NO Man in th emiddle attack. Requirements

– Known plaintext and ciphertext – 2k+1 encryption and decryption (2 keys of k bit) – |k|2|k| memory space

– Idea: try all possible encryptions of the plaintext and all possible decryption of the ciphertext. Check for a pair

  • f keys that transform the palintext in the ciphertext.

– Note: the method can be applied to all block codes

slide-29
SLIDE 29

Triple encoding

P Ek1 C Ek2 Ek3

slide-30
SLIDE 30

Triple encoding and CBC

M1 Ek1 Ek2 M2 Ek1 C1 Mn Ek1

0000000

... . . . . .... Ek3 Ek2 C2 Ek3

In the picture: External CBC: code (using triple encoding) each block ; then concatenate Other possibility: Internal CBC (the concatenation depends on the level of encoding)

slide-31
SLIDE 31

Group and Fields AES Advanced Encryption Standard

slide-32
SLIDE 32

Review - Groups

Def (group): A set G with a binary operation + (addition) is called a commutative group if 1 ∀ a,b∈G, a+b∈G 2 ∀ a,b,c∈G, (a+b)+c=a+(b+c) 3 ∀ a,b∈G, a+b=b+a 4 ∃ 0∈G, ∀ a∈G, a+0=a 5 ∀ a∈G, ∃ -a∈G, a+(-a)=0

+,0, and -a are only notations!

slide-33
SLIDE 33

Sub-groups

  • Let (G, +) be a group, (H,+) is a sub-group
  • f (G,+) if it is a group, and H⊆G.
  • Claim: Let (G, +) be a finite group, and H⊆
  • G. If H is closed under +, then (H,+) is a

sub-group of (G,+).

  • Examples
  • Lagrange theorem: if G is finite and (H,+)

is a sub-group of (G,+) then |H| divides |G|

slide-34
SLIDE 34

Order of Elements

  • Let an denote a+…+a (n times)
  • We say that a is of order n if an = 0, and

for any m<n, am≠0

  • Examples
  • Euler theorem: In the multiplicative group
  • f Zm, every element is of order at most φ

(m).

slide-35
SLIDE 35

Cyclic Groups

  • Claim: let G be a group and a be an

element of order n. The set <a>={1, a,…,an-1} is a sub-group of G.

  • a is called the generator of <a>.
  • If G is generated by a, then G is

called cyclic, and a is called a primitive element of G.

  • Theorem: for any prime p, the

multiplicative group of Zp is cyclic

slide-36
SLIDE 36

Group

Z set of integers (positive and negative) ; Zn integer modulo n (0,,2,3,…,n-1); Z*n =(1,2,3,…,n-1);

  • Z and addition (0 identity; -a inverse of a) is a group
  • Zn and addition addizione is a group (0 identity; -a inverse of a)
  • Zn and multiplication is NOT a group (inverse exist only for 1 and -1)
  • Set of rational numbers and multiplication is a group
  • Z*n [a mod n] and multiplication IS NOT ALWAYS a group
  • n=6 then {1,2,3,4,5} is not close (2*3= 0 mod 6)
  • n prime then it is a group
  • Zn* [a mod n] and multiplication if MCD(a,n) = 1 is a group ( 1 is identity
  • And if as + nt = 1 mod n then s is inverse of a
  • n =15 then {1,2,4,7,8,11,13,14}
  • n=5 {1,2,3,4} (in fact all numbers are prim ewith 5)
slide-37
SLIDE 37

Review - Rings

Def (ring): A set F with two binary

  • perations + (addition) and · (multiplication)

is called a commutative ring with identity if 6 ∀ a,b∈F, a·b∈F 7 ∀ a,b,c∈F, (a·b)·c=a·(b·c) 8 ∀ a,b∈F, a·b=b·a 9 ∃ 1∈F, ∀ a∈F, a·1=a 10 ∀ a,b,c∈F,a·(b+c)=a·b+a·c 1 ∀ a,b∈F, a+b∈F 2 ∀ a,b,c∈F, (a+b)+c=a+(b+c) 3 ∀ a,b∈F, a+b=b+a 4 ∃ 0∈F, ∀ a∈F, a+0=a 5 ∀ a∈F, ∃ -a∈F, a+(-a)=0

+,·,0, 1 and-a are only notations!

slide-38
SLIDE 38

Review - Fields

Def (field): A set F with two binary

  • perations + (addition) and · (multiplication)

is called a field if 6 ∀ a,b∈F, a·b∈F 7 ∀ a,b,c∈F, (a·b)·c=a·(b·c) 8 ∀ a,b∈F, a·b=b·a 9 ∃ 1∈F, ∀ a∈F, a·1=a 10 ∀ a,b,c∈F,a·(b+c)=a·b+a·c 1 ∀ a,b∈F, a+b∈F 2 ∀ a,b,c∈F, (a+b)+c=a+(b+c) 3 ∀ a,b∈F, a+b=b+a 4 ∃ 0∈F, ∀ a∈F, a+0=a 5 ∀ a∈F, ∃ -a∈F, a+(-a)=0

11 ∀ a≠0∈F, ∃ a-1∈F, a·a-1=1

+,·,0, 1,-a and a-1 are

  • nly notations!
slide-39
SLIDE 39

Review - Fields

A field is a commutative ring with identity where each non-zero element has a multiplicative inverse

∀ a≠0∈F, ∃ a-1∈F, a·a-1=1

Equivalently, (F,+) is a commutative (additive) group, and (F \ {0}, ·) is a commutative (multiplicative) group.

slide-40
SLIDE 40

Examples

Zn with addition and multiplication is a ring but not always a field

  • n=15 NO ( {1,2,3,4,….,15} is not a group with resepct ot

multiplication)

  • n=5 Yes ( {1,2,3,4} is a gropu w.r.t. multiplication)
slide-41
SLIDE 41

Polynomials over Fields

Let f(x)= an·xn + an-1·xn-1 + an-2·xn-2 + … + a1·x + a0 be a polynomial of degree n in one variable x over a field F (namely an, an-1,…, a1, a0 ∈ F). Theorem: The equation f(x)=0 has at most n solutions in F. Remark: The theorem does not hold over rings with identity. For example, in Z24 the equation 6·x = 0

has six solutions (0,4,8,12,16,20).

slide-42
SLIDE 42

Polynomial Remainders

Let f(x)= an·xn + an-1·xn-1 + an-2·xn-2 + … + a1·x + a0 g(x)= bm·xm + bm-1·xm-1 + bm-2·xm-2 + … + b1·x + b0 be two polynomials over F such that m < n (or m=n). Theorem: There is a unique polynomial r(x) of degree < m

  • ver F such that

f(x) = h(x) · g(x) + r(x).

Remark: r(x) is called the remainder of f(x) modulo g(x).

slide-43
SLIDE 43

Finite Fields

Def (finite field): A field (F,+,·) is called a finite field if the set F is finite. Example: Zp denotes {0,1,...,p-1}. We define + and · as addition and multiplication modulo p, respectively. One can prove that (Zp,+,·) is a field iff p is prime. Q.: Are there any finite fields except (Zp,+,·) ?

slide-44
SLIDE 44

Galois Fields GF(pk)

Évariste Galois (1811-1832) Theorem: For every prime power pk (k=1,2,…) there is a unique finite field containing pk elements. These fields are denoted by GF(pk). There are no finite fields with other cardinalities.

slide-45
SLIDE 45

Polynomials over Finite Fields

Polynomial equations and factorizations in finite fields can be different than over the rationals. Examples from an XMAPLE session:

slide-46
SLIDE 46

Irreducible Polynomials

A polynomial is irreducible in GF(p) if it does not factor over GF(p). Otherwise it is reducible. Examples: The same polynomial is reducible in Z5 but irreducible in Z2.

slide-47
SLIDE 47

Implementing GF(p^k) arithmetic

Theorem: Let f(x) be an irreducible polynomial

  • f degree k over Zp.

The finite field GF(pk) can be realized as the set

  • f degree k-1 polynomials over Zp, with addition

and multiplication done modulo f(x).

slide-48
SLIDE 48

Example: Implementing GF(2^k)

By the theorem the finite field GF(25) can be realized as the set of degree 4 polynomials over Z2, with addition and multiplication done modulo the irreducible polynomial f(x)=x5+x4+x3+x+1. The coefficients of polynomials over Z2 are 0 or 1. So a degree k polynomial can be written down by k+1 bits. For example, with k=4: x3+x+1 (0,1,0,1,1) x4+ x3+x+1 (1,1,0,1,1)

slide-49
SLIDE 49

Implementing GF(2^k)

Addition: bit-wise XOR (since 1+1=0) x3+x+1 (0,1,0,1,1) + x4+ x3+x (1,1,0,1,0)

  • x4 +1 (1,0,0,0,1)
slide-50
SLIDE 50

Multiplication: Polynomial multiplication, and then remainder modulo the defining polynomial f(x):

Implementing GF(2^k)

For small size finite field, a lookup table is the most efficient method for implementing multiplication. (1,1,0,1,1) *(0,1,0,1,1) = (1,1,0,0,1)

slide-51
SLIDE 51

Implementing GF(25) in XMAPLE

Irreducible polynomial

slide-52
SLIDE 52

More GF(25) Operations in XMAPLE

Addition: b+c test primitive element e <--inverse of a Multiplication: a*e Loop for finding primitive elements

slide-53
SLIDE 53

Back to Symmetric Block Ciphers

  • ut in

DES AES

slide-54
SLIDE 54

Historic Note

DES (data encryption standard) is a symmetric block cipher using 64 bit blocks and a 56 bit key. Developed at IBM, approved by the US goverment (1976) as a standard. Size of key (56 bits) was apparently small enough to allow the NSA (US national security agency) to break it exhaustively even back in 70’s. In the 90’s it became clear that DES is too weak for contemporary hardware & algorithmics. (Best attack, Matsui “linear attack”, requires only 243 known plaintext/ciphertext pairs.)

slide-55
SLIDE 55

Historic Note (cont.)

The US government NIST (national inst. of standards and technology) announced a call for an advanced encryption standard in 1997. This was an international open competition. Overall, 15 proposals were made and evaluated, and 6 were finalists. Out of those, a proposal named Rijndael, by Daemen and Rijmen (two Belgians) was chosen in February 2001.

slide-56
SLIDE 56

AES - Advanced Encryption Standard

  • Symmetric block cipher
  • Key lengthes: 128, 192, or 256 bits
  • Approved US standard (2001)
slide-57
SLIDE 57

AES Design Rationale

  • Resistance to all known attacks.
  • Speed and code compactness.
  • Simplicity.
slide-58
SLIDE 58

AES Specifications

  • Input & output block length: 128 bits.
  • State: 128 bits, arranged in a 4-by-4 matrix of bytes.

A3,3 A3,2 A3,1 A3,0 A2,3 A2,2 A2,1 A2,0 A1,3 A1,2 A1,1 A1,0 A0,3 A0,2 A0,1 A0,0

Each byte is viewed as an element in GF(28) Input/Output: A0,0, A1,0, A2,0, A3,0, A0,1,…

slide-59
SLIDE 59

AES Specifications

  • Key length: 128, 196, 256 bits.

Cipher Key Layout: n = 128, 196, 256 bits, arranged in a 4-by-n/32 matrix of bytes.

K3,3 K2,3 K1,3 K0,3 K3,4 K2,4 K1,4 K0,4 K3,5 K3,2 K3,1 K3,0 K2,5 K2,2 K2,1 K2,0 K1,5 K1,2 K1,1 K1,0 K0,5 K0,2 K0,1 K0,0

Initial layout: K0,0, K1,0, K2,0, K3,0, K0,1,…

slide-60
SLIDE 60

AES Specifications

  • High level code:
  • AES(State,Key)

– KeyExpansion(Key,ExpandKey) – AddRoundKey(State,ExpandKey[0]) – For (i=1; i<R; i++) Round(State,ExpandKey[i]); – FinalRound(State,ExpandKey[R]);

slide-61
SLIDE 61

Encryption: Carried out in rounds input block (128 bits)

  • utput block

(128 bits) Secret key (128 bits)

slide-62
SLIDE 62

Rounds in AES

128 bits AES uses 10 rounds, no shortcuts known for 6 rounds

  • The secret key is expanded from 128 bits

to 10 round keys, 128 bits each.

  • Each round changes the state, then

XORS the round key. (For longer keys, add One round for every extra 32 bits) Each rounds complicates things a little. Overall it seems infeasible to invert without the secret key (but easy given the key).

slide-63
SLIDE 63

AES Specifications: One Round

A3,3 A3,2 A3,1 A3,0 A2,3 A2,2 A2,1 A2,0 A1,3 A1,2 A1,1 A1,0 A0,3 A0,2 A0,1 A0,0

Transform the state by applying:

  • 1. Substitution.
  • 2. Shift rows
  • 3. Mix columns
  • 4. XOR round key
slide-64
SLIDE 64

Substitution operates on every Byte separately: Ai,j <-- Ai,j

  • 1

(multiplicative inverse in GF(28) which is highly non linear.)

Substitution (S-Box)

If Ai,j =0, don’t change Ai,j . Clearly, the substitution is invertible.

slide-65
SLIDE 65

Cyclic Shift of Rows

A3,0 A3,3 A3,2 A3,1 A2,1 A2,0 A2,3 A2,2 A1,2 A1,1 A1,0 A1,3 A0,3 A0,2 A0,1 A0,0

no shift shift 1 position shift 2 positions shift 3 positions Clearly, the shift is invertible.

slide-66
SLIDE 66

Mixing Columns

Every state column is considered as a Polynomial over GF(28) Multiply with an invertible polynomial 03 x3 + 01x2 + 01x + 02 (mod x4 + 1) Inv = 0B x3 + 0D x2 +09 x + 0E Round: Subbytes(State) ShiftRows(State) MixColumns(State) AddRoundKey(State,ExpandedKey[i])

slide-67
SLIDE 67

Key Expansion

  • Generate a “different key” per round
  • Need a 4 x 4 matrix of values (over

GF(28)) per round

  • Based upon a non-linear transformation of

the original key.

  • Details available:
  • The Design of Rijndael, Joan Daemen and

Vincent Rijmen, Springer

slide-68
SLIDE 68

Breaking AES

Breaking 1 or 2 rounds is easy. It is not known how to break 5 rounds. Breaking the full 10 rounds AES efficiently (say 1 year on existing hardware, or in less than 2128 operations) is considered impossible ! (a good, tough challenge…)

slide-69
SLIDE 69

Exercises

1. Evaluate error propagation in CBC e OFB:

  • Show how an adevrsary can modify a block as he/she

prefers assuming that the remaining part of the message is modified

  • Discuss the security of this and techniques for

avoiding such attacks 2. CBC and OFB use and initial seed that must be known to both the sender and the receiver

  • Assume that the initial seed is sent in the clear (so

it is known to the adversary). Show how the adversary is able to modify part of the messahe. Conclusion: either the initial seed is fixed in advance or it muts be encypted and sent before th message

  • Break OFB if you use the same key and the same

initial seed mote than once