Browse Source

long ElGamal private key

pull/138/head
orignal 10 years ago
parent
commit
3e13a1feed
  1. 7
      Destination.cpp
  2. 12
      ElGamal.h
  3. 4
      Identity.cpp

7
Destination.cpp

@ -1,13 +1,13 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <cryptopp/dh.h>
#include "Log.h" #include "Log.h"
#include "util.h" #include "util.h"
#include "ElGamal.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "NetDb.h" #include "NetDb.h"
#include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "Destination.h"
namespace i2p namespace i2p
{ {
@ -19,8 +19,7 @@ namespace client
m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0), m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0),
m_DatagramDestination (nullptr), m_PublishConfirmationTimer (m_Service) m_DatagramDestination (nullptr), m_PublishConfirmationTimer (m_Service)
{ {
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); i2p::crypto::GenerateElGamalKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
int inboundTunnelLen = DEFAULT_INBOUND_TUNNEL_LENGTH; int inboundTunnelLen = DEFAULT_INBOUND_TUNNEL_LENGTH;
int outboundTunnelLen = DEFAULT_OUTBOUND_TUNNEL_LENGTH; int outboundTunnelLen = DEFAULT_OUTBOUND_TUNNEL_LENGTH;
if (params) if (params)

12
ElGamal.h

@ -4,6 +4,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <cryptopp/integer.h> #include <cryptopp/integer.h>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include <cryptopp/dh.h>
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include "CryptoConst.h" #include "CryptoConst.h"
#include "Log.h" #include "Log.h"
@ -70,6 +71,17 @@ namespace crypto
memcpy (data, m + 33, 222); memcpy (data, m + 33, 222);
return true; return true;
} }
inline void GenerateElGamalKeyPair (CryptoPP::RandomNumberGenerator& rnd, uint8_t * priv, uint8_t * pub)
{
#if defined(__x86_64__) || defined(__i386__) || defined(_MSC_VER)
rnd.GenerateBlock (priv, 256);
a_exp_b_mod_c (elgg, CryptoPP::Integer (priv, 256), elgp).Encode (pub, 256);
#else
CryptoPP::DH dh (elgp, elgg);
dh.GenerateKeyPair(rnd, priv, pub);
#endif
}
} }
} }

4
Identity.cpp

@ -5,6 +5,7 @@
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include "base64.h" #include "base64.h"
#include "CryptoConst.h" #include "CryptoConst.h"
#include "ElGamal.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Identity.h" #include "Identity.h"
#include "I2PEndian.h" #include "I2PEndian.h"
@ -509,8 +510,7 @@ namespace data
Keys keys; Keys keys;
auto& rnd = i2p::context.GetRandomNumberGenerator (); auto& rnd = i2p::context.GetRandomNumberGenerator ();
// encryption // encryption
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); i2p::crypto::GenerateElGamalKeyPair(rnd, keys.privateKey, keys.publicKey);
dh.GenerateKeyPair(rnd, keys.privateKey, keys.publicKey);
// signing // signing
i2p::crypto::CreateDSARandomKeys (rnd, keys.signingPrivateKey, keys.signingKey); i2p::crypto::CreateDSARandomKeys (rnd, keys.signingPrivateKey, keys.signingKey);
return keys; return keys;

Loading…
Cancel
Save