Crypto++ 8.7
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...

#include <dh.h>

+ Inheritance diagram for DH:

Public Types

typedef DH_Domain< DL_GroupParameters_GFP_DefaultSafePrimeGroupParameters
 
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 GROUP_PARAMETERS::DefaultCofactorOption > DH_Algorithm
 
typedef DH_Domain< DL_GroupParameters_GFP_DefaultSafePrime, typename GROUP_PARAMETERS::DefaultCofactorOption > Domain
 
- Public Types inherited from DL_SimpleKeyAgreementDomainBase< GROUP_PARAMETERS::Element >
typedef GROUP_PARAMETERS::Element Element
 

Public Member Functions

 DH ()
 Create an uninitialized Diffie-Hellman object. More...
 
 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. More...
 
 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 GroupParametersGetGroupParameters () const
 Retrieves the group parameters for this domain. More...
 
GroupParametersAccessGroupParameters ()
 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< GROUP_PARAMETERS::Element >
CryptoParametersAccessCryptoParameters ()
 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 GeneratePrivateKey (RandomNumberGenerator &rng, byte *privateKey) const =0
 Generate private key in this domain. More...
 
virtual void GeneratePublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0
 Generate a public key from a private key in this domain. More...
 
virtual void GenerateKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
 Generate a private/public key pair. More...
 
virtual bool Agree (byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0
 Derive agreed value. More...
 
- Public Member Functions inherited from KeyAgreementAlgorithm
CryptoMaterialAccessMaterial ()
 Retrieves a reference to Crypto Parameters. More...
 
const CryptoMaterialGetMaterial () const
 Retrieves a reference to Crypto Parameters. More...
 
virtual CryptoParametersAccessCryptoParameters ()=0
 Retrieves a reference to Crypto Parameters. More...
 
virtual const CryptoParametersGetCryptoParameters () const
 Retrieves a reference to Crypto Parameters. More...
 
virtual CryptoMaterialAccessMaterial ()=0
 Retrieves a reference to CryptoMaterial. More...
 
virtual const CryptoMaterialGetMaterial () const =0
 Retrieves a reference to CryptoMaterial. 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 ClonableClone () 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.

Member Typedef Documentation

◆ GroupParameters

Definition at line 213 of file dh.h.

◆ Element

typedef GroupParameters::Element DH::Element

Definition at line 214 of file dh.h.

Constructor & Destructor Documentation

◆ ~DH()

virtual DH::~DH ( )
inlinevirtual

Definition at line 216 of file dh.h.

◆ DH() [1/6]

DH::DH ( )
inline

Create an uninitialized Diffie-Hellman object.

Definition at line 219 of file dh.h.

◆ DH() [2/6]

DH::DH ( BufferedTransformation bt)
inline

Initialize a Diffie-Hellman object.

Parameters
btBufferedTransformation with group parameters and options

Definition at line 223 of file dh.h.

◆ DH() [3/6]

DH::DH ( const GroupParameters params)
inline

Initialize a Diffie-Hellman object.

Parameters
paramsgroup parameters and options

Definition at line 227 of file dh.h.

◆ DH() [4/6]

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

Create a Diffie-Hellman object.

Parameters
rnga RandomNumberGenerator derived class
modulusBitsthe 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() [5/6]

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

Initialize a Diffie-Hellman object.

Parameters
pthe modulus
gthe generator

Definition at line 239 of file dh.h.

◆ DH() [6/6]

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

Initialize a Diffie-Hellman object.

Parameters
pthe modulus
qthe subgroup order
gthe 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
rnga RandomNumberGenerator derived class
modulusBitsthe 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
pthe modulus
gthe 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
pthe modulus
qthe subgroup order
gthe generator

Definition at line 265 of file dh.h.


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