Twofish is a 128-bit block cipher that can accept variable key length 128,192 and 256 bit. In this project we just use key length
128 bit. Twofish is fundamental built by F-function, rotate-left one bit, rotate-right one bit, and XOR.The cipher has 16 round F-function . F-function is made up by four key-dependent 8-by-8-bit S-box, a fixed 4-by-4 maximum distance separable matrix over GF(2^8), a pseudo-Hadamard transform, bitwise rotation, and key scedule.
As can be seen from figure 1, input will be latched first into a register and then separated into four word. The four word then XOR with K0,K1,K2,K3. This step is called input-whitening. Data then goes through F-function. On F-function, there are various rotation, transformation and permutation are applied to it. F-function is made of two h-functions containing key-dependant S-boxes and Maximum Distance Separable Matrix (MDS) , Pseudo-Hadamard Transform (PHT). After going 16 time through this function, the four word of data are one again XOR-ed with four sub-key K4,K5,K6,K7. This step is called output whitening. Finally encrypted or decrypted data is latched into output register.
FILE: twofish.jpg
DESCRIPTION: Figure 1. Structure of Twofish block Cipher
FILE: qper.jpg
DESCRIPTION: Q-permutation
FILE: s-boxes.jpg
DESCRIPTION: S-boxes
FILE: cleartext.jpg
DESCRIPTION: Input register module
FILE: ciphertext.jpg
DESCRIPTION: Output register module
FILE: key-mod.jpg
DESCRIPTION: Key-register module
FILE: modifiedF.jpg
DESCRIPTION: Modified-F module
1. Twofish can accept key-length 128, 192, 256 bit. In this project we used 128 bit key-length
2. Use little-endian convention for input, output and key
We have finished designing Twofish core using VHDL, and the test result is OK.