2015-04-09 17:03:21 +03:00
|
|
|
#include <memory>
|
2015-04-08 20:21:49 +03:00
|
|
|
#include <cryptopp/integer.h>
|
|
|
|
#include <cryptopp/eccrypto.h>
|
2015-07-30 16:34:56 +03:00
|
|
|
#include "util/Log.h"
|
2015-04-08 20:21:49 +03:00
|
|
|
#include "Signature.h"
|
|
|
|
|
2015-08-27 23:16:12 +03:00
|
|
|
namespace i2p {
|
|
|
|
namespace crypto {
|
2015-07-17 00:29:52 +03:00
|
|
|
|
2015-08-27 23:16:12 +03:00
|
|
|
DSASigner::DSASigner(const uint8_t * signingPrivateKey)
|
|
|
|
{
|
|
|
|
m_PrivateKey.Initialize(
|
|
|
|
dsap, dsaq, dsag,
|
|
|
|
CryptoPP::Integer(signingPrivateKey, DSA_PRIVATE_KEY_LENGTH)
|
|
|
|
);
|
2015-04-08 20:21:49 +03:00
|
|
|
}
|
2015-08-27 23:16:12 +03:00
|
|
|
|
|
|
|
void DSASigner::Sign(CryptoPP::RandomNumberGenerator& rnd, const uint8_t * buf,
|
|
|
|
int len, uint8_t * signature) const
|
|
|
|
{
|
|
|
|
CryptoPP::DSA::Signer signer(m_PrivateKey);
|
|
|
|
signer.SignMessage(rnd, buf, len, signature);
|
2015-04-08 20:21:49 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 23:16:12 +03:00
|
|
|
void CreateDSARandomKeys(CryptoPP::RandomNumberGenerator& rnd,
|
|
|
|
uint8_t* signingPrivateKey, uint8_t* signingPublicKey)
|
|
|
|
{
|
|
|
|
CryptoPP::DSA::PrivateKey privateKey;
|
|
|
|
CryptoPP::DSA::PublicKey publicKey;
|
|
|
|
privateKey.Initialize(rnd, dsap, dsaq, dsag);
|
|
|
|
privateKey.MakePublicKey(publicKey);
|
|
|
|
privateKey.GetPrivateExponent().Encode(signingPrivateKey, DSA_PRIVATE_KEY_LENGTH);
|
|
|
|
publicKey.GetPublicElement().Encode(signingPublicKey, DSA_PUBLIC_KEY_LENGTH);
|
|
|
|
}
|
2015-04-08 20:21:49 +03:00
|
|
|
|
2015-08-27 23:16:12 +03:00
|
|
|
|
|
|
|
} // crypto
|
|
|
|
} // i2p
|