License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | Good |
Safe Haskell | None |
Language | Haskell98 |
- data Error
- data PublicKey :: * = PublicKey {}
- data PrivateKey :: * = PrivateKey {}
- type HashF = ByteString -> ByteString
- type HashASN1 = ByteString
- generate :: CryptoRandomGen g => g -> Int -> Integer -> Either Error ((PublicKey, PrivateKey), g)
- decrypt :: PrivateKey -> ByteString -> Either Error ByteString
- encrypt :: CryptoRandomGen g => g -> PublicKey -> ByteString -> Either Error (ByteString, g)
- sign :: HashF -> HashASN1 -> PrivateKey -> ByteString -> Either Error ByteString
- verify :: HashF -> HashASN1 -> PublicKey -> ByteString -> ByteString -> Either Error Bool
Documentation
MessageSizeIncorrect | the message to decrypt is not of the correct size (need to be == private_size) |
MessageTooLong | the message to encrypt is too long (>= private_size - 11) |
MessageNotRecognized | the message decrypted doesn't have a PKCS15 structure (0 2 .. 0 msg) |
SignatureTooLong | the signature generated through the hash is too long to process with this key |
RandomGenFailure GenError | the random generator returns an error. give the opportunity to reseed for example. |
KeyInternalError | the whole key is probably not valid, since the message is bigger than the key size |
data PrivateKey :: *
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.
PrivateKey | |
|
type HashF = ByteString -> ByteString Source
type HashASN1 = ByteString Source
generate :: CryptoRandomGen g => g -> Int -> Integer -> Either Error ((PublicKey, PrivateKey), g) Source
generate a pair of (private, public) key of size in bytes.
decrypt :: PrivateKey -> ByteString -> Either Error ByteString Source
decrypt message using the private key.
encrypt :: CryptoRandomGen g => g -> PublicKey -> ByteString -> Either Error (ByteString, g) Source
encrypt a bytestring using the public key and a CryptoRandomGen random generator. - the message need to be smaller than the key size - 11
sign :: HashF -> HashASN1 -> PrivateKey -> ByteString -> Either Error ByteString Source
sign message using private key, a hash and its ASN1 description
verify :: HashF -> HashASN1 -> PublicKey -> ByteString -> ByteString -> Either Error Bool Source
verify message with the signed message