Crypto++ 8.4 Free C++ class library of cryptographic schemes

Public Types | Public Member Functions | List of all members
DH Struct Reference

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

Inheritance diagram for DH:

## Public Types
typedef DH_Domain< DL_GroupParameters_GFP_DefaultSafePrime > | GroupParameters
typedef GroupParameters::Element | Element
Public Types inherited from DH_Domain< DL_GroupParameters_GFP_DefaultSafePrime >
typedef DL_GroupParameters_GFP_DefaultSafePrime | GroupParameters
typedef GroupParameters::Element | Element
typedef DL_KeyAgreementAlgorithm_DH< Element, typename DL_GroupParameters_GFP_DefaultSafePrime ::DefaultCofactorOption > | DH_Algorithm
typedef DH_Domain< DL_GroupParameters_GFP_DefaultSafePrime, typename DL_GroupParameters_GFP_DefaultSafePrime ::DefaultCofactorOption > | Domain
Public Types inherited from DL_SimpleKeyAgreementDomainBase< DL_GroupParameters_GFP_DefaultSafePrime ::Element >
typedef DL_GroupParameters_GFP_DefaultSafePrime ::Element | Element

## Public Member Functions
| DH ()
| Create an uninitialized Diffie-Hellman object.
| DH (BufferedTransformation &bt)
| Initialize a Diffie-Hellman object. More...
| DH (const GroupParameters &params)
| Initialize a Diffie-Hellman object. More...
| DH (RandomNumberGenerator &rng, unsigned int modulusBits)
| Create a Diffie-Hellman object. More...
| DH (const Integer &p, const Integer &g)
| Initialize a Diffie-Hellman object. More...
| DH (const Integer &p, const Integer &q, const Integer &g)
| Initialize a Diffie-Hellman object. More...
void | Initialize (RandomNumberGenerator &rng, unsigned int modulusBits)
| Creates a Diffie-Hellman object. More...
void | Initialize (const Integer &p, const Integer &g)
| Initialize a Diffie-Hellman object. More...
void | Initialize (const Integer &p, const Integer &q, const Integer &g)
| Initialize a Diffie-Hellman object. More...
Public Member Functions inherited from DH_Domain< DL_GroupParameters_GFP_DefaultSafePrime >
| DH_Domain ()
| Construct a Diffie-Hellman domain.
| DH_Domain (const GroupParameters &params)
| Construct a Diffie-Hellman domain. More...
| DH_Domain (BufferedTransformation &bt)
| Construct a Diffie-Hellman domain. More...
| DH_Domain (RandomNumberGenerator &v1, const T2 &v2)
| Create a Diffie-Hellman domain. More...
| DH_Domain (RandomNumberGenerator &v1, const T2 &v2, const T3 &v3)
| Create a Diffie-Hellman domain. More...
| DH_Domain (RandomNumberGenerator &v1, const T2 &v2, const T3 &v3, const T4 &v4)
| Create a Diffie-Hellman domain. More...
| DH_Domain (const T1 &v1, const T2 &v2)
| Construct a Diffie-Hellman domain. More...
| DH_Domain (const T1 &v1, const T2 &v2, const T3 &v3)
| Construct a Diffie-Hellman domain. More...
| DH_Domain (const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
| Construct a Diffie-Hellman domain. More...
const GroupParameters & | GetGroupParameters () const
| Retrieves the group parameters for this domain. More...
GroupParameters & | AccessGroupParameters ()
| Retrieves the group parameters for this domain. More...
void | GeneratePublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
| Generate a public key from a private key in this domain. More...
std::string | AlgorithmName () const
| Provides the name of this algorithm. More...
Public Member Functions inherited from DL_SimpleKeyAgreementDomainBase< DL_GroupParameters_GFP_DefaultSafePrime ::Element >
CryptoParameters & | AccessCryptoParameters ()
| Retrieves a reference to Crypto Parameters. More...
unsigned int | AgreedValueLength () const
| Provides the size of the agreed value. More...
unsigned int | PrivateKeyLength () const
| Provides the size of the private key. More...
unsigned int | PublicKeyLength () const
| Provides the size of the public key. More...
void | GeneratePrivateKey (RandomNumberGenerator &rng, byte *privateKey) const
| Generate private key in this domain. More...
void | GeneratePublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
| Generate a public key from a private key in this domain. More...
bool | Agree (byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const
| Derive agreed value. More...
const Element & | GetGenerator () const
| Retrieves a reference to the group generator. More...
Public Member Functions inherited from SimpleKeyAgreementDomain
virtual unsigned int | AgreedValueLength () const =0
| Provides the size of the agreed value. More...
virtual unsigned int | PrivateKeyLength () const =0
| Provides the size of the private key. More...
virtual unsigned int | PublicKeyLength () const =0
| Provides the size of the public key. More...
virtual void | GenerateKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
| Generate a private/public key pair. More...
Public Member Functions inherited from KeyAgreementAlgorithm
CryptoMaterial & | AccessMaterial ()
| Retrieves a reference to Crypto Parameters. More...
const CryptoMaterial & | GetMaterial () const
| Retrieves a reference to Crypto Parameters. More...
virtual const CryptoParameters & | GetCryptoParameters () const
| Retrieves a reference to Crypto Parameters. More...
Public Member Functions inherited from Algorithm
| Algorithm (bool checkSelfTestStatus=true)
| Interface for all crypto algorithms. More...
virtual std::string | AlgorithmName () const
| Provides the name of this algorithm. More...
virtual std::string | AlgorithmProvider () const
| Retrieve the provider of this algorithm. More...
Public Member Functions inherited from Clonable
virtual Clonable * | Clone () const
| Copies this object. More...

## Additional Inherited Members
Static Public Member Functions inherited from DH_Domain< DL_GroupParameters_GFP_DefaultSafePrime >
static std::string | StaticAlgorithmName ()

## Detailed Description

Diffie-Hellman in GF(p)

DH() class is a typedef of DH_Domain(). The documentation that follows does not exist. Rather the documentation was created in response to Issue 328, Diffie-Hellman example code not compiling.

Generally speaking, a DH() object is ephemeral and is intended to execute one instance of the Diffie-Hellman protocol. The private and public key parts are not intended to be set or persisted. Rather, a new set of domain parameters are generated each time an object is created.

Once a DH() object is created, once can retrieve the ephemeral public key for the other party with code similar to the following.

       AutoSeededRandomPool prng;
      Integer p, q, g;
      PrimeAndGenerator pg;

      pg.Generate(1, prng, 512, 511);
      p = pg.Prime();
      q = pg.SubPrime();
      g = pg.Generator();

      DH dh(p, q, g);
      SecByteBlock t1(dh.PrivateKeyLength()), t2(dh.PublicKeyLength());
      dh.GenerateKeyPair(prng, t1, t2);
      Integer k1(t1, t1.size()), k2(t2, t2.size());

      cout << "Private key:\n";
      cout << hex << k1 << endl;

      cout << "Public key:\n";
      cout << hex << k2 << endl;

Output of the program above will be similar to the following.

       $ ./cryptest.exe
      Private key:
      72b45a42371545e9d4880f48589aefh
      Public key:
      45fdb13f97b1840626f0250cec1dba4a23b894100b51fb5d2dd13693d789948f8bfc88f9200014b2
      ba8dd8a6debc471c69ef1e2326c61184a2eca88ec866346bh

See also
  Diffie-Hellman on the Crypto++ wiki and Diffie-Hellman in GF(p) with key validation

Since
  Crypto++ 1.0

Definition at line 211 of file dh.h.

## Constructor & Destructor Documentation

## ◆ DH() [1/5]

DH::DH | ( | BufferedTransformation & | bt | ) |
| inline

Initialize a Diffie-Hellman object.

Parameters

  bt | BufferedTransformation with group parameters and options

Definition at line 223 of file dh.h.

## ◆ DH() [2/5]

DH::DH | ( | const GroupParameters & | params | ) |
| inline

Initialize a Diffie-Hellman object.

Parameters

  params | group parameters and options

Definition at line 227 of file dh.h.

## ◆ DH() [3/5]

DH::DH | ( | RandomNumberGenerator & | rng,
|  | unsigned int | modulusBits
| ) |  |
| inline

Create a Diffie-Hellman object.

Parameters

  rng | a RandomNumberGenerator derived class
  modulusBits | the size of the modulus, in bits

This function overload of Initialize() creates a new Diffie-Hellman object because it takes a RandomNumberGenerator() as a parameter.

Definition at line 234 of file dh.h.

## ◆ DH() [4/5]

DH::DH | ( | const Integer & | p,
|  | const Integer & | g
| ) |  |
| inline

Initialize a Diffie-Hellman object.

Parameters

  p | the modulus
  g | the generator

Definition at line 239 of file dh.h.

## ◆ DH() [5/5]

DH::DH | ( | const Integer & | p,
|  | const Integer & | q,
|  | const Integer & | g
| ) |  |
| inline

Initialize a Diffie-Hellman object.

Parameters

  p | the modulus
  q | the subgroup order
  g | the generator

Definition at line 245 of file dh.h.

## Member Function Documentation

## ◆ Initialize() [1/3]

void DH::Initialize | ( | RandomNumberGenerator & | rng,
|  | unsigned int | modulusBits
| ) |  |
| inline

Creates a Diffie-Hellman object.

Parameters

  rng | a RandomNumberGenerator derived class
  modulusBits | the size of the modulus, in bits

This function overload of Initialize() creates a new Diffie-Hellman object because it takes a RandomNumberGenerator() as a parameter.

Definition at line 252 of file dh.h.

## ◆ Initialize() [2/3]

void DH::Initialize | ( | const Integer & | p,
|  | const Integer & | g
| ) |  |
| inline

Initialize a Diffie-Hellman object.

Parameters

  p | the modulus
  g | the generator

Definition at line 258 of file dh.h.

## ◆ Initialize() [3/3]

void DH::Initialize | ( | const Integer & | p,
|  | const Integer & | q,
|  | const Integer & | g
| ) |  |
| inline

Initialize a Diffie-Hellman object.

Parameters

  p | the modulus
  q | the subgroup order
  g | the generator

Definition at line 265 of file dh.h.

The documentation for this struct was generated from the following file:

- dh.h