Cryptography Reference
In-Depth Information
always the same (all the integers ranging from 0 to 255) and are permuted by the
algorithm based on the values of the two counters i and j . In order to initialize the
inner state of the cipher, RC4 performs a first permutation of the S array (described
in Algorithm 4.1) according to the key supplied, which may be from 5 to 256 bytes
long. The initialization operates 256 swaps among the variables, employing an eight-
bit slice of the key together with the value of j to determine the index of the array
cells to swap.
Algorithm 14.1 : The RC4 key schedule
Input : K = ( k 0 , k 1 ,..., k l ) : cipher key l : key length in bytes
Output : i , j , S = ( s 0 ,..., s 255 ) : initialized inner state
begin
1
S ( 0 , 1 , 2 ,..., 255 )
2
j 0
3
i 0
4
for i <
255 do
5
j ( j + s j + k i mod l )
mod 256
6
temp s i
7
s i
s j
8
s j
temp
9
i
i
+
1
10
end
11
i
0
12
j
0
13
return i
,
j
,
S
14
end
15
Algorithm 14.2 : The RC4 step function
Input : i , j , S = ( s 0 ,..., s 255 ) the inner state of the cipher
Output : o the output byte
i i + 1 mod 256
1
j ( j + s i )
mod 256
2
temp s i
3
s i
s j
4
s j
temp
5
return o
s s i + s j
6
After the initialization step is completed, the cipher is able to output an eight-bit
value per step, obtaining it as described by Algorithm 4.2. At first, the value of i ,
which acts as a counter, is incremented by 1, and employed to update the value of
j based on the value of the i th cell of the state. After the updates, the values of i
and j are used to perform a swap between two values of the inner state and output
a single byte based on their contents. Due to the nature of the updating algorithm, it
 
Search WWH ::




Custom Search