I am trying to understand the Key Scheduler used in RC6 and I have a total of 3 questions. The RC6 Wikipedia page says that the only difference between the RC5 and RC6 key scheduler is that more words are produced from the key in RC6. In my application, I am using w=32bits, r=20rounds and b=16bytes.

My first question is are these are two separate for loops or is the second for loop that iterates from s-1 to v inside the first for loop that iterates from 1 to 2r+3? My second question is why are we setting A=B=i=j=0 and is this command and the v=3xmax{c,2r+4} inside the first for loop?

The RC6 paper also supplies this pseudo code:

Input: User-supplied b byte key preloaded into the c-word array L[0... c - 1]

Number r of rounds

Output: w-bit round keys S[0... 2r + 3]

Procedure: S[0] = Pw

for i = 1 to 2r + 3 do:
S[i] = S[i - 1] + Qw
A = B = i = j = 0
v = 3 x max{c,2r+4}

for s = 1 to v do:
A = S[i] = (S[i] + A + B)<<<3
B = L[j] = (L[j] + A + B)<<<(A + B)
i = (i + 1)mod(2r + 4)
j = (j + 1)modc

My third question is on how to preload the word array L with my 16byte key. The RC5 paper says:

The first algorithmic step of key expansion is to copy the secret key K[0...b-1] into an array L[0...c-1] of c=b/u words where u= w/8 is the number of bytes/word. This operation is done in a natural manner using u consecutive key bytes of K to fill up each successive word in L, low-order byte to high-order byte. Any unfilled byte positions of L are zeroed.

And the pseudo code for this operation is:

for i=b-1 downto 0 do:
    L[i/u] = (L[i/u]<<<8)+K[i];

To elaborate on my third question, if i is going from 15 down to 0, and my u = 32/8=4, how can I use a decimal to index L? For example, when i is 15 we have L[15/4]=(L[15/4]<<<8 + K[i]);

  1. The loops are disjoint. In other words, the first loop completes and then the second loop starts.

  2. A=B=i=j=0 are explicitly initialised to zero as in many languages failing to specify an initial value can lead to unspecified behaviour (e.g. setting the variables to random values lying in old memory). This initialisation and the initialisation of v occur outside of the loops.

  3. The expression i/u should be interpreted as C-like integer arithmetic that returns an integer value (in this case by taking floor). Thus in your example L[15/4]=L[3].


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.