Crypto++ 8.7
Free C++ class library of cryptographic schemes
Public Member Functions | List of all members
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. More...
 
 DH2 (SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain)
 Construct a DH2. More...
 
CryptoParametersAccessCryptoParameters ()
 Retrieves a reference to Crypto Parameters. More...
 
unsigned int AgreedValueLength () const
 Provides the size of the agreed value. More...
 
unsigned int StaticPrivateKeyLength () const
 Provides the size of the static private key. More...
 
unsigned int StaticPublicKeyLength () const
 Provides the size of the static public key. More...
 
void GenerateStaticPrivateKey (RandomNumberGenerator &rng, byte *privateKey) const
 Generate static private key in this domain. More...
 
void GenerateStaticPublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
 Generate a static public key from a private key in this domain. More...
 
void GenerateStaticKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
 Generate a static private/public key pair. More...
 
unsigned int EphemeralPrivateKeyLength () const
 Provides the size of ephemeral private key. More...
 
unsigned int EphemeralPublicKeyLength () const
 Provides the size of ephemeral public key. More...
 
void GenerateEphemeralPrivateKey (RandomNumberGenerator &rng, byte *privateKey) const
 Generate ephemeral private key. More...
 
void GenerateEphemeralPublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
 Generate ephemeral public key. More...
 
void GenerateEphemeralKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
 Generate private/public key pair. More...
 
bool Agree (byte *agreedValue, const byte *staticPrivateKey, const byte *ephemeralPrivateKey, const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, bool validateStaticOtherPublicKey=true) const
 Derive agreed value. More...
 
virtual unsigned int AgreedValueLength () const =0
 Provides the size of the agreed value. More...
 
virtual unsigned int StaticPrivateKeyLength () const =0
 Provides the size of the static private key. More...
 
virtual unsigned int StaticPublicKeyLength () const =0
 Provides the size of the static public key. More...
 
virtual void GenerateStaticPrivateKey (RandomNumberGenerator &rng, byte *privateKey) const =0
 Generate static private key in this domain. More...
 
virtual void GenerateStaticPublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0
 Generate a static public key from a private key in this domain. More...
 
virtual void GenerateStaticKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
 Generate a static private/public key pair. More...
 
virtual unsigned int EphemeralPrivateKeyLength () const =0
 Provides the size of ephemeral private key. More...
 
virtual unsigned int EphemeralPublicKeyLength () const =0
 Provides the size of ephemeral public key. More...
 
virtual void GenerateEphemeralPrivateKey (RandomNumberGenerator &rng, byte *privateKey) const =0
 Generate ephemeral private key. More...
 
virtual void GenerateEphemeralPublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0
 Generate ephemeral public key. More...
 
virtual void GenerateEphemeralKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
 Generate private/public key pair. More...
 
virtual bool Agree (byte *agreedValue, const byte *staticPrivateKey, const byte *ephemeralPrivateKey, const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, bool validateStaticOtherPublicKey=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...
 

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 ( )
inlinevirtual

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 ( )
inlinevirtual

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
inlinevirtual

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
inlinevirtual

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
inlinevirtual

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
inlinevirtual

Generate static private key in this domain.

Parameters
rnga RandomNumberGenerator derived class
privateKeya 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
inlinevirtual

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

Parameters
rnga RandomNumberGenerator derived class
privateKeya byte buffer with the previously generated private key
publicKeya 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
inlinevirtual

Generate a static private/public key pair.

Parameters
rnga RandomNumberGenerator derived class
privateKeya byte buffer for the generated private key in this domain
publicKeya 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
inlinevirtual

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
inlinevirtual

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
inlinevirtual

Generate ephemeral private key.

Parameters
rnga RandomNumberGenerator derived class
privateKeya 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
inlinevirtual

Generate ephemeral public key.

Parameters
rnga RandomNumberGenerator derived class
privateKeya byte buffer for the generated private key in this domain
publicKeya 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
inlinevirtual

Generate private/public key pair.

Parameters
rnga RandomNumberGenerator derived class
privateKeya byte buffer for the generated private key in this domain
publicKeya 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
agreedValuea byte buffer for the shared secret
staticPrivateKeya byte buffer with your static private key in this domain
ephemeralPrivateKeya byte buffer with your ephemeral private key in this domain
staticOtherPublicKeya byte buffer with the other party's static public key in this domain
ephemeralOtherPublicKeya byte buffer with the other party's ephemeral public key in this domain
validateStaticOtherPublicKeya 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: