##Serpent Encryption Process
-- KEY GENERATION
- Load 128bit key and 128bit plaintext
- Extend key to 256bits by appending after the MSB a '1' then '0' to the end
- Split key into 8 32bit segments
- Load key segments into first 8 places of 140 place (each 32bits) array
- Iterate over the rest of the 140 place array
for i in 8 to 140 {
prekeys[i] = (prekeys[i-8] ^ prekeys[i-5] ^ prekeys[i-3] ^ prekeys[i-1] ^ phi ^ (i-8)) <<< 11;
}
-
Generate subkeys from S-boxes
- Explanation of sbox output
- select current S-box row with ((32+3-i) mod 32)
- Form a 4 bit value that selects value in row by concatenating bits in prekeys following
prekey[8+0(4*i)]bit(j) & prekey[8+1(4*i)]bit(j) & prekey[8+2(4*i)]bit(j) & prekey[8+3(4*i)]bit(j)
- OR S-box output into empty array by bits using equation
k[l+4*i] |= ((sboxOut >> l)&1)<<j;
- Explanation of sbox output
-
Load above S-box array into subkeys (33x4 2d array)
-- PLAINTEXT TRANSFORMS
- Only in standard version
-
Description of initial permutation function
- Load first and last bits of input into empty bit array
- Iterate over rest of empty array and set bits from input at position ((i*32) mod 127)
-
Run plaintext through initial permutation function
-
Run each subkey through initial permutation function
-
- Start 32 rounds
- XOR plaintext permutation and current subkey permutation each round
- Standard Version
- Form 32bit value using the 8 4bit values to return S-box value and append
- First 31 rounds
- access Linear Transformation table with iterators to return bit position from above 32 bit value to load into plaintext permutation
- Bitslice Version
- Take one bit from each XOR'd 32bit value starting from position 0 (totaling 4bits) and use that as input to return a value from S-box i%8
- The 4bit value returned from the S-Box is distributed to the 32bit values the same way it was extracted
- Run the resulting 4 32bit values through the linear transformation equation referenced in the documentation
- Last round
- XOR above 32 bit value and 33rd subkey permutations into result
- Only in standard version
- Final permutation
- Exactly the same as initial permutation except using the bit selector ((i*4)%127)
- Final permutation
- End encryption
##Serpent Decryption Process
- Logically work backwards from encryption
- Use inverse tables such as Inverse Linear Transformation Table and Inverse S-boxes
- Note: In the bitslice, the LT equation uses shift left logical which should also be used in decryption
- The rotations are still the opposite, the shift is not