Security Scol plugin
Public Member Functions | Protected Attributes | List of all members
DH2 Class Reference

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

#include <dh2.h>

Inheritance diagram for DH2:
AuthenticatedKeyAgreementDomain KeyAgreementAlgorithm AsymmetricAlgorithm Algorithm Clonable

Public Member Functions

 DH2 (SimpleKeyAgreementDomain &domain)
 Construct a DH2.
 
 DH2 (SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain)
 Construct a DH2.
 
CryptoParametersAccessCryptoParameters ()
 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
CryptoMaterialAccessMaterial ()
 Retrieves a reference to Crypto Parameters.
 
const CryptoMaterialGetMaterial () const
 Retrieves a reference to Crypto Parameters.
 
virtual const CryptoParametersGetCryptoParameters () 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 ClonableClone () const
 Copies this object.
 

Protected Attributes

SimpleKeyAgreementDomaind1
 
SimpleKeyAgreementDomaind2
 

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

Member Data Documentation

◆ d1

SimpleKeyAgreementDomain& DH2::d1
protected

Definition at line 65 of file dh2.h.

◆ d2

SimpleKeyAgreementDomain & DH2::d2
protected

Definition at line 65 of file dh2.h.


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