Crypto.PubKey.Rabin.RW

crypton-1.0.1: 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.RW

Description

Rabin-Williams cryptosystem for public-key encryption and digital signature. See pages 323 - 324 in "Computational Number Theory and Modern Cryptography" by Song Y. Yan. Also inspired by https://github.com/vanilala/vncrypt/blob/master/vncrypt/vnrw_gmp.c.

Synopsis

- data PublicKey = PublicKey {
  - public_size :: Int
  - public_n :: Integer
  }
- data PrivateKey = PrivateKey {
  - private_pub :: PublicKey
  - private_p :: Integer
  - private_q :: Integer
  - private_d :: 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 :: HashAlgorithm hash => PrivateKey -> hash -> ByteString -> Either Error Integer
- verify :: HashAlgorithm hash => PublicKey -> hash -> ByteString -> Integer -> Bool

# Documentation

data PublicKey #

Represent a Rabin-Williams public key.

Constructors

PublicKey |
Fields public_size :: Int size of key in bytes public_n :: Integer public p*q

#### Instances

Instances details

Data PublicKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PublicKey -> c PublicKey # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PublicKey # toConstr :: PublicKey -> Constr # dataTypeOf :: PublicKey -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PublicKey) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PublicKey) # gmapT :: (forall b. Data b => b -> b) -> PublicKey -> PublicKey # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PublicKey -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PublicKey -> r # gmapQ :: (forall d. Data d => d -> u) -> PublicKey -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> PublicKey -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PublicKey -> m PublicKey #
Read PublicKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods readsPrec :: Int -> ReadS PublicKey # readList :: ReadS [PublicKey] # readPrec :: ReadPrec PublicKey # readListPrec :: ReadPrec [PublicKey] #
Show PublicKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods showsPrec :: Int -> PublicKey -> ShowS # show :: PublicKey -> String # showList :: [PublicKey] -> ShowS #
Eq PublicKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods (==) :: PublicKey -> PublicKey -> Bool # (/=) :: PublicKey -> PublicKey -> Bool #

data PrivateKey #

Represent a Rabin-Williams private key.

Constructors

PrivateKey |
Fields private_pub :: PublicKey private_p :: Integer p prime number private_q :: Integer q prime number private_d :: Integer

#### Instances

Instances details

Data PrivateKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PrivateKey -> c PrivateKey # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PrivateKey # toConstr :: PrivateKey -> Constr # dataTypeOf :: PrivateKey -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PrivateKey) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PrivateKey) # gmapT :: (forall b. Data b => b -> b) -> PrivateKey -> PrivateKey # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PrivateKey -> r # gmapQ :: (forall d. Data d => d -> u) -> PrivateKey -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> PrivateKey -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PrivateKey -> m PrivateKey #
Read PrivateKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods readsPrec :: Int -> ReadS PrivateKey # readList :: ReadS [PrivateKey] # readPrec :: ReadPrec PrivateKey # readListPrec :: ReadPrec [PrivateKey] #
Show PrivateKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods showsPrec :: Int -> PrivateKey -> ShowS # show :: PrivateKey -> String # showList :: [PrivateKey] -> ShowS #
Eq PrivateKey # |
Instance details Defined in Crypto.PubKey.Rabin.RW Methods (==) :: PrivateKey -> PrivateKey -> Bool # (/=) :: PrivateKey -> PrivateKey -> Bool #

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

Generate a pair of (private, public) key of size in bytes. Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8.

encrypt #

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 #

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 #

Arguments

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

Decrypt ciphertext using private key.

sign #

Arguments

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

Sign message using hash algorithm and private key.

verify #

Arguments

:: HashAlgorithm hash |
=> PublicKey | public key
-> hash | hash function
-> ByteString | message
-> Integer | signature
-> Bool |

Verify signature using hash algorithm and public key.