Browse Source

calculate store hash for encrypted LeaseSet2

pull/1313/head
orignal 6 years ago
parent
commit
24c5ed1cff
  1. 2
      libi2pd/Ed25519.cpp
  2. 14
      libi2pd/LeaseSet.cpp
  3. 2
      libi2pd/LeaseSet.h

2
libi2pd/Ed25519.cpp

@ -495,7 +495,7 @@ namespace crypto
{ {
BN_CTX * ctx = BN_CTX_new (); BN_CTX * ctx = BN_CTX_new ();
// calculate alpha = seed mod l // 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 BN_mod (alpha, alpha, l, ctx); // % l
uint8_t priv[32]; uint8_t priv[32];
EncodeBN (alpha, priv, 32); // back to Little Endian EncodeBN (alpha, priv, 32); // back to Little Endian

14
libi2pd/LeaseSet.cpp

@ -530,7 +530,7 @@ namespace data
memcpy (out, info.c_str (), l); out[l] = 0x01; memcpy (out, info.c_str (), l); out[l] = 0x01;
HMAC(EVP_sha256(), prk, 32, out, l + 1, out, &len); HMAC(EVP_sha256(), prk, 32, out, l + 1, out, &len);
memcpy (out + 32, info.c_str (), l); out[l + 32] = 0x02; 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<const IdentityEx> identity, const char * date, SigningKeyType blindedKeyType, uint8_t * blindedKey) void LeaseSet2::BlindPublicKey (std::shared_ptr<const IdentityEx> identity, const char * date, SigningKeyType blindedKeyType, uint8_t * blindedKey)
@ -543,6 +543,18 @@ namespace data
i2p::crypto::GetEd25519 ()->BlindPublicKey (identity->GetSigningPublicKeyBuffer (), seed, blindedKey); i2p::crypto::GetEd25519 ()->BlindPublicKey (identity->GetSigningPublicKeyBuffer (), seed, blindedKey);
} }
void LeaseSet2::CalculateStoreHash (std::shared_ptr<const IdentityEx> 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 void LeaseSet2::Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const
{ {
auto encryptor = m_Encryptor; // TODO: atomic auto encryptor = m_Encryptor; // TODO: atomic

2
libi2pd/LeaseSet.h

@ -139,6 +139,8 @@ namespace data
std::shared_ptr<const i2p::crypto::Verifier> GetTransientVerifier () const { return m_TransientVerifier; }; std::shared_ptr<const i2p::crypto::Verifier> GetTransientVerifier () const { return m_TransientVerifier; };
void Update (const uint8_t * buf, size_t len, bool verifySignature); void Update (const uint8_t * buf, size_t len, bool verifySignature);
static void CalculateStoreHash (std::shared_ptr<const IdentityEx> identity, const char * date, SigningKeyType blindedKeyType, i2p::data::IdentHash& hash);
// implements RoutingDestination // implements RoutingDestination
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const; void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) const;

Loading…
Cancel
Save