[Progress:] Completely re-done Block class to not use bitsets, and provide custom operators.

This commit is contained in:
Leonetienne
2022-05-24 01:02:06 +02:00
parent ed45b69342
commit 939df4731b
11 changed files with 619 additions and 191 deletions

View File

@@ -1,4 +1,5 @@
#include <GCrypt/Util.h>
#include <GCrypt/Block.h>
#include <GCrypt/Config.h>
#include <unordered_map>
#include <sstream>
@@ -59,7 +60,7 @@ TEST_CASE(__FILE__"/Password to key transformation collision resistance", "[Key
// 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::string, std::string> keys; // <key, password>
// Try NUM_RUN_TESTS passwords
const std::string charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -69,23 +70,23 @@ TEST_CASE(__FILE__"/Password to key transformation collision resistance", "[Key
const std::string password = Base10_2_X(i, charset, 0);
// Generate key
const std::bitset<BLOCK_SIZE> newKey = Key::FromPassword(password).Get();
const std::string newKeyBits = Key::FromPassword(password).ToString();
// Check if this block is already in our map
if (keys.find(newKey) != keys.cend()) {
if (keys.find(newKeyBits) != keys.cend()) {
std::cout << "Collision found between password \""
<< password
<< "\" and \""
<< keys[newKey]
<< keys[newKeyBits]
<< "\". The key is \""
<< newKey
<< newKeyBits
<< "\".";
FAIL();
}
// All good? Insert it into our map
keys[newKey] = password;
keys[newKeyBits] = password;
}
return;