-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Symmetrical Block, Stream and PubKey Ciphers -- -- Symmetrical Block, Stream and PubKey Ciphers @package cryptocipher @version 0.3.5 module Crypto.Cipher.DSA data Error -- | signature is not valid r or s is not between the bound 0..q InvalidSignature :: Error -- | the random generator returns an error. give the opportunity to reseed -- for example. RandomGenFailure :: GenError -> Error -- | Represent DSA parameters namely P, G, and Q. type Params = (Integer, Integer, Integer) -- | Represent a DSA signature namely R and S. type Signature = (Integer, Integer) -- | Represent a DSA public key. data PublicKey :: * PublicKey :: Params -> Integer -> PublicKey -- | DSA parameters public_params :: PublicKey -> Params -- | DSA public Y public_y :: PublicKey -> Integer -- | Represent a DSA private key. -- -- Only x need to be secret. the DSA parameters are publicly shared with -- the other side. data PrivateKey :: * PrivateKey :: Params -> Integer -> PrivateKey -- | DSA parameters private_params :: PrivateKey -> Params -- | DSA private X private_x :: PrivateKey -> Integer -- | sign message using the private key. sign :: CryptoRandomGen g => g -> (ByteString -> ByteString) -> PrivateKey -> ByteString -> Either GenError (Signature, g) -- | verify a bytestring using the public key. verify :: Signature -> (ByteString -> ByteString) -> PublicKey -> ByteString -> Either Error Bool instance Show Error instance Eq Error module Crypto.Cipher.DH -- | Represent Diffie Hellman parameters namely P (prime), and G -- (generator). type Params = (Integer, Integer) -- | Represent Diffie Hellman public number Y. data PublicNumber :: * -- | Represent Diffie Hellman private number X. data PrivateNumber :: * -- | Represent Diffie Hellman shared secret. data SharedKey :: * -- | generate params from a specific generator (2 or 5 are common values) -- we generate a safe prime (a prime number of the form 2p+1 where p is -- also prime) generateParams :: CryptoRandomGen g => g -> Int -> Integer -> Either GenError (Params, g) -- | generate a private number with no specific property this number is -- usually called X in DH text. generatePrivate :: CryptoRandomGen g => g -> Int -> Either GenError (PrivateNumber, g) -- | generate a public number that is for the other party benefits. this -- number is usually called Y in DH text. generatePublic :: Params -> PrivateNumber -> PublicNumber -- | generate a shared key using our private number and the other party -- public number getShared :: Params -> PrivateNumber -> PublicNumber -> SharedKey module Crypto.Cipher.RSA data Error -- | the message to decrypt is not of the correct size (need to be == -- private_size) MessageSizeIncorrect :: Error -- | the message to encrypt is too long (>= private_size - 11) MessageTooLong :: Error -- | the message decrypted doesn't have a PKCS15 structure (0 2 .. 0 msg) MessageNotRecognized :: Error -- | the signature generated through the hash is too long to process with -- this key SignatureTooLong :: Error -- | the random generator returns an error. give the opportunity to reseed -- for example. RandomGenFailure :: GenError -> Error -- | the whole key is probably not valid, since the message is bigger than -- the key size KeyInternalError :: Error -- | Represent a RSA public key data PublicKey :: * PublicKey :: Int -> Integer -> Integer -> PublicKey -- | size of key in bytes public_size :: PublicKey -> Int -- | public p*q public_n :: PublicKey -> Integer -- | public exponant e public_e :: PublicKey -> Integer -- | Represent a RSA private key. -- -- Only the sz, n and d fields are mandatory to fill. -- -- p, q, dP, dQ, qinv are by-product during RSA generation, but are -- useful to record here to speed up massively the decrypt and sign -- operation. -- -- implementations can leave optional fields to 0. data PrivateKey :: * PrivateKey :: Int -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> PrivateKey -- | size of key in bytes private_size :: PrivateKey -> Int -- | private p*q private_n :: PrivateKey -> Integer -- | private exponant d private_d :: PrivateKey -> Integer -- | p prime number private_p :: PrivateKey -> Integer -- | q prime number private_q :: PrivateKey -> Integer -- | d mod (p-1) private_dP :: PrivateKey -> Integer -- | d mod (q-1) private_dQ :: PrivateKey -> Integer -- | q^(-1) mod p private_qinv :: PrivateKey -> Integer type HashF = ByteString -> ByteString type HashASN1 = ByteString -- | generate a pair of (private, public) key of size in bytes. generate :: CryptoRandomGen g => g -> Int -> Integer -> Either Error ((PublicKey, PrivateKey), g) -- | decrypt message using the private key. decrypt :: PrivateKey -> ByteString -> Either Error ByteString -- | encrypt a bytestring using the public key and a CryptoRandomGen random -- generator. - the message need to be smaller than the key size - 11 encrypt :: CryptoRandomGen g => g -> PublicKey -> ByteString -> Either Error (ByteString, g) -- | sign message using private key, a hash and its ASN1 description sign :: HashF -> HashASN1 -> PrivateKey -> ByteString -> Either Error ByteString -- | verify message with the signed message verify :: HashF -> HashASN1 -> PublicKey -> ByteString -> ByteString -> Either Error Bool instance Show Error instance Eq Error -- | this only cover Camellia 128 bits for now, API will change once 192 -- and 256 mode are implemented too module Crypto.Cipher.Camellia data Key Key :: Vector Word64 -> Vector Word64 -> Vector Word64 -> Key k :: Key -> Vector Word64 kw :: Key -> Vector Word64 ke :: Key -> Vector Word64 initKey128 :: ByteString -> Either String Key -- | encrypt with the key a bytestring and returns the encrypted bytestring encrypt :: Key -> ByteString -> ByteString -- | decrypt with the key a bytestring and returns the encrypted bytestring decrypt :: Key -> ByteString -> ByteString instance Show Word128 instance Eq Word128 instance Show Key module Crypto.Cipher.Blowfish data Blowfish data Key initKey :: ByteString -> Either String Key encrypt, decrypt :: Key -> ByteString -> ByteString instance Eq Key instance Show Key instance BlockCipher Blowfish instance Serialize Key instance Serialize Blowfish module Crypto.Cipher.AES.Haskell data Key type IV = ByteString -- | encrypt using simple EBC mode encrypt :: Key -> ByteString -> ByteString -- | decrypt using simple EBC mode decrypt :: Key -> ByteString -> ByteString -- | encrypt using CBC mode - IV need to be 16 bytes and the data to -- encrypt a multiple of 16 bytes encryptCBC :: Key -> IV -> ByteString -> ByteString -- | decrypt using CBC mode - IV need to be 16 bytes and the data to -- decrypt a multiple of 16 bytes decryptCBC :: Key -> IV -> ByteString -> ByteString initKey128, initKey256, initKey192 :: ByteString -> Either String Key data AES128 data AES192 data AES256 instance Show Key instance Eq Key instance Serialize AES256 instance Serialize AES192 instance Serialize AES128 instance BlockCipher AES256 instance BlockCipher AES192 instance BlockCipher AES128 module Crypto.Cipher.AES module Crypto.Cipher.RC4 type Ctx = (Vector Word8, Word8, Word8) -- | initCtx initialize the Ctx with the key as parameter. the key can be -- of any size but not empty initCtx :: [Word8] -> Ctx -- | encrypt with the current context a bytestring and returns a new -- context and the resulted encrypted bytestring encrypt :: Ctx -> ByteString -> (Ctx, ByteString) -- | decrypt with the current context a bytestring and returns a new -- context and the resulted decrypted bytestring decrypt :: Ctx -> ByteString -> (Ctx, ByteString) -- | encrypt with the current context a lazy bytestring and returns a new -- context and the resulted lencrypted lazy bytestring encryptlazy :: Ctx -> ByteString -> (Ctx, ByteString) -- | decrypt with the current context a lazy bytestring and returns a new -- context and the resulted decrypted lazy bytestring decryptlazy :: Ctx -> ByteString -> (Ctx, ByteString)