Crypto++
|
00001 #ifndef CRYPTOPP_DH2_H 00002 #define CRYPTOPP_DH2_H 00003 00004 /** \file 00005 */ 00006 00007 #include "cryptlib.h" 00008 00009 NAMESPACE_BEGIN(CryptoPP) 00010 00011 /// <a href="http://www.weidai.com/scan-mirror/ka.html#DH2">Unified Diffie-Hellman</a> 00012 class DH2 : public AuthenticatedKeyAgreementDomain 00013 { 00014 public: 00015 DH2(SimpleKeyAgreementDomain &domain) 00016 : d1(domain), d2(domain) {} 00017 DH2(SimpleKeyAgreementDomain &staticDomain, SimpleKeyAgreementDomain &ephemeralDomain) 00018 : d1(staticDomain), d2(ephemeralDomain) {} 00019 00020 CryptoParameters & AccessCryptoParameters() {return d1.AccessCryptoParameters();} 00021 00022 unsigned int AgreedValueLength() const 00023 {return d1.AgreedValueLength() + d2.AgreedValueLength();} 00024 00025 unsigned int StaticPrivateKeyLength() const 00026 {return d1.PrivateKeyLength();} 00027 unsigned int StaticPublicKeyLength() const 00028 {return d1.PublicKeyLength();} 00029 void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const 00030 {d1.GeneratePrivateKey(rng, privateKey);} 00031 void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const 00032 {d1.GeneratePublicKey(rng, privateKey, publicKey);} 00033 void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const 00034 {d1.GenerateKeyPair(rng, privateKey, publicKey);} 00035 00036 unsigned int EphemeralPrivateKeyLength() const 00037 {return d2.PrivateKeyLength();} 00038 unsigned int EphemeralPublicKeyLength() const 00039 {return d2.PublicKeyLength();} 00040 void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const 00041 {d2.GeneratePrivateKey(rng, privateKey);} 00042 void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const 00043 {d2.GeneratePublicKey(rng, privateKey, publicKey);} 00044 void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const 00045 {d2.GenerateKeyPair(rng, privateKey, publicKey);} 00046 00047 bool Agree(byte *agreedValue, 00048 const byte *staticPrivateKey, const byte *ephemeralPrivateKey, 00049 const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, 00050 bool validateStaticOtherPublicKey=true) const; 00051 00052 protected: 00053 SimpleKeyAgreementDomain &d1, &d2; 00054 }; 00055 00056 NAMESPACE_END 00057 00058 #endif