crypton-1.0.4: Cryptography Primitives sink

License | BSD-style
Maintainer | Carlos Rodriguez-Vega <crodveg@yahoo.es>
Stability | experimental
Portability | unknown
Safe Haskell | None
Language | Haskell2010

Crypto.PubKey.Rabin.Basic

Description

Rabin cryptosystem for public-key cryptography and digital signature.

Synopsis

- data PublicKey = PublicKey {
  - public_size :: Int
  - public_n :: Integer
  }
- data PrivateKey = PrivateKey {
  - private_pub :: PublicKey
  - private_p :: Integer
  - private_q :: Integer
  - private_a :: Integer
  - private_b :: Integer
  }
- data Signature = Signature (Integer, Integer)
- generate :: MonadRandom m => Int -> m (PublicKey, PrivateKey)
- encrypt :: (HashAlgorithm hash, MonadRandom m) => OAEPParams hash ByteString ByteString -> PublicKey -> ByteString -> m (Either Error ByteString)
- encryptWithSeed :: HashAlgorithm hash => ByteString -> OAEPParams hash ByteString ByteString -> PublicKey -> ByteString -> Either Error ByteString
- decrypt :: HashAlgorithm hash => OAEPParams hash ByteString ByteString -> PrivateKey -> ByteString -> Maybe ByteString
- sign :: (MonadRandom m, HashAlgorithm hash) => PrivateKey -> hash -> ByteString -> m (Either Error Signature)
- signWith :: HashAlgorithm hash => ByteString -> PrivateKey -> hash -> ByteString -> Either Error Signature
- verify :: HashAlgorithm hash => PublicKey -> hash -> ByteString -> Signature -> Bool

# Documentation

data PublicKey Source #

Represent a Rabin public key.

Constructors

PublicKey |

Fields

- public_size :: Int

  size of key in bytes

- public_n :: Integer

  public p*q

#### Instances

Instances details

Data PublicKey Source # |

Instance details

Defined in Crypto.PubKey.Rabin.Basic

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PublicKey -> c PublicKey Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PublicKey Source #

toConstr :: PublicKey -> Constr Source #

dataTypeOf :: PublicKey -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PublicKey) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PublicKey) Source #

gmapT :: (forall b. Data b => b -> b) -> PublicKey -> PublicKey Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PublicKey -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PublicKey -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> PublicKey -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> PublicKey -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey Source #

Read PublicKey Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods readsPrec :: Int -> ReadS PublicKey Source # readList :: ReadS [PublicKey] Source # readPrec :: ReadPrec PublicKey Source # readListPrec :: ReadPrec [PublicKey] Source #
Show PublicKey Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods showsPrec :: Int -> PublicKey -> ShowS Source # show :: PublicKey -> String Source # showList :: [PublicKey] -> ShowS Source #
Eq PublicKey Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods (==) :: PublicKey -> PublicKey -> Bool Source # (/=) :: PublicKey -> PublicKey -> Bool Source #

data PrivateKey Source #

Represent a Rabin private key.

Constructors

PrivateKey |

Fields

- private_pub :: PublicKey
- private_p :: Integer

  p prime number

- private_q :: Integer

  q prime number

- private_a :: Integer
- private_b :: Integer

#### Instances

Instances details

Data PrivateKey Source # |

Instance details

Defined in Crypto.PubKey.Rabin.Basic

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PrivateKey -> c PrivateKey Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PrivateKey Source #

toConstr :: PrivateKey -> Constr Source #

dataTypeOf :: PrivateKey -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PrivateKey) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PrivateKey) Source #

gmapT :: (forall b. Data b => b -> b) -> PrivateKey -> PrivateKey Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> PrivateKey -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> PrivateKey -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey Source #

Read PrivateKey Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods readsPrec :: Int -> ReadS PrivateKey Source # readList :: ReadS [PrivateKey] Source # readPrec :: ReadPrec PrivateKey Source # readListPrec :: ReadPrec [PrivateKey] Source #
Show PrivateKey Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods showsPrec :: Int -> PrivateKey -> ShowS Source # show :: PrivateKey -> String Source # showList :: [PrivateKey] -> ShowS Source #
Eq PrivateKey Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods (==) :: PrivateKey -> PrivateKey -> Bool Source # (/=) :: PrivateKey -> PrivateKey -> Bool Source #

data Signature Source #

Rabin Signature.

Constructors

Signature (Integer, Integer) |

#### Instances

Instances details

Data Signature Source # |

Instance details

Defined in Crypto.PubKey.Rabin.Basic

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Signature -> c Signature Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Signature Source #

toConstr :: Signature -> Constr Source #

dataTypeOf :: Signature -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Signature) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Signature) Source #

gmapT :: (forall b. Data b => b -> b) -> Signature -> Signature Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Signature -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Signature -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Signature -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Signature -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Signature -> m Signature Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Signature -> m Signature Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Signature -> m Signature Source #

Read Signature Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods readsPrec :: Int -> ReadS Signature Source # readList :: ReadS [Signature] Source # readPrec :: ReadPrec Signature Source # readListPrec :: ReadPrec [Signature] Source #
Show Signature Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods showsPrec :: Int -> Signature -> ShowS Source # show :: Signature -> String Source # showList :: [Signature] -> ShowS Source #
Eq Signature Source # |
Instance details Defined in Crypto.PubKey.Rabin.Basic Methods (==) :: Signature -> Signature -> Bool Source # (/=) :: Signature -> Signature -> Bool Source #

generate :: MonadRandom m => Int -> m (PublicKey, PrivateKey) Source #

Generate a pair of (private, public) key of size in bytes. Primes p and q are both congruent 3 mod 4.

See algorithm 8.11 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.

encrypt Source #

Arguments

:: (HashAlgorithm hash, MonadRandom m) |
=> OAEPParams hash ByteString ByteString | OAEP padding parameters
-> PublicKey | public key
-> ByteString | plaintext
-> m (Either Error ByteString) |

Encrypt plaintext using public key.

encryptWithSeed Source #

Arguments

:: HashAlgorithm hash |
=> ByteString | Seed
-> OAEPParams hash ByteString ByteString | OAEP padding
-> PublicKey | public key
-> ByteString | plaintext
-> Either Error ByteString |

Encrypt plaintext using public key an a predefined OAEP seed.

See algorithm 8.11 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.

decrypt Source #

Arguments

:: HashAlgorithm hash |
=> OAEPParams hash ByteString ByteString | OAEP padding parameters
-> PrivateKey | private key
-> ByteString | ciphertext
-> Maybe ByteString |

Decrypt ciphertext using private key.

See algorithm 8.12 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.

sign Source #

Arguments

:: (MonadRandom m, HashAlgorithm hash) |
=> PrivateKey | private key
-> hash | hash function
-> ByteString | message to sign
-> m (Either Error Signature) |

Sign message using hash algorithm and private key.

See https://en.wikipedia.org/wiki/Rabin_signature_algorithm.

signWith Source #

Arguments

:: HashAlgorithm hash |
=> ByteString | padding
-> PrivateKey | private key
-> hash | hash function
-> ByteString | message to sign
-> Either Error Signature |

Sign message using padding, hash algorithm and private key.

See https://en.wikipedia.org/wiki/Rabin_signature_algorithm.

verify Source #

Arguments

:: HashAlgorithm hash |
=> PublicKey | private key
-> hash | hash function
-> ByteString | message
-> Signature | signature
-> Bool |

Verify signature using hash algorithm and public key.

See https://en.wikipedia.org/wiki/Rabin_signature_algorithm.