Crypto.Cipher.RSA

cryptocipher-0.2.8: Symmetrical Block, Stream and PubKey Ciphers

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | Good
Safe Haskell | None
Language | Haskell98

Crypto.Cipher.RSA

Description

Synopsis

- data Error
  - = MessageSizeIncorrect
  - | MessageTooLong
  - | MessageNotRecognized
  - | SignatureTooLong
  - | RandomGenFailure GenError
  - | KeyInternalError
- data PublicKey = PublicKey {
  - public_sz :: Int
  - public_n :: Integer
  - public_e :: Integer
  }
- data PrivateKey = PrivateKey {
  - private_sz :: Int
  - private_n :: Integer
  - private_d :: Integer
  - private_p :: Integer
  - private_q :: Integer
  - private_dP :: Integer
  - private_dQ :: Integer
  - private_qinv :: Integer
  }
- type HashF = ByteString -> ByteString
- type HashASN1 = ByteString
- 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

data Error

Constructors

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

Instances

Eq Error |
Show Error |

data PublicKey

Constructors

PublicKey |
Fields public_sz :: Int size of key in bytes public_n :: Integer public p*q public_e :: Integer public exponant e

Instances

Show PublicKey |

data PrivateKey

Constructors

PrivateKey |
Fields private_sz :: Int size of key in bytes private_n :: Integer private p*q private_d :: Integer private exponant d private_p :: Integer p prime number private_q :: Integer q prime number private_dP :: Integer d mod (p-1) private_dQ :: Integer d mod (q-1) private_qinv :: Integer q^(-1) mod p

Instances

Show PrivateKey |

type HashF = ByteString -> ByteString

type HashASN1 = ByteString

decrypt :: PrivateKey -> ByteString -> Either Error ByteString

decrypt message using the private key.

encrypt :: CryptoRandomGen g => g -> PublicKey -> ByteString -> Either Error (ByteString, g)

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

sign message using private key, a hash and its ASN1 description

verify :: HashF -> HashASN1 -> PublicKey -> ByteString -> ByteString -> Either Error Bool

verify message with the signed message