|
|
|
|
|
|
|
|
#include "../CodeDweller/mangler.hpp" |
|
|
#include "../CodeDweller/mangler.hpp" |
|
|
#include "snf_engine.hpp" |
|
|
#include "snf_engine.hpp" |
|
|
|
|
|
|
|
|
namespace codedweller { |
|
|
|
|
|
|
|
|
namespace cd = codedweller; |
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////// |
|
|
/////////////////////////////////////////////////////////////////////////////////////////// |
|
|
// BEGIN IMPLEMENTATIONS ////////////////////////////////////////////////////////////////// |
|
|
// BEGIN IMPLEMENTATIONS ////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TokenMatrix::Load(stream) |
|
|
// TokenMatrix::Load(stream) |
|
|
|
|
|
|
|
|
const AbortCheck CompatibleIntSizeCheck("TokenMatrix::Load():CompatibleIntSizeCheck(sizeof(unsigned int)==4)"); |
|
|
|
|
|
|
|
|
const cd::AbortCheck CompatibleIntSizeCheck("TokenMatrix::Load():CompatibleIntSizeCheck(sizeof(unsigned int)==4)"); |
|
|
|
|
|
|
|
|
void TokenMatrix::Load(std::ifstream& F) { // Initializes the token matrix from a file. |
|
|
void TokenMatrix::Load(std::ifstream& F) { // Initializes the token matrix from a file. |
|
|
CompatibleIntSizeCheck(sizeof(unsigned int)==4); // Check our assumptions. |
|
|
CompatibleIntSizeCheck(sizeof(unsigned int)==4); // Check our assumptions. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TokenMatrix::Validate(std::string& SecurityKey) { // Decrypts and validates the matrix. |
|
|
void TokenMatrix::Validate(std::string& SecurityKey) { // Decrypts and validates the matrix. |
|
|
|
|
|
|
|
|
MANGLER ValidationChecker; // Create a mangler engine for validation. |
|
|
|
|
|
|
|
|
cd::MANGLER ValidationChecker; // Create a mangler engine for validation. |
|
|
|
|
|
|
|
|
// In order to do the validation we must look at the token matrix as a sequence of bytes. |
|
|
// In order to do the validation we must look at the token matrix as a sequence of bytes. |
|
|
// We will be decrypting the first and last SecurtySegmentSize of this sequence and then |
|
|
// We will be decrypting the first and last SecurtySegmentSize of this sequence and then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TokenMatrix::Verify(std::string& SecurityKey) { // Builds and verifies a file digest. |
|
|
void TokenMatrix::Verify(std::string& SecurityKey) { // Builds and verifies a file digest. |
|
|
|
|
|
|
|
|
MANGLER DigestChecker; // Create a mangler for the digest. |
|
|
|
|
|
|
|
|
cd::MANGLER DigestChecker; // Create a mangler for the digest. |
|
|
|
|
|
|
|
|
// Gain access to our token matrix as bytes. |
|
|
// Gain access to our token matrix as bytes. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
finish = (finish < data.size()) ? finish : data.size(); |
|
|
finish = (finish < data.size()) ? finish : data.size(); |
|
|
for(unsigned int a = start; a < finish; a++) EvaluateThis(data[a]); |
|
|
for(unsigned int a = start; a < finish; a++) EvaluateThis(data[a]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} // End namespace codedweller |
|
|
|