Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

  1. // dh2.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \headerfile dh2.h
  4. //! \brief Classes for Diffie-Hellman authenticated key exchange
  5. #ifndef CRYPTOPP_DH2_H
  6. #define CRYPTOPP_DH2_H
  7. #include "cryptlib.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. /// <a href="http://www.weidai.com/scan-mirror/ka.html#DH2">Unified Diffie-Hellman</a>
  10. class DH2 : public AuthenticatedKeyAgreementDomain
  11. {
  12. public:
  13. DH2(SimpleKeyAgreementDomain &domain)
  14. : d1(domain), d2(domain) {}
  15. DH2(SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain)
  16. : d1(staticDomain), d2(ephemeralDomain) {}
  17. CryptoParameters & AccessCryptoParameters() {return d1.AccessCryptoParameters();}
  18. unsigned int AgreedValueLength() const
  19. {return d1.AgreedValueLength() + d2.AgreedValueLength();}
  20. unsigned int StaticPrivateKeyLength() const
  21. {return d1.PrivateKeyLength();}
  22. unsigned int StaticPublicKeyLength() const
  23. {return d1.PublicKeyLength();}
  24. void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
  25. {d1.GeneratePrivateKey(rng, privateKey);}
  26. void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
  27. {d1.GeneratePublicKey(rng, privateKey, publicKey);}
  28. void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
  29. {d1.GenerateKeyPair(rng, privateKey, publicKey);}
  30. unsigned int EphemeralPrivateKeyLength() const
  31. {return d2.PrivateKeyLength();}
  32. unsigned int EphemeralPublicKeyLength() const
  33. {return d2.PublicKeyLength();}
  34. void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const
  35. {d2.GeneratePrivateKey(rng, privateKey);}
  36. void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
  37. {d2.GeneratePublicKey(rng, privateKey, publicKey);}
  38. void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
  39. {d2.GenerateKeyPair(rng, privateKey, publicKey);}
  40. bool Agree(byte *agreedValue,
  41. const byte *staticPrivateKey, const byte *ephemeralPrivateKey,
  42. const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,
  43. bool validateStaticOtherPublicKey=true) const;
  44. #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
  45. virtual ~DH2() {}
  46. #endif
  47. protected:
  48. SimpleKeyAgreementDomain &d1, &d2;
  49. };
  50. NAMESPACE_END
  51. #endif