The rc5 Encryption Algorithm
The rc5 Encryption Algorithm
Ronald L. Rivest
MIT Laboratory for Computer Science
545 Technology Square, Cambridge, Mass. 02139
rivest@theory.lcs.mit.edu
species an RC5 algorithm (version 1.0) with 32-bit words, 16 rounds, and a
10-byte (80-bit) key \20 33 ... 09".
P64 = 1011011111100001010100010110001010001010111011010010101001101011
= b7e151628aed2a6b
Q64 = 1001111000110111011110011011100101111111010010100111110000010101
= 9e3779b97f4a7c15
Converting the Secret Key from Bytes to Words. The rst step of key
expansion is to copy the secret key K [0:::b ; 1] into an array L[0:::c ; 1] of c = db=ue
words, where u = w=8 is the number of bytes/word. This is done in a natural manner,
using u successive key bytes of K to ll up each successive words in L, low-order byte
to high-order byte. Unlled byte positions of L, if any, are zeroed.
On \little-endian" machines such as an Intel '486, the above task can be accom-
plished merely by zeroing the array L, and then copying the string K directly into the
memory positions representing L. The following pseudo-code achieves the same eect,
assuming that all bytes are \unsigned" and that array L is initially zeroed.
for i = b ; 1 downto 0 do
L[i=u] = (L[i=u] <<< 8) + K [i];
Initializing the Array S. The second step of key expansion is to initialize array S
using a linear congruential generator modulo 2w determined by the \magic constants"
Pw and Qw . Since Qw is odd, the generator has period 2w .
S [0] = Pw ;
for i = 1 to t ; 1 do
S [i] = S [i ; 1] + Qw ;
Mixing in the Secret Key. The third step of key expansion is mix in the user's
secret key in three passes over the arrays S and L. Actually, due to the diering sizes
of these arrays, the largest array will be processed three times, and the other may be
handled more times.
i = j = 0;
A = B = 0;
do 3 max(t; c) times:
A = S [i] = (S [i] + A + B ) <<< 3;
B = L[j ] = (L[j ] + A + B ) <<< (A + B );
i = (i + 1) mod(t);
j = (j + 1) mod(c);
4.2 Encryption
We assume that the input block is given in two w-bit registers A and B . (We assume
standard little-endian conventions for packing bytes into input/output blocks: the rst
byte goes into the low-order bit positions of register A, and so on.) We also assume
that key-expansion has already been performed. Here is the encryption algorithm in
pseudo-code:
A = A + S [0];
B = B + S [1];
for i = 1 to r do
A = ((A B ) <<< B ) + S [2 i];
B = ((B A) <<< A) + S [2 i + 1];
4.3 Decryption
The decryption routine is easily derived from the encryption routine.
for i = r downto 1 do
B = ((B ; S [2 i + 1]) >>> A) A;
A = ((A ; S [2 i]) >>> B ) B ;
B = B ; S [1];
A = A ; S [0];
5 Discussion
A distinguishing feature of RC5 is its heavy use of data-dependent rotations|the
amount of rotation performed is dependent on the input data, and is not pre-determined.
The encryption/decryption routines are very simple. While other operations (such
as substitution operations) could have been included in the basic round operations, the
objective here is to focus on the data-dependent rotations as a source of cryptographic
strength.
Some of the expanded key from S is initially added to the plaintext, and each round
ends by adding expanded key from S to the intermediate values just computed. This
assures that each round acts in a potentially dierent manner, in terms of the shift
amounts used.
The xor operations provide some avalanche properties, causing a single-bit change
in an input block to cause multiple bit-changes in following rounds.
The encryption algorithm is very compact, and can be coded eciently in assembly
language on most processors. The table S is accessed sequentially, minimizing issues
of cache size. The RC5 encryption speeds obtainable are yet to be fully determined.
For RC5-32/12/16 on a 90MhZ Pentium, a preliminary C++ implementation compiled
with the Borland C++ compiler (in 16-bit mode) performs a key-setup in 220 microsec-
onds and performs an encryption in 22 microseconds (equivalent to 360,000 bytes/sec).
These timings can presumably be improved by more than an order of magnitude us-
ing a 32-bit compiler and/or assembly language|an assembly-language routine for the
'486 can perform each round in eight instructions.
6 Analysis
This section contains some preliminary results on the strength of RC5. Much more
work remains to be done. Here we report the results of two experiments studying how
changing the number of rounds aects properties of RC5.
The rst test involved uniformity of correlation between input and output bits. We
found that four rounds suced to get very uniform correlations between individual
input and output bits in RC5-32.
The second test checked to see if the amount of variable rotations performed de-
pended on every plaintext bit, in 10,000 trials. That is, it checked whether
ipping a
plaintext bit caused some intermediate rotation to be a rotation by a dierent amount.
We found that seven rounds in RC5-32 were sucient to cause each message bit to
aect some rotation amount.
The number of rounds chosen in practice should always be at least as great (if not
substantially greater) than these simple-minded tests would suggest. As noted above,
we suggest 12 rounds as a \nominal" choice.
The use by RC5 of variable rotations should help defeat dierential cryptanalysis
(Biham/Shamir [1]) and linear cryptanalysis (Matsui [2]), since bits are rotated to
\random" positions in each round.
There is no obvious way in which an RC5 key can be \weak," other than by being
too short.
I invite the reader to help determine the strength of RC5.
7 Acknowledgements
I'd like to thank Burt Kaliski, Lisa Yin, Paul Kocher, and everyone else at RSA Lab-
oratories for their comments and constructive criticisms.
References
1. E. Biham and A. Shamir. A Dierential Cryptanalysis of the Data Encryption
Standard. Springer-Verlag, 1993.
2. Mitsuru Matsui. The rst experimental cryptanalysis of the data encryption stan-
dard. In Yvo G. Desmedt, editor, Proceedings CRYPTO 94, pages 1{11, Springer,
1994. Lecture Notes in Computer Science No. 839.
This article was processed using the LaTEX macro package with LLNCS style