Safe Haskell | None |
---|
Implements the Twofish symmetric block cipher, designed by: Bruce Schneier, John Kelsey, Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson.
Implemented from the paper entitled Twofish: A 128-Bit Block Cipher, http://www.counterpane.com/twofish.html with help from the reference C implementation.
This module provides two methods for constructiong a Twofish cipher from a 128, 192 or 256 bit key. The mkCipher function allows you to customize the number of rounds, while the mkStdCipher function gives you the standard 16 rounds.
- class (Bits a, Integral a) => Key a
- data TwofishCipher
- mkStdCipher :: Key a => a -> TwofishCipher
- mkCipher :: Key a => Int -> a -> TwofishCipher
- encrypt :: TwofishCipher -> Word128 -> Word128
- decrypt :: TwofishCipher -> Word128 -> Word128
- mkS :: Key a => a -> SVector
- mkfH :: Key a => a -> HFunc
- mkK :: Key a => a -> Int -> HFunc -> KIndexor
- mkG :: HFunc -> SVector -> GFunc
- encryptRounds :: GFunc -> KIndexor -> Int -> Block -> Block
- q0o :: Word8 -> Word8
- q1o :: Word8 -> Word8
Classes
class (Bits a, Integral a) => Key a Source
A key is a vector of bytes of a certain size (given in bits). Twofish suppports key sizes of 128, 192, and 256 bits.
Types
data TwofishCipher Source
A keyed Twofish cipher capable of both encryption and decryption.
Functions
mkStdCipher :: Key a => a -> TwofishCipherSource
Constructs a standard Twofish cipher from the given key
mkCipher :: Key a => Int -> a -> TwofishCipherSource
Constructs an encryption/decryption cipher from the given key, and a given number of rounds (standard Twofish uses 16 rounds)
encrypt :: TwofishCipher -> Word128 -> Word128Source
decrypt :: TwofishCipher -> Word128 -> Word128Source
Utility functions
encryptRounds :: GFunc -> KIndexor -> Int -> Block -> BlockSource
This function performs n rounds of the encryption algorithm
Generates the q0
byte vector using the algorithm specified in
the Twofish paper. This function isn't used by the cipher; instead
the pre-computed array is contained in the code.