diff --git a/crypto.cc b/crypto.cc index 107be2c..25b1425 100644 --- a/crypto.cc +++ b/crypto.cc @@ -184,7 +184,9 @@ std::ostream& CryptoBase::Log(void *obj) { CryptoPubConnBase::CryptoPubConnBase(const SecretKey& secret_key) : secret_key_(secret_key), - state_(AWAITING_HANDSHAKE) {} + state_(AWAITING_HANDSHAKE) { + CryptoUtil::DerivePublicKey(secret_key_, &public_key_); +} CryptoPubConnBase::~CryptoPubConnBase() { bufferevent_free(bev_); @@ -209,9 +211,7 @@ std::unique_ptr CryptoPubConnBase::BuildHandshake() { auto secure_handshake = BuildSecureHandshake(); std::unique_ptr handshake(new TLVNode(TLV_TYPE_HANDSHAKE)); - PublicKey public_key; - CryptoUtil::DerivePublicKey(secret_key_, &public_key); - handshake->AppendChild(new TLVNode(TLV_TYPE_PUBLIC_KEY, public_key.AsString())); + handshake->AppendChild(new TLVNode(TLV_TYPE_PUBLIC_KEY, public_key_.AsString())); handshake->AppendChild(secure_handshake.release()); return handshake; diff --git a/crypto.h b/crypto.h index ea14837..7cb7f02 100644 --- a/crypto.h +++ b/crypto.h @@ -89,7 +89,9 @@ class CryptoPubConnBase : public CryptoBase { struct bufferevent* bev_; const SecretKey& secret_key_; + PublicKey public_key_; PublicKey peer_public_key_; + SecretKey ephemeral_secret_key_; PublicKey peer_ephemeral_public_key_; };