cryptonite-0.10: 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
  }
- newtype PublicNumber = PublicNumber Integer
- newtype PrivateNumber = PrivateNumber Integer
- newtype SharedKey = SharedKey Integer
- 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

Instances

Eq Params Source |
Data Params Source |
Read Params Source |
Show Params Source |

newtype PublicNumber Source

Represent Diffie Hellman public number Y.

Constructors

PublicNumber Integer |

Instances

Enum PublicNumber Source |
Eq PublicNumber Source |
Num PublicNumber Source |
Ord PublicNumber Source |
Read PublicNumber Source |
Real PublicNumber Source |
Show PublicNumber Source |

newtype PrivateNumber Source

Represent Diffie Hellman private number X.

Constructors

PrivateNumber Integer |

Instances

Enum PrivateNumber Source |
Eq PrivateNumber Source |
Num PrivateNumber Source |
Ord PrivateNumber Source |
Read PrivateNumber Source |
Real PrivateNumber Source |
Show PrivateNumber Source |

newtype SharedKey Source

Represent Diffie Hellman shared secret.

Constructors

SharedKey Integer |

Instances

Enum SharedKey Source |
Eq SharedKey Source |
Num SharedKey Source |
Ord SharedKey Source |
Read SharedKey Source |
Real SharedKey Source |
Show SharedKey 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