68 #define BYTES_TO_DWORD(strptr) \ 69 (((uint32_t) *((strptr)+3) << 24) | \ 70 ((uint32_t) *((strptr)+2) << 16) | \ 71 ((uint32_t) *((strptr)+1) << 8) | \ 72 ((uint32_t) *(strptr))) 76 #define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 79 #define F(x, y, z) ((x) ^ (y) ^ (z)) 80 #define G(x, y, z) (((x) & (y)) | (~(x) & (z))) 81 #define H(x, y, z) (((x) | ~(y)) ^ (z)) 82 #define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) 83 #define J(x, y, z) ((x) ^ ((y) | ~(z))) 86 #define FF(a, b, c, d, e, x, s) {\ 87 (a) += F((b), (c), (d)) + (x);\ 88 (a) = ROL((a), (s)) + (e);\ 91 #define GG(a, b, c, d, e, x, s) {\ 92 (a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\ 93 (a) = ROL((a), (s)) + (e);\ 96 #define HH(a, b, c, d, e, x, s) {\ 97 (a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\ 98 (a) = ROL((a), (s)) + (e);\ 101 #define II(a, b, c, d, e, x, s) {\ 102 (a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\ 103 (a) = ROL((a), (s)) + (e);\ 106 #define JJ(a, b, c, d, e, x, s) {\ 107 (a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\ 108 (a) = ROL((a), (s)) + (e);\ 111 #define FFF(a, b, c, d, e, x, s) {\ 112 (a) += F((b), (c), (d)) + (x);\ 113 (a) = ROL((a), (s)) + (e);\ 116 #define GGG(a, b, c, d, e, x, s) {\ 117 (a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\ 118 (a) = ROL((a), (s)) + (e);\ 121 #define HHH(a, b, c, d, e, x, s) {\ 122 (a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\ 123 (a) = ROL((a), (s)) + (e);\ 126 #define III(a, b, c, d, e, x, s) {\ 127 (a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\ 128 (a) = ROL((a), (s)) + (e);\ 131 #define JJJ(a, b, c, d, e, x, s) {\ 132 (a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\ 133 (a) = ROL((a), (s)) + (e);\ 139 MDbuf[0] = 0x67452301
UL;
140 MDbuf[1] = 0xefcdab89
UL;
141 MDbuf[2] = 0x98badcfe
UL;
142 MDbuf[3] = 0x10325476
UL;
143 MDbuf[4] = 0xc3d2e1f0
UL;
152 uint32_t aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2],
153 dd = MDbuf[3], ee = MDbuf[4];
154 uint32_t aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2],
155 ddd = MDbuf[3], eee = MDbuf[4];
158 FF(aa, bb, cc, dd, ee, X[ 0], 11);
159 FF(ee, aa, bb, cc, dd, X[ 1], 14);
160 FF(dd, ee, aa, bb, cc, X[ 2], 15);
161 FF(cc, dd, ee, aa, bb, X[ 3], 12);
162 FF(bb, cc, dd, ee, aa, X[ 4], 5);
163 FF(aa, bb, cc, dd, ee, X[ 5], 8);
164 FF(ee, aa, bb, cc, dd, X[ 6], 7);
165 FF(dd, ee, aa, bb, cc, X[ 7], 9);
166 FF(cc, dd, ee, aa, bb, X[ 8], 11);
167 FF(bb, cc, dd, ee, aa, X[ 9], 13);
168 FF(aa, bb, cc, dd, ee, X[10], 14);
169 FF(ee, aa, bb, cc, dd, X[11], 15);
170 FF(dd, ee, aa, bb, cc, X[12], 6);
171 FF(cc, dd, ee, aa, bb, X[13], 7);
172 FF(bb, cc, dd, ee, aa, X[14], 9);
173 FF(aa, bb, cc, dd, ee, X[15], 8);
176 GG(ee, aa, bb, cc, dd, X[ 7], 7);
177 GG(dd, ee, aa, bb, cc, X[ 4], 6);
178 GG(cc, dd, ee, aa, bb, X[13], 8);
179 GG(bb, cc, dd, ee, aa, X[ 1], 13);
180 GG(aa, bb, cc, dd, ee, X[10], 11);
181 GG(ee, aa, bb, cc, dd, X[ 6], 9);
182 GG(dd, ee, aa, bb, cc, X[15], 7);
183 GG(cc, dd, ee, aa, bb, X[ 3], 15);
184 GG(bb, cc, dd, ee, aa, X[12], 7);
185 GG(aa, bb, cc, dd, ee, X[ 0], 12);
186 GG(ee, aa, bb, cc, dd, X[ 9], 15);
187 GG(dd, ee, aa, bb, cc, X[ 5], 9);
188 GG(cc, dd, ee, aa, bb, X[ 2], 11);
189 GG(bb, cc, dd, ee, aa, X[14], 7);
190 GG(aa, bb, cc, dd, ee, X[11], 13);
191 GG(ee, aa, bb, cc, dd, X[ 8], 12);
194 HH(dd, ee, aa, bb, cc, X[ 3], 11);
195 HH(cc, dd, ee, aa, bb, X[10], 13);
196 HH(bb, cc, dd, ee, aa, X[14], 6);
197 HH(aa, bb, cc, dd, ee, X[ 4], 7);
198 HH(ee, aa, bb, cc, dd, X[ 9], 14);
199 HH(dd, ee, aa, bb, cc, X[15], 9);
200 HH(cc, dd, ee, aa, bb, X[ 8], 13);
201 HH(bb, cc, dd, ee, aa, X[ 1], 15);
202 HH(aa, bb, cc, dd, ee, X[ 2], 14);
203 HH(ee, aa, bb, cc, dd, X[ 7], 8);
204 HH(dd, ee, aa, bb, cc, X[ 0], 13);
205 HH(cc, dd, ee, aa, bb, X[ 6], 6);
206 HH(bb, cc, dd, ee, aa, X[13], 5);
207 HH(aa, bb, cc, dd, ee, X[11], 12);
208 HH(ee, aa, bb, cc, dd, X[ 5], 7);
209 HH(dd, ee, aa, bb, cc, X[12], 5);
212 II(cc, dd, ee, aa, bb, X[ 1], 11);
213 II(bb, cc, dd, ee, aa, X[ 9], 12);
214 II(aa, bb, cc, dd, ee, X[11], 14);
215 II(ee, aa, bb, cc, dd, X[10], 15);
216 II(dd, ee, aa, bb, cc, X[ 0], 14);
217 II(cc, dd, ee, aa, bb, X[ 8], 15);
218 II(bb, cc, dd, ee, aa, X[12], 9);
219 II(aa, bb, cc, dd, ee, X[ 4], 8);
220 II(ee, aa, bb, cc, dd, X[13], 9);
221 II(dd, ee, aa, bb, cc, X[ 3], 14);
222 II(cc, dd, ee, aa, bb, X[ 7], 5);
223 II(bb, cc, dd, ee, aa, X[15], 6);
224 II(aa, bb, cc, dd, ee, X[14], 8);
225 II(ee, aa, bb, cc, dd, X[ 5], 6);
226 II(dd, ee, aa, bb, cc, X[ 6], 5);
227 II(cc, dd, ee, aa, bb, X[ 2], 12);
230 JJ(bb, cc, dd, ee, aa, X[ 4], 9);
231 JJ(aa, bb, cc, dd, ee, X[ 0], 15);
232 JJ(ee, aa, bb, cc, dd, X[ 5], 5);
233 JJ(dd, ee, aa, bb, cc, X[ 9], 11);
234 JJ(cc, dd, ee, aa, bb, X[ 7], 6);
235 JJ(bb, cc, dd, ee, aa, X[12], 8);
236 JJ(aa, bb, cc, dd, ee, X[ 2], 13);
237 JJ(ee, aa, bb, cc, dd, X[10], 12);
238 JJ(dd, ee, aa, bb, cc, X[14], 5);
239 JJ(cc, dd, ee, aa, bb, X[ 1], 12);
240 JJ(bb, cc, dd, ee, aa, X[ 3], 13);
241 JJ(aa, bb, cc, dd, ee, X[ 8], 14);
242 JJ(ee, aa, bb, cc, dd, X[11], 11);
243 JJ(dd, ee, aa, bb, cc, X[ 6], 8);
244 JJ(cc, dd, ee, aa, bb, X[15], 5);
245 JJ(bb, cc, dd, ee, aa, X[13], 6);
248 JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8);
249 JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9);
250 JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9);
251 JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11);
252 JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13);
253 JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15);
254 JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15);
255 JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5);
256 JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7);
257 JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7);
258 JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8);
259 JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11);
260 JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14);
261 JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14);
262 JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12);
263 JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6);
266 III(eee, aaa, bbb, ccc, ddd, X[ 6], 9);
267 III(ddd, eee, aaa, bbb, ccc, X[11], 13);
268 III(ccc, ddd, eee, aaa, bbb, X[ 3], 15);
269 III(bbb, ccc, ddd, eee, aaa, X[ 7], 7);
270 III(aaa, bbb, ccc, ddd, eee, X[ 0], 12);
271 III(eee, aaa, bbb, ccc, ddd, X[13], 8);
272 III(ddd, eee, aaa, bbb, ccc, X[ 5], 9);
273 III(ccc, ddd, eee, aaa, bbb, X[10], 11);
274 III(bbb, ccc, ddd, eee, aaa, X[14], 7);
275 III(aaa, bbb, ccc, ddd, eee, X[15], 7);
276 III(eee, aaa, bbb, ccc, ddd, X[ 8], 12);
277 III(ddd, eee, aaa, bbb, ccc, X[12], 7);
278 III(ccc, ddd, eee, aaa, bbb, X[ 4], 6);
279 III(bbb, ccc, ddd, eee, aaa, X[ 9], 15);
280 III(aaa, bbb, ccc, ddd, eee, X[ 1], 13);
281 III(eee, aaa, bbb, ccc, ddd, X[ 2], 11);
284 HHH(ddd, eee, aaa, bbb, ccc, X[15], 9);
285 HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7);
286 HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15);
287 HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11);
288 HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8);
289 HHH(ddd, eee, aaa, bbb, ccc, X[14], 6);
290 HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6);
291 HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14);
292 HHH(aaa, bbb, ccc, ddd, eee, X[11], 12);
293 HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13);
294 HHH(ddd, eee, aaa, bbb, ccc, X[12], 5);
295 HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14);
296 HHH(bbb, ccc, ddd, eee, aaa, X[10], 13);
297 HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13);
298 HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7);
299 HHH(ddd, eee, aaa, bbb, ccc, X[13], 5);
302 GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15);
303 GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5);
304 GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8);
305 GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11);
306 GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14);
307 GGG(ccc, ddd, eee, aaa, bbb, X[11], 14);
308 GGG(bbb, ccc, ddd, eee, aaa, X[15], 6);
309 GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14);
310 GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6);
311 GGG(ddd, eee, aaa, bbb, ccc, X[12], 9);
312 GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12);
313 GGG(bbb, ccc, ddd, eee, aaa, X[13], 9);
314 GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12);
315 GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5);
316 GGG(ddd, eee, aaa, bbb, ccc, X[10], 15);
317 GGG(ccc, ddd, eee, aaa, bbb, X[14], 8);
320 FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8);
321 FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5);
322 FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12);
323 FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9);
324 FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12);
325 FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5);
326 FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14);
327 FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6);
328 FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8);
329 FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13);
330 FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6);
331 FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5);
332 FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15);
333 FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13);
334 FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11);
335 FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11);
338 ddd += cc + MDbuf[1];
339 MDbuf[1] = MDbuf[2] + dd + eee;
340 MDbuf[2] = MDbuf[3] + ee + aaa;
341 MDbuf[3] = MDbuf[4] + aa + bbb;
342 MDbuf[4] = MDbuf[0] + bb + ccc;
348 void MDfinish(uint32_t *MDbuf,
byte const *strptr, uint32_t lswlen, uint32_t mswlen)
353 memset(X, 0, 16*
sizeof(uint32_t));
356 for (i=0; i<(lswlen&63); i++) {
358 X[i>>2] ^= (uint32_t) *strptr++ << (8 * (i&3));
362 X[(lswlen>>2)&15] ^= (uint32_t)1 << (8*(lswlen&3) + 7);
364 if ((lswlen & 63) > 55) {
367 memset(X, 0, 16*
sizeof(uint32_t));
372 X[15] = (lswlen >> 29) | (mswlen << 3);
404 uint32_t current[16];
408 byte const* message = _input.
data();
409 uint32_t remaining = _input.
size();
412 for (; remaining >= 64; remaining -= 64)
414 for (
unsigned i = 0; i < 16; i++)
426 for (
unsigned i = 0; i <
RMDsize / 8; i += 4)
428 hashcode[i] = buffer[i >> 2];
429 hashcode[i + 1] = (buffer[i >> 2] >> 8);
430 hashcode[i + 2] = (buffer[i >> 2] >> 16);
431 hashcode[i + 3] = (buffer[i >> 2] >> 24);
437 #undef BYTES_TO_DWORD Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
#define II(a, b, c, d, e, x, s)
void MDcompress(uint32_t *MDbuf, uint32_t *X)
void hash256(RaIter first, RaIter last, OutIter first2, OutIter last2)
#define HHH(a, b, c, d, e, x, s)
#define JJJ(a, b, c, d, e, x, s)
std::hash for asio::adress
void MDfinish(uint32_t *MDbuf, byte const *strptr, uint32_t lswlen, uint32_t mswlen)
#define HH(a, b, c, d, e, x, s)
#define FFF(a, b, c, d, e, x, s)
#define GG(a, b, c, d, e, x, s)
#define FF(a, b, c, d, e, x, s)
#define GGG(a, b, c, d, e, x, s)
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
#define III(a, b, c, d, e, x, s)
void MDinit(uint32_t *MDbuf)
h160 ripemd160(bytesConstRef _input)
h256 sha256(bytesConstRef _input)
#define JJ(a, b, c, d, e, x, s)
#define BYTES_TO_DWORD(strptr)