8 #include <sha3/sph_blake.h>
9 #include <sha3/sph_bmw.h>
10 #include <sha3/sph_groestl.h>
11 #include <sha3/sph_jh.h>
12 #include <sha3/sph_keccak.h>
13 #include <sha3/sph_skein.h>
14 #include <sha3/sph_luffa.h>
15 #include <sha3/sph_cubehash.h>
16 #include <sha3/sph_shavite.h>
17 #include <sha3/sph_simd.h>
18 #include <sha3/sph_echo.h>
19 #include <sha3/sph_hamsi.h>
20 #include <sha3/sph_fugue.h>
21 #include <sha3/sph_shabal.h>
22 #include <sha3/sph_whirlpool.h>
23 #include <sha3/sph_sha2.h>
24 #include <sha3/sph_haval.h>
26 void sonoa_hash(void *state, const void *input)
28 uint8_t _ALIGN(128) hash[64];
30 sph_blake512_context ctx_blake;
31 sph_bmw512_context ctx_bmw;
32 sph_groestl512_context ctx_groestl;
33 sph_jh512_context ctx_jh;
34 sph_keccak512_context ctx_keccak;
35 sph_skein512_context ctx_skein;
36 sph_luffa512_context ctx_luffa;
37 sph_cubehash512_context ctx_cubehash;
38 sph_shavite512_context ctx_shavite;
39 sph_simd512_context ctx_simd;
40 sph_echo512_context ctx_echo;
41 sph_hamsi512_context ctx_hamsi;
42 sph_fugue512_context ctx_fugue;
43 sph_shabal512_context ctx_shabal;
44 sph_whirlpool_context ctx_whirlpool;
45 sph_sha512_context ctx_sha512;
46 sph_haval256_5_context ctx_haval;
49 sph_blake512_init(&ctx_blake);
50 sph_blake512(&ctx_blake, input, 80);
51 sph_blake512_close(&ctx_blake, hash);
53 sph_bmw512_init(&ctx_bmw);
54 sph_bmw512(&ctx_bmw, hash, 64);
55 sph_bmw512_close(&ctx_bmw, hash);
57 sph_groestl512_init(&ctx_groestl);
58 sph_groestl512(&ctx_groestl, hash, 64);
59 sph_groestl512_close(&ctx_groestl, hash);
61 sph_skein512_init(&ctx_skein);
62 sph_skein512(&ctx_skein, hash, 64);
63 sph_skein512_close(&ctx_skein, hash);
65 sph_jh512_init(&ctx_jh);
66 sph_jh512(&ctx_jh, hash, 64);
67 sph_jh512_close(&ctx_jh, hash);
69 sph_keccak512_init(&ctx_keccak);
70 sph_keccak512(&ctx_keccak, hash, 64);
71 sph_keccak512_close(&ctx_keccak, hash);
73 sph_luffa512_init(&ctx_luffa);
74 sph_luffa512(&ctx_luffa, hash, 64);
75 sph_luffa512_close(&ctx_luffa, hash);
77 sph_cubehash512_init(&ctx_cubehash);
78 sph_cubehash512(&ctx_cubehash, hash, 64);
79 sph_cubehash512_close(&ctx_cubehash, hash);
81 sph_shavite512_init(&ctx_shavite);
82 sph_shavite512(&ctx_shavite, hash, 64);
83 sph_shavite512_close(&ctx_shavite, hash);
85 sph_simd512_init(&ctx_simd);
86 sph_simd512(&ctx_simd, hash, 64);
87 sph_simd512_close(&ctx_simd, hash);
89 sph_echo512_init(&ctx_echo);
90 sph_echo512(&ctx_echo, hash, 64);
91 sph_echo512_close(&ctx_echo, hash);
94 sph_bmw512(&ctx_bmw, hash, 64);
95 sph_bmw512_close(&ctx_bmw, hash);
97 sph_groestl512(&ctx_groestl, hash, 64);
98 sph_groestl512_close(&ctx_groestl, hash);
100 sph_skein512(&ctx_skein, hash, 64);
101 sph_skein512_close(&ctx_skein, hash);
103 sph_jh512(&ctx_jh, hash, 64);
104 sph_jh512_close(&ctx_jh, hash);
106 sph_keccak512(&ctx_keccak, hash, 64);
107 sph_keccak512_close(&ctx_keccak, hash);
109 sph_luffa512(&ctx_luffa, hash, 64);
110 sph_luffa512_close(&ctx_luffa, hash);
112 sph_cubehash512(&ctx_cubehash, hash, 64);
113 sph_cubehash512_close(&ctx_cubehash, hash);
115 sph_shavite512(&ctx_shavite, hash, 64);
116 sph_shavite512_close(&ctx_shavite, hash);
118 sph_simd512(&ctx_simd, hash, 64);
119 sph_simd512_close(&ctx_simd, hash);
121 sph_echo512(&ctx_echo, hash, 64);
122 sph_echo512_close(&ctx_echo, hash);
124 sph_hamsi512_init(&ctx_hamsi);
125 sph_hamsi512(&ctx_hamsi, hash, 64);
126 sph_hamsi512_close(&ctx_hamsi, hash);
129 sph_bmw512(&ctx_bmw, hash, 64);
130 sph_bmw512_close(&ctx_bmw, hash);
132 sph_groestl512(&ctx_groestl, hash, 64);
133 sph_groestl512_close(&ctx_groestl, hash);
135 sph_skein512(&ctx_skein, hash, 64);
136 sph_skein512_close(&ctx_skein, hash);
138 sph_jh512(&ctx_jh, hash, 64);
139 sph_jh512_close(&ctx_jh, hash);
141 sph_keccak512(&ctx_keccak, hash, 64);
142 sph_keccak512_close(&ctx_keccak, hash);
144 sph_luffa512(&ctx_luffa, hash, 64);
145 sph_luffa512_close(&ctx_luffa, hash);
147 sph_cubehash512(&ctx_cubehash, hash, 64);
148 sph_cubehash512_close(&ctx_cubehash, hash);
150 sph_shavite512(&ctx_shavite, hash, 64);
151 sph_shavite512_close(&ctx_shavite, hash);
153 sph_simd512(&ctx_simd, hash, 64);
154 sph_simd512_close(&ctx_simd, hash);
156 sph_echo512(&ctx_echo, hash, 64);
157 sph_echo512_close(&ctx_echo, hash);
159 sph_hamsi512(&ctx_hamsi, hash, 64);
160 sph_hamsi512_close(&ctx_hamsi, hash);
162 sph_fugue512_init(&ctx_fugue);
163 sph_fugue512(&ctx_fugue, hash, 64);
164 sph_fugue512_close(&ctx_fugue, hash);
167 sph_bmw512(&ctx_bmw, hash, 64);
168 sph_bmw512_close(&ctx_bmw, hash);
170 sph_groestl512(&ctx_groestl, hash, 64);
171 sph_groestl512_close(&ctx_groestl, hash);
173 sph_skein512(&ctx_skein, hash, 64);
174 sph_skein512_close(&ctx_skein, hash);
176 sph_jh512(&ctx_jh, hash, 64);
177 sph_jh512_close(&ctx_jh, hash);
179 sph_keccak512(&ctx_keccak, hash, 64);
180 sph_keccak512_close(&ctx_keccak, hash);
182 sph_luffa512(&ctx_luffa, hash, 64);
183 sph_luffa512_close(&ctx_luffa, hash);
185 sph_cubehash512(&ctx_cubehash, hash, 64);
186 sph_cubehash512_close(&ctx_cubehash, hash);
188 sph_shavite512(&ctx_shavite, hash, 64);
189 sph_shavite512_close(&ctx_shavite, hash);
191 sph_simd512(&ctx_simd, hash, 64);
192 sph_simd512_close(&ctx_simd, hash);
194 sph_echo512(&ctx_echo, hash, 64);
195 sph_echo512_close(&ctx_echo, hash);
197 sph_hamsi512(&ctx_hamsi, hash, 64);
198 sph_hamsi512_close(&ctx_hamsi, hash);
200 sph_fugue512(&ctx_fugue, hash, 64);
201 sph_fugue512_close(&ctx_fugue, hash);
203 sph_shabal512_init(&ctx_shabal);
204 sph_shabal512(&ctx_shabal, hash, 64);
205 sph_shabal512_close(&ctx_shabal, hash);
207 sph_hamsi512(&ctx_hamsi, hash, 64);
208 sph_hamsi512_close(&ctx_hamsi, hash);
210 sph_echo512(&ctx_echo, hash, 64);
211 sph_echo512_close(&ctx_echo, hash);
213 sph_shavite512(&ctx_shavite, hash, 64);
214 sph_shavite512_close(&ctx_shavite, hash);
217 sph_bmw512(&ctx_bmw, hash, 64);
218 sph_bmw512_close(&ctx_bmw, hash);
220 sph_shabal512(&ctx_shabal, hash, 64);
221 sph_shabal512_close(&ctx_shabal, hash);
223 sph_groestl512(&ctx_groestl, hash, 64);
224 sph_groestl512_close(&ctx_groestl, hash);
226 sph_skein512(&ctx_skein, hash, 64);
227 sph_skein512_close(&ctx_skein, hash);
229 sph_jh512(&ctx_jh, hash, 64);
230 sph_jh512_close(&ctx_jh, hash);
232 sph_keccak512(&ctx_keccak, hash, 64);
233 sph_keccak512_close(&ctx_keccak, hash);
235 sph_luffa512(&ctx_luffa, hash, 64);
236 sph_luffa512_close(&ctx_luffa, hash);
238 sph_cubehash512(&ctx_cubehash, hash, 64);
239 sph_cubehash512_close(&ctx_cubehash, hash);
241 sph_shavite512(&ctx_shavite, hash, 64);
242 sph_shavite512_close(&ctx_shavite, hash);
244 sph_simd512(&ctx_simd, hash, 64);
245 sph_simd512_close(&ctx_simd, hash);
247 sph_echo512(&ctx_echo, hash, 64);
248 sph_echo512_close(&ctx_echo, hash);
250 sph_hamsi512(&ctx_hamsi, hash, 64);
251 sph_hamsi512_close(&ctx_hamsi, hash);
253 sph_fugue512(&ctx_fugue, hash, 64);
254 sph_fugue512_close(&ctx_fugue, hash);
256 sph_shabal512(&ctx_shabal, hash, 64);
257 sph_shabal512_close(&ctx_shabal, hash);
259 sph_whirlpool_init(&ctx_whirlpool);
260 sph_whirlpool(&ctx_whirlpool, hash, 64);
261 sph_whirlpool_close(&ctx_whirlpool, hash);
264 sph_bmw512(&ctx_bmw, hash, 64);
265 sph_bmw512_close(&ctx_bmw, hash);
267 sph_groestl512(&ctx_groestl, hash, 64);
268 sph_groestl512_close(&ctx_groestl, hash);
270 sph_skein512(&ctx_skein, hash, 64);
271 sph_skein512_close(&ctx_skein, hash);
273 sph_jh512(&ctx_jh, hash, 64);
274 sph_jh512_close(&ctx_jh, hash);
276 sph_keccak512(&ctx_keccak, hash, 64);
277 sph_keccak512_close(&ctx_keccak, hash);
279 sph_luffa512(&ctx_luffa, hash, 64);
280 sph_luffa512_close(&ctx_luffa, hash);
282 sph_cubehash512(&ctx_cubehash, hash, 64);
283 sph_cubehash512_close(&ctx_cubehash, hash);
285 sph_shavite512(&ctx_shavite, hash, 64);
286 sph_shavite512_close(&ctx_shavite, hash);
288 sph_simd512(&ctx_simd, hash, 64);
289 sph_simd512_close(&ctx_simd, hash);
291 sph_echo512(&ctx_echo, hash, 64);
292 sph_echo512_close(&ctx_echo, hash);
294 sph_hamsi512(&ctx_hamsi, hash, 64);
295 sph_hamsi512_close(&ctx_hamsi, hash);
297 sph_fugue512(&ctx_fugue, hash, 64);
298 sph_fugue512_close(&ctx_fugue, hash);
300 sph_shabal512(&ctx_shabal, hash, 64);
301 sph_shabal512_close(&ctx_shabal, hash);
303 sph_whirlpool(&ctx_whirlpool, hash, 64);
304 sph_whirlpool_close(&ctx_whirlpool, hash);
306 sph_sha512_init(&ctx_sha512);
307 sph_sha512(&ctx_sha512,(const void*) hash, 64);
308 sph_sha512_close(&ctx_sha512,(void*) hash);
310 sph_whirlpool(&ctx_whirlpool, hash, 64);
311 sph_whirlpool_close(&ctx_whirlpool, hash);
314 sph_bmw512(&ctx_bmw, hash, 64);
315 sph_bmw512_close(&ctx_bmw, hash);
317 sph_groestl512(&ctx_groestl, hash, 64);
318 sph_groestl512_close(&ctx_groestl, hash);
320 sph_skein512(&ctx_skein, hash, 64);
321 sph_skein512_close(&ctx_skein, hash);
323 sph_jh512(&ctx_jh, hash, 64);
324 sph_jh512_close(&ctx_jh, hash);
326 sph_keccak512(&ctx_keccak, hash, 64);
327 sph_keccak512_close(&ctx_keccak, hash);
329 sph_luffa512(&ctx_luffa, hash, 64);
330 sph_luffa512_close(&ctx_luffa, hash);
332 sph_cubehash512(&ctx_cubehash, hash, 64);
333 sph_cubehash512_close(&ctx_cubehash, hash);
335 sph_shavite512(&ctx_shavite, hash, 64);
336 sph_shavite512_close(&ctx_shavite, hash);
338 sph_simd512(&ctx_simd, hash, 64);
339 sph_simd512_close(&ctx_simd, hash);
341 sph_echo512(&ctx_echo, hash, 64);
342 sph_echo512_close(&ctx_echo, hash);
344 sph_hamsi512(&ctx_hamsi, hash, 64);
345 sph_hamsi512_close(&ctx_hamsi, hash);
347 sph_fugue512(&ctx_fugue, hash, 64);
348 sph_fugue512_close(&ctx_fugue, hash);
350 sph_shabal512(&ctx_shabal, hash, 64);
351 sph_shabal512_close(&ctx_shabal, hash);
353 sph_whirlpool(&ctx_whirlpool, hash, 64);
354 sph_whirlpool_close(&ctx_whirlpool, hash);
356 sph_sha512(&ctx_sha512,(const void*) hash, 64);
357 sph_sha512_close(&ctx_sha512,(void*) hash);
359 sph_haval256_5_init(&ctx_haval);
360 sph_haval256_5(&ctx_haval,(const void*) hash, 64);
361 sph_haval256_5_close(&ctx_haval, hash);
363 memcpy(state, hash, 32);
366 int scanhash_sonoa(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
368 uint32_t _ALIGN(128) hash32[8];
369 uint32_t _ALIGN(128) endiandata[20];
370 uint32_t *pdata = work->data;
371 uint32_t *ptarget = work->target;
372 const uint32_t first_nonce = pdata[19];
373 const uint32_t Htarg = ptarget[7];
374 uint32_t n = pdata[19] - 1;
393 // we need bigendian data...
394 for (int i=0; i < 19; i++) {
395 be32enc(&endiandata[i], pdata[i]);
399 printf("[%d] Htarg=%X\n", thr_id, Htarg);
401 for (int m=0; m < 6; m++) {
402 if (Htarg <= htmax[m]) {
403 uint32_t mask = masks[m];
406 be32enc(&endiandata[19], n);
407 sonoa_hash(hash32, endiandata);
409 if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) {
410 work_set_target_ratio(work, hash32);
411 *hashes_done = n - first_nonce + 1;
415 if (!(n % 0x1000) && !thr_id) printf(".");
416 if (!(hash32[7] & mask)) {
417 printf("[%d]",thr_id);
418 if (fulltest(hash32, ptarget)) {
419 work_set_target_ratio(work, hash32);
420 *hashes_done = n - first_nonce + 1;
425 } while (n < max_nonce && !work_restart[thr_id].restart);
426 // see blake.c if else to understand the loop on htmax => mask
431 *hashes_done = n - first_nonce + 1;