2017-01-27 12:05:45 +00:00
|
|
|
// dh2.cpp - originally written and placed in the public domain by Wei Dai
|
2015-11-05 06:59:46 +00:00
|
|
|
|
|
|
|
#include "pch.h"
|
2017-08-17 00:49:03 +00:00
|
|
|
#include "cryptlib.h"
|
|
|
|
#include "misc.h"
|
2015-11-05 06:59:46 +00:00
|
|
|
#include "dh2.h"
|
|
|
|
|
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
|
2016-10-18 02:00:31 +00:00
|
|
|
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
|
2017-08-17 00:49:03 +00:00
|
|
|
struct NullCryptoParameters : public CryptoParameters
|
|
|
|
{
|
|
|
|
void AssignFrom(const NameValuePairs &source) {
|
2017-08-17 02:56:36 +00:00
|
|
|
CRYPTOPP_UNUSED(source);
|
2017-08-17 00:49:03 +00:00
|
|
|
}
|
|
|
|
bool Validate(RandomNumberGenerator &rng, unsigned int level) const {
|
2017-08-17 02:56:36 +00:00
|
|
|
CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(level);
|
2017-08-17 00:49:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {
|
2017-08-17 02:56:36 +00:00
|
|
|
CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue);
|
2017-08-17 00:49:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NullSimpleKeyAgreementDomain : public TwoBases<NullCryptoParameters, SimpleKeyAgreementDomain>
|
|
|
|
{
|
|
|
|
CryptoParameters & AccessCryptoParameters() {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
unsigned int AgreedValueLength() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
unsigned int PrivateKeyLength() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
unsigned int PublicKeyLength() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const {
|
2017-08-17 02:56:36 +00:00
|
|
|
CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey);
|
2017-08-17 00:49:03 +00:00
|
|
|
}
|
|
|
|
void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const {
|
2017-08-17 02:56:36 +00:00
|
|
|
CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey); CRYPTOPP_UNUSED(publicKey);
|
2017-08-17 00:49:03 +00:00
|
|
|
}
|
|
|
|
bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const {
|
2017-08-17 02:56:36 +00:00
|
|
|
CRYPTOPP_UNUSED(agreedValue); CRYPTOPP_UNUSED(privateKey);
|
|
|
|
CRYPTOPP_UNUSED(otherPublicKey); CRYPTOPP_UNUSED(validateOtherPublicKey);
|
2017-08-17 00:49:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
void DH2_TestInstantiations()
|
|
|
|
{
|
2017-08-17 00:49:03 +00:00
|
|
|
NullSimpleKeyAgreementDomain dom;
|
|
|
|
DH2 dh(dom);
|
2015-11-05 06:59:46 +00:00
|
|
|
}
|
2015-11-18 20:32:28 +00:00
|
|
|
#endif
|
2015-11-05 06:59:46 +00:00
|
|
|
|
|
|
|
bool DH2::Agree(byte *agreedValue,
|
2016-09-10 08:57:48 +00:00
|
|
|
const byte *staticSecretKey, const byte *ephemeralSecretKey,
|
2015-11-05 06:59:46 +00:00
|
|
|
const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,
|
|
|
|
bool validateStaticOtherPublicKey) const
|
|
|
|
{
|
|
|
|
return d1.Agree(agreedValue, staticSecretKey, staticOtherPublicKey, validateStaticOtherPublicKey)
|
|
|
|
&& d2.Agree(agreedValue+d1.AgreedValueLength(), ephemeralSecretKey, ephemeralOtherPublicKey, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAMESPACE_END
|