Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/cryptopp/dh2.cpp
2 views
1
// dh2.cpp - originally written and placed in the public domain by Wei Dai
2
3
#include "pch.h"
4
#include "cryptlib.h"
5
#include "misc.h"
6
#include "dh2.h"
7
8
NAMESPACE_BEGIN(CryptoPP)
9
10
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
11
struct NullCryptoParameters : public CryptoParameters
12
{
13
void AssignFrom(const NameValuePairs &source) {
14
CRYPTOPP_UNUSED(source);
15
}
16
bool Validate(RandomNumberGenerator &rng, unsigned int level) const {
17
CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(level);
18
return false;
19
}
20
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {
21
CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue);
22
return false;
23
}
24
};
25
26
struct NullSimpleKeyAgreementDomain : public TwoBases<NullCryptoParameters, SimpleKeyAgreementDomain>
27
{
28
CryptoParameters & AccessCryptoParameters() {
29
return *this;
30
}
31
unsigned int AgreedValueLength() const {
32
return 1;
33
}
34
unsigned int PrivateKeyLength() const {
35
return 1;
36
}
37
unsigned int PublicKeyLength() const {
38
return 1;
39
}
40
void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const {
41
CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey);
42
}
43
void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const {
44
CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(privateKey); CRYPTOPP_UNUSED(publicKey);
45
}
46
bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const {
47
CRYPTOPP_UNUSED(agreedValue); CRYPTOPP_UNUSED(privateKey);
48
CRYPTOPP_UNUSED(otherPublicKey); CRYPTOPP_UNUSED(validateOtherPublicKey);
49
return false;
50
}
51
};
52
53
void DH2_TestInstantiations()
54
{
55
NullSimpleKeyAgreementDomain dom;
56
DH2 dh(dom);
57
}
58
#endif
59
60
bool DH2::Agree(byte *agreedValue,
61
const byte *staticSecretKey, const byte *ephemeralSecretKey,
62
const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,
63
bool validateStaticOtherPublicKey) const
64
{
65
return d1.Agree(agreedValue, staticSecretKey, staticOtherPublicKey, validateStaticOtherPublicKey)
66
&& d2.Agree(agreedValue+d1.AgreedValueLength(), ephemeralSecretKey, ephemeralOtherPublicKey, true);
67
}
68
69
NAMESPACE_END
70
71