Crypto++  5.6.3
Free C++ class library of cryptographic schemes
dh2.h
Go to the documentation of this file.
1 // dh2.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \headerfile dh2.h
5 //! \brief Classes for Diffie-Hellman authenticated key exchange
6 
7 #ifndef CRYPTOPP_DH2_H
8 #define CRYPTOPP_DH2_H
9 
10 #include "cryptlib.h"
11 
12 NAMESPACE_BEGIN(CryptoPP)
13 
14 /// <a href="http://www.weidai.com/scan-mirror/ka.html#DH2">Unified Diffie-Hellman</a>
16 {
17 public:
19  : d1(domain), d2(domain) {}
20  DH2(SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain)
21  : d1(staticDomain), d2(ephemeralDomain) {}
22 
23  CryptoParameters & AccessCryptoParameters() {return d1.AccessCryptoParameters();}
24 
25  unsigned int AgreedValueLength() const
26  {return d1.AgreedValueLength() + d2.AgreedValueLength();}
27 
28  unsigned int StaticPrivateKeyLength() const
29  {return d1.PrivateKeyLength();}
30  unsigned int StaticPublicKeyLength() const
31  {return d1.PublicKeyLength();}
32  void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
33  {d1.GeneratePrivateKey(rng, privateKey);}
34  void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
35  {d1.GeneratePublicKey(rng, privateKey, publicKey);}
36  void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
37  {d1.GenerateKeyPair(rng, privateKey, publicKey);}
38 
39  unsigned int EphemeralPrivateKeyLength() const
40  {return d2.PrivateKeyLength();}
41  unsigned int EphemeralPublicKeyLength() const
42  {return d2.PublicKeyLength();}
43  void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
44  {d2.GeneratePrivateKey(rng, privateKey);}
45  void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
46  {d2.GeneratePublicKey(rng, privateKey, publicKey);}
47  void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
48  {d2.GenerateKeyPair(rng, privateKey, publicKey);}
49 
50  bool Agree(byte *agreedValue,
51  const byte *staticPrivateKey, const byte *ephemeralPrivateKey,
52  const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,
53  bool validateStaticOtherPublicKey=true) const;
54 
55 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
56  virtual ~DH2() {}
57 #endif
58 
59 protected:
60  SimpleKeyAgreementDomain &d1, &d2;
61 };
62 
63 NAMESPACE_END
64 
65 #endif
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:34
Abstract base classes that provide a uniform interface to this library.
void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
Generate static private key in this domain.
Definition: dh2.h:32
Interface for random number generators.
Definition: cryptlib.h:1176
CryptoParameters & AccessCryptoParameters()
Retrieves a reference to Crypto Parameters.
Definition: dh2.h:23
Interface for domains of simple key agreement protocols.
Definition: cryptlib.h:2665
unsigned int AgreedValueLength() const
Provides the size of the agreed value.
Definition: dh2.h:25
unsigned int EphemeralPrivateKeyLength() const
Provides the size of ephemeral private key.
Definition: dh2.h:39
Unified Diffie-Hellman
Definition: dh2.h:15
void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a static private/public key pair.
Definition: dh2.h:36
void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
Generate ephemeral public key.
Definition: dh2.h:45
void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate private/public key pair.
Definition: dh2.h:47
unsigned int StaticPublicKeyLength() const
Provides the size of the static public key.
Definition: dh2.h:30
Interface for crypto prameters.
Definition: cryptlib.h:2179
unsigned int EphemeralPublicKeyLength() const
Provides the size of ephemeral public key.
Definition: dh2.h:41
Crypto++ library namespace.
Interface for domains of authenticated key agreement protocols.
Definition: cryptlib.h:2730
void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
Generate ephemeral private key.
Definition: dh2.h:43
unsigned int StaticPrivateKeyLength() const
Provides the size of the static private key.
Definition: dh2.h:28