Hello!
Please tell me how the procedure for building key-dependent S blocks in Twofish-128 should work correctly. After reading the official Twofish-128 specification, I realized that after the S vector was generated from 2 32 bit words, you need to build 4 S blocks with 256 entries, since during the encryption rounds each S block accepts an 8 bit number (maximum 255 in decimal) and produces 8 bit output. The specification of the Twofish-128 algorithm says that S blocks are built by calling the H function, h (X, S), where the L vector in the h function is used as the S vector. Given that X serves as an input, it must be a number in the range from 0 to 255.
The pseudocode for building 4 S blocks with 256 entries will look like this:
UInt32[,] SBOX=new UInt32[4,256]; for(int i=0;i<4;i+=1) { for(int j=0;j<256;j+=1) { SBOX[i,j]=h(j,S); } } But I believe that this is wrong since all 4 S blocks will have the same values as j will always be in the range from 0 to 255 and the S vector will be fixed for the entire duration of the algorithm. Therefore, I am not much confused about what exactly should be taken for X as an input to the h function. Could you tell us exactly how the procedure for building 4 S blocks with 256 entries should work? Maybe there is a teaching example of building S blocks? Thank!