RC4 Encryption Algorithm

19
RC4 Encryption By : Ahmed Loqman Yousify Computer Science Department University Of Zakho

description

RC4 Encryption Algorithm with explained example

Transcript of RC4 Encryption Algorithm

Page 1: RC4 Encryption Algorithm

RC4 Encryption

By:

Ahmed Loqman Yousify

Computer Science Department

University Of Zakho

Page 2: RC4 Encryption Algorithm

Overview

History

Discussion of RC4 Algorithm

Analysis of RC4

Weaknesses of RC4

Example

Page 3: RC4 Encryption Algorithm

History

RC4 was designed by Ron Rivest of RSA Security in 1987. While it is officially termed “Rivest Cipher 4.”

RC4 was initially a trade secret, but in September 1994 a description of it was anonymously posted to the Cypherpunks mailing list.

and from there to many sites on the Internet. RC4 has become part of some commonly used encryption protocols and standards, including WEP and WPA for wireless cards.

The main factors in RC4's success over such a wide range of applications are its speed and simplicity: efficient implementations in both software and hardware are very easy to develop.

Page 4: RC4 Encryption Algorithm

Analysis of RC4

Advantages

Faster than DES

Enormous key space (average of 1700 bits)

RC4 is used in popular protocols such as Secure Sockets Layer (SSL) and (to protect Internet traffic) SSL

In 802.11 WEP(to secure wireless networks) .

Disadvantages

Large number of “weak” keys 1 of 256

“ Weak” keys can be detected and exploited with a high probability

Page 5: RC4 Encryption Algorithm

Weaknesses of RC4

Almost all weaknesses are in the KSA since attacking the PRGA is fairly infeasible due to the huge effective key. The fastest known method requires 2700 time.

The KSA can be attacked with several methods mainly because of the simple initialization permutation used.

Invariance Weakness is the most devastating attack.(5% chance of guessing one or more bytes of the key).

Page 6: RC4 Encryption Algorithm

RC4 Description

Symmetric

Stream Cipher

Two main parts:KSA (Key Scheduling Algorithm)

PRGA (Pseudo Random Generation Algorithm)

Notation:S = {0, 1, 2, … N-1} is the initial permutation

l = length of

Page 7: RC4 Encryption Algorithm

RC4 Description

Page 8: RC4 Encryption Algorithm

Encryption

Page 9: RC4 Encryption Algorithm

Decryption

Page 10: RC4 Encryption Algorithm

RC4 Example

Simple 4-byte exampleS = {0, 1, 2, 3}K = {1, 7, 1, 7}

Set i = j = 0

Page 11: RC4 Encryption Algorithm

KSA

