Browse Source

blind ECDSA private key

pull/1359/head
orignal 6 years ago
parent
commit
e40c139ff1
  1. 41
      libi2pd/Blinding.cpp
  2. 2
      libi2pd/Blinding.h
  3. 6
      libi2pd/LeaseSet.cpp

41
libi2pd/Blinding.cpp

@ -9,6 +9,7 @@
#include "Timestamp.h" #include "Timestamp.h"
#include "I2PEndian.h" #include "I2PEndian.h"
#include "Ed25519.h" #include "Ed25519.h"
#include "Signature.h"
#include "Blinding.h" #include "Blinding.h"
namespace i2p namespace i2p
@ -51,7 +52,7 @@ namespace data
BN_CTX_free (ctx); BN_CTX_free (ctx);
} }
void BlindPrivateKeyECDSA (size_t publicKeyLen, const EC_GROUP * group, const uint8_t * priv, const uint8_t * seed, uint8_t * blindedPriv, uint8_t * blindedPub) static void BlindPrivateKeyECDSA (size_t publicKeyLen, const EC_GROUP * group, const uint8_t * priv, const uint8_t * seed, uint8_t * blindedPriv, uint8_t * blindedPub)
{ {
BIGNUM * a = BN_bin2bn (priv, publicKeyLen/2, NULL); BIGNUM * a = BN_bin2bn (priv, publicKeyLen/2, NULL);
BIGNUM * a1 = BN_new (); BIGNUM * a1 = BN_new ();
@ -166,11 +167,47 @@ namespace data
i2p::crypto::GetEd25519 ()->BlindPublicKey (GetPublicKey (), seed, blindedKey); i2p::crypto::GetEd25519 ()->BlindPublicKey (GetPublicKey (), seed, blindedKey);
} }
void BlindedPublicKey::BlindPrivateKey (const uint8_t * priv, const char * date, uint8_t * blindedPriv, uint8_t * blindedPub) const size_t BlindedPublicKey::BlindPrivateKey (const uint8_t * priv, const char * date, uint8_t * blindedPriv, uint8_t * blindedPub) const
{ {
uint8_t seed[64]; uint8_t seed[64];
GenerateAlpha (date, seed); GenerateAlpha (date, seed);
size_t publicKeyLength = 0;
switch (m_SigType)
{
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256:
{
publicKeyLength = i2p::crypto::ECDSAP256_KEY_LENGTH;
EC_GROUP * group = EC_GROUP_new_by_curve_name (NID_X9_62_prime256v1);
BlindPrivateKeyECDSA (publicKeyLength, group, priv, seed, blindedPriv, blindedPub);
EC_GROUP_free (group);
break;
}
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384:
{
publicKeyLength = i2p::crypto::ECDSAP384_KEY_LENGTH;
EC_GROUP * group = EC_GROUP_new_by_curve_name (NID_secp384r1);
BlindPrivateKeyECDSA (publicKeyLength, group, priv, seed, blindedPriv, blindedPub);
EC_GROUP_free (group);
break;
}
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521:
{
publicKeyLength = i2p::crypto::ECDSAP521_KEY_LENGTH;
EC_GROUP * group = EC_GROUP_new_by_curve_name (NID_secp521r1);
BlindPrivateKeyECDSA (publicKeyLength, group, priv, seed, blindedPriv, blindedPub);
EC_GROUP_free (group);
break;
}
case i2p::data::SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519:
{
i2p::crypto::GetEd25519 ()->BlindPrivateKey (priv, seed, blindedPriv, blindedPub); i2p::crypto::GetEd25519 ()->BlindPrivateKey (priv, seed, blindedPriv, blindedPub);
publicKeyLength = i2p::crypto::EDDSA25519_PUBLIC_KEY_LENGTH;
break;
}
default:
LogPrint (eLogError, "Blinding: can't blind signature type ", (int)m_SigType);
}
return publicKeyLength;
} }
void BlindedPublicKey::H (const std::string& p, const std::vector<std::pair<const uint8_t *, size_t> >& bufs, uint8_t * hash) const void BlindedPublicKey::H (const std::string& p, const std::vector<std::pair<const uint8_t *, size_t> >& bufs, uint8_t * hash) const

2
libi2pd/Blinding.h

@ -25,7 +25,7 @@ namespace data
void GetSubcredential (const uint8_t * blinded, size_t len, uint8_t * subcredential) const; // 32 bytes void GetSubcredential (const uint8_t * blinded, size_t len, uint8_t * subcredential) const; // 32 bytes
void GetBlindedKey (const char * date, uint8_t * blindedKey) const; // blinded key 32 bytes, date is 8 chars "YYYYMMDD" void GetBlindedKey (const char * date, uint8_t * blindedKey) const; // blinded key 32 bytes, date is 8 chars "YYYYMMDD"
void BlindPrivateKey (const uint8_t * priv, const char * date, uint8_t * blindedPriv, uint8_t * blindedPub) const; // blinded key 32 bytes, date is 8 chars "YYYYMMDD" size_t BlindPrivateKey (const uint8_t * priv, const char * date, uint8_t * blindedPriv, uint8_t * blindedPub) const; // date is 8 chars "YYYYMMDD", return public key length
i2p::data::IdentHash GetStoreHash (const char * date = nullptr) const; // date is 8 chars "YYYYMMDD", use current if null i2p::data::IdentHash GetStoreHash (const char * date = nullptr) const; // date is 8 chars "YYYYMMDD", use current if null
private: private:

6
libi2pd/LeaseSet.cpp

@ -727,12 +727,12 @@ namespace data
auto timestamp = i2p::util::GetSecondsSinceEpoch (); auto timestamp = i2p::util::GetSecondsSinceEpoch ();
char date[9]; char date[9];
i2p::util::GetDateString (timestamp, date); i2p::util::GetDateString (timestamp, date);
uint8_t blindedPriv[32], blindedPub[32]; uint8_t blindedPriv[64], blindedPub[128]; // 64 and 128 max
blindedKey.BlindPrivateKey (keys.GetSigningPrivateKey (), date, blindedPriv, blindedPub); size_t publicKeyLen = blindedKey.BlindPrivateKey (keys.GetSigningPrivateKey (), date, blindedPriv, blindedPub);
std::unique_ptr<i2p::crypto::Signer> blindedSigner (i2p::data::PrivateKeys::CreateSigner (blindedKeyType, blindedPriv)); std::unique_ptr<i2p::crypto::Signer> blindedSigner (i2p::data::PrivateKeys::CreateSigner (blindedKeyType, blindedPriv));
auto offset = 1; auto offset = 1;
htobe16buf (m_Buffer + offset, blindedKeyType); offset += 2; // Blinded Public Key Sig Type htobe16buf (m_Buffer + offset, blindedKeyType); offset += 2; // Blinded Public Key Sig Type
memcpy (m_Buffer + offset, blindedPub, 32); offset += 32; // Blinded Public Key memcpy (m_Buffer + offset, blindedPub, publicKeyLen); offset += publicKeyLen; // Blinded Public Key
htobe32buf (m_Buffer + offset, timestamp); offset += 4; // published timestamp (seconds) htobe32buf (m_Buffer + offset, timestamp); offset += 4; // published timestamp (seconds)
auto nextMidnight = (timestamp/86400LL + 1)*86400LL; // 86400 = 24*3600 seconds auto nextMidnight = (timestamp/86400LL + 1)*86400LL; // 86400 = 24*3600 seconds
auto expirationTime = ls->GetExpirationTime ()/1000LL; auto expirationTime = ls->GetExpirationTime ()/1000LL;

Loading…
Cancel
Save