DH2 Class Reference

Unified Diffie-Hellman in GF(p) More...

`#include <dh2.h>`

Inheritance diagram for DH2:

## Public Member Functions

| DH2 (SimpleKeyAgreementDomain &domain)
| Construct a DH2.
| DH2 (SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain)
| Construct a DH2.
CryptoParameters & | AccessCryptoParameters ()
| Retrieves a reference to Crypto Parameters.
unsigned int | AgreedValueLength () const
| Provides the size of the agreed value.
unsigned int | StaticPrivateKeyLength () const
| Provides the size of the static private key.
unsigned int | StaticPublicKeyLength () const
| Provides the size of the static public key.
void | GenerateStaticPrivateKey (RandomNumberGenerator &rng, byte *privateKey) const
| Generate static private key in this domain.
void | GenerateStaticPublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
| Generate a static public key from a private key in this domain.
void | GenerateStaticKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
| Generate a static private/public key pair.
unsigned int | EphemeralPrivateKeyLength () const
| Provides the size of ephemeral private key.
unsigned int | EphemeralPublicKeyLength () const
| Provides the size of ephemeral public key.
void | GenerateEphemeralPrivateKey (RandomNumberGenerator &rng, byte *privateKey) const
| Generate ephemeral private key.
void | GenerateEphemeralPublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
| Generate ephemeral public key.
void | GenerateEphemeralKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
| Generate private/public key pair.
bool | Agree (byte *agreedValue, const byte *staticPrivateKey, const byte *ephemeralPrivateKey, const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, bool validateStaticOtherPublicKey=true) const
| Derive agreed value.
Public Member Functions inherited from KeyAgreementAlgorithm
CryptoMaterial & | AccessMaterial ()
| Retrieves a reference to Crypto Parameters.
const CryptoMaterial & | GetMaterial () const
| Retrieves a reference to Crypto Parameters.
virtual const CryptoParameters & | GetCryptoParameters () const
| Retrieves a reference to Crypto Parameters.
Public Member Functions inherited from Algorithm
| Algorithm (bool checkSelfTestStatus=true)
| Interface for all crypto algorithms.
virtual std::string | AlgorithmName () const
| Provides the name of this algorithm.
virtual std::string | AlgorithmProvider () const
| Retrieve the provider of this algorithm.
Public Member Functions inherited from Clonable
virtual Clonable * | Clone () const
| Copies this object.

## Detailed Description

Unified Diffie-Hellman in GF(p)

A Diffie-Hellman domain is a set of parameters that must be shared by two parties in a key agreement protocol, along with the algorithms for generating key pairs and deriving agreed values.

See also
  AuthenticatedKeyAgreementDomain, Unified Diffie-Hellman

Since
  Crypto++ 3.0

Definition at line 20 of file dh2.h.

## Constructor & Destructor Documentation

## ~DH2()

virtual DH2::~DH2 | ( |  | ) |

inline virtual

Definition at line 23 of file dh2.h.

## DH2() [1/2]

DH2::DH2 | ( | SimpleKeyAgreementDomain & | domain | ) |

inline

Construct a DH2.

Definition at line 26 of file dh2.h.

## DH2() [2/2]

DH2::DH2 | ( | SimpleKeyAgreementDomain & | staticDomain,
|  | SimpleKeyAgreementDomain & | ephemeralDomain
| ) |  |

inline

Construct a DH2.

Definition at line 29 of file dh2.h.

## Member Function Documentation

## AccessCryptoParameters()

CryptoParameters & DH2::AccessCryptoParameters | ( |  | ) |

inline virtual

Retrieves a reference to Crypto Parameters.

Returns
  a reference the crypto parameters

Implements KeyAgreementAlgorithm.

Definition at line 32 of file dh2.h.

## AgreedValueLength()

unsigned int DH2::AgreedValueLength | ( |  | ) | const

inline virtual

Provides the size of the agreed value.

Returns
  size of agreed value produced in this domain

Implements AuthenticatedKeyAgreementDomain.

Definition at line 34 of file dh2.h.

## StaticPrivateKeyLength()

unsigned int DH2::StaticPrivateKeyLength | ( |  | ) | const

inline virtual

Provides the size of the static private key.

Returns
  size of static private keys in this domain

Implements AuthenticatedKeyAgreementDomain.

Definition at line 37 of file dh2.h.

## StaticPublicKeyLength()

unsigned int DH2::StaticPublicKeyLength | ( |  | ) | const

inline virtual

Provides the size of the static public key.

Returns
  size of static public keys in this domain

Implements AuthenticatedKeyAgreementDomain.

Definition at line 39 of file dh2.h.

## GenerateStaticPrivateKey()

void DH2::GenerateStaticPrivateKey | ( | RandomNumberGenerator & | rng,
|  | byte * | privateKey
| ) |  | const

inline virtual

Generate static private key in this domain.

Parameters

  rng | a RandomNumberGenerator derived class
  privateKey | a byte buffer for the generated private key in this domain

Precondition
  `COUNTOF(privateKey) == PrivateStaticKeyLength()`

Implements AuthenticatedKeyAgreementDomain.

Definition at line 41 of file dh2.h.

## GenerateStaticPublicKey()

void DH2::GenerateStaticPublicKey | ( | RandomNumberGenerator & | rng,
|  | const byte * | privateKey,
|  | byte * | publicKey
| ) |  | const

inline virtual

Generate a static public key from a private key in this domain.

