I'm trying to figure out how Twofish cipher expanded key is generated.
For now, I have figured out that firstly one part of the key is generated, and used for whitening, and then in each round 2x32bit key part is generated.
The first part of the key is made up of 3 vectors, Mo, Me and S.
Mo and Me are generated simply by expanding the primary key to first defined length, and splitting it to even and odd 32b words, that are then put in the Mo and Me vectors.
Vector S on the other hand is made up of k words, where k = N/64, in case of N=128, S contains 2x32b words.
So, we got to Mo(2x32) + Me(2x32) + S(2x32) + 16x2x32 = 38 32bit words. 2 words are missing. Why??
And what if N=192, or N=256? How can the expanded key be 40 32bit words instead of 41 and 44?
Any help would be great.
Thanks
To answer my own question, I found out that vectors Mo, Me and S are not actually part of the expanded key, as I first thought, actually they are just used for generating expanded key and key-dependent S boxes. Part of the key that is used for whitening is generated the same way as the parts that are used in each round, using h function, just they are not used anywhere else except for whitening. Hope this saves some trouble to people with this kind of question. :)