Skip to content

Commit

Permalink
Tests: update namespaces and organization
Browse files Browse the repository at this point in the history
Updated against previous commits

References monero-project#339 monero-project#98
  • Loading branch information
anonimal committed Oct 27, 2016
1 parent 0e0a384 commit cf4828b
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 135 deletions.
2 changes: 1 addition & 1 deletion tests/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(BENCHMARKS_SRC
"signature.cc")

include_directories("../../src/core/")
include_directories("../../src/")

if(WITH_BENCHMARKS)
add_executable(${BENCHMARKS_NAME} ${BENCHMARKS_SRC})
Expand Down
56 changes: 28 additions & 28 deletions tests/benchmarks/signature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <chrono>
#include <iostream>

#include "crypto/rand.h"
#include "crypto/signature.h"
#include "core/crypto/rand.h"
#include "core/crypto/signature.h"

typedef void (*KeyGenerator)(uint8_t*,uint8_t*) ;

Expand All @@ -57,7 +57,7 @@ void benchmark(
std::chrono::nanoseconds verify_duration(0);
for (std::size_t i = 0; i < count; ++i) {
try {
kovri::crypto::RandBytes(message, 512);
kovri::core::RandBytes(message, 512);
TimePoint begin1 = std::chrono::high_resolution_clock::now();
signer.Sign(message, 512, output);
TimePoint end1 = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -85,38 +85,38 @@ void benchmark(
int main() {
const size_t benchmark_count = 1000;
std::cout << "--------DSA---------" << std::endl;
benchmark<kovri::crypto::DSAVerifier, kovri::crypto::DSASigner>(
benchmark<kovri::core::DSAVerifier, kovri::core::DSASigner>(
benchmark_count,
kovri::crypto::DSA_PUBLIC_KEY_LENGTH,
kovri::crypto::DSA_PRIVATE_KEY_LENGTH,
kovri::crypto::DSA_SIGNATURE_LENGTH,
kovri::crypto::CreateDSARandomKeys);
kovri::core::DSA_PUBLIC_KEY_LENGTH,
kovri::core::DSA_PRIVATE_KEY_LENGTH,
kovri::core::DSA_SIGNATURE_LENGTH,
kovri::core::CreateDSARandomKeys);
std::cout << "-----ECDSAP256------" << std::endl;
benchmark<kovri::crypto::ECDSAP256Verifier, kovri::crypto::ECDSAP256Signer>(
benchmark<kovri::core::ECDSAP256Verifier, kovri::core::ECDSAP256Signer>(
benchmark_count,
kovri::crypto::ECDSAP256_KEY_LENGTH,
kovri::crypto::ECDSAP256_KEY_LENGTH / 2,
kovri::crypto::ECDSAP256_KEY_LENGTH,
kovri::crypto::CreateECDSAP256RandomKeys);
kovri::core::ECDSAP256_KEY_LENGTH,
kovri::core::ECDSAP256_KEY_LENGTH / 2,
kovri::core::ECDSAP256_KEY_LENGTH,
kovri::core::CreateECDSAP256RandomKeys);
std::cout << "-----ECDSAP384------" << std::endl;
benchmark<kovri::crypto::ECDSAP384Verifier, kovri::crypto::ECDSAP384Signer>(
benchmark<kovri::core::ECDSAP384Verifier, kovri::core::ECDSAP384Signer>(
benchmark_count,
kovri::crypto::ECDSAP384_KEY_LENGTH,
kovri::crypto::ECDSAP384_KEY_LENGTH / 2,
kovri::crypto::ECDSAP384_KEY_LENGTH,
kovri::crypto::CreateECDSAP384RandomKeys);
kovri::core::ECDSAP384_KEY_LENGTH,
kovri::core::ECDSAP384_KEY_LENGTH / 2,
kovri::core::ECDSAP384_KEY_LENGTH,
kovri::core::CreateECDSAP384RandomKeys);
std::cout << "-----ECDSAP521------" << std::endl;
benchmark<kovri::crypto::ECDSAP521Verifier, kovri::crypto::ECDSAP521Signer>(
benchmark<kovri::core::ECDSAP521Verifier, kovri::core::ECDSAP521Signer>(
benchmark_count,
kovri::crypto::ECDSAP521_KEY_LENGTH,
kovri::crypto::ECDSAP521_KEY_LENGTH / 2,
kovri::crypto::ECDSAP521_KEY_LENGTH,
kovri::crypto::CreateECDSAP521RandomKeys);
kovri::core::ECDSAP521_KEY_LENGTH,
kovri::core::ECDSAP521_KEY_LENGTH / 2,
kovri::core::ECDSAP521_KEY_LENGTH,
kovri::core::CreateECDSAP521RandomKeys);
std::cout << "-----EDDSA25519-----" << std::endl;
benchmark<kovri::crypto::EDDSA25519Verifier, kovri::crypto::EDDSA25519Signer>(
benchmark<kovri::core::EDDSA25519Verifier, kovri::core::EDDSA25519Signer>(
benchmark_count,
kovri::crypto::EDDSA25519_PUBLIC_KEY_LENGTH,
kovri::crypto::EDDSA25519_PRIVATE_KEY_LENGTH,
kovri::crypto::EDDSA25519_SIGNATURE_LENGTH,
kovri::crypto::CreateEDDSARandomKeys);
kovri::core::EDDSA25519_PUBLIC_KEY_LENGTH,
kovri::core::EDDSA25519_PRIVATE_KEY_LENGTH,
kovri::core::EDDSA25519_SIGNATURE_LENGTH,
kovri::core::CreateEDDSARandomKeys);
}
8 changes: 2 additions & 6 deletions tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ set(TESTS_CORE
"core/crypto/elgamal.cc"
"core/crypto/rand.cc"
"core/crypto/util/x509.cc"
"core/transport/ssu_packet.cc"
"core/router/transports/ssu/packet.cc"
"core/util/base64.cc")

set(TESTS_MAIN
${TESTS_CLIENT}
${TESTS_CORE}
"main.cc")

include_directories(
"../../src/"
"../../src/app/"
"../../src/core/"
"../../src/client/")
include_directories("../../src/")

if(WITH_TESTS)
find_package(
Expand Down
11 changes: 6 additions & 5 deletions tests/unit_tests/client/reseed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
#include <string>
#include <vector>

#include "reseed.h"
#include "crypto/util/x509.h"
#include "client/reseed.h"

#include "core/crypto/util/x509.h"

BOOST_AUTO_TEST_SUITE(SU3);

Expand Down Expand Up @@ -216,8 +217,8 @@ struct SU3Fixture {
};

// Map the signature for verification
kovri::crypto::util::PublicKey pubkey = signing_key.data();
std::map<std::string, kovri::crypto::util::PublicKey> x509 {
kovri::core::PublicKey pubkey = signing_key.data();
std::map<std::string, kovri::core::PublicKey> x509 {
{ "[email protected]", pubkey },
};
};
Expand All @@ -243,7 +244,7 @@ class SU3FixtureImpl : SU3Fixture {
std::vector<unsigned char> bad_bytes = good_bytes;
std::fill_n(bad_bytes.begin() + offset, amount, byte);
std::string str(bad_bytes.begin(), bad_bytes.end());
kovri::data::SU3 su3(str, x509);
kovri::client::SU3 su3(str, x509);
return su3.SU3Impl();
}
};
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/client/util/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

#include <boost/test/unit_test.hpp>

#include "util/http.h"
#include "client/util/http.h"

BOOST_AUTO_TEST_SUITE(HTTPUtilityTests)

kovri::util::http::HTTP http;
kovri::client::HTTP http;

BOOST_AUTO_TEST_CASE(UriParse) {
// Note: cpp-netlib has better tests.
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/client/util/zip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <string>
#include <vector>

#include "util/zip.h"
#include "client/util/zip.h"

BOOST_AUTO_TEST_SUITE(ZIP);

Expand Down Expand Up @@ -148,7 +148,7 @@ class ZIPFixtureImpl : ZIPFixture {
std::vector<unsigned char> bad_bytes = good_bytes;
std::fill_n(bad_bytes.begin() + offset, amount, byte);
std::string str(bad_bytes.begin(), bad_bytes.end());
kovri::util::ZIP zip(str, str.size());
kovri::client::ZIP zip(str, str.size());
return zip.Unzip();
}
};
Expand Down
36 changes: 18 additions & 18 deletions tests/unit_tests/core/crypto/aes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,42 @@

#include <boost/test/unit_test.hpp>

#include "crypto/aes.h"
#include "core/crypto/aes.h"

BOOST_AUTO_TEST_SUITE(AESTests)

BOOST_AUTO_TEST_CASE(XorZeroCipherBlocks) {
kovri::crypto::CipherBlock block = {0};
kovri::core::CipherBlock block = {0};
block ^= block;
const kovri::crypto::CipherBlock result = {0};
const kovri::core::CipherBlock result = {0};
BOOST_CHECK_EQUAL_COLLECTIONS(
result.buf, result.buf + 16,
block.buf, block.buf + 16);
}

BOOST_AUTO_TEST_CASE(XorSelfCipherBlocks) {
kovri::crypto::CipherBlock block = {
kovri::core::CipherBlock block = {
0xc9, 0x4c, 0xaf, 0x5, 0x9c, 0x1c, 0x10, 0x1e, 0x20, 0xb3, 0x7e,
0xcf, 0xf5, 0xbf, 0xf0, 0xd6
};
block ^= block;
const kovri::crypto::CipherBlock result = {0};
const kovri::core::CipherBlock result = {0};
BOOST_CHECK_EQUAL_COLLECTIONS(
result.buf, result.buf + 16,
block.buf, block.buf + 16);
}

BOOST_AUTO_TEST_CASE(XorCipherBlocks) {
const kovri::crypto::CipherBlock block1 = {
const kovri::core::CipherBlock block1 = {
0xc9, 0x4c, 0xaf, 0x5, 0x9c, 0x1c, 0x10, 0x1e, 0x20, 0xb3, 0x7e,
0xcf, 0xf5, 0xbf, 0xf0, 0xd6
};
kovri::crypto::CipherBlock block2 = {
kovri::core::CipherBlock block2 = {
0x2e, 0xfb, 0x26, 0xa9, 0x90, 0x3b, 0xf7, 0xc8, 0x5c, 0xfe, 0x20,
0x23, 0x1d, 0xaf, 0x67, 0xac
};
block2 ^= block1;
const kovri::crypto::CipherBlock result = {
const kovri::core::CipherBlock result = {
0xe7, 0xb7, 0x89, 0xac, 0xc, 0x27, 0xe7, 0xd6, 0x7c, 0x4d, 0x5e,
0xec, 0xe8, 0x10, 0x97, 0x7a
};
Expand All @@ -83,10 +83,10 @@ BOOST_AUTO_TEST_CASE(XorCipherBlocks) {
struct AesCbcFixture {
AesCbcFixture()
: cbc_encrypt(
kovri::crypto::AESKey(key),
kovri::core::AESKey(key),
iv),
cbc_decrypt(
kovri::crypto::AESKey(key),
kovri::core::AESKey(key),
iv) {}
uint8_t key[32] = {
0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73,
Expand All @@ -98,8 +98,8 @@ struct AesCbcFixture {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
kovri::crypto::CBCEncryption cbc_encrypt;
kovri::crypto::CBCDecryption cbc_decrypt;
kovri::core::CBCEncryption cbc_encrypt;
kovri::core::CBCDecryption cbc_decrypt;
};

BOOST_FIXTURE_TEST_CASE(AesCbcSingleBlockEncrypt, AesCbcFixture) {
Expand Down Expand Up @@ -131,8 +131,8 @@ BOOST_FIXTURE_TEST_CASE(AesCbcSingleBlockDecrypt, AesCbcFixture) {
}

BOOST_FIXTURE_TEST_CASE(AesCbcEncrypt, AesCbcFixture) {
kovri::crypto::CipherBlock output[4] = {};
kovri::crypto::CipherBlock input[4] = {};
kovri::core::CipherBlock output[4] = {};
kovri::core::CipherBlock input[4] = {};
input[0] = {
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d,
0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
Expand All @@ -149,7 +149,7 @@ BOOST_FIXTURE_TEST_CASE(AesCbcEncrypt, AesCbcFixture) {
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b,
0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
};
kovri::crypto::CipherBlock result[4] = {};
kovri::core::CipherBlock result[4] = {};
result[0] = {
0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, 0x77, 0x9e,
0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6
Expand All @@ -175,8 +175,8 @@ BOOST_FIXTURE_TEST_CASE(AesCbcEncrypt, AesCbcFixture) {
}

BOOST_FIXTURE_TEST_CASE(AesCbcDecrypt, AesCbcFixture) {
kovri::crypto::CipherBlock output[4] = {};
kovri::crypto::CipherBlock input[4] = {};
kovri::core::CipherBlock output[4] = {};
kovri::core::CipherBlock input[4] = {};
input[0] = {
0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, 0x77, 0x9e,
0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6
Expand All @@ -193,7 +193,7 @@ BOOST_FIXTURE_TEST_CASE(AesCbcDecrypt, AesCbcFixture) {
0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc, 0xda, 0x6c,
0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b
};
kovri::crypto::CipherBlock result[4] = {};
kovri::core::CipherBlock result[4] = {};
result[0] = {
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d,
0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
Expand Down
34 changes: 17 additions & 17 deletions tests/unit_tests/core/crypto/dsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,71 +34,71 @@

#include <memory>

#include "crypto/rand.h"
#include "crypto/signature.h"
#include "core/crypto/rand.h"
#include "core/crypto/signature.h"

BOOST_AUTO_TEST_SUITE(DSASHA1ests)

struct DSAFixture {
DSAFixture() {
// TODO(unassigned): generate static test keys
kovri::crypto::CreateDSARandomKeys(private_key, public_key);
verifier = std::make_unique<kovri::crypto::DSAVerifier>(public_key);
signer = std::make_unique<kovri::crypto::DSASigner>(private_key);
kovri::core::CreateDSARandomKeys(private_key, public_key);
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];
std::unique_ptr<kovri::crypto::DSAVerifier> verifier;
std::unique_ptr<kovri::crypto::DSASigner> signer;
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::crypto::DSA_PUBLIC_KEY_LENGTH);
kovri::core::DSA_PUBLIC_KEY_LENGTH);
}

BOOST_FIXTURE_TEST_CASE(DSASHA1SignatureLength, DSAFixture) {
BOOST_CHECK_EQUAL(
verifier->GetSignatureLen(),
kovri::crypto::DSA_SIGNATURE_LENGTH);
kovri::core::DSA_SIGNATURE_LENGTH);
}

BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyValid, DSAFixture) {
uint8_t signature[40], message[key_message_len];
kovri::crypto::RandBytes(message, key_message_len);
kovri::core::RandBytes(message, key_message_len);
signer->Sign(message, key_message_len, signature);
// check that the signature is valid
BOOST_CHECK_EQUAL(verifier->Verify(message, key_message_len, signature), true);
}

BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadSignature, DSAFixture) {
uint8_t signature[40], message[key_message_len];
kovri::crypto::RandBytes(message, key_message_len);
kovri::core::RandBytes(message, key_message_len);
signer->Sign(message, key_message_len, signature);
// introduce an error in the signature
signature[5] ^= kovri::crypto::RandInRange<uint8_t>(1, 128);
signature[5] ^= kovri::core::RandInRange<uint8_t>(1, 128);
// it should fail verification
BOOST_CHECK_EQUAL(verifier->Verify(message, key_message_len, signature), false);
}

BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadMessage, DSAFixture) {
uint8_t signature[40], message[key_message_len];
kovri::crypto::RandBytes(message, key_message_len);
kovri::core::RandBytes(message, key_message_len);
signer->Sign(message, key_message_len, signature);
// introduce an error in the message
message[5] ^= kovri::crypto::RandInRange<uint8_t>(1, 128);
message[5] ^= kovri::core::RandInRange<uint8_t>(1, 128);
// this should also fail verification
BOOST_CHECK_EQUAL(verifier->Verify(message, key_message_len, signature), false);
}

BOOST_FIXTURE_TEST_CASE(DSASHA1SignVerifyBadSignatureAndMessage, DSAFixture) {
uint8_t signature[40], message[key_message_len];
kovri::crypto::RandBytes(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
message[6] ^= kovri::crypto::RandInRange<uint8_t>(1, 128);
signature[2] ^= kovri::crypto::RandInRange<uint8_t>(1, 128);
message[6] ^= kovri::core::RandInRange<uint8_t>(1, 128);
signature[2] ^= kovri::core::RandInRange<uint8_t>(1, 128);
// this should fail verification as well
BOOST_CHECK_EQUAL(verifier->Verify(message, key_message_len, signature), false);
}
Expand Down
Loading

0 comments on commit cf4828b

Please sign in to comment.