1 // (C) 2018 The Verus Developers
\r
2 // Distributed under the MIT software license, see the accompanying
\r
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
\r
6 This provides the PoW hash function for Verus, enabling CPU mining.
\r
8 #ifndef VERUS_HASH_H_
\r
9 #define VERUS_HASH_H_
\r
14 #if !XERCES_HAVE_INTRIN_H
\r
20 #include "crypto/haraka.h"
\r
21 #include "crypto/haraka_portable.h"
\r
27 static void Hash(void *result, const void *data, size_t len);
\r
31 CVerusHash &Write(const unsigned char *data, size_t len);
\r
38 std::fill(buf1, buf1 + sizeof(buf1), 0);
\r
41 void Finalize(unsigned char hash[32])
\r
45 std::fill(curBuf + 32 + curPos, curBuf + 64, 0);
\r
46 haraka512(hash, curBuf);
\r
49 std::memcpy(hash, curBuf, 32);
\r
53 // only buf1, the first source, needs to be zero initialized
\r
54 unsigned char buf1[64] = {0}, buf2[64];
\r
55 unsigned char *curBuf = buf1, *result = buf2;
\r
59 class CVerusHashPortable
\r
62 static void Hash(void *result, const void *data, size_t len);
\r
64 CVerusHashPortable() {}
\r
66 CVerusHashPortable &Write(const unsigned char *data, size_t len);
\r
68 CVerusHashPortable &Reset()
\r
73 std::fill(buf1, buf1 + sizeof(buf1), 0);
\r
76 void Finalize(unsigned char hash[32])
\r
80 std::fill(curBuf + 32 + curPos, curBuf + 64, 0);
\r
81 haraka512_port(hash, curBuf);
\r
84 std::memcpy(hash, curBuf, 32);
\r
88 // only buf1, the first source, needs to be zero initialized
\r
89 unsigned char buf1[64] = {0}, buf2[64];
\r
90 unsigned char *curBuf = buf1, *result = buf2;
\r
94 extern void verus_hash(void *result, const void *data, size_t len);
\r
96 inline bool IsCPUVerusOptimized()
\r
98 unsigned int eax,ebx,ecx,edx;
\r
105 if (!__get_cpuid(CPUInfo, 1))
\r
107 if (!__get_cpuid(1,&eax,&ebx,&ecx,&edx))
\r
112 return ((ecx & (bit_AVX | bit_AES)) == (bit_AVX | bit_AES));
\r