-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Collects together existing Haskell cryptographic functions into a package -- -- DES, Blowfish, AES, TEA, SHA1, MD5, RSA, BubbleBabble, Hexdump, -- Support for Word128, Word192 and Word256 and Beyond, PKCS5 Padding, -- Various Encryption Modes e.g. Cipher Block Chaining all in one -- package, with HUnit and QuickCheck tests, and examples. @package Crypto @version 4.2.1 -- | Implements SHA-256, SHA-384, SHA-512, and SHA-224 as defined in FIPS -- 180-2 -- http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf. module Data.Digest.SHA2 -- | sha256 currently requires that the bitSize of a divide -- 32 sha256 :: (Bits a, Integral a) => [a] -> Hash256 -- | shaXXXAscii assumes that all characters of the strings are -- ISO-latin-1 characters. ie. each characters fits in one octet. sha256Ascii :: String -> Hash256 type Hash256 = Hash8 Word32 -- | sha384 currently requires that the bitSize of a divide -- 64 sha512 :: (Bits a, Integral a) => [a] -> Hash512 sha512Ascii :: String -> Hash512 type Hash512 = Hash8 Word64 -- | sha384 currently requires that the bitSize of a divide -- 64 sha384 :: (Bits a, Integral a) => [a] -> Hash384 sha384Ascii :: String -> Hash384 data Hash384 -- | sha224 currently requires that the bitSize of a divide -- 32 sha224 :: (Bits a, Integral a) => [a] -> Hash224 sha224Ascii :: String -> Hash224 data Hash224 toOctets :: (Hash h) => h -> [Word8] instance Eq Hash224 instance Ord Hash224 instance Eq Hash384 instance Ord Hash384 instance (Eq w) => Eq (Hash8 w) instance (Ord w) => Ord (Hash8 w) instance Hash Hash224 instance Hash Hash384 instance (Integral h, Bits h) => Hash (Hash8 h) instance Show Hash224 instance Show Hash384 instance (Integral a) => Show (Hash8 a) instance ShaData Word64 instance ShaData Word32 -- | This module currently supports Cipher Block Chaining (CBC) mode. See -- http://www.itl.nist.gov/fipspubs/fip81.htm for further details. module Codec.Encryption.Modes -- | In CBC or Cipher Block Chaining mode each block is XORed with the -- previous enciphered block before encryption. For the first block, -- start with an initialization vector. Take an encryption function, an -- initialisation vector, a key and a list of blocks and return the -- encrypted blocks using CBC. cbc :: (Bits block) => (key -> block -> block) -> block -> key -> [block] -> [block] -- | To decipher in CBC or Cipher Block Chaining mode, decipher each block, -- then XOR the result with the previous block of plaintext result. Note -- that the initialization vector is treated as the zeroth block of -- plaintext. Take a decryption function, an initialisation vector, a key -- and a list of encrypted blocks using CBC and return plaintext blocks. unCbc :: (Bits block) => (key -> block -> block) -> block -> key -> [block] -> [block] -- | Implementation of the TEA tiny encryption algorithm module Codec.Encryption.TEA data TEAKey TEAKey :: !!Word32 -> !!Word32 -> !!Word32 -> !!Word32 -> TEAKey encrypt :: TEAKey -> Word64 -> Word64 decrypt :: TEAKey -> Word64 -> Word64 -- | Provides Word128, Word192 and Word256 and a way of producing other -- large words if required. module Data.LargeWord data LargeKey a b type Word96 = LargeKey Word32 Word64 type Word128 = LargeKey Word64 Word64 type Word160 = LargeKey Word32 Word128 type Word192 = LargeKey Word64 Word128 type Word224 = LargeKey Word32 Word192 type Word256 = LargeKey Word64 Word192 instance (Eq a, Eq b) => Eq (LargeKey a b) instance (Ord a, Ord b) => Ord (LargeKey a b) instance Enum (LargeKey a b) instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) => Real (LargeKey a b) instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) => Integral (LargeKey a b) instance (Ord a, Bits a, Bounded a, Integral a, LargeWord a, Bits b, Bounded b, Integral b, LargeWord b) => Bounded (LargeKey a b) instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Bits (LargeKey a b) instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Num (LargeKey a b) instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Show (LargeKey a b) instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => LargeWord (LargeKey a b) instance LargeWord Word64 instance LargeWord Word32 -- | Takes the DES module supplied by Ian Lynagh and wraps it so it can -- used with the standard modes. -- -- See http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/. module Codec.Encryption.DES -- | Basic DES encryption which takes a key and a block of plaintext and -- returns the encrypted block of ciphertext according to the standard. encrypt :: Word64 -> Word64 -> Word64 -- | Basic DES decryption which takes a key and a block of ciphertext and -- returns the decrypted block of plaintext according to the standard. decrypt :: Word64 -> Word64 -> Word64 module Codec.Encryption.RSA.NumberTheory inverse :: Integer -> Integer -> Integer extEuclGcd :: Integer -> Integer -> (Integer, Integer) simplePrimalityTest :: Integer -> Bool getPrime :: Int -> IO Integer pg :: Integer -> Integer -> Integer -> IO (Integer) isPrime :: Integer -> IO Bool rabinMillerPrimalityTest :: Integer -> IO Bool expmod :: Integer -> Integer -> Integer -> Integer factor :: Integer -> [Int] testInverse :: Integer -> Integer -> Bool primes :: [Integer] (/|) :: Integer -> Integer -> Bool randomOctet :: Int -> IO (String) -- | Utilities for coding and decoding. module Codec.Utils -- | The basic type for encoding and decoding. type Octet = Word8 -- | The most significant bit of an Octet. msb :: Int -- | Convert from twos complement. fromTwosComp :: (Integral a) => [Octet] -> a toTwosComp :: (Integral a) => a -> [Octet] -- | Take a number a convert it to base n as a list of octets. toOctets :: (Integral a, Integral b) => a -> b -> [Octet] -- | Take a list of octets (a number expressed in base n) and convert it to -- a number. fromOctets :: (Integral a, Integral b) => a -> [Octet] -> b -- | See listToOctets. listFromOctets :: (Integral a, Bits a) => [Octet] -> [a] -- | Converts a list of numbers into a list of octets. The resultant list -- has nulls trimmed from the end to make this the dual of listFromOctets -- (except when the original octet list ended with nulls; see -- trimNulls). listToOctets :: (Bits a, Integral a) => [a] -> [Octet] -- | Take the length of the required number of octets and convert the -- number to base 256 padding it out to the required length. If the -- required length is less than the number of octets of the converted -- number then return the converted number. NB this is different from the -- standard -- ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf but -- mimics how replicate behaves. i2osp :: (Integral a) => Int -> a -> [Octet] -- | A modified version of the RSA module supplied by David J. Sankel -- (http://www.electronconsulting.com/rsa-haskell). -- -- As the original code is GPL, this has to be. This code is free -- software; you can redistribute it and/or modify it under the terms of -- the GNU General Public License as published by the Free Software -- Foundation; either version 2 of the License, or (at your option) any -- later version. -- -- This code is distributed in the hope that it will be useful, but -- WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this code; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA module Codec.Encryption.RSA -- | Take the modulus of the RSA key and the public exponent expressed as -- lists of octets and the plaintext also expressed as a list of octets -- and return the ciphertext as a list of octets. Of course, these are -- all large integers but using lists of octets makes everything easier. -- See http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/index.html -- for more details. encrypt :: ([Octet], [Octet]) -> [Octet] -> [Octet] -- | Take the modulus of the RSA key and the private exponent expressed as -- lists of octets and the ciphertext also expressed as a list of octets -- and return the plaintext as a list of octets. decrypt :: ([Octet], [Octet]) -> [Octet] -> [Octet] -- | A modified version of the EMEOAEP module supplied by David J. Sankel -- (http://www.electronconsulting.com/rsa-haskell). -- -- As the original code is GPL, this has to be. This code is free -- software; you can redistribute it and/or modify it under the terms of -- the GNU General Public License as published by the Free Software -- Foundation; either version 2 of the License, or (at your option) any -- later version. -- -- This code is distributed in the hope that it will be useful, but -- WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this code; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA module Codec.Encryption.RSA.EMEOAEP -- | Take a mask generating function, a hash function, a label (which may -- be null), a random seed, the modulus of the key and the message and -- returns an encoded message. NB you could pass in the length of the -- modulus but it seems safer to pass in the modulus itself and calculate -- the length when required. See -- ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf for -- more details. encode :: (([Octet] -> [Octet]) -> [Octet] -> Int -> [Octet]) -> ([Octet] -> [Octet]) -> [Octet] -> [Octet] -> [Octet] -> [Octet] -> [Octet] -- | Take a mask generating function, a hash function, a label (which may -- be null) and the message and returns the decoded. decode :: (([Octet] -> [Octet]) -> [Octet] -> Int -> [Octet]) -> ([Octet] -> [Octet]) -> [Octet] -> [Octet] -> [Octet] -- | Implements the mask generation function as specified in: -- ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf module Codec.Encryption.RSA.MGF -- | Take a hash function, a seed and the intended length of the the mask -- and deliver a mask of the requested length. mgf :: ([Octet] -> [Octet]) -> [Octet] -> Int -> [Octet] -- | Takes the AES module supplied by Lukasz Anforowicz and wraps it so it -- can used with the standard modes. module Codec.Encryption.AES -- | Basic AES encryption which takes a key and a block of plaintext and -- returns the encrypted block of ciphertext according to the standard. encrypt :: (AESKey a) => a -> Word128 -> Word128 -- | Basic AES decryption which takes a key and a block of ciphertext and -- returns the decrypted block of plaintext according to the standard. decrypt :: (AESKey a) => a -> Word128 -> Word128 class (AESKeyIndirection a) => AESKey a instance AESKey Word256 instance AESKey Word192 instance AESKey Word128 instance AESKeyIndirection Word256 instance AESKeyIndirection Word192 instance AESKeyIndirection Word128 -- | Takes the Blowfish module supplied by Doug Hoyte and wraps it so it -- can used with the standard modes. module Codec.Encryption.Blowfish -- | Basic Blowfish encryption which takes a key and a block of plaintext -- and returns the encrypted block of ciphertext according to the -- standard. Typical keys are Word8, Word16, Word32, Word64, Word128. See -- http://www.counterpane.com/vectors.txt. encrypt :: (Integral a) => a -> Word64 -> Word64 -- | Basic Blowfish decryption which takes a key and a block of ciphertext -- and returns the decrypted block of plaintext. decrypt :: (Integral a) => a -> Word64 -> Word64 -- | Padding algorithms for use with block ciphers. -- -- This module currently supports: -- --