| crypto-api-0.2.1: A generic interface for cryptographic operations | Contents | Index
Crypto.Classes |
Portability | portable
Stability | beta
Maintainer | Thomas.DuBuisson@gmail.com
Description
This is the heart of the crypto-api package. By making (or having) an instance of Hash, AsymCipher, BlockCipher or StreamCipher you provide (or obtain) access to any infrastructure built on these primitives include block cipher modes of operation, hashing, hmac, signing, etc. These classes allow users to build routines that are agnostic to the algorithm used so changing algorithms is as simple as changing a type signature.
Synopsis
class (Serialize d, Eq d, Ord d) => Hash ctx d | d -> ctx, ctx -> d where
outputLength :: Tagged d BitLength
blockLength :: Tagged d BitLength
initialCtx :: ctx
updateCtx :: ctx -> ByteString -> ctx
finalize :: ctx -> ByteString -> d
class Serialize k => BlockCipher k where
blockSize :: Tagged k BitLength
encryptBlock :: k -> ByteString -> ByteString
decryptBlock :: k -> ByteString -> ByteString
buildKey :: ByteString -> Maybe k
keyLength :: k -> BitLength
blockSizeBytes :: BlockCipher k => Tagged k ByteLength
class Serialize k => StreamCipher k iv | k -> iv where
buildStreamKey :: ByteString -> Maybe k
encryptStream :: k -> iv -> ByteString -> (ByteString, iv)
decryptStream :: k -> iv -> ByteString -> (ByteString, iv)
streamKeyLength :: k -> BitLength
class Serialize p => AsymCipher p where
buildKeyPair :: CryptoRandomGen g => g -> BitLength -> Maybe ((p, p), g)
encryptAsym :: p -> ByteString -> ByteString
decryptAsym :: p -> ByteString -> ByteString
asymKeyLength :: p -> BitLength
class (Serialize p, Serialize v) => Signing p v | p -> v, v -> p where
sign :: v -> ByteString -> ByteString
verify :: p -> ByteString -> ByteString -> Bool
buildSigningPair :: CryptoRandomGen g => g -> BitLength -> Maybe ((p, v), g)
signingKeyLength :: v -> BitLength
verifyingKeyLength :: p -> BitLength
for :: Tagged a b -> a -> b
(.::.) :: Tagged a b -> a -> b
hash :: Hash ctx d => ByteString -> d
hash' :: Hash ctx d => ByteString -> d
hashFunc :: Hash c d => d -> ByteString -> d
hashFunc' :: Hash c d => d -> ByteString -> d
Documentation
class (Serialize d, Eq d, Ord d) => Hash ctx d | d -> ctx, ctx -> d where
The Hash class is intended as the generic interface targeted by maintainers of Haskell digest implementations. Using this generic interface, higher level functions such as `hash` and `hash'` provide a useful API for comsumers of hash implementations. Any instantiated implementation must handle unaligned data
Methods
outputLength
:: Tagged d BitLength | The size of the digest when encoded
blockLength
:: Tagged d BitLength | The amount of data operated on in each round of the digest computation
initialCtx
:: ctx | An initial context, provided with the first call to `updateCtx`
updateCtx
:: ctx |
-> ByteString |
-> ctx | Used to update a context, repeatedly called until all data is exhausted must operate correctly for imputs of `n*blockLength` bytes for `n `elem` [0..]`
finalize
:: ctx |
-> ByteString |
-> d | Finializing a context, plus any message data less than the block size, into a digest
class Serialize k => BlockCipher k where
The BlockCipher class is intended as the generic interface targeted by maintainers of Haskell cipher implementations. Using this generic interface higher level functions such as cbc, and other functions from Data.Crypto.Modes, provide a useful API for comsumers of cipher implementations. Instances must handle unaligned data
Methods
blockSize
:: Tagged k BitLength | The size of a single block; the smallest unit on which the cipher operates.
encryptBlock
:: k |
-> ByteString |
-> ByteString | encrypt data of size `n*blockSize` where `n `elem` [0..]` (ecb encryption)
decryptBlock
:: k |
-> ByteString |
-> ByteString | decrypt data of size `n*blockSize` where `n `elem` [0..]` (ecb decryption)
buildKey
:: ByteString |
-> Maybe k | smart constructor for keys from a bytestring.
keyLength
:: k |
-> BitLength | keyLength may inspect its argument to return the length
blockSizeBytes :: BlockCipher k => Tagged k ByteLength
class Serialize k => StreamCipher k iv | k -> iv where
A stream cipher class. Instance are expected to work on messages as small as one byte The length of the resulting cipher text should be equal to the length of the input message.
Methods
buildStreamKey :: ByteString -> Maybe k
encryptStream :: k -> iv -> ByteString -> (ByteString, iv)
decryptStream :: k -> iv -> ByteString -> (ByteString, iv)
streamKeyLength :: k -> BitLength
class Serialize p => AsymCipher p where
Asymetric ciphers (common ones being RSA or EC based)
Methods
buildKeyPair
:: CryptoRandomGen g |
=> g |
-> BitLength |
-> Maybe ((p, p), g) | build a public/private key pair using the provided generator
encryptAsym
:: p |
-> ByteString |
-> ByteString | Asymetric encryption
decryptAsym
:: p |
-> ByteString |
-> ByteString | Asymetric decryption
asymKeyLength :: p -> BitLength
class (Serialize p, Serialize v) => Signing p v | p -> v, v -> p where
A class for signing operations which inherently can not be as generic as asymetric ciphers (ex: DSA).
Methods
sign :: v -> ByteString -> ByteString
verify :: p -> ByteString -> ByteString -> Bool
buildSigningPair :: CryptoRandomGen g => g -> BitLength -> Maybe ((p, v), g)
signingKeyLength :: v -> BitLength
verifyingKeyLength :: p -> BitLength
for :: Tagged a b -> a -> b
Obtain a tagged value for a given type
(.::.) :: Tagged a b -> a -> b
Infix `for` operator
hash :: Hash ctx d => ByteString -> d
Hash a lazy ByteString, creating a digest
hash' :: Hash ctx d => ByteString -> d
Hash a strict ByteString, creating a digest
hashFunc :: Hash c d => d -> ByteString -> d
Obtain a lazy hash function from a digest
hashFunc' :: Hash c d => d -> ByteString -> d
Obtain a strict hash function from a digest
Produced by Haddock version 2.7.2