written 6.2 years ago by |
RC-5 Algorithm
In RC-5, the word size (i.e. input plaintext block size), number of rounds and number of keys are not fixed i.e. all can be of variable length.
Once w, r, k (word size, number of rounds, number of keys) are finalized then they remain same for all the rounds.
Plain text can be 32 bits, 64 bits or 128 bits
Number of rounds can be between 0-255
Key size can be between 0 to 255 bytes
Encryption using RC5
Encryption involved several rounds of a simple function. 12 or 20 rounds seem to be recommended, depending on security needs and time considerations.
We initialize the counter to 1 and perform some permutation and combination using addition and XOR
The algorithm works into two phases:
a. First it starts with phase one
b. Output of phase one become input of phase two
We divide the plaintext block into two equal parts A and B
Then they are XOR with two subkeys S{0} and S{1}
$\hspace{1.5cm} C = A + S[0]$
$\hspace{1.5cm} D = B + S[1]$
for i = 1 to r do:
$\hspace{1.5cm}$ 1. C ⊕ D = E
$\hspace{1.5cm}$ 2. perform circular left shift on E by D bits
$\hspace{1.5cm}$ 3. add E and S[2 * i] and store the result in F which is input for step 4
$\hspace{1.5cm}$ 4. D ⊕ F = G
$\hspace{1.5cm}$ 5. perform circular left shift on G by F bits
$\hspace{1.5cm}$ 6. add G and S[2 * i + 1] and store the result in H
$\hspace{1.5cm}$ 7. If i< r
$\hspace{1.5cm}$ Call F as C and H as D and repeat the steps from 1 to 7
$\hspace{1.5cm}$ else stop
- Once both the phases are completed the counter is incriminated and we check if it is greater than the number of rounds, if yes then the algorithm terminals and if no then the algorithm iterates.
Decryption:
Decryption is a straightforward reversal of the encryption process