56 #define fillz() do { \ 57 sph_blake512_init(&z_blake); \ 58 sph_bmw512_init(&z_bmw); \ 59 sph_groestl512_init(&z_groestl); \ 60 sph_jh512_init(&z_jh); \ 61 sph_keccak512_init(&z_keccak); \ 62 sph_skein512_init(&z_skein); \ 63 sph_luffa512_init(&z_luffa); \ 64 sph_cubehash512_init(&z_cubehash); \ 65 sph_shavite512_init(&z_shavite); \ 66 sph_simd512_init(&z_simd); \ 67 sph_echo512_init(&z_echo); \ 69 #define ZBLAKE (memcpy(&ctx_blake, &z_blake, sizeof(z_blake))) 70 #define ZBMW (memcpy(&ctx_bmw, &z_bmw, sizeof(z_bmw))) 71 #define ZGROESTL (memcpy(&ctx_groestl, &z_groestl, sizeof(z_groestl))) 72 #define ZJH (memcpy(&ctx_jh, &z_jh, sizeof(z_jh))) 73 #define ZKECCAK (memcpy(&ctx_keccak, &z_keccak, sizeof(z_keccak))) 74 #define ZSKEIN (memcpy(&ctx_skein, &z_skein, sizeof(z_skein))) 82 void Finalize(
unsigned char hash[OUTPUT_SIZE]) {
113 sha.
Write(data, len);
124 template<
typename T1>
127 static const unsigned char pblank[1] = {};
129 CHash256().
Write(pbegin == pend ? pblank : (
const unsigned char*)&pbegin[0], (pend - pbegin) *
sizeof(pbegin[0]))
135 template<
typename T1,
typename T2>
137 const T2 p2begin,
const T2 p2end) {
138 static const unsigned char pblank[1] = {};
140 CHash256().
Write(p1begin == p1end ? pblank : (
const unsigned char*)&p1begin[0], (p1end - p1begin) *
sizeof(p1begin[0]))
141 .
Write(p2begin == p2end ? pblank : (
const unsigned char*)&p2begin[0], (p2end - p2begin) *
sizeof(p2begin[0]))
146 template<
typename T1,
typename T2,
typename T3>
148 const T2 p2begin,
const T2 p2end,
149 const T3 p3begin,
const T3 p3end) {
150 static const unsigned char pblank[1] = {};
152 CHash256().
Write(p1begin == p1end ? pblank : (
const unsigned char*)&p1begin[0], (p1end - p1begin) *
sizeof(p1begin[0]))
153 .
Write(p2begin == p2end ? pblank : (
const unsigned char*)&p2begin[0], (p2end - p2begin) *
sizeof(p2begin[0]))
154 .
Write(p3begin == p3end ? pblank : (
const unsigned char*)&p3begin[0], (p3end - p3begin) *
sizeof(p3begin[0]))
158 template<
typename T1,
typename T2,
typename T3,
typename T4>
160 const T2 p2begin,
const T2 p2end,
161 const T3 p3begin,
const T3 p3end,
162 const T4 p4begin,
const T4 p4end) {
163 static const unsigned char pblank[1] = {};
165 CHash256().
Write(p1begin == p1end ? pblank : (
const unsigned char*)&p1begin[0], (p1end - p1begin) *
sizeof(p1begin[0]))
166 .
Write(p2begin == p2end ? pblank : (
const unsigned char*)&p2begin[0], (p2end - p2begin) *
sizeof(p2begin[0]))
167 .
Write(p3begin == p3end ? pblank : (
const unsigned char*)&p3begin[0], (p3end - p3begin) *
sizeof(p3begin[0]))
168 .
Write(p4begin == p4end ? pblank : (
const unsigned char*)&p4begin[0], (p4end - p4begin) *
sizeof(p4begin[0]))
172 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
174 const T2 p2begin,
const T2 p2end,
175 const T3 p3begin,
const T3 p3end,
176 const T4 p4begin,
const T4 p4end,
177 const T5 p5begin,
const T5 p5end) {
178 static const unsigned char pblank[1] = {};
180 CHash256().
Write(p1begin == p1end ? pblank : (
const unsigned char*)&p1begin[0], (p1end - p1begin) *
sizeof(p1begin[0]))
181 .
Write(p2begin == p2end ? pblank : (
const unsigned char*)&p2begin[0], (p2end - p2begin) *
sizeof(p2begin[0]))
182 .
Write(p3begin == p3end ? pblank : (
const unsigned char*)&p3begin[0], (p3end - p3begin) *
sizeof(p3begin[0]))
183 .
Write(p4begin == p4end ? pblank : (
const unsigned char*)&p4begin[0], (p4end - p4begin) *
sizeof(p4begin[0]))
184 .
Write(p5begin == p5end ? pblank : (
const unsigned char*)&p5begin[0], (p5end - p5begin) *
sizeof(p5begin[0]))
188 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6>
190 const T2 p2begin,
const T2 p2end,
191 const T3 p3begin,
const T3 p3end,
192 const T4 p4begin,
const T4 p4end,
193 const T5 p5begin,
const T5 p5end,
194 const T6 p6begin,
const T6 p6end) {
195 static const unsigned char pblank[1] = {};
197 CHash256().
Write(p1begin == p1end ? pblank : (
const unsigned char*)&p1begin[0], (p1end - p1begin) *
sizeof(p1begin[0]))
198 .
Write(p2begin == p2end ? pblank : (
const unsigned char*)&p2begin[0], (p2end - p2begin) *
sizeof(p2begin[0]))
199 .
Write(p3begin == p3end ? pblank : (
const unsigned char*)&p3begin[0], (p3end - p3begin) *
sizeof(p3begin[0]))
200 .
Write(p4begin == p4end ? pblank : (
const unsigned char*)&p4begin[0], (p4end - p4begin) *
sizeof(p4begin[0]))
201 .
Write(p5begin == p5end ? pblank : (
const unsigned char*)&p5begin[0], (p5end - p5begin) *
sizeof(p5begin[0]))
202 .
Write(p6begin == p6end ? pblank : (
const unsigned char*)&p6begin[0], (p6end - p6begin) *
sizeof(p6begin[0]))
207 template<
typename T1>
210 static unsigned char pblank[1] = {};
212 CHash160().
Write(pbegin == pend ? pblank : (
const unsigned char*)&pbegin[0], (pend - pbegin) *
sizeof(pbegin[0]))
220 return Hash160(vch.begin(), vch.end());
224 template<
unsigned int N>
240 CHashWriter(
int nTypeIn,
int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
245 void write(
const char *pch,
size_t size) {
246 ctx.
Write((
const unsigned char*)pch, size);
252 ctx.
Finalize((
unsigned char*)&result);
265 template<
typename Source>
274 void read(
char* pch,
size_t nSize)
276 source->read(pch, nSize);
277 this->write(pch, nSize);
284 size_t now = std::min<size_t>(nSize, 1024);
308 unsigned int MurmurHash3(
unsigned int nHashSeed,
const std::vector<unsigned char>& vDataToHash);
310 void BIP32Hash(
const ChainCode &chainCode,
unsigned int nChild,
unsigned char header,
const unsigned char data[32],
unsigned char output[64]);
351 #define START_OF_LAST_16_NIBBLES_OF_HASH 48 353 return(hashSelection);
360 template<
typename T1>
366 sph_blake512_context ctx_blake;
367 sph_bmw512_context ctx_bmw;
371 sph_skein512_context ctx_skein;
380 sph_whirlpool_context ctx_whirlpool;
381 sph_sha512_context ctx_sha512;
383 static unsigned char pblank[1];
387 for (
int i=0;i<16;i++)
392 toHash = (pbegin == pend ? pblank :
static_cast<const void*
>(&pbegin[0]));
393 lenToHash = (pend - pbegin) *
sizeof(pbegin[0]);
395 toHash =
static_cast<const void*
>(&hash[i-1]);
401 switch(hashSelection) {
403 sph_blake512_init(&ctx_blake);
404 sph_blake512 (&ctx_blake, toHash, lenToHash);
405 sph_blake512_close(&ctx_blake, static_cast<void*>(&hash[i]));
408 sph_bmw512_init(&ctx_bmw);
409 sph_bmw512 (&ctx_bmw, toHash, lenToHash);
410 sph_bmw512_close(&ctx_bmw, static_cast<void*>(&hash[i]));
428 sph_skein512_init(&ctx_skein);
429 sph_skein512 (&ctx_skein, toHash, lenToHash);
430 sph_skein512_close(&ctx_skein, static_cast<void*>(&hash[i]));
474 sph_whirlpool(&ctx_whirlpool, toHash, lenToHash);
475 sph_whirlpool_close(&ctx_whirlpool, static_cast<void*>(&hash[i]));
478 sph_sha512_init(&ctx_sha512);
479 sph_sha512 (&ctx_sha512, toHash, lenToHash);
480 sph_sha512_close(&ctx_sha512, static_cast<void*>(&hash[i]));
489 #endif // RAVEN_HASH_H
CSHA256 & Write(const unsigned char *data, size_t len)
GLOBAL sph_blake512_context z_blake
void sph_fugue512(void *cc, const void *data, size_t len)
void write(const char *pch, size_t size)
void sph_shabal512_init(void *cc)
Initialize a Shabal-512 context.
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector< unsigned char > &vDataToHash)
This structure is a context for ECHO computations: it contains the intermediate values and some data ...
GLOBAL sph_shavite512_context z_shavite
int GetNibble(int index) const
void sph_echo512(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_hamsi512(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_simd512(void *cc, const void *data, size_t len)
Process some data bytes.
CHash256 & Write(const unsigned char *data, size_t len)
void sph_simd512_close(void *cc, void *dst)
Terminate the current SIMD-512 computation and output the result into the provided buffer...
This structure is a context for SHAvite-384 and SHAvite-512 computations: it contains the intermediat...
GLOBAL sph_cubehash512_context z_cubehash
void sph_echo512_init(void *cc)
Initialize an ECHO-512 context.
void sph_jh512_init(void *cc)
Initialize a JH-512 context.
A hasher class for Raven's 256-bit hash (double SHA-256).
uint160 Hash160(const T1 pbegin, const T1 pend)
Compute the 160-bit hash an object.
GLOBAL sph_keccak512_context z_keccak
void ignore(size_t nSize)
Reads data from an underlying stream, while hashing the read data.
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
void sph_luffa512_close(void *cc, void *dst)
Terminate the current Luffa-512 computation and output the result into the provided buffer...
This structure is a context for Shabal computations: it contains the intermediate values and some dat...
void sph_luffa512(void *cc, const void *data, size_t len)
Process some data bytes.
void Serialize(Stream &s, char a)
void sph_shavite512_init(void *cc)
Initialize a SHAvite-512 context.
void sph_cubehash512(void *cc, const void *data, size_t len)
Process some data bytes.
uint256 HashX16R(const T1 pbegin, const T1 pend, const uint256 PrevBlockHash)
void Finalize(unsigned char hash[OUTPUT_SIZE])
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object's serialization.
This structure is a context for SIMD computations: it contains the intermediate values and some data ...
SHA-224, SHA-256, SHA-384 and SHA-512 interface.
void sph_shabal512_close(void *cc, void *dst)
Terminate the current Shabal-512 computation and output the result into the provided buffer...
void sph_jh512_close(void *cc, void *dst)
Terminate the current JH-512 computation and output the result into the provided buffer.
This structure is a context for Hamsi-384 and Hamsi-512 computations: it contains the intermediate va...
void sph_hamsi512_init(void *cc)
Initialize a Hamsi-512 context.
static const size_t OUTPUT_SIZE
#define START_OF_LAST_16_NIBBLES_OF_HASH
void sph_cubehash512_close(void *cc, void *dst)
Terminate the current CubeHash-512 computation and output the result into the provided buffer...
GLOBAL sph_echo512_context z_echo
void Finalize(unsigned char hash[OUTPUT_SIZE])
CHash160 & Write(const unsigned char *data, size_t len)
CHashVerifier< Source > & operator>>(T &obj)
GLOBAL sph_luffa512_context z_luffa
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
int GetHashSelection(const uint256 PrevBlockHash, int index)
CHashWriter(int nTypeIn, int nVersionIn)
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
void sph_whirlpool_init(void *cc)
CRIPEMD160 & Write(const unsigned char *data, size_t len)
void sph_shavite512(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_echo512_close(void *cc, void *dst)
Terminate the current ECHO-512 computation and output the result into the provided buffer...
GLOBAL sph_simd512_context z_simd
void sph_keccak512_init(void *cc)
Initialize a Keccak-512 context.
void sph_hamsi512_close(void *cc, void *dst)
Terminate the current Hamsi-512 computation and output the result into the provided buffer...
This structure is a context for Luffa-512 computations.
void sph_keccak512(void *cc, const void *data, size_t len)
Process some data bytes.
GLOBAL sph_groestl512_context z_groestl
void sph_fugue512_close(void *cc, void *dst)
GLOBAL sph_bmw512_context z_bmw
void Finalize(unsigned char hash[OUTPUT_SIZE])
CHashVerifier(Source *source_)
void sph_shavite512_close(void *cc, void *dst)
Terminate the current SHAvite-512 computation and output the result into the provided buffer...
uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256 &val, uint32_t extra)
static const size_t OUTPUT_SIZE
static const size_t OUTPUT_SIZE
CHashWriter & operator<<(const T &obj)
void Unserialize(Stream &s, char &a)
void read(char *pch, size_t nSize)
GLOBAL sph_jh512_context z_jh
void sph_groestl512(void *cc, const void *data, size_t len)
Process some data bytes.
A writer stream (for serialization) that computes a 256-bit hash.
This structure is a context for JH computations: it contains the intermediate values and some data fr...
void sph_keccak512_close(void *cc, void *dst)
Terminate the current Keccak-512 computation and output the result into the provided buffer...
void sph_shabal512(void *cc, const void *data, size_t len)
Process some data bytes.
A hasher class for Raven's 160-bit hash (SHA-256 + RIPEMD-160).
void sph_groestl512_init(void *cc)
Initialize a Groestl-512 context.
void sph_simd512_init(void *cc)
Initialize an SIMD-512 context.
void Finalize(unsigned char hash[OUTPUT_SIZE])
This structure is a context for Keccak computations: it contains the intermediate values and some dat...
void sph_jh512(void *cc, const void *data, size_t len)
Process some data bytes.
void sph_groestl512_close(void *cc, void *dst)
Terminate the current Groestl-512 computation and output the result into the provided buffer...
A hasher class for SHA-256.
void sph_cubehash512_init(void *cc)
Initialize a CubeHash-512 context.
This structure is a context for CubeHash computations: it contains the intermediate values and some d...
A hasher class for RIPEMD-160.
void sph_fugue512_init(void *cc)
GLOBAL sph_skein512_context z_skein
This structure is a context for Groestl-384 and Groestl-512 computations: it contains the intermediat...
void sph_luffa512_init(void *cc)
Initialize a Luffa-512 context.