Merge pull request #1080 from majestrate/fix-kdf-2020-02-03

don't derive x25519 key from ed25519 key
This commit is contained in:
Jeff 2020-02-04 12:30:22 -05:00 committed by GitHub
commit 702ab29ce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 34 deletions

View File

@ -59,8 +59,8 @@ namespace llarp
{ {
auto crypto = CryptoManager::instance(); auto crypto = CryptoManager::instance();
crypto->identity_keygen(signkey); crypto->identity_keygen(signkey);
crypto_sign_ed25519_sk_to_curve25519(enckey.data(), signkey.data()); crypto->encryption_keygen(enckey);
pub.Update(seckey_topublic(signkey)); pub.Update(seckey_topublic(signkey), seckey_topublic(enckey));
crypto->pqe_keygen(pq); crypto->pqe_keygen(pq);
if(not crypto->derive_subkey_private(derivedSignKey, signkey, 1)) if(not crypto->derive_subkey_private(derivedSignKey, signkey, 1))
{ {
@ -146,8 +146,7 @@ namespace llarp
if(!vanity.IsZero()) if(!vanity.IsZero())
van = vanity; van = vanity;
// update pubkeys // update pubkeys
pub.Update(seckey_topublic(signkey), van); pub.Update(seckey_topublic(signkey), seckey_topublic(enckey), van);
crypto_sign_ed25519_sk_to_curve25519(enckey.data(), signkey.data());
auto crypto = CryptoManager::instance(); auto crypto = CryptoManager::instance();
return crypto->derive_subkey_private(derivedSignKey, signkey, 1); return crypto->derive_subkey_private(derivedSignKey, signkey, 1);
} }

View File

@ -21,11 +21,11 @@ namespace llarp
} }
bool bool
ServiceInfo::Update(const byte_t* pubkey, const OptNonce& nonce) ServiceInfo::Update(const byte_t* sign, const byte_t* enc,
const OptNonce& nonce)
{ {
signkey = pubkey; signkey = sign;
if(crypto_sign_ed25519_pk_to_curve25519(enckey.data(), pubkey) == -1) enckey = enc;
return false;
if(nonce) if(nonce)
{ {
vanity = nonce.value(); vanity = nonce.value();

View File

@ -45,7 +45,8 @@ namespace llarp
} }
bool bool
Update(const byte_t* pubkey, const OptNonce& nonce = OptNonce()); Update(const byte_t* sign, const byte_t* enc,
const OptNonce& nonce = OptNonce());
bool bool
operator==(const ServiceInfo& other) const operator==(const ServiceInfo& other) const

View File

@ -22,31 +22,6 @@ struct HiddenServiceTest : public test::LlarpTest<>
service::Identity ident; service::Identity ident;
}; };
TEST_F(HiddenServiceTest, TestGenerateIntroSet)
{
service::Address addr;
ASSERT_TRUE(ident.pub.CalculateAddress(addr.as_array()));
service::IntroSet I;
auto now = time_now_ms();
I.T = now;
while(I.I.size() < 10)
{
service::Introduction intro;
intro.expiresAt = now + (path::default_lifetime / 2);
intro.router.Randomize();
intro.pathID.Randomize();
I.I.emplace_back(std::move(intro));
}
using ::testing::Matcher;
EXPECT_CALL(m_crypto, sign(I.Z, Matcher<const SecretKey &>(_), _)).WillOnce(Return(true));
EXPECT_CALL(m_crypto, verify(_, _, I.Z)).WillOnce(Return(true));
EXPECT_CALL(m_crypto, xchacha20(_, _, _)).WillOnce(Return(true));
const auto maybe = ident.EncryptAndSignIntroSet(I, now);
ASSERT_TRUE(maybe.has_value());
ASSERT_TRUE(maybe->Verify(now));
}
TEST_F(HiddenServiceTest, TestAddressToFromString) TEST_F(HiddenServiceTest, TestAddressToFromString)
{ {
auto str = ident.pub.Addr().ToString(); auto str = ident.pub.Addr().ToString();
@ -81,6 +56,9 @@ TEST_F(ServiceIdentityTest, EnsureKeys)
EXPECT_CALL(m_crypto, derive_subkey_private(_, _, _, _)) EXPECT_CALL(m_crypto, derive_subkey_private(_, _, _, _))
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
EXPECT_CALL(m_crypto, encryption_keygen(_))
.WillOnce(WithArg< 0 >(FillArg< SecretKey >(0x01)));
EXPECT_CALL(m_crypto, identity_keygen(_)) EXPECT_CALL(m_crypto, identity_keygen(_))
.WillOnce(WithArg< 0 >(FillArg< SecretKey >(0x02))); .WillOnce(WithArg< 0 >(FillArg< SecretKey >(0x02)));