Browse Source

ECDSA for local destinations

pull/93/head
orignal 10 years ago
parent
commit
0e230fdd05
  1. 5
      Identity.cpp
  2. 21
      Streaming.cpp

5
Identity.cpp

@ -50,15 +50,18 @@ namespace data
m_ExtendedBuffer = new uint8_t[m_ExtendedLen]; m_ExtendedBuffer = new uint8_t[m_ExtendedLen];
*(uint16_t *)m_ExtendedBuffer = htobe16 (SIGNING_KEY_TYPE_ECDSA_SHA256_P256); *(uint16_t *)m_ExtendedBuffer = htobe16 (SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
*(uint16_t *)(m_ExtendedBuffer + 2) = htobe16 (CRYPTO_KEY_TYPE_ELGAMAL); *(uint16_t *)(m_ExtendedBuffer + 2) = htobe16 (CRYPTO_KEY_TYPE_ELGAMAL);
uint8_t buf[DEFAULT_IDENTITY_SIZE + 4];
ToBuffer (buf, DEFAULT_IDENTITY_SIZE + 4);
CryptoPP::SHA256().CalculateDigest(m_IdentHash, buf, GetFullLen ());
} }
else // DSA-SHA1 else // DSA-SHA1
{ {
memcpy (m_StandardIdentity.signingKey, signingKey, sizeof (m_StandardIdentity.signingKey)); memcpy (m_StandardIdentity.signingKey, signingKey, sizeof (m_StandardIdentity.signingKey));
memset (&m_StandardIdentity.certificate, 0, sizeof (m_StandardIdentity.certificate)); memset (&m_StandardIdentity.certificate, 0, sizeof (m_StandardIdentity.certificate));
m_IdentHash = m_StandardIdentity.Hash ();
m_ExtendedLen = 0; m_ExtendedLen = 0;
m_ExtendedBuffer = nullptr; m_ExtendedBuffer = nullptr;
} }
m_IdentHash = m_StandardIdentity.Hash ();
CreateVerifier (); CreateVerifier ();
} }

21
Streaming.cpp

@ -261,15 +261,17 @@ namespace stream
if (isNoAck) flags |= PACKET_FLAG_NO_ACK; if (isNoAck) flags |= PACKET_FLAG_NO_ACK;
*(uint16_t *)(packet + size) = htobe16 (flags); *(uint16_t *)(packet + size) = htobe16 (flags);
size += 2; // flags size += 2; // flags
*(uint16_t *)(packet + size) = htobe16 (i2p::data::DEFAULT_IDENTITY_SIZE + 40 + 2); // identity + signature + packet size size_t identityLen = m_LocalDestination->GetIdentity ().GetFullLen ();
size_t signatureLen = m_LocalDestination->GetIdentity ().GetSignatureLen ();
*(uint16_t *)(packet + size) = htobe16 (identityLen + signatureLen + 2); // identity + signature + packet size
size += 2; // options size size += 2; // options size
memcpy (packet + size, &m_LocalDestination->GetIdentity (), i2p::data::DEFAULT_IDENTITY_SIZE); m_LocalDestination->GetIdentity ().ToBuffer (packet + size, identityLen);
size += i2p::data::DEFAULT_IDENTITY_SIZE; // from size += identityLen; // from
*(uint16_t *)(packet + size) = htobe16 (STREAMING_MTU); *(uint16_t *)(packet + size) = htobe16 (STREAMING_MTU);
size += 2; // max packet size size += 2; // max packet size
uint8_t * signature = packet + size; // set it later uint8_t * signature = packet + size; // set it later
memset (signature, 0, 40); // zeroes for now memset (signature, 0, signatureLen); // zeroes for now
size += 40; // signature size += signatureLen; // signature
size_t sentLen = STREAMING_MTU - size; size_t sentLen = STREAMING_MTU - size;
if (len < sentLen) sentLen = len; if (len < sentLen) sentLen = len;
memcpy (packet + size, buf, sentLen); memcpy (packet + size, buf, sentLen);
@ -347,11 +349,12 @@ namespace stream
size++; // resend delay size++; // resend delay
*(uint16_t *)(packet + size) = htobe16 (PACKET_FLAG_CLOSE | PACKET_FLAG_SIGNATURE_INCLUDED); *(uint16_t *)(packet + size) = htobe16 (PACKET_FLAG_CLOSE | PACKET_FLAG_SIGNATURE_INCLUDED);
size += 2; // flags size += 2; // flags
*(uint16_t *)(packet + size) = htobe16 (40); // 40 bytes signature size_t signatureLen = m_LocalDestination->GetIdentity ().GetSignatureLen ();
*(uint16_t *)(packet + size) = htobe16 (signatureLen); // signature only
size += 2; // options size size += 2; // options size
uint8_t * signature = packet + size; uint8_t * signature = packet + size;
memset (packet + size, 0, 40); memset (packet + size, 0, signatureLen);
size += 40; // signature size += signatureLen; // signature
m_LocalDestination->Sign (packet, size, signature); m_LocalDestination->Sign (packet, size, signature);
p->len = size; p->len = size;
@ -505,7 +508,7 @@ namespace stream
StreamingDestination::StreamingDestination (boost::asio::io_service& service): StreamingDestination::StreamingDestination (boost::asio::io_service& service):
m_Service (service), m_LeaseSet (nullptr), m_IsPublic (false) m_Service (service), m_LeaseSet (nullptr), m_IsPublic (false)
{ {
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (); m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (/*i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256*/); // uncomment for ECDSA
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3); // 3-hops tunnel

Loading…
Cancel
Save