Unverified Commit 088218b9 authored by oneiric's avatar oneiric

Crypto: add DSA and RSASHA5124096 lengths

parent c0d26405
......@@ -71,12 +71,7 @@ class DSAVerifier::DSAVerifierImpl {
DSAVerifierImpl(
const std::uint8_t* signing_key) {
m_PublicKey.Initialize(
dsap,
dsaq,
dsag,
CryptoPP::Integer(
signing_key,
DSA_PUBLIC_KEY_LENGTH));
dsap, dsaq, dsag, CryptoPP::Integer(signing_key, crypto::PkLen::DSA));
}
bool Verify(
......@@ -84,7 +79,7 @@ class DSAVerifier::DSAVerifierImpl {
std::size_t len,
const std::uint8_t* signature) const {
CryptoPP::DSA::Verifier verifier(m_PublicKey);
return verifier.VerifyMessage(buf, len, signature, DSA_SIGNATURE_LENGTH);
return verifier.VerifyMessage(buf, len, signature, crypto::SigLen::DSA);
}
private:
......@@ -162,11 +157,11 @@ class RSARawVerifier {
/// @class RSASHA5124096RawVerifierImpl
/// @brief RSASHA5124096 verifier implementation
class RSASHA5124096RawVerifier::RSASHA5124096RawVerifierImpl
: public RSARawVerifier<CryptoPP::SHA512, RSASHA5124096_KEY_LENGTH> {
: public RSARawVerifier<CryptoPP::SHA512, crypto::PkLen::RSASHA5124096> {
public:
RSASHA5124096RawVerifierImpl(
const std::uint8_t* signing_key)
: RSARawVerifier<CryptoPP::SHA512, RSASHA5124096_KEY_LENGTH>(signing_key) {}
: RSARawVerifier<CryptoPP::SHA512, crypto::PkLen::RSASHA5124096>(signing_key) {}
};
RSASHA5124096RawVerifier::RSASHA5124096RawVerifier(
......
......@@ -49,9 +49,32 @@ namespace core {
*
*/
const std::size_t DSA_PUBLIC_KEY_LENGTH = 128;
const std::size_t DSA_SIGNATURE_LENGTH = 40;
const std::size_t DSA_PRIVATE_KEY_LENGTH = DSA_SIGNATURE_LENGTH / 2;
namespace crypto
{
namespace PkLen
{
enum
{
DSA = 128,
};
} // namespace PkLen
namespace SkLen
{
enum
{
DSA = 20,
};
} // namespace SkLen
namespace SigLen
{
enum
{
DSA = 40,
};
} // namespace SigLen
} // namespace crypto
/// @class DSAVerifier
class DSAVerifier : public Verifier {
......@@ -66,15 +89,15 @@ class DSAVerifier : public Verifier {
const std::uint8_t* signature) const;
std::size_t GetPublicKeyLen() const {
return DSA_PUBLIC_KEY_LENGTH;
return crypto::PkLen::DSA;
}
std::size_t GetSignatureLen() const {
return DSA_SIGNATURE_LENGTH;
return crypto::SigLen::DSA;
}
std::size_t GetPrivateKeyLen() const {
return DSA_PRIVATE_KEY_LENGTH;
return crypto::SkLen::DSA;
}
private:
......@@ -82,6 +105,39 @@ class DSAVerifier : public Verifier {
std::unique_ptr<DSAVerifierImpl> m_DSAVerifierPimpl;
};
/**
*
* RSASHA5124096
*
*/
namespace crypto
{
namespace PkLen
{
enum
{
RSASHA5124096 = 512,
};
} // namespace PkLen
namespace SkLen
{
enum
{
RSASHA5124096 = 1024,
};
} // namespace SkLen
namespace SigLen
{
enum
{
RSASHA5124096 = 512,
};
} // namespace SigLen
} // namespace crypto
/**
*
* RSASHA5124096Raw
......
......@@ -67,7 +67,7 @@ struct RouterInfoTraits
/// @brief Router Info size constants
enum Size : std::uint16_t
{
MinBuffer = crypto::SigLen::Ed25519,
MinBuffer = crypto::SigLen::DSA,
MaxBuffer = 2048, // TODO(anonimal): review if arbitrary
MinUnsignedBuffer = 399, // Minimum RouterInfo length w/o signature, see spec
// TODO(unassigned): algorithm to dynamically determine cost
......
......@@ -44,26 +44,22 @@ struct DSAFixture {
verifier = std::make_unique<kovri::core::DSAVerifier>(public_key);
signer = std::make_unique<kovri::core::DSASigner>(private_key);
}
uint8_t private_key[20], public_key[128];
uint8_t private_key[crypto::SkLen::DSA], public_key[crypto::PkLen::DSA];
std::unique_ptr<kovri::core::DSAVerifier> verifier;
std::unique_ptr<kovri::core::DSASigner> signer;
static constexpr size_t key_message_len = 1024;
};
BOOST_FIXTURE_TEST_CASE(DSASHA1KeyLength, DSAFixture) {
BOOST_CHECK_EQUAL(
verifier->GetPublicKeyLen(),
kovri::core::DSA_PUBLIC_KEY_LENGTH);
BOOST_CHECK_EQUAL(verifier->GetPublicKeyLen(), crypto::PkLen::DSA);
}
BOOST_FIXTURE_TEST_CASE(DSASHA1SignatureLength, DSAFixture) {
BOOST_CHECK_EQUAL(
verifier->GetSignatureLen(),
kovri::core::DSA_SIGNATURE_LENGTH);
BOOST_CHECK_EQUAL(verifier->GetSignatureLen(), crypto::SigLen::DSA);
}
BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyValid, DSAFixture) {
uint8_t signature[40], message[key_message_len];
uint8_t signature[crypto::SigLen::DSA], message[key_message_len];
kovri::core::RandBytes(message, key_message_len);
signer->Sign(message, key_message_len, signature);
// check that the signature is valid
......@@ -71,7 +67,7 @@ BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyValid, DSAFixture) {
}
BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadSignature, DSAFixture) {
uint8_t signature[40], message[key_message_len];
uint8_t signature[crypto::SigLen::DSA], message[key_message_len];
kovri::core::RandBytes(message, key_message_len);
signer->Sign(message, key_message_len, signature);
// introduce an error in the signature
......@@ -81,7 +77,7 @@ BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadSignature, DSAFixture) {
}
BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadMessage, DSAFixture) {
uint8_t signature[40], message[key_message_len];
uint8_t signature[crypto::SigLen::DSA], message[key_message_len];
kovri::core::RandBytes(message, key_message_len);
signer->Sign(message, key_message_len, signature);
// introduce an error in the message
......@@ -91,7 +87,7 @@ BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadMessage, DSAFixture) {
}
BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadSignatureAndMessage, DSAFixture) {
uint8_t signature[40], message[key_message_len];
uint8_t signature[crypto::SigLen::DSA], message[key_message_len];
kovri::core::RandBytes(message, key_message_len);
signer->Sign(message, key_message_len, signature);
// introduce errors in both the message and signature
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment