cryptonite-0.30: 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 Source #

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 Source # |
Instance details Defined in Crypto.PubKey.DH Methods rnf :: Params -> () Source #
Data Params Source # |

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 Source #

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

toConstr :: Params -> Constr Source #

dataTypeOf :: Params -> DataType Source #

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

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

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

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

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

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

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

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

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

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

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

newtype PublicNumber Source #

Represent Diffie Hellman public number Y.

Constructors

PublicNumber Integer |

#### Instances

Instances details

NFData PublicNumber Source # |
Instance details Defined in Crypto.PubKey.DH Methods rnf :: PublicNumber -> () Source #
Enum PublicNumber Source # |

Instance details

Defined in Crypto.PubKey.DH

Methods

succ :: PublicNumber -> PublicNumber Source #

pred :: PublicNumber -> PublicNumber Source #

toEnum :: Int -> PublicNumber Source #

fromEnum :: PublicNumber -> Int Source #

enumFrom :: PublicNumber -> [PublicNumber] Source #

enumFromThen :: PublicNumber -> PublicNumber -> [PublicNumber] Source #

enumFromTo :: PublicNumber -> PublicNumber -> [PublicNumber] Source #

enumFromThenTo :: PublicNumber -> PublicNumber -> PublicNumber -> [PublicNumber] Source #

Num PublicNumber Source # |

Instance details

Defined in Crypto.PubKey.DH

Methods

(+) :: PublicNumber -> PublicNumber -> PublicNumber Source #

(-) :: PublicNumber -> PublicNumber -> PublicNumber Source #

(*) :: PublicNumber -> PublicNumber -> PublicNumber Source #

negate :: PublicNumber -> PublicNumber Source #

abs :: PublicNumber -> PublicNumber Source #

signum :: PublicNumber -> PublicNumber Source #

fromInteger :: Integer -> PublicNumber Source #

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

Instance details

Defined in Crypto.PubKey.DH

Methods

compare :: PublicNumber -> PublicNumber -> Ordering Source #

(<) :: PublicNumber -> PublicNumber -> Bool Source #

(<=) :: PublicNumber -> PublicNumber -> Bool Source #

(>) :: PublicNumber -> PublicNumber -> Bool Source #

(>=) :: PublicNumber -> PublicNumber -> Bool Source #

max :: PublicNumber -> PublicNumber -> PublicNumber Source #

min :: PublicNumber -> PublicNumber -> PublicNumber Source #

newtype PrivateNumber Source #

Represent Diffie Hellman private number X.

Constructors

PrivateNumber Integer |

#### Instances

Instances details

NFData PrivateNumber Source # |
Instance details Defined in Crypto.PubKey.DH Methods rnf :: PrivateNumber -> () Source #
Enum PrivateNumber Source # |

Instance details

Defined in Crypto.PubKey.DH

Methods

succ :: PrivateNumber -> PrivateNumber Source #

pred :: PrivateNumber -> PrivateNumber Source #

toEnum :: Int -> PrivateNumber Source #

fromEnum :: PrivateNumber -> Int Source #

enumFrom :: PrivateNumber -> [PrivateNumber] Source #

enumFromThen :: PrivateNumber -> PrivateNumber -> [PrivateNumber] Source #

enumFromTo :: PrivateNumber -> PrivateNumber -> [PrivateNumber] Source #

enumFromThenTo :: PrivateNumber -> PrivateNumber -> PrivateNumber -> [PrivateNumber] Source #

Num PrivateNumber Source # |

Instance details

Defined in Crypto.PubKey.DH

Methods

(+) :: PrivateNumber -> PrivateNumber -> PrivateNumber Source #

(-) :: PrivateNumber -> PrivateNumber -> PrivateNumber Source #

(*) :: PrivateNumber -> PrivateNumber -> PrivateNumber Source #

negate :: PrivateNumber -> PrivateNumber Source #

abs :: PrivateNumber -> PrivateNumber Source #

signum :: PrivateNumber -> PrivateNumber Source #

fromInteger :: Integer -> PrivateNumber Source #

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

Instance details

Defined in Crypto.PubKey.DH

Methods

compare :: PrivateNumber -> PrivateNumber -> Ordering Source #

(<) :: PrivateNumber -> PrivateNumber -> Bool Source #

(<=) :: PrivateNumber -> PrivateNumber -> Bool Source #

(>) :: PrivateNumber -> PrivateNumber -> Bool Source #

(>=) :: PrivateNumber -> PrivateNumber -> Bool Source #

max :: PrivateNumber -> PrivateNumber -> PrivateNumber Source #

min :: PrivateNumber -> PrivateNumber -> PrivateNumber Source #

newtype SharedKey Source #

Represent Diffie Hellman shared secret.

Constructors

SharedKey ScrubbedBytes |

#### Instances

Instances details

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

generateParams Source #

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 Source #

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

calculatePublic :: Params -> PrivateNumber -> PublicNumber Source #

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

generatePublic :: Params -> PrivateNumber -> PublicNumber Source #

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 Source #

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