Adjusted tests

This commit is contained in:
Leonetienne
2022-05-22 14:26:23 +02:00
parent 967eba2f03
commit fe6ec11672
3 changed files with 80 additions and 84 deletions

View File

@@ -55,39 +55,39 @@ inline std::string Base10_2_X(const unsigned long long int i, const std::string
// Already validated range: Password 0 - 1.000.000
TEST_CASE(__FILE__"/Password to key transformation collision resistance", "[Key extrapolation]") {
// To test resistence set this to a high number around a million.
// This will take a LONG while to execute though (about 2.5hrs on my machine), hence why it's set so low.
constexpr std::size_t NUM_RUN_TESTS = 1000;
// To test resistence set this to a high number around a million.
// This will take a LONG while to execute though (about 2.5hrs on my machine), hence why it's set so low.
constexpr std::size_t NUM_RUN_TESTS = 10;
std::unordered_map<std::bitset<BLOCK_SIZE>, std::string> keys; // <key, password>
std::unordered_map<std::bitset<BLOCK_SIZE>, std::string> keys; // <key, password>
// Try NUM_RUN_TESTS passwords
const std::string charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Try NUM_RUN_TESTS passwords
const std::string charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (std::size_t i = 0; i < NUM_RUN_TESTS; i++) {
// Get password
const std::string password = Base10_2_X(i, charset, 0);
for (std::size_t i = 0; i < NUM_RUN_TESTS; i++) {
// Get password
const std::string password = Base10_2_X(i, charset, 0);
// Generate key
const std::bitset<BLOCK_SIZE> newKey = PasswordToKey(password).Get();
// Generate key
const std::bitset<BLOCK_SIZE> newKey = Key::FromPassword(password).Get();
// Check if this block is already in our map
if (keys.find(newKey) != keys.cend()) {
std::cout << "Collision found between password \""
<< password
<< "\" and \""
<< keys[newKey]
<< "\". The key is \""
<< newKey
<< "\".";
// Check if this block is already in our map
if (keys.find(newKey) != keys.cend()) {
std::cout << "Collision found between password \""
<< password
<< "\" and \""
<< keys[newKey]
<< "\". The key is \""
<< newKey
<< "\".";
FAIL();
}
FAIL();
}
// All good? Insert it into our map
keys[newKey] = password;
}
// All good? Insert it into our map
keys[newKey] = password;
}
return;
return;
}