Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Crypto.Cipher.Xtea
Contents
Description
Implementation of the XTEA (eXtended Tiny Encryption Algorithm) block cipher.
Its specification can be found here.
Synopsis
- data SymmetricKey = SymmetricKey !Word32 !Word32 !Word32 !Word32
- data Endianness
- data EncryptionError = EncryptionInvalidInputLengthError !Int
- encryptBlock :: SymmetricKey -> (Word32, Word32) -> (Word32, Word32)
- encrypt :: SymmetricKey -> ByteString -> Either EncryptionError ByteString
- encrypt' :: Endianness -> SymmetricKey -> ByteString -> Either EncryptionError ByteString
- data DecryptionError = DecryptionInvalidInputLengthError !Int
- decryptBlock :: SymmetricKey -> (Word32, Word32) -> (Word32, Word32)
- decrypt :: SymmetricKey -> ByteString -> Either DecryptionError ByteString
- decrypt' :: Endianness -> SymmetricKey -> ByteString -> Either DecryptionError ByteString
Documentation
data SymmetricKey Source #
128-bit XTEA symmetric key.
Constructors
SymmetricKey !Word32 !Word32 !Word32 !Word32 |
data Endianness Source #
Byte ordering.
Constructors
LittleEndian | Little-endian byte ordering. |
BigEndian | Big-endian byte ordering. |
Instances
Show Endianness Source # | |
Defined in Crypto.Cipher.Xtea Methods showsPrec :: Int -> Endianness -> ShowS # show :: Endianness -> String # showList :: [Endianness] -> ShowS # | |
Eq Endianness Source # | |
Defined in Crypto.Cipher.Xtea |
Encryption
data EncryptionError Source #
XTEA encryption error.
Constructors
EncryptionInvalidInputLengthError !Int | Input length is not a multiple of XTEA's block size (64 bits). |
Instances
Show EncryptionError Source # | |
Defined in Crypto.Cipher.Xtea Methods showsPrec :: Int -> EncryptionError -> ShowS # show :: EncryptionError -> String # showList :: [EncryptionError] -> ShowS # | |
Eq EncryptionError Source # | |
Defined in Crypto.Cipher.Xtea Methods (==) :: EncryptionError -> EncryptionError -> Bool # (/=) :: EncryptionError -> EncryptionError -> Bool # |
encryptBlock :: SymmetricKey -> (Word32, Word32) -> (Word32, Word32) Source #
XTEA encrypt a 64-bit block.
This function is based on the following C implementation:
void encipher(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]) { unsigned int i; uint32_t v0=v[0], v1=v[1], sum=0, delta=0x9E3779B9; for (i=0; i < num_rounds; i++) { v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); sum += delta; v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); } v[0]=v0; v[1]=v1; }
encrypt :: SymmetricKey -> ByteString -> Either EncryptionError ByteString Source #
XTEA encrypt a ByteString
.
Endianness defaults to BigEndian
.
encrypt' :: Endianness -> SymmetricKey -> ByteString -> Either EncryptionError ByteString Source #
XTEA encrypt a ByteString
.
Decryption
data DecryptionError Source #
XTEA decryption error.
Constructors
DecryptionInvalidInputLengthError !Int | Input length is not a multiple of XTEA's block size (64 bits). |
Instances
Show DecryptionError Source # | |
Defined in Crypto.Cipher.Xtea Methods showsPrec :: Int -> DecryptionError -> ShowS # show :: DecryptionError -> String # showList :: [DecryptionError] -> ShowS # | |
Eq DecryptionError Source # | |
Defined in Crypto.Cipher.Xtea Methods (==) :: DecryptionError -> DecryptionError -> Bool # (/=) :: DecryptionError -> DecryptionError -> Bool # |
decryptBlock :: SymmetricKey -> (Word32, Word32) -> (Word32, Word32) Source #
Decrypt an XTEA-encrypted 64-bit block.
This function is based on the following C implementation:
void decipher(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]) { unsigned int i; uint32_t v0=v[0], v1=v[1], delta=0x9E3779B9, sum=delta*num_rounds; for (i=0; i < num_rounds; i++) { v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); sum -= delta; v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); } v[0]=v0; v[1]=v1; }
decrypt :: SymmetricKey -> ByteString -> Either DecryptionError ByteString Source #
Decrypt an XTEA-encrypted ByteString
.
Endianness defaults to BigEndian
.
decrypt' :: Endianness -> SymmetricKey -> ByteString -> Either DecryptionError ByteString Source #
Decrypt an XTEA-encrypted ByteString
.