Counter Strike : Global Offensive Source Code
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.

58 lines
2.1 KiB

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