From 24c5ed1cfff723c2731479299d8253738e18d797 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 6 Mar 2019 16:08:04 -0500 Subject: [PATCH] calculate store hash for encrypted LeaseSet2 --- libi2pd/Ed25519.cpp | 2 +- libi2pd/LeaseSet.cpp | 14 +++++++++++++- libi2pd/LeaseSet.h | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libi2pd/Ed25519.cpp b/libi2pd/Ed25519.cpp index 4e631291..64ddeaf4 100644 --- a/libi2pd/Ed25519.cpp +++ b/libi2pd/Ed25519.cpp @@ -495,7 +495,7 @@ namespace crypto { BN_CTX * ctx = BN_CTX_new (); // calculate alpha = seed mod l - BIGNUM * alpha = DecodeBN<64> (seed); // pub is in Little Endian + BIGNUM * alpha = DecodeBN<64> (seed); // seed is in Little Endian BN_mod (alpha, alpha, l, ctx); // % l uint8_t priv[32]; EncodeBN (alpha, priv, 32); // back to Little Endian diff --git a/libi2pd/LeaseSet.cpp b/libi2pd/LeaseSet.cpp index 24578988..0cf69102 100644 --- a/libi2pd/LeaseSet.cpp +++ b/libi2pd/LeaseSet.cpp @@ -530,7 +530,7 @@ namespace data memcpy (out, info.c_str (), l); out[l] = 0x01; HMAC(EVP_sha256(), prk, 32, out, l + 1, out, &len); memcpy (out + 32, info.c_str (), l); out[l + 32] = 0x02; - HMAC(EVP_sha256(), prk, 32, out, 41, out + 32, &len); + HMAC(EVP_sha256(), prk, 32, out, l + 33, out + 32, &len); } void LeaseSet2::BlindPublicKey (std::shared_ptr identity, const char * date, SigningKeyType blindedKeyType, uint8_t * blindedKey) @@ -543,6 +543,18 @@ namespace data i2p::crypto::GetEd25519 ()->BlindPublicKey (identity->GetSigningPublicKeyBuffer (), seed, blindedKey); } + void LeaseSet2::CalculateStoreHash (std::shared_ptr identity, const char * date, SigningKeyType blindedKeyType, i2p::data::IdentHash& hash) + { + uint8_t blinded[32]; + BlindPublicKey (identity, date, blindedKeyType, blinded); + auto stA1 = htobe16 (blindedKeyType); + SHA256_CTX ctx; + SHA256_Init (&ctx); + SHA256_Update (&ctx, (const uint8_t *)&stA1, 2); + SHA256_Update (&ctx, blinded, 32); + SHA256_Final ((uint8_t *)hash, &ctx); + } + void LeaseSet2::Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const { auto encryptor = m_Encryptor; // TODO: atomic diff --git a/libi2pd/LeaseSet.h b/libi2pd/LeaseSet.h index 985517d9..4d1ee121 100644 --- a/libi2pd/LeaseSet.h +++ b/libi2pd/LeaseSet.h @@ -139,6 +139,8 @@ namespace data std::shared_ptr GetTransientVerifier () const { return m_TransientVerifier; }; void Update (const uint8_t * buf, size_t len, bool verifySignature); + static void CalculateStoreHash (std::shared_ptr identity, const char * date, SigningKeyType blindedKeyType, i2p::data::IdentHash& hash); + // implements RoutingDestination void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;