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

dh2.h
Go to the documentation of this file.
1 // dh2.h - originally written and placed in the public domain by Wei Dai
2
3 /// \file dh2.h
4 /// \brief Classes for Unified Diffie-Hellman key exchange
5 /// \since Crypto++ 3.0
6
7 #ifndef CRYPTOPP_DH2_H
8 #define CRYPTOPP_DH2_H
9
10 #include "cryptlib.h"
11
12 NAMESPACE_BEGIN(CryptoPP)
13
14 /// \brief Unified Diffie-Hellman in GF(p)
15 /// \details A Diffie-Hellman domain is a set of parameters that must be shared
16 /// by two parties in a key agreement protocol, along with the algorithms
17 /// for generating key pairs and deriving agreed values.
18 /// \sa AuthenticatedKeyAgreementDomain, <a href="http://www.weidai.com/scan-mirror/ka.html#DH2">Unified Diffie-Hellman</a>
19 /// \since Crypto++ 3.0
20 class DH2 : public AuthenticatedKeyAgreementDomain
21 {
22 public:
23 virtual ~DH2() {}
24
25 /// \brief Construct a DH2
26 DH2(SimpleKeyAgreementDomain &domain)
27 : d1(domain), d2(domain) {}
28 /// \brief Construct a DH2
29 DH2(SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain)
30 : d1(staticDomain), d2(ephemeralDomain) {}
31
32 CryptoParameters & AccessCryptoParameters() {return d1.AccessCryptoParameters();}
33
34 unsigned int AgreedValueLength() const
35 {return d1.AgreedValueLength() + d2.AgreedValueLength();}
36
37 unsigned int StaticPrivateKeyLength() const
38 {return d1.PrivateKeyLength();}
39 unsigned int StaticPublicKeyLength() const
40 {return d1.PublicKeyLength();}
41 void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
42 {d1.GeneratePrivateKey(rng, privateKey);}
43 void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
44 {d1.GeneratePublicKey(rng, privateKey, publicKey);}
45 void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
46 {d1.GenerateKeyPair(rng, privateKey, publicKey);}
47
48 unsigned int EphemeralPrivateKeyLength() const
49 {return d2.PrivateKeyLength();}
50 unsigned int EphemeralPublicKeyLength() const
51 {return d2.PublicKeyLength();}
52 void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
53 {d2.GeneratePrivateKey(rng, privateKey);}
54 void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
55 {d2.GeneratePublicKey(rng, privateKey, publicKey);}
56 void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
57 {d2.GenerateKeyPair(rng, privateKey, publicKey);}
58
59 bool Agree(byte *agreedValue,
60 const byte *staticPrivateKey, const byte *ephemeralPrivateKey,
61 const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,
62 bool validateStaticOtherPublicKey=true) const;
63
64 protected:
65 SimpleKeyAgreementDomain &d1, &d2;
66 };
67
68 NAMESPACE_END
69
70 #endif
AuthenticatedKeyAgreementDomain
Interface for domains of authenticated key agreement protocols.
Definition: cryptlib.h:3077
CryptoParameters
Interface for crypto parameters.
Definition: cryptlib.h:2551
DH2
Unified Diffie-Hellman in GF(p)
Definition: dh2.h:21
DH2::GenerateStaticPublicKey
void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
Generate a static public key from a private key in this domain.
Definition: dh2.h:43
DH2::DH2
DH2(SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain)
Construct a DH2.
Definition: dh2.h:29
DH2::AgreedValueLength
unsigned int AgreedValueLength() const
Provides the size of the agreed value.
Definition: dh2.h:34
DH2::StaticPrivateKeyLength
unsigned int StaticPrivateKeyLength() const
Provides the size of the static private key.
Definition: dh2.h:37
DH2::AccessCryptoParameters
CryptoParameters & AccessCryptoParameters()
Retrieves a reference to Crypto Parameters.
Definition: dh2.h:32
DH2::EphemeralPrivateKeyLength
unsigned int EphemeralPrivateKeyLength() const
Provides the size of ephemeral private key.
Definition: dh2.h:48
DH2::EphemeralPublicKeyLength
unsigned int EphemeralPublicKeyLength() const
Provides the size of ephemeral public key.
Definition: dh2.h:50
DH2::GenerateEphemeralKeyPair
void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate private/public key pair.
Definition: dh2.h:56
DH2::GenerateEphemeralPrivateKey
void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
Generate ephemeral private key.
Definition: dh2.h:52
DH2::GenerateStaticPrivateKey
void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
Generate static private key in this domain.
Definition: dh2.h:41
DH2::GenerateEphemeralPublicKey
void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
Generate ephemeral public key.
Definition: dh2.h:54
DH2::StaticPublicKeyLength
unsigned int StaticPublicKeyLength() const
Provides the size of the static public key.
Definition: dh2.h:39
DH2::GenerateStaticKeyPair
void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a static private/public key pair.
Definition: dh2.h:45
DH2::DH2
DH2(SimpleKeyAgreementDomain &domain)
Construct a DH2.
Definition: dh2.h:26
RandomNumberGenerator
Interface for random number generators.
Definition: cryptlib.h:1440
SimpleKeyAgreementDomain
Interface for domains of simple key agreement protocols.
Definition: cryptlib.h:3018
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
CryptoPP
Crypto++ library namespace.