Parameters

  rng | a RandomNumberGenerator derived class
  privateKey | a byte buffer with the previously generated private key
  publicKey | a byte buffer for the generated public key in this domain

Precondition
  `COUNTOF(publicKey) == PublicStaticKeyLength()`

Implements AuthenticatedKeyAgreementDomain.

Definition at line 43 of file dh2.h.

## GenerateStaticKeyPair()

void DH2::GenerateStaticKeyPair | ( | RandomNumberGenerator & | rng,
|  | byte * | privateKey,
|  | byte * | publicKey
| ) |  | const

inline virtual

Generate a static private/public key pair.

Parameters

  rng | a RandomNumberGenerator derived class
  privateKey | a byte buffer for the generated private key in this domain
  publicKey | a byte buffer for the generated public key in this domain

GenerateStaticKeyPair() is equivalent to calling GenerateStaticPrivateKey() and then GenerateStaticPublicKey().

Precondition
  `COUNTOF(privateKey) == PrivateStaticKeyLength()`
  `COUNTOF(publicKey) == PublicStaticKeyLength()`

Reimplemented from AuthenticatedKeyAgreementDomain.

Definition at line 45 of file dh2.h.

## EphemeralPrivateKeyLength()

unsigned int DH2::EphemeralPrivateKeyLength | ( |  | ) | const

inline virtual

Provides the size of ephemeral private key.

Returns
  the size of ephemeral private key in this domain

Implements AuthenticatedKeyAgreementDomain.

Definition at line 48 of file dh2.h.

## EphemeralPublicKeyLength()

unsigned int DH2::EphemeralPublicKeyLength | ( |  | ) | const

inline virtual

Provides the size of ephemeral public key.

Returns
  the size of ephemeral public key in this domain

Implements AuthenticatedKeyAgreementDomain.

Definition at line 50 of file dh2.h.

## GenerateEphemeralPrivateKey()

void DH2::GenerateEphemeralPrivateKey | ( | RandomNumberGenerator & | rng,
|  | byte * | privateKey
| ) |  | const

inline virtual

Generate ephemeral private key.

Parameters

  rng | a RandomNumberGenerator derived class
  privateKey | a byte buffer for the generated private key in this domain

Precondition
  `COUNTOF(privateKey) == PrivateEphemeralKeyLength()`

Implements AuthenticatedKeyAgreementDomain.

Definition at line 52 of file dh2.h.

## GenerateEphemeralPublicKey()

void DH2::GenerateEphemeralPublicKey | ( | RandomNumberGenerator & | rng,
|  | const byte * | privateKey,
|  | byte * | publicKey
| ) |  | const

inline virtual

Generate ephemeral public key.

Parameters

  rng | a RandomNumberGenerator derived class
  privateKey | a byte buffer for the generated private key in this domain
  publicKey | a byte buffer for the generated public key in this domain

Precondition
  `COUNTOF(publicKey) == PublicEphemeralKeyLength()`

Implements AuthenticatedKeyAgreementDomain.

Definition at line 54 of file dh2.h.

## GenerateEphemeralKeyPair()

void DH2::GenerateEphemeralKeyPair | ( | RandomNumberGenerator & | rng,
|  | byte * | privateKey,
|  | byte * | publicKey
| ) |  | const

inline virtual

Generate private/public key pair.

Parameters

  rng | a RandomNumberGenerator derived class
  privateKey | a byte buffer for the generated private key in this domain
  publicKey | a byte buffer for the generated public key in this domain

GenerateEphemeralKeyPair() is equivalent to calling GenerateEphemeralPrivateKey() and then GenerateEphemeralPublicKey()

Reimplemented from AuthenticatedKeyAgreementDomain.

Definition at line 56 of file dh2.h.

## Agree()

bool DH2::Agree | ( | byte * | agreedValue,
|  | const byte * | staticPrivateKey,
|  | const byte * | ephemeralPrivateKey,
|  | const byte * | staticOtherPublicKey,
|  | const byte * | ephemeralOtherPublicKey,
|  | bool | validateStaticOtherPublicKey = `true`
| ) |  | const

virtual

Derive agreed value.

Parameters

  agreedValue | a byte buffer for the shared secret
  staticPrivateKey | a byte buffer with your static private key in this domain
  ephemeralPrivateKey | a byte buffer with your ephemeral private key in this domain
  staticOtherPublicKey | a byte buffer with the other party's static public key in this domain
  ephemeralOtherPublicKey | a byte buffer with the other party's ephemeral public key in this domain
  validateStaticOtherPublicKey | a flag indicating if the other party's public key should be validated

Returns
  true upon success, false in case of failure

Agree() derives an agreed value from your private keys and couterparty's public keys.

The other party's ephemeral public key is validated by default. If you have previously validated the static public key, use `validateStaticOtherPublicKey=false` to save time.

Precondition
  `COUNTOF(agreedValue) == AgreedValueLength()`
  `COUNTOF(staticPrivateKey) == StaticPrivateKeyLength()`
  `COUNTOF(ephemeralPrivateKey) == EphemeralPrivateKeyLength()`
  `COUNTOF(staticOtherPublicKey) == StaticPublicKeyLength()`
  `COUNTOF(ephemeralOtherPublicKey) == EphemeralPublicKeyLength()`

Implements AuthenticatedKeyAgreementDomain.

Definition at line 60 of file dh2.cpp.

The documentation for this class was generated from the following files:

- dh2.h
- dh2.cpp