I am trying to implement the speck cipher as specified here: Speck Cipher. On page 18 of the document you can find some speck pseudo-code I want to implement.
It seems that I got a problem on understanding the pseudo-code. As you can find there, x and y are plaintext words with length n. l[m-2],...l[0], k[0] are key words (as for words, they have length n right?). When you do the key expansion, we iterate for i from 0 to T-2, where T are the round numbers (for example 34). However I get an IndexOutofBoundsException, because the array with the l's has only m-2 positions and not T-2.
Can someone clarify what the key expansions does and how?
Ah, I get where the confusion lies:
these are the input key words, in other words, they represent the key. These are not declarations of the size of the arrays, as you might expect if you're a developer.
Then the subkey's in array
kshould be derived, using arraylfor intermediate values.According to the formulas, taking the largest
i, i.e.i_max = T - 2you get a highest index for arraylofi_max + m - 1 = T - 2 + m - 1 = T + m - 3and therefore a size of the array of one more:T + m - 2. The size of a zero-based array is always the index of the last element - plus one, after all.Similarly, for subkey array
kyou get a highest index ofi_max + 1, which isT - 2 + 1orT - 1. Again, the size of the array is one more, so there areTelements ink. This makes a lot of sense if you requireTround keys :)Note that it seems possible to simply redo the subkey derivation for each round if you require a minimum of RAM. The entire
larray doesn't seem necessary either. For software implementations that doesn't matter a single iota of course.