-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | safe nettle binding -- -- safe binding for the nettle -- (http://www.lysator.liu.se/~nisse/nettle/nettle.html) library. @package nettle @version 0.1.0 -- | Generic interface to calculate key based hashes. module Crypto.Nettle.KeyedHash -- | KeyedHashAlgorithm is a class for keyed hash algorithms that -- take a key and a message to produce a digest. The most popular example -- is HMAC. class KeyedHashAlgorithm k where implKeyedHashUpdateLazy k = foldl' implKeyedHashUpdate k . toChunks implKeyedHashDigestSize :: KeyedHashAlgorithm k => Tagged k Int implKeyedHashName :: KeyedHashAlgorithm k => Tagged k String implKeyedHashInit :: KeyedHashAlgorithm k => ByteString -> k implKeyedHashUpdate :: KeyedHashAlgorithm k => k -> ByteString -> k implKeyedHashUpdateLazy :: KeyedHashAlgorithm k => k -> ByteString -> k implKeyedHashFinalize :: KeyedHashAlgorithm k => k -> ByteString -- | KeyedHash hides the KeyedHashAlgorithm implementation. data KeyedHash KeyedHash :: !k -> KeyedHash -- | Untagged variant of implKeyedHashDigestSize; takes a (possible -- undefined) key typed value from a KeyedHashAlgorithm -- instance as parameter. keyedHashDigestSize :: KeyedHashAlgorithm k => k -> Int -- | Get implKeyedHashDigestSize from a KeyedHash keyedHashDigestSize' :: KeyedHash -> Int -- | Untagged variant of implKeyedHashName; takes a (possible -- undefined) key typed value from a KeyedHashAlgorithm -- instance as parameter. keyedHashName :: KeyedHashAlgorithm k => k -> String -- | Get implKeyedHashName from a KeyedHash keyedHashName' :: KeyedHash -> String -- | Initialize a KeyedHash context from a key keyedHashInit :: KeyedHashAlgorithm k => ByteString -> Tagged k KeyedHash -- | Untagged variant of keyedHashInit; takes a (possible -- undefined) key typed value from a KeyedHashAlgorithm -- instance as parameter. keyedHashInit' :: KeyedHashAlgorithm k => k -> ByteString -> KeyedHash -- | Add more message data to the context keyedHashUpdate :: KeyedHash -> ByteString -> KeyedHash -- | Add more lazy message data to the context keyedHashUpdateLazy :: KeyedHash -> ByteString -> KeyedHash -- | Produce final digest keyedHashFinalize :: KeyedHash -> ByteString -- | Helper to hash key and message in one step -- -- Example: -- --
--   untag (keyedHash (fromString "secretkey") (fromString "secret message") :: Tagged (HMAC SHA256) B.ByteString)
--   
keyedHash :: KeyedHashAlgorithm k => ByteString -> ByteString -> Tagged k ByteString -- | Untagged variant of keyedHash; takes a (possible -- undefined) key typed value from a KeyedHashAlgorithm -- instance as parameter. -- -- Example: -- --
--   keyedHash' (undefined :: HMAC SHA256) (fromString "secretkey") (fromString "secret message")
--   
keyedHash' :: KeyedHashAlgorithm k => k -> ByteString -> ByteString -> ByteString -- | Helper to hash key and lazy message in one step -- -- Example: -- --
--   untag (keyedHashLazy (fromString "secretkey") (fromString "secret message") :: Tagged (HMAC SHA256) B.ByteString)
--   
keyedHashLazy :: KeyedHashAlgorithm k => ByteString -> ByteString -> Tagged k ByteString -- | Untagged variant of keyedHashLazy; takes a (possible -- undefined) key typed value from a KeyedHashAlgorithm -- instance as parameter. -- -- Example: -- --
--   keyedHashLazy' (undefined :: HMAC SHA256) (fromString "secretkey") (fromString "secret message")
--   
keyedHashLazy' :: KeyedHashAlgorithm k => k -> ByteString -> ByteString -> ByteString -- | Generic HMAC implementation based on the HashAlgorithm class, -- implementing the KeyedHashAlgorithm class. module Crypto.Nettle.HMAC -- | HMAC is a generic KeyedHashAlgorithm instance to -- calculate the HMAC based on a HashAlgorithm data HMAC a -- | hmacInit is the default implementation for hashHMAC and -- initializes a KeyedHash to calculate the HMAC for a message -- with the given key. -- -- Example: -- --
--   let c = untag (hmacInit (fromString "secretkey") :: Tagged SHA256 KeyedHash) in keyedHashFinalize $ keyedHashUpdate c (fromString "secret message")
--   
hmacInit :: HashAlgorithm a => ByteString -> Tagged a KeyedHash -- | Untagged variant of hmacInit; takes a (possible -- undefined) typed HashAlgorithm context as parameter. -- -- Example: -- --
--   keyedHashFinalize $ flip keyedHashUpdate (fromString "secret message") $ hmacInit' (undefined :: SHA256) (fromString "secretkey")
--   
hmacInit' :: HashAlgorithm a => a -> ByteString -> KeyedHash -- | calculate HMAC with a HashAlgorithm for a key and -- message -- -- Example: -- --
--   untag (hmac (fromString "secretkey") (fromString "secret message") :: Tagged SHA256 B.ByteString)
--   
hmac :: HashAlgorithm a => ByteString -> ByteString -> Tagged a ByteString -- | Untagged variant of hmac; takes a (possible undefined) -- typed HashAlgorithm context as parameter. -- -- Example: -- --
--   hmac' (undefined :: SHA256) (fromString "secretkey") (fromString "secret message")
--   
hmac' :: HashAlgorithm a => a -> ByteString -> ByteString -> ByteString -- | calculate HMAC with a HashAlgorithm for a key and lazy -- message -- -- Example: -- --
--   untag (hmacLazy (fromString "secretkey") (fromString "secret message") :: Tagged SHA256 B.ByteString)
--   
hmacLazy :: HashAlgorithm a => ByteString -> ByteString -> Tagged a ByteString -- | Untagged variant of hmacLazy; takes a (possible -- undefined) typed HashAlgorithm context as parameter. -- -- Example: -- --
--   hmacLazy' (undefined :: SHA256) (fromString "secretkey") (fromString "secret message")
--   
hmacLazy' :: HashAlgorithm a => a -> ByteString -> ByteString -> ByteString -- | This module exports hash algorithms supported by nettle: -- http://www.lysator.liu.se/~nisse/nettle/ module Crypto.Nettle.Hash -- | HashAlgorithm is a class that hash algorithms will implement. -- generating a digest is a 3 step procedure: -- -- -- -- The final digest has hashDigestSize bytes, and the algorithm -- uses hashBlockSize as internal block size. class HashAlgorithm a where hashUpdateLazy a = foldl' hashUpdate a . toChunks hashHMAC = hmacInit hashBlockSize :: HashAlgorithm a => Tagged a Int hashDigestSize :: HashAlgorithm a => Tagged a Int hashName :: HashAlgorithm a => Tagged a String hashInit :: HashAlgorithm a => a hashUpdate :: HashAlgorithm a => a -> ByteString -> a hashUpdateLazy :: HashAlgorithm a => a -> ByteString -> a hashFinalize :: HashAlgorithm a => a -> ByteString hashHMAC :: HashAlgorithm a => ByteString -> Tagged a KeyedHash -- | Helper to hash a single (strict) ByteString in one step. -- -- Example: -- --
--   untag (hash (fromString "abc") :: Tagged SHA256 B.ByteString)
--   
hash :: HashAlgorithm a => ByteString -> Tagged a ByteString -- | Untagged variant of hash; takes a (possible undefined) -- typed HashAlgorithm context as parameter. -- -- Example: -- --
--   hash' (undefined :: SHA256) $ fromString "abc"
--   
hash' :: HashAlgorithm a => a -> ByteString -> ByteString -- | Helper to hash a single (lazy) ByteString in one step. -- -- Example: -- --
--   untag (hashLazy (fromString "abc") :: Tagged SHA256 L.ByteString)
--   
hashLazy :: HashAlgorithm a => ByteString -> Tagged a ByteString -- | Untagged variant of hashLazy; takes a (possible -- undefined) typed HashAlgorithm context as parameter. -- -- Example: -- --
--   hashLazy' (undefined :: SHA256) $ fromString "abc"
--   
hashLazy' :: HashAlgorithm a => a -> ByteString -> ByteString -- | The GOST94 or GOST R 34.11-94 hash algorithm is a Soviet-era algorithm -- used in Russian government standards (see RFC 4357). It outputs -- message digests of 32 bytes (256 bits). data GOSTHASH94 -- | MD2 is a hash function of Ronald Rivest's, described in RFC -- 1319. It outputs message digests of 16 bytes (128 bits). data MD2 -- | MD4 is a hash function of Ronald Rivest's, described in RFC -- 1320. It outputs message digests of 16 bytes (128 bits). data MD4 -- | MD5 is a hash function of Ronald Rivest's, described in RFC -- 1321. It outputs message digests of 16 bytes (128 bits). data MD5 -- | RIPEMD160 is a hash function designed by Hans Dobbertin, Antoon -- Bosselaers, and Bart Preneel, as a strengthened version of RIPEMD. It -- produces message digests of 20 bytes (160 bits). data RIPEMD160 -- | SHA1 is a hash function specified by NIST (The U.S. National -- Institute for Standards and Technology). It produces message digests -- of 20 bytes (160 bits). data SHA1 -- | SHA224 is a member of the SHA2 family which outputs messages -- digests of 28 bytes (224 bits). data SHA224 -- | SHA256 is a member of the SHA2 family which outputs messages -- digests of 32 bytes (256 bits). data SHA256 -- | SHA384 is a member of the SHA2 family which outputs messages -- digests of 48 bytes (384 bits). data SHA384 -- | SHA512 is a member of the SHA2 family which outputs messages -- digests of 64 bytes (512 bits). data SHA512 -- | SHA3_224 is a member of the SHA3 family which outputs messages -- digests of 28 bytes (224 bits). data SHA3_224 -- | SHA3_256 is a member of the SHA3 family which outputs messages -- digests of 32 bytes (256 bits). data SHA3_256 -- | SHA3_384 is a member of the SHA3 family which outputs messages -- digests of 48 bytes (384 bits). data SHA3_384 -- | SHA3_512 is a member of the SHA3 family which outputs messages -- digests of 64 bytes (512 bits). data SHA3_512 instance HashAlgorithm SHA3_512 instance NettleHashAlgorithm SHA3_512 instance HashAlgorithm SHA3_384 instance NettleHashAlgorithm SHA3_384 instance HashAlgorithm SHA3_256 instance NettleHashAlgorithm SHA3_256 instance HashAlgorithm SHA3_224 instance NettleHashAlgorithm SHA3_224 instance HashAlgorithm SHA512 instance NettleHashAlgorithm SHA512 instance HashAlgorithm SHA384 instance NettleHashAlgorithm SHA384 instance HashAlgorithm SHA256 instance NettleHashAlgorithm SHA256 instance HashAlgorithm SHA224 instance NettleHashAlgorithm SHA224 instance HashAlgorithm SHA1 instance NettleHashAlgorithm SHA1 instance HashAlgorithm RIPEMD160 instance NettleHashAlgorithm RIPEMD160 instance HashAlgorithm MD5 instance NettleHashAlgorithm MD5 instance HashAlgorithm MD4 instance NettleHashAlgorithm MD4 instance HashAlgorithm MD2 instance NettleHashAlgorithm MD2 instance HashAlgorithm GOSTHASH94 instance NettleHashAlgorithm GOSTHASH94 -- | This module exports the UMAC algorithms supported by nettle: -- http://www.lysator.liu.se/~nisse/nettle/ module Crypto.Nettle.UMAC -- | UMAC is a class of keyed hash algorithms that take an -- additional nonce. -- -- Keys for UMAC are always 16 bytes; there are different digest -- sizes: 4, 8, 12 and 16 bytes (32, 64, 96 and 128 bits), and the -- variants are named after the digest length in bits. -- -- On initialization the nonce is set to 0; each finalize returns a new -- state with an incremented nonce. The nonce is interpreted as 16-byte -- (128-bit) big-endian integer (and for string shorter than 16 bytes -- padded with zeroes on the left; setting empty nonces is not -- allowed). class UMAC u where umacName = (("UMAC" ++) . show . (8 *)) <$> umacDigestSize umacUpdateLazy u = foldl' umacUpdate u . toChunks umacDigestSize :: UMAC u => Tagged u Int umacName :: UMAC u => Tagged u String umacInit :: UMAC u => ByteString -> u umacSetNonce :: UMAC u => u -> ByteString -> u umacUpdate :: UMAC u => u -> ByteString -> u umacUpdateLazy :: UMAC u => u -> ByteString -> u umacFinalize :: UMAC u => u -> (ByteString, u) -- | UMAC32 is the 32-bit (4 byte) digest variant. See -- umacInitKeyedHash for the KeyedHashAlgorithm instance. data UMAC32 -- | UMAC64 is the 32-bit (4 byte) digest variant. See -- umacInitKeyedHash for the KeyedHashAlgorithm instance. data UMAC64 -- | UMAC96 is the 32-bit (4 byte) digest variant. See -- umacInitKeyedHash for the KeyedHashAlgorithm instance. data UMAC96 -- | UMAC128 is the 32-bit (4 byte) digest variant. See -- umacInitKeyedHash for the KeyedHashAlgorithm instance. data UMAC128 -- | The default KeyedHash generated for UMAC -- KeyedHashAlgorithm instances use a zero nonce; to set a -- different nonce you need to use this initialization function (or use -- the UMAC interface). -- -- Once the UMAC lives as KeyedHash the nonce cannot be changed -- anymore, as KeyedHash hides all internal state. umacInitKeyedHash :: (UMAC u, KeyedHashAlgorithm u) => ByteString -> ByteString -> Tagged u KeyedHash instance KeyedHashAlgorithm UMAC128 instance UMAC UMAC128 instance NettleUMAC UMAC128 instance KeyedHashAlgorithm UMAC96 instance UMAC UMAC96 instance NettleUMAC UMAC96 instance KeyedHashAlgorithm UMAC64 instance UMAC UMAC64 instance NettleUMAC UMAC64 instance KeyedHashAlgorithm UMAC32 instance UMAC UMAC32 instance NettleUMAC UMAC32 -- | (This is not a binding to nettle; it is implemented in pure haskell) -- -- This module adds CCM support to all 128-bit block ciphers: -- --
--   aeadInit AEAD_CCM = ccmInitTLS
--   
-- -- CCM uses 2 parameters t and q: t is the tag length -- (2,4,6,8,10,12,14,16) and q (2..8) is the length in bytes that the -- length of the message is stored in (and the length of the counter -- variable). Maximum message length is 2^(8*q) - 1. -- -- CCM requires a nonce of length (15 - q). TLS uses CCM with t = -- 16 and q = 3, and a nonce length of 12 (the first 4 -- bytes are fixed from the handshake, the other 8 usually represent the -- sequence counter). -- -- CCM encrypts with a CTR mode, the start IV is based on the (t,q,nonce) -- parameters; the tag is encrypted with counter value = 0, then the -- message follows. -- -- Calculating the tag needs the message length first - so this -- implementation needs to gather all data before calculating it. -- -- In RFC 3610 t is called M, and q is called -- L. module Crypto.Nettle.CCM -- | Start a CCM encryption with specified tag length t, length -- q of the message length field and a 15-q bytes long -- nonce. Fails if any parameter is invalid or the block cipher -- doesn't use a 16-byte blockSize. ccmInit :: (BlockCipher cipher, Byteable iv) => Int -> Int -> cipher -> iv -> Maybe (AEAD cipher) -- | Start a CCM encryption with specified tag length t = 16, -- length q = 3 for the message length field and a 8 -- bytes long nonce. Fails if any parameter is invalid or the -- block cipher doesn't use a 16-byte blockSize. This are the -- parameters used for TLS. ccmInitTLS :: (BlockCipher cipher, Byteable iv) => cipher -> iv -> Maybe (AEAD cipher) instance BlockCipher cipher => AEADModeImpl cipher (CCM cipher) -- | This module exports ciphers supported by nettle: -- http://www.lysator.liu.se/~nisse/nettle/ module Crypto.Nettle.Ciphers -- | AES is the generic cipher context for the AES cipher, -- supporting key sizes of 128, 196 and 256 bits (16, 24 and 32 bytes). -- The blockSize is always 128 bits (16 bytes). -- -- aeadInit only supports the AEAD_GCM mode for now. data AES -- | AES128 provides the same interface as AES, but is -- restricted to 128-bit keys. data AES128 -- | AES192 provides the same interface as AES, but is -- restricted to 192-bit keys. data AES192 -- | AES256 provides the same interface as AES, but is -- restricted to 256-bit keys. data AES256 -- | ARCTWO (also known as the trade marked name RC2) is a block -- cipher specified in RFC 2268. -- -- The default cipherInit uses ekb = bit-length of the -- key; arctwoInitEKB allows to specify ekb manually. -- arctwoInitGutmann uses ekb = 1024 (the maximum). -- -- ARCTWO uses keysizes from 1 to 128 bytes, and uses a -- blockSize of 64 bits (8 bytes). data ARCTWO -- | Initialize cipher with an explicit ekb value (valid values -- from 1 to 1024, 0 meaning the same as 1024). arctwoInitEKB :: Key ARCTWO -> Word -> ARCTWO -- | Initialize cipher with ekb = 1024. arctwoInitGutmann :: Key ARCTWO -> ARCTWO -- | BLOWFISH is a block cipher designed by Bruce Schneier. It uses -- a blockSize of 64 bits (8 bytes), and a variable key size from -- 64 to 448 bits (8 to 56 bytes). data BLOWFISH -- | Camellia is a block cipher developed by Mitsubishi and Nippon -- Telegraph and Telephone Corporation, described in RFC3713, and -- recommended by some Japanese and European authorities as an -- alternative to AES. The algorithm is patented (details see -- http://www.lysator.liu.se/~nisse/nettle/nettle.html). -- -- Camellia uses a the same blockSize and key sizes as AES. -- -- aeadInit only supports the AEAD_GCM mode for now. data Camellia -- | Camellia128 provides the same interface as Camellia, but -- is restricted to 128-bit keys. data Camellia128 -- | Camellia192 provides the same interface as Camellia, but -- is restricted to 192-bit keys. data Camellia192 -- | Camellia256 provides the same interface as Camellia, but -- is restricted to 256-bit keys. data Camellia256 -- | CAST128 is a block cipher specified in RFC 2144. It uses a 64 -- bit (8 bytes) blockSize, and a variable key size of 40 up to -- 128 bits (5 to 16 bytes). data CAST128 -- | DES is the old Data Encryption Standard, specified by NIST. It -- uses a blockSize of 64 bits (8 bytes), and a key size of 56 -- bits. -- -- The key is given as 8 bytes, as one bit per byte is used as a parity -- bit. The parity bit is ignored by this implementation. data DES -- | DES_EDE3 uses 3 DES keys k1 || k2 || k3. -- Encryption first encrypts with k1, then decrypts with k2, then -- encrypts with k3. -- -- The blockSize is the same as for DES: 64 bits (8 bytes), -- and the keys are simply concatenated, forming a 24 byte key string -- (with 168 bits actually getting used). data DES_EDE3 -- | TWOFISH is another AES finalist, designed by Bruce Schneier and -- others. -- -- TWOFISH uses a the same blockSize and key sizes as -- AES. -- -- aeadInit only supports the AEAD_GCM mode for now. data TWOFISH -- | SERPENT is one of the AES finalists, designed by Ross Anderson, -- Eli Biham and Lars Knudsen. -- -- The blockSize is 128 bits (16 bytes), and the valid key sizes -- are from 128 bits to 256 bits (16 to 32 bytes), although smaller bits -- are just padded with zeroes. -- -- aeadInit only supports the AEAD_GCM mode for now. data SERPENT -- | StreamNonceCipher are special stream ciphers that can encrypt -- many messages with the same key; setting a nonce restarts the cipher. -- -- A good value for the nonce is a message/packet counter. Usually a -- nonce should not be reused with the same key. class StreamCipher cipher => StreamNonceCipher cipher streamNonceSize :: StreamNonceCipher cipher => cipher -> KeySizeSpecifier streamSetNonce :: StreamNonceCipher cipher => cipher -> ByteString -> Maybe cipher -- | Sets a Word64 as 8-byte nonce (bigendian encoded) streamSetNonceWord64 :: StreamNonceCipher cipher => cipher -> Word64 -> Maybe cipher -- | ARCFOUR is a stream cipher, also known under the trade marked -- name RC4. -- -- Valid key sizes are from 1 to 256 bytes. data ARCFOUR -- | SALSA20 is a fairly recent stream cipher designed by D. J. -- Bernstein. -- -- Valid key sizes are 128 and 256 bits (16 and 32 bytes). -- -- Salsa20 uses a blocksize of 64 bytes internally; if crpyted input -- isn't aligned to 64 bytes it will pad it with 0 and store the -- encrypted padding to xor with future input data. -- -- Each message also requires a 8-byte (Word64) nonce (which is -- initialized to 0; you can use a message sequence number). Don't reuse -- a nonce with the same key. -- -- Setting a nonce also resets the remaining padding data. data SALSA20 -- | ESTREAM_SALSA20 is the same as SALSA20, but uses only 12 -- instead of 20 rounds in mixing. data ESTREAM_SALSA20 instance StreamNonceCipher ESTREAM_SALSA20 instance StreamCipher ESTREAM_SALSA20 instance Cipher ESTREAM_SALSA20 instance NettleBlockedStreamCipher ESTREAM_SALSA20 instance NettleCipher ESTREAM_SALSA20 instance StreamNonceCipher SALSA20 instance StreamCipher SALSA20 instance Cipher SALSA20 instance NettleBlockedStreamCipher SALSA20 instance NettleCipher SALSA20 instance StreamCipher ARCFOUR instance Cipher ARCFOUR instance NettleStreamCipher ARCFOUR instance NettleCipher ARCFOUR instance AEADModeImpl TWOFISH NettleGCM instance BlockCipher TWOFISH instance Cipher TWOFISH instance NettleBlockCipher TWOFISH instance NettleCipher TWOFISH instance AEADModeImpl SERPENT NettleGCM instance BlockCipher SERPENT instance Cipher SERPENT instance NettleBlockCipher SERPENT instance NettleCipher SERPENT instance AEADModeImpl DES_EDE3 NettleGCM instance BlockCipher DES_EDE3 instance Cipher DES_EDE3 instance NettleBlockCipher DES_EDE3 instance NettleCipher DES_EDE3 instance AEADModeImpl DES NettleGCM instance BlockCipher DES instance Cipher DES instance NettleBlockCipher DES instance NettleCipher DES instance AEADModeImpl CAST128 NettleGCM instance BlockCipher CAST128 instance Cipher CAST128 instance NettleBlockCipher CAST128 instance NettleCipher CAST128 instance AEADModeImpl Camellia256 NettleGCM instance BlockCipher Camellia256 instance Cipher Camellia256 instance NettleBlockCipher Camellia256 instance NettleCipher Camellia256 instance AEADModeImpl Camellia192 NettleGCM instance BlockCipher Camellia192 instance Cipher Camellia192 instance NettleBlockCipher Camellia192 instance NettleCipher Camellia192 instance AEADModeImpl Camellia128 NettleGCM instance BlockCipher Camellia128 instance Cipher Camellia128 instance NettleBlockCipher Camellia128 instance NettleCipher Camellia128 instance AEADModeImpl Camellia NettleGCM instance BlockCipher Camellia instance Cipher Camellia instance NettleBlockCipher Camellia instance NettleCipher Camellia instance AEADModeImpl BLOWFISH NettleGCM instance BlockCipher BLOWFISH instance Cipher BLOWFISH instance NettleBlockCipher BLOWFISH instance NettleCipher BLOWFISH instance AEADModeImpl ARCTWO NettleGCM instance BlockCipher ARCTWO instance Cipher ARCTWO instance NettleBlockCipher ARCTWO instance NettleCipher ARCTWO instance AEADModeImpl AES256 NettleGCM instance BlockCipher AES256 instance Cipher AES256 instance NettleBlockCipher AES256 instance NettleCipher AES256 instance AEADModeImpl AES192 NettleGCM instance BlockCipher AES192 instance Cipher AES192 instance NettleBlockCipher AES192 instance NettleCipher AES192 instance AEADModeImpl AES128 NettleGCM instance BlockCipher AES128 instance Cipher AES128 instance NettleBlockCipher AES128 instance NettleCipher AES128 instance AEADModeImpl AES NettleGCM instance BlockCipher AES instance Cipher AES instance NettleBlockCipher AES instance NettleCipher AES