Cache derived public key.
This commit is contained in:
@@ -184,7 +184,9 @@ std::ostream& CryptoBase::Log(void *obj) {
|
|||||||
|
|
||||||
CryptoPubConnBase::CryptoPubConnBase(const SecretKey& secret_key)
|
CryptoPubConnBase::CryptoPubConnBase(const SecretKey& secret_key)
|
||||||
: secret_key_(secret_key),
|
: secret_key_(secret_key),
|
||||||
state_(AWAITING_HANDSHAKE) {}
|
state_(AWAITING_HANDSHAKE) {
|
||||||
|
CryptoUtil::DerivePublicKey(secret_key_, &public_key_);
|
||||||
|
}
|
||||||
|
|
||||||
CryptoPubConnBase::~CryptoPubConnBase() {
|
CryptoPubConnBase::~CryptoPubConnBase() {
|
||||||
bufferevent_free(bev_);
|
bufferevent_free(bev_);
|
||||||
@@ -209,9 +211,7 @@ std::unique_ptr<TLVNode> CryptoPubConnBase::BuildHandshake() {
|
|||||||
auto secure_handshake = BuildSecureHandshake();
|
auto secure_handshake = BuildSecureHandshake();
|
||||||
|
|
||||||
std::unique_ptr<TLVNode> handshake(new TLVNode(TLV_TYPE_HANDSHAKE));
|
std::unique_ptr<TLVNode> handshake(new TLVNode(TLV_TYPE_HANDSHAKE));
|
||||||
PublicKey public_key;
|
handshake->AppendChild(new TLVNode(TLV_TYPE_PUBLIC_KEY, public_key_.AsString()));
|
||||||
CryptoUtil::DerivePublicKey(secret_key_, &public_key);
|
|
||||||
handshake->AppendChild(new TLVNode(TLV_TYPE_PUBLIC_KEY, public_key.AsString()));
|
|
||||||
handshake->AppendChild(secure_handshake.release());
|
handshake->AppendChild(secure_handshake.release());
|
||||||
|
|
||||||
return handshake;
|
return handshake;
|
||||||
|
|||||||
2
crypto.h
2
crypto.h
@@ -89,7 +89,9 @@ class CryptoPubConnBase : public CryptoBase {
|
|||||||
struct bufferevent* bev_;
|
struct bufferevent* bev_;
|
||||||
|
|
||||||
const SecretKey& secret_key_;
|
const SecretKey& secret_key_;
|
||||||
|
PublicKey public_key_;
|
||||||
PublicKey peer_public_key_;
|
PublicKey peer_public_key_;
|
||||||
|
|
||||||
SecretKey ephemeral_secret_key_;
|
SecretKey ephemeral_secret_key_;
|
||||||
PublicKey peer_ephemeral_public_key_;
|
PublicKey peer_ephemeral_public_key_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user