-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhashblock.h
150 lines (123 loc) · 4.23 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#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
#ifdef GLOBALDEFINED
#define GLOBAL
#else
#define GLOBAL extern
#endif
GLOBAL sph_blake512_context z_blake;
GLOBAL sph_bmw512_context z_bmw;
GLOBAL sph_groestl512_context z_groestl;
GLOBAL sph_jh512_context z_jh;
GLOBAL sph_keccak512_context z_keccak;
GLOBAL sph_skein512_context z_skein;
#define fillz() do { \
sph_blake512_init(&z_blake); \
sph_bmw512_init(&z_bmw); \
sph_groestl512_init(&z_groestl); \
sph_jh512_init(&z_jh); \
sph_keccak512_init(&z_keccak); \
sph_skein512_init(&z_skein); \
} while (0)
#define ZBLAKE (memcpy(&ctx_blake, &z_blake, sizeof(z_blake)))
#define ZBMW (memcpy(&ctx_bmw, &z_bmw, sizeof(z_bmw)))
#define ZGROESTL (memcpy(&ctx_groestl, &z_groestl, sizeof(z_groestl)))
#define ZJH (memcpy(&ctx_jh, &z_jh, sizeof(z_jh)))
#define ZKECCAK (memcpy(&ctx_keccak, &z_keccak, sizeof(z_keccak)))
#define ZSKEIN (memcpy(&ctx_skein, &z_skein, sizeof(z_skein)))
template<typename T1>
inline uint256 Hash9(const T1 pbegin, const T1 pend)
{
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);
// ZBLAKE;
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);
// ZBMW;
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);
// ZGROESTL;
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);
// ZSKEIN;
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);
// ZGROESTL;
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);
// ZJH;
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);
// ZBLAKE;
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);
// ZBMW;
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);
// ZKECCAK;
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);
// 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);
// ZKECCAK;
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);
// ZJH;
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