mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
978 B
40 lines
978 B
11 years ago
|
#include <cryptopp/sha.h>
|
||
|
#include <cryptopp/osrng.h>
|
||
|
#include <cryptopp/dh.h>
|
||
|
#include <cryptopp/dsa.h>
|
||
|
#include "CryptoConst.h"
|
||
|
#include "Identity.h"
|
||
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
namespace data
|
||
|
{
|
||
|
IdentHash CalculateIdentHash (const Identity& identity)
|
||
|
{
|
||
|
IdentHash hash;
|
||
|
CryptoPP::SHA256().CalculateDigest((uint8_t *)hash, (uint8_t *)&identity, sizeof (Identity));
|
||
|
return hash;
|
||
|
}
|
||
|
|
||
|
Keys CreateRandomKeys ()
|
||
|
{
|
||
|
Keys keys;
|
||
|
CryptoPP::AutoSeededRandomPool rnd;
|
||
|
|
||
|
// encryption
|
||
|
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||
|
dh.GenerateKeyPair(rnd, keys.privateKey, keys.publicKey);
|
||
|
|
||
|
// signing
|
||
|
CryptoPP::DSA::PrivateKey privateKey;
|
||
|
CryptoPP::DSA::PublicKey publicKey;
|
||
|
privateKey.Initialize (rnd, i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag);
|
||
|
privateKey.MakePublicKey (publicKey);
|
||
|
privateKey.GetPrivateExponent ().Encode (keys.signingPrivateKey, 20);
|
||
|
publicKey.GetPublicElement ().Encode (keys.signingKey, 128);
|
||
|
|
||
|
return keys;
|
||
|
}
|
||
|
}
|
||
|
}
|