-
Notifications
You must be signed in to change notification settings - Fork 39
/
hashblock.h
110 lines (86 loc) · 3.14 KB
/
hashblock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef HASHBLOCK_H
#define HASHBLOCK_H
#include "uint256.h"
#include "sph_blake.h"
#include "sph_bmw.h"
#include "sph_groestl.h"
#include "sph_jh.h"
#include "sph_keccak.h"
#include "sph_skein.h"
#ifndef QT_NO_DEBUG
#include <string>
#endif
template<typename T1>
inline uint256 Hash9(const T1 pbegin, const T1 pend, uint256 prevHash)
{
sph_blake512_context ctx_blake;
sph_bmw512_context ctx_bmw;
sph_groestl512_context ctx_groestl;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_skein512_context ctx_skein;
static unsigned char pblank[1];
#ifndef QT_NO_DEBUG
//std::string strhash;
//strhash = "";
#endif
uint512 mask = 8;
uint512 zero = 0;
uint512 hash[9];
sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, (pbegin == pend ? pblank : static_cast<const void*>(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0]));
sph_blake512_close(&ctx_blake, static_cast<void*>(&hash[0]));
sph_bmw512_init(&ctx_bmw);
sph_bmw512 (&ctx_bmw, static_cast<const void*>(&hash[0]), 64);
sph_bmw512_close(&ctx_bmw, static_cast<void*>(&hash[1]));
if ((hash[1] & mask) != zero)
{
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, static_cast<const void*>(&hash[1]), 64);
sph_groestl512_close(&ctx_groestl, static_cast<void*>(&hash[2]));
}
else
{
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, static_cast<const void*>(&hash[1]), 64);
sph_skein512_close(&ctx_skein, static_cast<void*>(&hash[2]));
}
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, static_cast<const void*>(&hash[2]), 64);
sph_groestl512_close(&ctx_groestl, static_cast<void*>(&hash[3]));
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, static_cast<const void*>(&hash[3]), 64);
sph_jh512_close(&ctx_jh, static_cast<void*>(&hash[4]));
if ((hash[4] & mask) != zero)
{
sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, static_cast<const void*>(&hash[4]), 64);
sph_blake512_close(&ctx_blake, static_cast<void*>(&hash[5]));
}
else
{
sph_bmw512_init(&ctx_bmw);
sph_bmw512 (&ctx_bmw, static_cast<const void*>(&hash[4]), 64);
sph_bmw512_close(&ctx_bmw, static_cast<void*>(&hash[5]));
}
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, static_cast<const void*>(&hash[5]), 64);
sph_keccak512_close(&ctx_keccak, static_cast<void*>(&hash[6]));
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, static_cast<const void*>(&hash[6]), 64);
sph_skein512_close(&ctx_skein, static_cast<void*>(&hash[7]));
if ((hash[7] & mask) != zero)
{
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, static_cast<const void*>(&hash[7]), 64);
sph_keccak512_close(&ctx_keccak, static_cast<void*>(&hash[8]));
}
else
{
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, static_cast<const void*>(&hash[7]), 64);
sph_jh512_close(&ctx_jh, static_cast<void*>(&hash[8]));
}
return hash[8].trim256();
}
#endif // HASHBLOCK_H