Crypto.PubKey.DH

crypton-1.0.1: Cryptography Primitives sink

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

Crypto.PubKey.DH

Description

Synopsis

- data Params = Params {
  - params_p :: Integer
  - params_g :: Integer
  - params_bits :: Int
  }
- newtype PublicNumber = PublicNumber Integer
- newtype PrivateNumber = PrivateNumber Integer
- newtype SharedKey = SharedKey ScrubbedBytes
- generateParams :: MonadRandom m => Int -> Integer -> m Params
- generatePrivate :: MonadRandom m => Params -> m PrivateNumber
- calculatePublic :: Params -> PrivateNumber -> PublicNumber
- generatePublic :: Params -> PrivateNumber -> PublicNumber
- getShared :: Params -> PrivateNumber -> PublicNumber -> SharedKey

# Documentation

data Params #

Represent Diffie Hellman parameters namely P (prime), and G (generator).

Constructors

Params |
Fields params_p :: Integer params_g :: Integer params_bits :: Int

#### Instances

Instances details

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

newtype PublicNumber #

Represent Diffie Hellman public number Y.

Constructors

PublicNumber Integer |

#### Instances

Instances details

NFData PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods rnf :: PublicNumber -> () #
Enum PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods succ :: PublicNumber -> PublicNumber # pred :: PublicNumber -> PublicNumber # toEnum :: Int -> PublicNumber # fromEnum :: PublicNumber -> Int # enumFrom :: PublicNumber -> [PublicNumber] # enumFromThen :: PublicNumber -> PublicNumber -> [PublicNumber] # enumFromTo :: PublicNumber -> PublicNumber -> [PublicNumber] # enumFromThenTo :: PublicNumber -> PublicNumber -> PublicNumber -> [PublicNumber] #
Num PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods (+) :: PublicNumber -> PublicNumber -> PublicNumber # (-) :: PublicNumber -> PublicNumber -> PublicNumber # (*) :: PublicNumber -> PublicNumber -> PublicNumber # negate :: PublicNumber -> PublicNumber # abs :: PublicNumber -> PublicNumber # signum :: PublicNumber -> PublicNumber # fromInteger :: Integer -> PublicNumber #
Read PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods readsPrec :: Int -> ReadS PublicNumber # readList :: ReadS [PublicNumber] # readPrec :: ReadPrec PublicNumber # readListPrec :: ReadPrec [PublicNumber] #
Real PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods toRational :: PublicNumber -> Rational #
Show PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods showsPrec :: Int -> PublicNumber -> ShowS # show :: PublicNumber -> String # showList :: [PublicNumber] -> ShowS #
Eq PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods (==) :: PublicNumber -> PublicNumber -> Bool # (/=) :: PublicNumber -> PublicNumber -> Bool #
Ord PublicNumber # |
Instance details Defined in Crypto.PubKey.DH Methods compare :: PublicNumber -> PublicNumber -> Ordering # (<) :: PublicNumber -> PublicNumber -> Bool # (<=) :: PublicNumber -> PublicNumber -> Bool # (>) :: PublicNumber -> PublicNumber -> Bool # (>=) :: PublicNumber -> PublicNumber -> Bool # max :: PublicNumber -> PublicNumber -> PublicNumber # min :: PublicNumber -> PublicNumber -> PublicNumber #

newtype PrivateNumber #

Represent Diffie Hellman private number X.

Constructors

PrivateNumber Integer |

#### Instances

Instances details

NFData PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods rnf :: PrivateNumber -> () #
Enum PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods succ :: PrivateNumber -> PrivateNumber # pred :: PrivateNumber -> PrivateNumber # toEnum :: Int -> PrivateNumber # fromEnum :: PrivateNumber -> Int # enumFrom :: PrivateNumber -> [PrivateNumber] # enumFromThen :: PrivateNumber -> PrivateNumber -> [PrivateNumber] # enumFromTo :: PrivateNumber -> PrivateNumber -> [PrivateNumber] # enumFromThenTo :: PrivateNumber -> PrivateNumber -> PrivateNumber -> [PrivateNumber] #
Num PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods (+) :: PrivateNumber -> PrivateNumber -> PrivateNumber # (-) :: PrivateNumber -> PrivateNumber -> PrivateNumber # (*) :: PrivateNumber -> PrivateNumber -> PrivateNumber # negate :: PrivateNumber -> PrivateNumber # abs :: PrivateNumber -> PrivateNumber # signum :: PrivateNumber -> PrivateNumber # fromInteger :: Integer -> PrivateNumber #
Read PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods readsPrec :: Int -> ReadS PrivateNumber # readList :: ReadS [PrivateNumber] # readPrec :: ReadPrec PrivateNumber # readListPrec :: ReadPrec [PrivateNumber] #
Real PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods toRational :: PrivateNumber -> Rational #
Show PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods showsPrec :: Int -> PrivateNumber -> ShowS # show :: PrivateNumber -> String # showList :: [PrivateNumber] -> ShowS #
Eq PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods (==) :: PrivateNumber -> PrivateNumber -> Bool # (/=) :: PrivateNumber -> PrivateNumber -> Bool #
Ord PrivateNumber # |
Instance details Defined in Crypto.PubKey.DH Methods compare :: PrivateNumber -> PrivateNumber -> Ordering # (<) :: PrivateNumber -> PrivateNumber -> Bool # (<=) :: PrivateNumber -> PrivateNumber -> Bool # (>) :: PrivateNumber -> PrivateNumber -> Bool # (>=) :: PrivateNumber -> PrivateNumber -> Bool # max :: PrivateNumber -> PrivateNumber -> PrivateNumber # min :: PrivateNumber -> PrivateNumber -> PrivateNumber #

newtype SharedKey #

Represent Diffie Hellman shared secret.

Constructors

SharedKey ScrubbedBytes |

#### Instances

Instances details

NFData SharedKey # |
Instance details Defined in Crypto.PubKey.DH Methods rnf :: SharedKey -> () #
Show SharedKey # |
Instance details Defined in Crypto.PubKey.DH Methods showsPrec :: Int -> SharedKey -> ShowS # show :: SharedKey -> String # showList :: [SharedKey] -> ShowS #
Eq SharedKey # |
Instance details Defined in Crypto.PubKey.DH Methods (==) :: SharedKey -> SharedKey -> Bool # (/=) :: SharedKey -> SharedKey -> Bool #
ByteArrayAccess SharedKey # |
Instance details Defined in Crypto.PubKey.DH Methods length :: SharedKey -> Int # withByteArray :: SharedKey -> (Ptr p -> IO a) -> IO a # copyByteArrayToPtr :: SharedKey -> Ptr p -> IO () #

generateParams #

Arguments

:: MonadRandom m |
=> Int | number of bits
-> Integer | generator
-> m Params |

generate params from a specific generator (2 or 5 are common values) we generate a safe prime (a prime number of the form 2p+1 where p is also prime)

generatePrivate :: MonadRandom m => Params -> m PrivateNumber #

generate a private number with no specific property this number is usually called X in DH text.

calculatePublic :: Params -> PrivateNumber -> PublicNumber #

calculate the public number from the parameters and the private key this number is usually called Y in DH text.

generatePublic :: Params -> PrivateNumber -> PublicNumber #

calculate the public number from the parameters and the private key this number is usually called Y in DH text.

DEPRECATED use calculatePublic

getShared :: Params -> PrivateNumber -> PublicNumber -> SharedKey #

generate a shared key using our private number and the other party public number