Twofish-0.3.2: An implementation of the Twofish Symmetric-key cipher.

Safe HaskellNone

Codec.Encryption.Twofish

Contents

Description

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.

Synopsis

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)

Utility functions

mkS :: Key a => a -> SVectorSource

mkfH :: Key a => a -> HFuncSource

mkK :: Key a => a -> Int -> HFunc -> KIndexorSource

mkG :: HFunc -> SVector -> GFuncSource

encryptRounds :: GFunc -> KIndexor -> Int -> Block -> BlockSource

This function performs n rounds of the encryption algorithm

q0o :: Word8 -> Word8Source

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.

q1o :: Word8 -> Word8Source

Generates the q1 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.