Renamed class Hasher to GHash

This commit is contained in:
Leonetienne 2022-05-22 12:55:39 +02:00
parent 4e2f99c28e
commit 734324ec10
No known key found for this signature in database
GPG Key ID: C33879CD92E9708C
3 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,5 @@
#ifndef GCRYPT_HASHER_H
#define GCRYPT_HASHER_H
#ifndef GCRYPT_GHASH_H
#define GCRYPT_GHASH_H
#include "GCrypt/Flexblock.h"
#include "GCrypt/Block.h"
@ -8,9 +8,9 @@
namespace Leonetienne::GCrypt {
/** This class implements a hash function, based on the GCrypt cipher
*/
class Hasher {
class GHash {
public:
Hasher();
GHash();
//! Will add the hash value of the block `data` to the hashsum.
//! WARNING: If you compute hashes using this digestive method,

View File

@ -1,10 +1,10 @@
#include "GCrypt/Hasher.h"
#include "GCrypt/GHash.h"
#include "GCrypt/Util.h"
#include "GCrypt/InitializationVector.h"
namespace Leonetienne::GCrypt {
Hasher::Hasher() :
GHash::GHash() :
// Initialize our cipher with a static, but randomly distributed key.
cipher(
StringToBitblock("CfRtNdMTP4Y5CWRd"),
@ -15,17 +15,17 @@ namespace Leonetienne::GCrypt {
return;
}
void Hasher::DigestBlock(const Block& data) {
void GHash::DigestBlock(const Block& data) {
// Encipher the current block, and xor it on the current hashsum
block ^= cipher.Digest(data);
return;
}
const Block& Hasher::GetHashsum() const {
const Block& GHash::GetHashsum() const {
return block;
}
Block Hasher::CalculateHashsum(const Flexblock& data) {
Block GHash::CalculateHashsum(const Flexblock& data) {
// Split input into blocks
std::vector<Block> blocks;
@ -42,7 +42,7 @@ namespace Leonetienne::GCrypt {
blocks.push_back(lengthBlock);
// Create hasher instance
Hasher hasher;
GHash hasher;
// Digest all blocks
for (Block& block : blocks) {

View File

@ -1,12 +1,12 @@
#include "GCrypt/Util.h"
#include "GCrypt/Hasher.h"
#include "GCrypt/GHash.h"
namespace Leonetienne::GCrypt {
Block PasswordToKey(const std::string& in) {
// We already have a hashing algorithm, so why not use it
// Yeah, this won't work, because it would create an include loop. This method needs to be outsourced to a cpp file..
const Block hashedPassword = Hasher::CalculateHashsum(StringToBits(in));
const Block hashedPassword = GHash::CalculateHashsum(StringToBits(in));
return hashedPassword;
}
}