Added module for hashing
This commit is contained in:
parent
bf8a6454ae
commit
ffea2bfb5b
18
GCryptCLI/include/ModuleHashing.h
Normal file
18
GCryptCLI/include/ModuleHashing.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef GCRYPTCLI_MODULE_HASHING_H
|
||||||
|
#define GCRYPTCLI_MODULE_HASHING_H
|
||||||
|
|
||||||
|
namespace Module {
|
||||||
|
//! This module will hash supplied input
|
||||||
|
class Hashing {
|
||||||
|
public:
|
||||||
|
//! Will run the module
|
||||||
|
static void Run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// No instanciation! >:(
|
||||||
|
Hashing() {};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -93,11 +93,8 @@ void Configuration::DecideCiphertextFormat() {
|
|||||||
|
|
||||||
// So we have no iobase explicitly specified.. Let's default..
|
// So we have no iobase explicitly specified.. Let's default..
|
||||||
|
|
||||||
// If we are encrypting or hashing,
|
// If we are encrypting,
|
||||||
else if (
|
else if (activeModule == MODULE::ENCRYPTION) {
|
||||||
(activeModule == MODULE::ENCRYPTION) ||
|
|
||||||
(activeModule == MODULE::HASH)
|
|
||||||
) {
|
|
||||||
// and input comes from a parameter,
|
// and input comes from a parameter,
|
||||||
// and output goes to stdout,
|
// and output goes to stdout,
|
||||||
// let's assume base-16.
|
// let's assume base-16.
|
||||||
@ -116,6 +113,12 @@ void Configuration::DecideCiphertextFormat() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Else, if we are hashing,
|
||||||
|
else if (activeModule == MODULE::HASH) {
|
||||||
|
// output is always defaults to base 16
|
||||||
|
ciphertextFormat = IOBASE_FORMAT::BASE_16;
|
||||||
|
}
|
||||||
|
|
||||||
// Else, if we are decrypting,
|
// Else, if we are decrypting,
|
||||||
else if (activeModule == MODULE::DECRYPTION) {
|
else if (activeModule == MODULE::DECRYPTION) {
|
||||||
// and input comes from a parameter, we'll assume base-16.
|
// and input comes from a parameter, we'll assume base-16.
|
||||||
|
53
GCryptCLI/src/ModuleHashing.cpp
Normal file
53
GCryptCLI/src/ModuleHashing.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "ModuleHashing.h"
|
||||||
|
#include "DataIngestionLayer.h"
|
||||||
|
#include "DataOutputLayer.h"
|
||||||
|
#include "KeyManager.h"
|
||||||
|
#include <GCrypt/GHash.h>
|
||||||
|
|
||||||
|
using namespace Module;
|
||||||
|
using namespace Leonetienne::GCrypt;
|
||||||
|
|
||||||
|
void Hashing::Run() {
|
||||||
|
|
||||||
|
// Initialize the data ingestion layer
|
||||||
|
IO::DataIngestionLayer::Init();
|
||||||
|
|
||||||
|
// Initialize the data output layer
|
||||||
|
IO::DataOutputLayer::Init();
|
||||||
|
|
||||||
|
// Initialize a ghasher
|
||||||
|
GHash hasher;
|
||||||
|
|
||||||
|
// Read in new blocks, if not reached eof
|
||||||
|
while (!IO::DataIngestionLayer::IsFinished()) {
|
||||||
|
if (!IO::DataIngestionLayer::ReachedEOF()) {
|
||||||
|
IO::DataIngestionLayer::ReadBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process a block, if one is ready
|
||||||
|
if (IO::DataIngestionLayer::IsBlockReady()) {
|
||||||
|
const Block cleartext = IO::DataIngestionLayer::GetNextBlock();
|
||||||
|
hasher.Digest(cleartext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait until we've finished digesting all blocks
|
||||||
|
// Enqueue that single block (the hash result) to the output layer
|
||||||
|
IO::DataOutputLayer::Enqueue(hasher.GetHashsum());
|
||||||
|
|
||||||
|
// Tell the data output layer that that was the last block
|
||||||
|
IO::DataOutputLayer::ReachedEOF();
|
||||||
|
|
||||||
|
// Dump it
|
||||||
|
while (!IO::DataOutputLayer::IsFinished()) {
|
||||||
|
IO::DataOutputLayer::WriteBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destruct the data ingestion layer
|
||||||
|
IO::DataIngestionLayer::Destruct();
|
||||||
|
|
||||||
|
// Destruct the data output layer
|
||||||
|
IO::DataOutputLayer::Destruct();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
#include "ModuleGenerateKey.h"
|
#include "ModuleGenerateKey.h"
|
||||||
#include "ModuleEncryption.h"
|
#include "ModuleEncryption.h"
|
||||||
#include "ModuleDecryption.h"
|
#include "ModuleDecryption.h"
|
||||||
|
#include "ModuleHashing.h"
|
||||||
|
|
||||||
int main(int argc, char* const* argv) {
|
int main(int argc, char* const* argv) {
|
||||||
|
|
||||||
@ -18,10 +19,6 @@ int main(int argc, char* const* argv) {
|
|||||||
|
|
||||||
// Launch our module
|
// Launch our module
|
||||||
switch (Configuration::activeModule) {
|
switch (Configuration::activeModule) {
|
||||||
case Configuration::MODULE::GENERATE_KEY:
|
|
||||||
Module::GenerateKey::Run();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Configuration::MODULE::ENCRYPTION:
|
case Configuration::MODULE::ENCRYPTION:
|
||||||
Module::Encryption::Run();
|
Module::Encryption::Run();
|
||||||
break;
|
break;
|
||||||
@ -29,6 +26,14 @@ int main(int argc, char* const* argv) {
|
|||||||
case Configuration::MODULE::DECRYPTION:
|
case Configuration::MODULE::DECRYPTION:
|
||||||
Module::Decryption::Run();
|
Module::Decryption::Run();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Configuration::MODULE::GENERATE_KEY:
|
||||||
|
Module::GenerateKey::Run();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Configuration::MODULE::HASH:
|
||||||
|
Module::Hashing::Run();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user