RC5
RC5 is a symmetric key algorithm for block encryption designed by Ron Rivest. It is
suitable for both hardware and software implementations due to the following
characteristics:
• Simplicity: The algorithm only uses primitive computer operations, such as
addition, subtraction, bitwise XOR, and circular shifts. This makes it easy to
implement and analyze.
Flexibility: It allows a variable number of rounds and bit size of the key.
• Low memory utilization: It can be implemented on devices with limited
memory.
Parameterization
RC5 is a parameterized, word-oriented algorithm. This means it is a block cipher
with a two-word input (plaintext) and a two-word output (ciphertext) block size.
The parameters are detailed as follows:
Word size: w
This is the word size in bits. RC5 has two w bit blocks, so the input and output
blocks are each 2w bits long. For example, if w is 32 bit, then the input block will
be 64 bit long.
Number of rounds: r
This is the number of rounds and determines the trade-off between speed and
security, where greater rounds imply higher security but lower speed. r also
influences the size t of the expanded key table S that is derived from the secret key.
The formula for t is as follows:
t=2(r+1)
Number of bytes in secret key: b
This is the number of 8-bit bytes in the user-provided secret key, K, and has the
allowable range from 0−255 bytes.
The table below summarizes the parameters:
Parameters of the RC5 encyrption algorithm
Parameter Explanation Accepted values
w Word size in bits. 16, 32, 64
r Number of rounds. 0–255
b umber of octets (8-bit bytes) in the secret key K. 0–255
Given these parameters, the notation for the algorithm is as follows:
RC5−w/r/b
The nominal version of this is RC5−32/12/16, which implies there are two 32 bit word inputs
and outputs, 12 rounds, and a 16 byte (128 bit) key.
Primitive operations
RC5 uses only three primitive operations and their inverses. These are:
• Addition: This refers to the two's complement addition of words and is denoted by +. The
inverse of this is subtraction, denoted by −.
Bitwise XOR: This is the bitwise exclusive-OR of words and is denoted by ⊕..
• Left rotation: This is the cyclic left rotation of words, denoted by x<<<y, where x is the
word and y is the number of bits to be shifted. The inverse is cyclic right rotation,
represented by x>>>y.
The algorithm
Now that we have defined the parameters and operations, we can begin taking a look at the three
components of the RC5 encryption algorithm:
• Key expansion algorithm
• Encryption
• Decryption
The diagram below illustrates the order of these components:
RC5 is a symmetric block cipher that uses a variable-length key. Before encryption/decryption,
the key you provide is expanded into a set of subkeys, which are used in each round of
encryption.
Think of key expansion as preparing all the “tools” (subkeys) you’ll need during the encryption
process.
. Key Expansion Steps
Suppose:
Word size (w) = 32 bits
Number of rounds (r) = 12
Key length (b) = 16 bytes (128 bits)
Step 1: Convert key bytes to words
The key K is first converted into an array L of c words (each w bits).
c = ceil(b / (w/8)) → number of words
Example:
Key (16 bytes):
01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10
Split into 4 words (w = 32 bits):
L[0] L[1] L[2] L[3]
0x67452301 0xEFCDAB89 0x10325476 0x98BADCFE
(Note: RC5 uses little-endian, so bytes are reversed within each word.)
Step 2: Initialize subkey array S
Total subkeys: t = 2 * (r + 1) → For 12 rounds: t = 26
Initialize S[0..t-1] with constants P and Q:
For 32-bit word size:
P = 0xB7E15163
Q = 0x9E3779B9
Initialize S as:
S[0] = P
S[i] = S[i-1] + Q for i = 1 to t-1
Step 3: Mix S and L arrays
Use 3 times max(t, c) iterations
Variables i = j = 0, A = B = 0
for k = 0 to 3*max(t,c)-1:
A = S[i] = (S[i] + A + B) <<< 3 # <<< 3 means rotate left by 3 bits
B = L[j] = (L[j] + A + B) <<< (A + B)
i = (i + 1) mod t
j = (j + 1) mod c
This step scrambles the key and subkey array, making it secure.
Key Points
RC5 key expansion diffuses the key into subkeys.
The number of subkeys depends on the number of rounds.
Uses addition modulo 2^w and rotation to mix keys.
Very simple but secure due to repeated mixing.
RC5’s subkey array initialization (S[0..t-1])
[Link] of the S array
In RC5, S is the subkey array used in every round of encryption/decryption.
Its size depends on the number of rounds r:
t=2×(r+1)
For example, if r = 12 rounds:
t=2×(12+1)=26
So S[0..25] needs to be filled.
2. Constants P and Q
RC5 defines two magic constants for 32-bit words (w = 32):
P = 0xB7E15163 → used for S[0]
Q = 0x9E3779B9 → used to fill the rest of S
These constants come from fractional part of e and golden ratio, chosen to avoid patterns in
keys.
3. How to initialize S
1. Set the first subkey:
S[0]=P
2. Fill the remaining subkeys by adding Q repeatedly:
S[i]=S[i−1]+Q for i=1 to t−1
Example:
Number of rounds r = 12 → t = 26
First few subkeys:
i S[i] (hex)
0 B7E15163
1 B7E15163 + 9E3779B9 = 5529CDBC
2 5529CDBC + 9E3779B9 = F0B0AB75
3 F0B0AB75 + 9E3779B9 = 8EEB852E
……
Continue until S[25]
This gives an initial evenly spaced subkey array before it’s mixed with the secret key L
Encryption:
The input block to RC5 consists of two w-bit words given in two registers, W0 and X0. In the
registers L1 and R1 the o/p is placed there also. As explained in RC5 uses expended key array
S[0, 1, . . . , T − 1], consisting of T = 2(r + 1) [Link] From the user’s secret key K the key-
expansion algorithm initializes [Link], the S table in RC5 encryption is not like an S- box
used by DES. The formulas is given in code of encryption algorithm as shown below:
W0 = G + S[0];
X0 = H + S[1];
for i = 1 to r do
Wi = ((Wi-1 Xor Xi-1) <<< Xi-1) + S[2i];
Xi = ((Xi-1 Xor Wi) <<< Wi) + S[2i + 1];
The output is in the registers W1 and X1.