Path: blob/a-new-beginning/SharedDependencies/Sources/cryptopp/dh2.cpp
2 views
// dh2.cpp - originally written and placed in the public domain by Wei Dai12#include "pch.h"3#include "cryptlib.h"4#include "misc.h"5#include "dh2.h"67NAMESPACE_BEGIN(CryptoPP)89#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)10struct NullCryptoParameters : public CryptoParameters11{12void AssignFrom(const NameValuePairs &source) {13CRYPTOPP_UNUSED(source);14}15bool Validate(RandomNumberGenerator &rng, unsigned int level) const {16CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(level);17return false;18}19bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {20CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue);21return false;22}23};2425struct NullSimpleKeyAgreementDomain : public TwoBases<NullCryptoParameters, SimpleKeyAgreementDomain>26{27CryptoParameters & AccessCryptoParameters() {28return *this;29}30unsigned int AgreedValueLength() const {31return 1;32}33unsigned int PrivateKeyLength() const {34return 1;35}36unsigned int PublicKeyLength() const {37return 1;38}39void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const {40CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey);41}42void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const {43CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey); CRYPTOPP_UNUSED(publicKey);44}45bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const {46CRYPTOPP_UNUSED(agreedValue); CRYPTOPP_UNUSED(privateKey);47CRYPTOPP_UNUSED(otherPublicKey); CRYPTOPP_UNUSED(validateOtherPublicKey);48return false;49}50};5152void DH2_TestInstantiations()53{54NullSimpleKeyAgreementDomain dom;55DH2 dh(dom);56}57#endif5859bool DH2::Agree(byte *agreedValue,60const byte *staticSecretKey, const byte *ephemeralSecretKey,61const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,62bool validateStaticOtherPublicKey) const63{64return d1.Agree(agreedValue, staticSecretKey, staticOtherPublicKey, validateStaticOtherPublicKey)65&& d2.Agree(agreedValue+d1.AgreedValueLength(), ephemeralSecretKey, ephemeralOtherPublicKey, true);66}6768NAMESPACE_END697071