    -- |
    -- Module      : Crypto.PubKey.RSA.Types
    -- License     : BSD-style
    -- Maintainer  : Vincent Hanquez <vincent@snarc.org>
    -- Stability   : experimental
    -- Portability : Good
    --
    {-# LANGUAGE DeriveDataTypeable #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    module Crypto.PubKey.RSA.Types
        ( Error(..)
        , Blinder(..)
        , PublicKey(..)
        , PrivateKey(..)
        , KeyPair(..)
        , toPublicKey
        , toPrivateKey
        , private_size
        , private_n
        , private_e
        ) where

    import           Data.Data
    import           Crypto.Internal.Imports

    -- | Blinder which is used to obfuscate the timing
    -- of the decryption primitive (used by decryption and signing).
    data Blinder = Blinder !Integer !Integer
                 deriving (Int -> Blinder -> ShowS
    [Blinder] -> ShowS
    Blinder -> String
    (Int -> Blinder -> ShowS)
    -> (Blinder -> String) -> ([Blinder] -> ShowS) -> Show Blinder
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [Blinder] -> ShowS
    $cshowList :: [Blinder] -> ShowS
    show :: Blinder -> String
    $cshow :: Blinder -> String
    showsPrec :: Int -> Blinder -> ShowS
    $cshowsPrec :: Int -> Blinder -> ShowS
    Show,Blinder -> Blinder -> Bool
    (Blinder -> Blinder -> Bool)
    -> (Blinder -> Blinder -> Bool) -> Eq Blinder
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Blinder -> Blinder -> Bool
    $c/= :: Blinder -> Blinder -> Bool
    == :: Blinder -> Blinder -> Bool
    $c== :: Blinder -> Blinder -> Bool
    Eq)

    -- | error possible during encryption, decryption or signing.
    data Error =
          MessageSizeIncorrect -- ^ the message to decrypt is not of the correct size (need to be == private_size)
        | MessageTooLong       -- ^ the message to encrypt is too long
        | MessageNotRecognized -- ^ the message decrypted doesn't have a PKCS15 structure (0 2 .. 0 msg)
        | SignatureTooLong     -- ^ the message's digest is too long
        | InvalidParameters    -- ^ some parameters lead to breaking assumptions.
        deriving (Int -> Error -> ShowS
    [Error] -> ShowS
    Error -> String
    (Int -> Error -> ShowS)
    -> (Error -> String) -> ([Error] -> ShowS) -> Show Error
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [Error] -> ShowS
    $cshowList :: [Error] -> ShowS
    show :: Error -> String
    $cshow :: Error -> String
    showsPrec :: Int -> Error -> ShowS
    $cshowsPrec :: Int -> Error -> ShowS
    Show,Error -> Error -> Bool
    (Error -> Error -> Bool) -> (Error -> Error -> Bool) -> Eq Error
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Error -> Error -> Bool
    $c/= :: Error -> Error -> Bool
    == :: Error -> Error -> Bool
    $c== :: Error -> Error -> Bool
    Eq)

    -- | Represent a RSA public key
    data PublicKey = PublicKey
        { PublicKey -> Int
    public_size :: Int      -- ^ size of key in bytes
        , PublicKey -> Integer
    public_n    :: Integer  -- ^ public p*q
        , PublicKey -> Integer
    public_e    :: Integer  -- ^ public exponent e
        } deriving (Int -> PublicKey -> ShowS
    [PublicKey] -> ShowS
    PublicKey -> String
    (Int -> PublicKey -> ShowS)
    -> (PublicKey -> String)
    -> ([PublicKey] -> ShowS)
    -> Show PublicKey
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [PublicKey] -> ShowS
    $cshowList :: [PublicKey] -> ShowS
    show :: PublicKey -> String
    $cshow :: PublicKey -> String
    showsPrec :: Int -> PublicKey -> ShowS
    $cshowsPrec :: Int -> PublicKey -> ShowS
    Show,ReadPrec [PublicKey]
    ReadPrec PublicKey
    Int -> ReadS PublicKey
    ReadS [PublicKey]
    (Int -> ReadS PublicKey)
    -> ReadS [PublicKey]
    -> ReadPrec PublicKey
    -> ReadPrec [PublicKey]
    -> Read PublicKey
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [PublicKey]
    $creadListPrec :: ReadPrec [PublicKey]
    readPrec :: ReadPrec PublicKey
    $creadPrec :: ReadPrec PublicKey
    readList :: ReadS [PublicKey]
    $creadList :: ReadS [PublicKey]
    readsPrec :: Int -> ReadS PublicKey
    $creadsPrec :: Int -> ReadS PublicKey
    Read,PublicKey -> PublicKey -> Bool
    (PublicKey -> PublicKey -> Bool)
    -> (PublicKey -> PublicKey -> Bool) -> Eq PublicKey
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: PublicKey -> PublicKey -> Bool
    $c/= :: PublicKey -> PublicKey -> Bool
    == :: PublicKey -> PublicKey -> Bool
    $c== :: PublicKey -> PublicKey -> Bool
    Eq,Typeable PublicKey
    DataType
    Constr
    Typeable PublicKey =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> PublicKey -> c PublicKey)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c PublicKey)
    -> (PublicKey -> Constr)
    -> (PublicKey -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c PublicKey))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PublicKey))
    -> ((forall b. Data b => b -> b) -> PublicKey -> PublicKey)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> PublicKey -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> PublicKey -> r)
    -> (forall u. (forall d. Data d => d -> u) -> PublicKey -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> PublicKey -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey)
    -> Data PublicKey
    PublicKey -> DataType
    PublicKey -> Constr
    (forall b. Data b => b -> b) -> PublicKey -> PublicKey
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PublicKey -> c PublicKey
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PublicKey
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> PublicKey -> u
    forall u. (forall d. Data d => d -> u) -> PublicKey -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PublicKey -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PublicKey -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PublicKey
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PublicKey -> c PublicKey
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PublicKey)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PublicKey)
    $cPublicKey :: Constr
    $tPublicKey :: DataType
    gmapMo :: (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    gmapMp :: (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    gmapM :: (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey
    gmapQi :: Int -> (forall d. Data d => d -> u) -> PublicKey -> u
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PublicKey -> u
    gmapQ :: (forall d. Data d => d -> u) -> PublicKey -> [u]
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> PublicKey -> [u]
    gmapQr :: (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PublicKey -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PublicKey -> r
    gmapQl :: (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PublicKey -> r
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PublicKey -> r
    gmapT :: (forall b. Data b => b -> b) -> PublicKey -> PublicKey
    $cgmapT :: (forall b. Data b => b -> b) -> PublicKey -> PublicKey
    dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PublicKey)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PublicKey)
    dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c PublicKey)
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PublicKey)
    dataTypeOf :: PublicKey -> DataType
    $cdataTypeOf :: PublicKey -> DataType
    toConstr :: PublicKey -> Constr
    $ctoConstr :: PublicKey -> Constr
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PublicKey
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PublicKey
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PublicKey -> c PublicKey
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PublicKey -> c PublicKey
    $cp1Data :: Typeable PublicKey
    Data)

    instance NFData PublicKey where
        rnf :: PublicKey -> ()
    rnf (PublicKey sz :: Int
    sz n :: Integer
    n e :: Integer
    e) = Integer -> ()
    forall a. NFData a => a -> ()
    rnf Integer
    n () -> () -> ()
    forall a b. a -> b -> b
    `seq` Integer -> ()
    forall a. NFData a => a -> ()
    rnf Integer
    e () -> () -> ()
    forall a b. a -> b -> b
    `seq` Int
    sz Int -> () -> ()
    forall a b. a -> b -> b
    `seq` ()

    -- | Represent a RSA private key.
    --
    -- Only the pub, 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
        { PrivateKey -> PublicKey
    private_pub  :: PublicKey -- ^ public part of a private key (size, n and e)
        , PrivateKey -> Integer
    private_d    :: Integer   -- ^ private exponent d
        , PrivateKey -> Integer
    private_p    :: Integer   -- ^ p prime number
        , PrivateKey -> Integer
    private_q    :: Integer   -- ^ q prime number
        , PrivateKey -> Integer
    private_dP   :: Integer   -- ^ d mod (p-1)
        , PrivateKey -> Integer
    private_dQ   :: Integer   -- ^ d mod (q-1)
        , PrivateKey -> Integer
    private_qinv :: Integer   -- ^ q^(-1) mod p
        } deriving (Int -> PrivateKey -> ShowS
    [PrivateKey] -> ShowS
    PrivateKey -> String
    (Int -> PrivateKey -> ShowS)
    -> (PrivateKey -> String)
    -> ([PrivateKey] -> ShowS)
    -> Show PrivateKey
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [PrivateKey] -> ShowS
    $cshowList :: [PrivateKey] -> ShowS
    show :: PrivateKey -> String
    $cshow :: PrivateKey -> String
    showsPrec :: Int -> PrivateKey -> ShowS
    $cshowsPrec :: Int -> PrivateKey -> ShowS
    Show,ReadPrec [PrivateKey]
    ReadPrec PrivateKey
    Int -> ReadS PrivateKey
    ReadS [PrivateKey]
    (Int -> ReadS PrivateKey)
    -> ReadS [PrivateKey]
    -> ReadPrec PrivateKey
    -> ReadPrec [PrivateKey]
    -> Read PrivateKey
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [PrivateKey]
    $creadListPrec :: ReadPrec [PrivateKey]
    readPrec :: ReadPrec PrivateKey
    $creadPrec :: ReadPrec PrivateKey
    readList :: ReadS [PrivateKey]
    $creadList :: ReadS [PrivateKey]
    readsPrec :: Int -> ReadS PrivateKey
    $creadsPrec :: Int -> ReadS PrivateKey
    Read,PrivateKey -> PrivateKey -> Bool
    (PrivateKey -> PrivateKey -> Bool)
    -> (PrivateKey -> PrivateKey -> Bool) -> Eq PrivateKey
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: PrivateKey -> PrivateKey -> Bool
    $c/= :: PrivateKey -> PrivateKey -> Bool
    == :: PrivateKey -> PrivateKey -> Bool
    $c== :: PrivateKey -> PrivateKey -> Bool
    Eq,Typeable PrivateKey
    DataType
    Constr
    Typeable PrivateKey =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> PrivateKey -> c PrivateKey)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c PrivateKey)
    -> (PrivateKey -> Constr)
    -> (PrivateKey -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c PrivateKey))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c PrivateKey))
    -> ((forall b. Data b => b -> b) -> PrivateKey -> PrivateKey)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r)
    -> (forall u. (forall d. Data d => d -> u) -> PrivateKey -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> PrivateKey -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey)
    -> Data PrivateKey
    PrivateKey -> DataType
    PrivateKey -> Constr
    (forall b. Data b => b -> b) -> PrivateKey -> PrivateKey
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PrivateKey -> c PrivateKey
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PrivateKey
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> PrivateKey -> u
    forall u. (forall d. Data d => d -> u) -> PrivateKey -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PrivateKey
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PrivateKey -> c PrivateKey
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PrivateKey)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PrivateKey)
    $cPrivateKey :: Constr
    $tPrivateKey :: DataType
    gmapMo :: (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    gmapMp :: (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    gmapM :: (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey
    gmapQi :: Int -> (forall d. Data d => d -> u) -> PrivateKey -> u
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PrivateKey -> u
    gmapQ :: (forall d. Data d => d -> u) -> PrivateKey -> [u]
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> PrivateKey -> [u]
    gmapQr :: (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r
    gmapQl :: (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r
    gmapT :: (forall b. Data b => b -> b) -> PrivateKey -> PrivateKey
    $cgmapT :: (forall b. Data b => b -> b) -> PrivateKey -> PrivateKey
    dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PrivateKey)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PrivateKey)
    dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c PrivateKey)
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PrivateKey)
    dataTypeOf :: PrivateKey -> DataType
    $cdataTypeOf :: PrivateKey -> DataType
    toConstr :: PrivateKey -> Constr
    $ctoConstr :: PrivateKey -> Constr
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PrivateKey
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PrivateKey
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PrivateKey -> c PrivateKey
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PrivateKey -> c PrivateKey
    $cp1Data :: Typeable PrivateKey
    Data)

    instance NFData PrivateKey where
        rnf :: PrivateKey -> ()
    rnf (PrivateKey pub :: PublicKey
    pub d :: Integer
    d p :: Integer
    p q :: Integer
    q dp :: Integer
    dp dq :: Integer
    dq qinv :: Integer
    qinv) =
            PublicKey -> ()
    forall a. NFData a => a -> ()
    rnf PublicKey
    pub () -> () -> ()
    forall a b. a -> b -> b
    `seq` Integer -> ()
    forall a. NFData a => a -> ()
    rnf Integer
    d () -> () -> ()
    forall a b. a -> b -> b
    `seq` Integer -> ()
    forall a. NFData a => a -> ()
    rnf Integer
    p () -> () -> ()
    forall a b. a -> b -> b
    `seq` Integer -> ()
    forall a. NFData a => a -> ()
    rnf Integer
    q () -> () -> ()
    forall a b. a -> b -> b
    `seq` Integer -> ()
    forall a. NFData a => a -> ()
    rnf Integer
    dp () -> () -> ()
    forall a b. a -> b -> b
    `seq` Integer -> ()
    forall a. NFData a => a -> ()
    rnf Integer
    dq () -> () -> ()
    forall a b. a -> b -> b
    `seq` Integer
    qinv Integer -> () -> ()
    forall a b. a -> b -> b
    `seq` ()

    -- | get the size in bytes from a private key
    private_size :: PrivateKey -> Int
    private_size :: PrivateKey -> Int
    private_size = PublicKey -> Int
    public_size (PublicKey -> Int)
    -> (PrivateKey -> PublicKey) -> PrivateKey -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . PrivateKey -> PublicKey
    private_pub

    -- | get n from a private key
    private_n :: PrivateKey -> Integer
    private_n :: PrivateKey -> Integer
    private_n = PublicKey -> Integer
    public_n (PublicKey -> Integer)
    -> (PrivateKey -> PublicKey) -> PrivateKey -> Integer
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . PrivateKey -> PublicKey
    private_pub

    -- | get e from a private key
    private_e :: PrivateKey -> Integer
    private_e :: PrivateKey -> Integer
    private_e = PublicKey -> Integer
    public_e (PublicKey -> Integer)
    -> (PrivateKey -> PublicKey) -> PrivateKey -> Integer
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . PrivateKey -> PublicKey
    private_pub

    -- | Represent RSA KeyPair
    --
    -- note the RSA private key contains already an instance of public key for efficiency
    newtype KeyPair = KeyPair PrivateKey
        deriving (Int -> KeyPair -> ShowS
    [KeyPair] -> ShowS
    KeyPair -> String
    (Int -> KeyPair -> ShowS)
    -> (KeyPair -> String) -> ([KeyPair] -> ShowS) -> Show KeyPair
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [KeyPair] -> ShowS
    $cshowList :: [KeyPair] -> ShowS
    show :: KeyPair -> String
    $cshow :: KeyPair -> String
    showsPrec :: Int -> KeyPair -> ShowS
    $cshowsPrec :: Int -> KeyPair -> ShowS
    Show,ReadPrec [KeyPair]
    ReadPrec KeyPair
    Int -> ReadS KeyPair
    ReadS [KeyPair]
    (Int -> ReadS KeyPair)
    -> ReadS [KeyPair]
    -> ReadPrec KeyPair
    -> ReadPrec [KeyPair]
    -> Read KeyPair
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [KeyPair]
    $creadListPrec :: ReadPrec [KeyPair]
    readPrec :: ReadPrec KeyPair
    $creadPrec :: ReadPrec KeyPair
    readList :: ReadS [KeyPair]
    $creadList :: ReadS [KeyPair]
    readsPrec :: Int -> ReadS KeyPair
    $creadsPrec :: Int -> ReadS KeyPair
    Read,KeyPair -> KeyPair -> Bool
    (KeyPair -> KeyPair -> Bool)
    -> (KeyPair -> KeyPair -> Bool) -> Eq KeyPair
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: KeyPair -> KeyPair -> Bool
    $c/= :: KeyPair -> KeyPair -> Bool
    == :: KeyPair -> KeyPair -> Bool
    $c== :: KeyPair -> KeyPair -> Bool
    Eq,Typeable KeyPair
    DataType
    Constr
    Typeable KeyPair =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> KeyPair -> c KeyPair)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c KeyPair)
    -> (KeyPair -> Constr)
    -> (KeyPair -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c KeyPair))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c KeyPair))
    -> ((forall b. Data b => b -> b) -> KeyPair -> KeyPair)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> KeyPair -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> KeyPair -> r)
    -> (forall u. (forall d. Data d => d -> u) -> KeyPair -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> KeyPair -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair)
    -> Data KeyPair
    KeyPair -> DataType
    KeyPair -> Constr
    (forall b. Data b => b -> b) -> KeyPair -> KeyPair
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> KeyPair -> c KeyPair
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c KeyPair
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> KeyPair -> u
    forall u. (forall d. Data d => d -> u) -> KeyPair -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> KeyPair -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> KeyPair -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c KeyPair
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> KeyPair -> c KeyPair
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c KeyPair)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c KeyPair)
    $cKeyPair :: Constr
    $tKeyPair :: DataType
    gmapMo :: (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    gmapMp :: (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    gmapM :: (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> KeyPair -> m KeyPair
    gmapQi :: Int -> (forall d. Data d => d -> u) -> KeyPair -> u
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> KeyPair -> u
    gmapQ :: (forall d. Data d => d -> u) -> KeyPair -> [u]
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> KeyPair -> [u]
    gmapQr :: (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> KeyPair -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> KeyPair -> r
    gmapQl :: (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> KeyPair -> r
    $cgmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> KeyPair -> r
    gmapT :: (forall b. Data b => b -> b) -> KeyPair -> KeyPair
    $cgmapT :: (forall b. Data b => b -> b) -> KeyPair -> KeyPair
    dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c KeyPair)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c KeyPair)
    dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c KeyPair)
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c KeyPair)
    dataTypeOf :: KeyPair -> DataType
    $cdataTypeOf :: KeyPair -> DataType
    toConstr :: KeyPair -> Constr
    $ctoConstr :: KeyPair -> Constr
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c KeyPair
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c KeyPair
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> KeyPair -> c KeyPair
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> KeyPair -> c KeyPair
    $cp1Data :: Typeable KeyPair
    Data,KeyPair -> ()
    (KeyPair -> ()) -> NFData KeyPair
    forall a. (a -> ()) -> NFData a
    rnf :: KeyPair -> ()
    $crnf :: KeyPair -> ()
    NFData)

    -- | Public key of a RSA KeyPair
    toPublicKey :: KeyPair -> PublicKey
    toPublicKey :: KeyPair -> PublicKey
    toPublicKey (KeyPair priv :: PrivateKey
    priv) = PrivateKey -> PublicKey
    private_pub PrivateKey
    priv

    -- | Private key of a RSA KeyPair
    toPrivateKey :: KeyPair -> PrivateKey
    toPrivateKey :: KeyPair -> PrivateKey
    toPrivateKey (KeyPair priv :: PrivateKey
    priv) = PrivateKey
    priv