First Iteration (i = 0, j = 0, S = {0, 1, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (0 + 0 + 1) = 1

Swap S[ i ] with S[ j ]: S = {1, 0, 2, 3}

Second Iteration (i = 1, j = 1, S = {1, 0, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (1 + 0 + 7) = 0 (mod 4)

Swap S[ i ] with S[ j ]: S = {0, 1, 2, 3}

K = {1, 7, 1, 7}

K[0]

S[0]

S = {0,1, 2, 3}

S[i]

S[j]

Page 12: RC4 Encryption Algorithm

KSA

First Iteration (i = 0, j = 0, S = {0, 1, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (0 + 0 + 1) = 1

Swap S[ i ] with S[ j ]: S = {1, 0, 2, 3}

Second Iteration (i = 1, j = 1, S = {1, 0, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (1 + 0 + 7) = 0 (mod 4)

Swap S[ i ] with S[ j ]: S = {0, 1, 2, 3}

K = {1, 7, 1, 7}

K[0]

S[0]

S = { , , 2, 3}

S[i]

S[j]

11

00

Page 13: RC4 Encryption Algorithm

KSA

First Iteration (i = 0, j = 0, S = {0, 1, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (0 + 0 + 1) = 1

Swap S[ i ] with S[ j ]: S = {1, 0, 2, 3}

Second Iteration (i = 1, j = 1, S = {1, 0, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (1 + 0 + 7) = 0 (mod 4)

Swap S[ i ] with S[ j ]: S = {0, 1, 2, 3}

K = {1, 7, 1, 7}

K[0]

S[0]

S = { , , 2, 3} 0

11 0

Page 14: RC4 Encryption Algorithm

KSA

First Iteration (i = 0, j = 0, S = {0, 1, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (0 + 0 + 1) = 1

Swap S[ i ] with S[ j ]: S = {1, 0, 2, 3}

Second Iteration (i = 1, j = 1, S = {1, 0, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (1 + 0 + 7) = 0 (mod 4)

Swap S[ i ] with S[ j ]: S = {0, 1, 2, 3}

K = {1, 7, 1, 7}

K[1]

S[1]

Page 15: RC4 Encryption Algorithm

KSA

Third Iteration (i = 2, j = 0, S = {0, 1, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (0 + 2 + 1) = 3

Swap S[ i ] with S[ j ]: S = {0, 1, 3, 2}

Fourth Iteration (i = 3, j = 3, S = {0, 1, 3, 2}):

j = (j + S[ i ] + K[ i ]) = (3 + 2 + 7) = 0 (mod 4)

Swap S[ i ] with S[ j ]: S = {2, 1, 3, 0}

K = {1, 7, 1, 7}

K[2]

S[2]

Page 16: RC4 Encryption Algorithm

KSA

Third Iteration (i = 2, j = 0, S = {0, 1, 2, 3}):

j = (j + S[ i ] + K[ i ]) = (0 + 2 + 1) = 3

Swap S[ i ] with S[ j ]: S = {0, 1, 3, 2}

Fourth Iteration (i = 3, j = 3, S = {0, 1, 3, 2}):

j = (j + S[ i ] + K[ i ]) = (3 + 2 + 7) = 0 (mod 4)

Swap S[ i ] with S[ j ]: S = {2, 1, 3, 0}

K = {1, 7, 1, 7}

K[3]

S[3]

Page 17: RC4 Encryption Algorithm

PRGA

Reset i = j = 0, Recall S = {2, 1, 3, 0}

i = i + 1 = 1

j = j + S[ i ] = 0 + 1 = 1

Swap S[ i ] and S[ j ]: S = {2, 1, 3, 0}

Output z = S[ S[ i ] + S[ j ] ] = S[2] = 3

Z = 3 ( 0000 0011 )

H

0100 1000

XOR 0000 0011

0100 1011

For this example we use plaintext “HI”

Page 18: RC4 Encryption Algorithm

i=1 , j=1 , S = {2, 1, 3, 0}

i = i + 1 = 2

j = j + S[ i ] = 1 + 3 = 4 (mod 4) = 0

Swap S[ i ] and S[ j ]: S = {3, 1, 2, 0}

Output z = S[ S[ i ] + S[ j ] ] = S[1] = 1

Z = 3 ( 0000 0001 )

I

0100 1001

XOR 0000 0001

0100 1000

Result : Plaint Text : 0100 1000 0100 1001

Cipher Text: 0100 1011 0100 1000

Page 19: RC4 Encryption Algorithm

Resources

Fluhrer, Mantin, Shamir - Weakness in the Key Scheduling Algorithm of RC4.http://www.drizzle.com/~aboba/IEEE/rc4_ksaproc.pdf

Stubblefield, Loannidis, Rubin – Using the Fluhrer, Mantin, and Shamir Attack to Break WEP.http://www.cs.rice.edu/~astubble/wep/wep_attack.pdf

Rivest – RSA Security Response to Weakness in the Key Scheduling Algorithm of RC4.http://www.rsasecurity.com/rsalabs/technotes/wep.html

RC4 Encryption Algorithm.http://www.ncat.edu/~grogans/algorithm_breakdown.htm