Implementation of VerusHash CPU-friendly hash algorithm, parameters to enable it, miner, and all changes required to support it on new asset chains

This commit is contained in:
miketout
2018-04-27 00:34:50 -07:00
parent a1af306f81
commit 42181656c2
20 changed files with 1197 additions and 19 deletions

54
src/crypto/verus_hash.h Normal file
View File

@@ -0,0 +1,54 @@
// (C) 2018 The Verus Developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
/*
This provides the PoW hash function for Verus, enabling CPU mining.
*/
#ifndef VERUS_HASH_H_
#define VERUS_HASH_H_
#include <cstring>
#include <vector>
extern "C"
{
#include "crypto/haraka.h"
}
class CVerusHash
{
public:
static void Hash(void *result, const void *data, size_t len);
CVerusHash() {}
CVerusHash &Write(const unsigned char *data, size_t len);
CVerusHash &Reset()
{
curBuf = buf1;
result = buf2;
curPos = 0;
std::fill(buf1, buf1 + sizeof(buf1), 0);
std::fill(buf2, buf2 + sizeof(buf2), 0);
}
void Finalize(unsigned char hash[32])
{
if (curPos)
{
std::fill(curBuf + 32 + curPos, curBuf + 64, 0);
haraka512(hash, curBuf);
}
else
std::memcpy(hash, result, 32);
}
private:
unsigned char buf1[64], buf2[64];
unsigned char *curBuf = buf1, *result = buf2;
size_t curPos = 0;
};
#endif