Renamed class Hasher to GHash
This commit is contained in:
parent
4e2f99c28e
commit
734324ec10
@ -1,5 +1,5 @@
|
|||||||
#ifndef GCRYPT_HASHER_H
|
#ifndef GCRYPT_GHASH_H
|
||||||
#define GCRYPT_HASHER_H
|
#define GCRYPT_GHASH_H
|
||||||
|
|
||||||
#include "GCrypt/Flexblock.h"
|
#include "GCrypt/Flexblock.h"
|
||||||
#include "GCrypt/Block.h"
|
#include "GCrypt/Block.h"
|
||||||
@ -8,9 +8,9 @@
|
|||||||
namespace Leonetienne::GCrypt {
|
namespace Leonetienne::GCrypt {
|
||||||
/** This class implements a hash function, based on the GCrypt cipher
|
/** This class implements a hash function, based on the GCrypt cipher
|
||||||
*/
|
*/
|
||||||
class Hasher {
|
class GHash {
|
||||||
public:
|
public:
|
||||||
Hasher();
|
GHash();
|
||||||
|
|
||||||
//! Will add the hash value of the block `data` to the hashsum.
|
//! Will add the hash value of the block `data` to the hashsum.
|
||||||
//! WARNING: If you compute hashes using this digestive method,
|
//! WARNING: If you compute hashes using this digestive method,
|
@ -1,10 +1,10 @@
|
|||||||
#include "GCrypt/Hasher.h"
|
#include "GCrypt/GHash.h"
|
||||||
#include "GCrypt/Util.h"
|
#include "GCrypt/Util.h"
|
||||||
#include "GCrypt/InitializationVector.h"
|
#include "GCrypt/InitializationVector.h"
|
||||||
|
|
||||||
namespace Leonetienne::GCrypt {
|
namespace Leonetienne::GCrypt {
|
||||||
|
|
||||||
Hasher::Hasher() :
|
GHash::GHash() :
|
||||||
// Initialize our cipher with a static, but randomly distributed key.
|
// Initialize our cipher with a static, but randomly distributed key.
|
||||||
cipher(
|
cipher(
|
||||||
StringToBitblock("CfRtNdMTP4Y5CWRd"),
|
StringToBitblock("CfRtNdMTP4Y5CWRd"),
|
||||||
@ -15,17 +15,17 @@ namespace Leonetienne::GCrypt {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hasher::DigestBlock(const Block& data) {
|
void GHash::DigestBlock(const Block& data) {
|
||||||
// Encipher the current block, and xor it on the current hashsum
|
// Encipher the current block, and xor it on the current hashsum
|
||||||
block ^= cipher.Digest(data);
|
block ^= cipher.Digest(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Block& Hasher::GetHashsum() const {
|
const Block& GHash::GetHashsum() const {
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block Hasher::CalculateHashsum(const Flexblock& data) {
|
Block GHash::CalculateHashsum(const Flexblock& data) {
|
||||||
// Split input into blocks
|
// Split input into blocks
|
||||||
std::vector<Block> blocks;
|
std::vector<Block> blocks;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ namespace Leonetienne::GCrypt {
|
|||||||
blocks.push_back(lengthBlock);
|
blocks.push_back(lengthBlock);
|
||||||
|
|
||||||
// Create hasher instance
|
// Create hasher instance
|
||||||
Hasher hasher;
|
GHash hasher;
|
||||||
|
|
||||||
// Digest all blocks
|
// Digest all blocks
|
||||||
for (Block& block : blocks) {
|
for (Block& block : blocks) {
|
@ -1,12 +1,12 @@
|
|||||||
#include "GCrypt/Util.h"
|
#include "GCrypt/Util.h"
|
||||||
#include "GCrypt/Hasher.h"
|
#include "GCrypt/GHash.h"
|
||||||
|
|
||||||
namespace Leonetienne::GCrypt {
|
namespace Leonetienne::GCrypt {
|
||||||
Block PasswordToKey(const std::string& in) {
|
Block PasswordToKey(const std::string& in) {
|
||||||
// We already have a hashing algorithm, so why not use it
|
// 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..
|
// 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;
|
return hashedPassword;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user