A Description of the RC2(r) Encryption AlgorithmRSA Laboratories100 Marine Parkway#500Redwood CityCA 94065USA(650) 595-7703rsa-labs@rsa.com
Security
Rivest variable key-size block cipherencryption
This memo is an RSA Laboratories Technical Note. It is meant for
informational use by the Internet community.
This memo describes a conventional (secret-key) block encryption
algorithm, called RC2, which may be considered as a proposal for a
DES replacement. The input and output block sizes are 64 bits each.
The key size is variable, from one byte up to 128 bytes, although the
current implementation uses eight bytes.
The algorithm is designed to be easy to implement on 16-bit
microprocessors. On an IBM AT, the encryption runs about twice as
fast as DES (assuming that key expansion has been done).
We use the term "word" to denote a 16-bit quantity. The symbol + will
denote twos-complement addition. The symbol & will denote the bitwise
"and" operation. The term XOR will denote the bitwise "exclusive-or"
operation. The symbol ~ will denote bitwise complement. The symbol ^
will denote the exponentiation operation. The term MOD will denote
the modulo operation.
There are three separate algorithms involved:
Key expansion. This takes a (variable-length) input key and
produces an expanded key consisting of 64 words K[0],...,K[63].
Encryption. This takes a 64-bit input quantity stored in words
R[0], ..., R[3] and encrypts it "in place" (the result is left in
R[0], ..., R[3]).
Decryption. The inverse operation to encryption.
Since we will be dealing with eight-bit byte operations as well as
16-bit word operations, we will use two alternative notations
for referring to the key buffer:
These are alternative views of the same data buffer. At all times it
will be true that
(Note that the low-order byte of each K word is given before the
high-order byte.)
We will assume that exactly T bytes of key are supplied, for some T
in the range 1 <= T <= 128. (Our current implementation uses T = 8.)
However, regardless of T, the algorithm has a maximum effective key
length in bits, denoted T1. That is, the search space is 2^(8*T), or
2^T1, whichever is smaller.
The purpose of the key-expansion algorithm is to modify the key
buffer so that each bit of the expanded key depends in a complicated
way on every bit of the supplied input key.
The key expansion algorithm begins by placing the supplied T-byte key
into bytes L[0], ..., L[T-1] of the key buffer.
The key expansion algorithm then computes the effective key length in
bytes T8 and a mask TM based on the effective key length in bits T1.
It uses the following operations:
T8 = (T1+7)/8;
TM = 255 MOD 2^(8 + T1 - 8*T8);
Thus TM has its 8 - (8*T8 - T1) least significant bits set.
For example, with an effective key length of 64 bits, T1 = 64, T8 = 8
and TM = 0xff. With an effective key length of 63 bits, T1 = 63, T8
= 8 and TM = 0x7f.
Here PITABLE[0], ..., PITABLE[255] is an array of "random" bytes
based on the digits of PI = 3.14159... . More precisely, the array
PITABLE is a random permutation of the values 0, ..., 255. Here is
the PITABLE in hexadecimal notation:
The key expansion operation consists of the following two loops and
intermediate step:
(In the first loop, the addition of L[i-1] and L[i-T] is performed
modulo 256.)
The "effective key" consists of the values L[128-T8],..., L[127].
The intermediate step's bitwise "and" operation reduces the search
space for L[128-T8] so that the effective number of key bits is T1.
The expanded key depends only on the effective key bits, regardless
of the supplied key K. Since the expanded key is not itself modified
during encryption or decryption, as a pragmatic matter one can expand
the key just once when encrypting or decrypting a large block of
data.
The encryption operation is defined in terms of primitive "mix" and
"mash" operations.
Here the expression "x rol k" denotes the 16-bit word x rotated left
by k bits, with the bits shifted out the top end entering the bottom
end.
The primitive "Mix up R[i]" operation is defined as follows, where
s[0] is 1, s[1] is 2, s[2] is 3, and s[3] is 5, and where the indices
of the array R are always to be considered "modulo 4," so that R[i-1]
refers to R[3] if i is 0 (these values are
"wrapped around" so that R always has a subscript in the range 0 to 3
inclusive):
In words: The next key word K[j] is added to R[i], and j is advanced.
Then R[i-1] is used to create a "composite" word which is added to
R[i]. The composite word is identical with R[i-2] in those positions
where R[i-1] is one, and identical to R[i-3] in those positions where
R[i-1] is zero. Then R[i] is rotated left by s[i] bits (bits rotated
out the left end of R[i] are brought back in at the right). Here j is
a "global" variable so that K[j] is always the first key word in the
expanded key which has not yet been used in a "mix" operation.
A "mixing round" consists of the following operations:
The primitive "Mash R[i]" operation is defined as follows (using the
previous conventions regarding subscripts for R):
In words: R[i] is "mashed" by adding to it one of the words of the
expanded key. The key word to be used is determined by looking at the
low-order six bits of R[i-1], and using that as an index into the key
array K.
A "mashing round" consists of:
The entire encryption operation can now be described as follows. Here
j is a global integer variable which is affected by the mixing
operations.
1. Initialize words R[0], ..., R[3] to contain the
64-bit input value.
2. Expand the key, so that words K[0], ..., K[63] become
defined.
3. Initialize j to zero.
4. Perform five mixing rounds.
5. Perform one mashing round.
6. Perform six mixing rounds.
7. Perform one mashing round.
8. Perform five mixing rounds.
Note that each mixing round uses four key words, and that there are
16 mixing rounds altogether, so that each key word is used exactly
once in a mixing round. The mashing rounds will refer to up to eight
of the key words in a data-dependent manner. (There may be
repetitions, and the actual set of words referred to will vary from
encryption to encryption.)
The decryption operation is defined in terms of primitive operations
that undo the "mix" and "mash" operations of the encryption
algorithm. They are named "r-mix" and "r-mash" (r- denotes the
reverse operation).
Here the expression "x ror k" denotes the 16-bit word x rotated right
by k bits, with the bits shifted out the bottom end entering the top
end.
The primitive "R-Mix up R[i]" operation is defined as follows, where
s[0] is 1, s[1] is 2, s[2] is 3, and s[3] is 5, and where the indices
of the array R are always to be considered "modulo 4," so that R[i-1]
refers to R[3] if i is 0 (these values are "wrapped around" so that R
always has a subscript in the range 0 to 3 inclusive):
In words: R[i] is rotated right by s[i] bits (bits rotated out the
right end of R[i] are brought back in at the left). Here j is a
"global" variable so that K[j] is always the key word with greatest
index in the expanded key which has not yet been used in a "r-mix"
operation. The key word K[j] is subtracted from R[i], and j is
decremented. R[i-1] is used to create a "composite" word which is
subtracted from R[i]. The composite word is identical with R[i-2] in
those positions where R[i-1] is one, and identical to R[i-3] in those
positions where R[i-1] is zero.
An "r-mixing round" consists of the following operations:
The primitive "R-Mash R[i]" operation is defined as follows (using
the previous conventions regarding subscripts for R):
In words: R[i] is "r-mashed" by subtracting from it one of the words
of the expanded key. The key word to be used is determined by looking
at the low-order six bits of R[i-1], and using that as an index into
the key array K.
An "r-mashing round" consists of:
The entire decryption operation can now be described as follows.
Here j is a global integer variable which is affected by the mixing
operations.
1. Initialize words R[0], ..., R[3] to contain the 64-bit
ciphertext value.
2. Expand the key, so that words K[0], ..., K[63] become
defined.
3. Initialize j to 63.
4. Perform five r-mixing rounds.
5. Perform one r-mashing round.
6. Perform six r-mixing rounds.
7. Perform one r-mashing round.
8. Perform five r-mixing rounds.
Test vectors for encryption with RC2 are provided below.
All quantities are given in hexadecimal notation.
The Object Identifier for RC2 in cipher block chaining mode is
RC2-CBC takes parameters
where
RC2 in CBC mode has two parameters: an 8-byte initialization vector
(IV) and a version number in the range 1-1024 which specifies in a
roundabout manner the number of effective key bits to be used for the
RC2 encryption/decryption.
The correspondence between effective key bits and version number is
as follows:
1. If the number EKB of effective key bits is in the range 1-255,
then the version number is given by Table[EKB], where the 256-byte
translation table Table[] is specified below. Table[] specifies a
permutation on the numbers 0-255; note that it is not the same
table that appears in the key expansion phase of RC2.
2. If the number EKB of effective key bits is in the range
256-1024, then the version number is simply EKB.
The default number of effective key bits for RC2 is 32. If RC2-CBC
is being performed with 32 effective key bits, the parameters
should be supplied as a simple IV, rather than as a SEQUENCE
containing a version and an IV.
RC2 is a registered trademark of RSA Data Security, Inc. RSA's
copyrighted RC2 software is available under license from RSA Data
Security, Inc.