]> Git Repo - cpuminer-multi.git/blob - algo/sonoa.c
update build.sh
[cpuminer-multi.git] / algo / sonoa.c
1 #include "miner.h"
2
3 #include <stdlib.h>
4 #include <stdint.h>
5 #include <string.h>
6 #include <stdio.h>
7
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>
25
26 void sonoa_hash(void *state, const void *input)
27 {
28         uint8_t _ALIGN(128) hash[64];
29
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;
47
48
49         sph_blake512_init(&ctx_blake);
50         sph_blake512(&ctx_blake, input, 80);
51         sph_blake512_close(&ctx_blake, hash);
52
53         sph_bmw512_init(&ctx_bmw);
54         sph_bmw512(&ctx_bmw, hash, 64);
55         sph_bmw512_close(&ctx_bmw, hash);
56
57         sph_groestl512_init(&ctx_groestl);
58         sph_groestl512(&ctx_groestl, hash, 64);
59         sph_groestl512_close(&ctx_groestl, hash);
60
61         sph_skein512_init(&ctx_skein);
62         sph_skein512(&ctx_skein, hash, 64);
63         sph_skein512_close(&ctx_skein, hash);
64
65         sph_jh512_init(&ctx_jh);
66         sph_jh512(&ctx_jh, hash, 64);
67         sph_jh512_close(&ctx_jh, hash);
68
69         sph_keccak512_init(&ctx_keccak);
70         sph_keccak512(&ctx_keccak, hash, 64);
71         sph_keccak512_close(&ctx_keccak, hash);
72
73         sph_luffa512_init(&ctx_luffa);
74         sph_luffa512(&ctx_luffa, hash, 64);
75         sph_luffa512_close(&ctx_luffa, hash);
76
77         sph_cubehash512_init(&ctx_cubehash);
78         sph_cubehash512(&ctx_cubehash, hash, 64);
79         sph_cubehash512_close(&ctx_cubehash, hash);
80
81         sph_shavite512_init(&ctx_shavite);
82         sph_shavite512(&ctx_shavite, hash, 64);
83         sph_shavite512_close(&ctx_shavite, hash);
84
85         sph_simd512_init(&ctx_simd);
86         sph_simd512(&ctx_simd, hash, 64);
87         sph_simd512_close(&ctx_simd, hash);
88
89         sph_echo512_init(&ctx_echo);
90         sph_echo512(&ctx_echo, hash, 64);
91         sph_echo512_close(&ctx_echo, hash);
92
93
94         sph_bmw512(&ctx_bmw, hash, 64);
95         sph_bmw512_close(&ctx_bmw, hash);
96
97         sph_groestl512(&ctx_groestl, hash, 64);
98         sph_groestl512_close(&ctx_groestl, hash);
99
100         sph_skein512(&ctx_skein, hash, 64);
101         sph_skein512_close(&ctx_skein, hash);
102
103         sph_jh512(&ctx_jh, hash, 64);
104         sph_jh512_close(&ctx_jh, hash);
105
106         sph_keccak512(&ctx_keccak, hash, 64);
107         sph_keccak512_close(&ctx_keccak, hash);
108
109         sph_luffa512(&ctx_luffa, hash, 64);
110         sph_luffa512_close(&ctx_luffa, hash);
111
112         sph_cubehash512(&ctx_cubehash, hash, 64);
113         sph_cubehash512_close(&ctx_cubehash, hash);
114
115         sph_shavite512(&ctx_shavite, hash, 64);
116         sph_shavite512_close(&ctx_shavite, hash);
117
118         sph_simd512(&ctx_simd, hash, 64);
119         sph_simd512_close(&ctx_simd, hash);
120
121         sph_echo512(&ctx_echo, hash, 64);
122         sph_echo512_close(&ctx_echo, hash);
123
124         sph_hamsi512_init(&ctx_hamsi);
125         sph_hamsi512(&ctx_hamsi, hash, 64);
126         sph_hamsi512_close(&ctx_hamsi, hash);
127
128
129         sph_bmw512(&ctx_bmw, hash, 64);
130         sph_bmw512_close(&ctx_bmw, hash);
131
132         sph_groestl512(&ctx_groestl, hash, 64);
133         sph_groestl512_close(&ctx_groestl, hash);
134
135         sph_skein512(&ctx_skein, hash, 64);
136         sph_skein512_close(&ctx_skein, hash);
137
138         sph_jh512(&ctx_jh, hash, 64);
139         sph_jh512_close(&ctx_jh, hash);
140
141         sph_keccak512(&ctx_keccak, hash, 64);
142         sph_keccak512_close(&ctx_keccak, hash);
143
144         sph_luffa512(&ctx_luffa, hash, 64);
145         sph_luffa512_close(&ctx_luffa, hash);
146
147         sph_cubehash512(&ctx_cubehash, hash, 64);
148         sph_cubehash512_close(&ctx_cubehash, hash);
149
150         sph_shavite512(&ctx_shavite, hash, 64);
151         sph_shavite512_close(&ctx_shavite, hash);
152
153         sph_simd512(&ctx_simd, hash, 64);
154         sph_simd512_close(&ctx_simd, hash);
155
156         sph_echo512(&ctx_echo, hash, 64);
157         sph_echo512_close(&ctx_echo, hash);
158
159         sph_hamsi512(&ctx_hamsi, hash, 64);
160         sph_hamsi512_close(&ctx_hamsi, hash);
161
162         sph_fugue512_init(&ctx_fugue);
163         sph_fugue512(&ctx_fugue, hash, 64);
164         sph_fugue512_close(&ctx_fugue, hash);
165
166
167         sph_bmw512(&ctx_bmw, hash, 64);
168         sph_bmw512_close(&ctx_bmw, hash);
169
170         sph_groestl512(&ctx_groestl, hash, 64);
171         sph_groestl512_close(&ctx_groestl, hash);
172
173         sph_skein512(&ctx_skein, hash, 64);
174         sph_skein512_close(&ctx_skein, hash);
175
176         sph_jh512(&ctx_jh, hash, 64);
177         sph_jh512_close(&ctx_jh, hash);
178
179         sph_keccak512(&ctx_keccak, hash, 64);
180         sph_keccak512_close(&ctx_keccak, hash);
181
182         sph_luffa512(&ctx_luffa, hash, 64);
183         sph_luffa512_close(&ctx_luffa, hash);
184
185         sph_cubehash512(&ctx_cubehash, hash, 64);
186         sph_cubehash512_close(&ctx_cubehash, hash);
187
188         sph_shavite512(&ctx_shavite, hash, 64);
189         sph_shavite512_close(&ctx_shavite, hash);
190
191         sph_simd512(&ctx_simd, hash, 64);
192         sph_simd512_close(&ctx_simd, hash);
193
194         sph_echo512(&ctx_echo, hash, 64);
195         sph_echo512_close(&ctx_echo, hash);
196
197         sph_hamsi512(&ctx_hamsi, hash, 64);
198         sph_hamsi512_close(&ctx_hamsi, hash);
199
200         sph_fugue512(&ctx_fugue, hash, 64);
201         sph_fugue512_close(&ctx_fugue, hash);
202
203         sph_shabal512_init(&ctx_shabal);
204         sph_shabal512(&ctx_shabal, hash, 64);
205         sph_shabal512_close(&ctx_shabal, hash);
206
207         sph_hamsi512(&ctx_hamsi, hash, 64);
208         sph_hamsi512_close(&ctx_hamsi, hash);
209
210         sph_echo512(&ctx_echo, hash, 64);
211         sph_echo512_close(&ctx_echo, hash);
212
213         sph_shavite512(&ctx_shavite, hash, 64);
214         sph_shavite512_close(&ctx_shavite, hash);
215
216
217         sph_bmw512(&ctx_bmw, hash, 64);
218         sph_bmw512_close(&ctx_bmw, hash);
219
220         sph_shabal512(&ctx_shabal, hash, 64);
221         sph_shabal512_close(&ctx_shabal, hash);
222
223         sph_groestl512(&ctx_groestl, hash, 64);
224         sph_groestl512_close(&ctx_groestl, hash);
225
226         sph_skein512(&ctx_skein, hash, 64);
227         sph_skein512_close(&ctx_skein, hash);
228
229         sph_jh512(&ctx_jh, hash, 64);
230         sph_jh512_close(&ctx_jh, hash);
231
232         sph_keccak512(&ctx_keccak, hash, 64);
233         sph_keccak512_close(&ctx_keccak, hash);
234
235         sph_luffa512(&ctx_luffa, hash, 64);
236         sph_luffa512_close(&ctx_luffa, hash);
237
238         sph_cubehash512(&ctx_cubehash, hash, 64);
239         sph_cubehash512_close(&ctx_cubehash, hash);
240
241         sph_shavite512(&ctx_shavite, hash, 64);
242         sph_shavite512_close(&ctx_shavite, hash);
243
244         sph_simd512(&ctx_simd, hash, 64);
245         sph_simd512_close(&ctx_simd, hash);
246
247         sph_echo512(&ctx_echo, hash, 64);
248         sph_echo512_close(&ctx_echo, hash);
249
250         sph_hamsi512(&ctx_hamsi, hash, 64);
251         sph_hamsi512_close(&ctx_hamsi, hash);
252
253         sph_fugue512(&ctx_fugue, hash, 64);
254         sph_fugue512_close(&ctx_fugue, hash);
255
256         sph_shabal512(&ctx_shabal, hash, 64);
257         sph_shabal512_close(&ctx_shabal, hash);
258
259         sph_whirlpool_init(&ctx_whirlpool);
260         sph_whirlpool(&ctx_whirlpool, hash, 64);
261         sph_whirlpool_close(&ctx_whirlpool, hash);
262
263
264         sph_bmw512(&ctx_bmw, hash, 64);
265         sph_bmw512_close(&ctx_bmw, hash);
266
267         sph_groestl512(&ctx_groestl, hash, 64);
268         sph_groestl512_close(&ctx_groestl, hash);
269
270         sph_skein512(&ctx_skein, hash, 64);
271         sph_skein512_close(&ctx_skein, hash);
272
273         sph_jh512(&ctx_jh, hash, 64);
274         sph_jh512_close(&ctx_jh, hash);
275
276         sph_keccak512(&ctx_keccak, hash, 64);
277         sph_keccak512_close(&ctx_keccak, hash);
278
279         sph_luffa512(&ctx_luffa, hash, 64);
280         sph_luffa512_close(&ctx_luffa, hash);
281
282         sph_cubehash512(&ctx_cubehash, hash, 64);
283         sph_cubehash512_close(&ctx_cubehash, hash);
284
285         sph_shavite512(&ctx_shavite, hash, 64);
286         sph_shavite512_close(&ctx_shavite, hash);
287
288         sph_simd512(&ctx_simd, hash, 64);
289         sph_simd512_close(&ctx_simd, hash);
290
291         sph_echo512(&ctx_echo, hash, 64);
292         sph_echo512_close(&ctx_echo, hash);
293
294         sph_hamsi512(&ctx_hamsi, hash, 64);
295         sph_hamsi512_close(&ctx_hamsi, hash);
296
297         sph_fugue512(&ctx_fugue, hash, 64);
298         sph_fugue512_close(&ctx_fugue, hash);
299
300         sph_shabal512(&ctx_shabal, hash, 64);
301         sph_shabal512_close(&ctx_shabal, hash);
302
303         sph_whirlpool(&ctx_whirlpool, hash, 64);
304         sph_whirlpool_close(&ctx_whirlpool, hash);
305
306         sph_sha512_init(&ctx_sha512);
307         sph_sha512(&ctx_sha512,(const void*) hash, 64);
308         sph_sha512_close(&ctx_sha512,(void*) hash);
309
310         sph_whirlpool(&ctx_whirlpool, hash, 64);
311         sph_whirlpool_close(&ctx_whirlpool, hash);
312
313
314         sph_bmw512(&ctx_bmw, hash, 64);
315         sph_bmw512_close(&ctx_bmw, hash);
316
317         sph_groestl512(&ctx_groestl, hash, 64);
318         sph_groestl512_close(&ctx_groestl, hash);
319
320         sph_skein512(&ctx_skein, hash, 64);
321         sph_skein512_close(&ctx_skein, hash);
322
323         sph_jh512(&ctx_jh, hash, 64);
324         sph_jh512_close(&ctx_jh, hash);
325
326         sph_keccak512(&ctx_keccak, hash, 64);
327         sph_keccak512_close(&ctx_keccak, hash);
328
329         sph_luffa512(&ctx_luffa, hash, 64);
330         sph_luffa512_close(&ctx_luffa, hash);
331
332         sph_cubehash512(&ctx_cubehash, hash, 64);
333         sph_cubehash512_close(&ctx_cubehash, hash);
334
335         sph_shavite512(&ctx_shavite, hash, 64);
336         sph_shavite512_close(&ctx_shavite, hash);
337
338         sph_simd512(&ctx_simd, hash, 64);
339         sph_simd512_close(&ctx_simd, hash);
340
341         sph_echo512(&ctx_echo, hash, 64);
342         sph_echo512_close(&ctx_echo, hash);
343
344         sph_hamsi512(&ctx_hamsi, hash, 64);
345         sph_hamsi512_close(&ctx_hamsi, hash);
346
347         sph_fugue512(&ctx_fugue, hash, 64);
348         sph_fugue512_close(&ctx_fugue, hash);
349
350         sph_shabal512(&ctx_shabal, hash, 64);
351         sph_shabal512_close(&ctx_shabal, hash);
352
353         sph_whirlpool(&ctx_whirlpool, hash, 64);
354         sph_whirlpool_close(&ctx_whirlpool, hash);
355
356         sph_sha512(&ctx_sha512,(const void*) hash, 64);
357         sph_sha512_close(&ctx_sha512,(void*) hash);
358
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);
362
363         memcpy(state, hash, 32);
364 }
365
366 int scanhash_sonoa(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
367 {
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;
375
376         uint64_t htmax[] = {
377                 0,
378                 0xF,
379                 0xFF,
380                 0xFFF,
381                 0xFFFF,
382                 0x10000000
383         };
384         uint32_t masks[] = {
385                 0xFFFFFFFF,
386                 0xFFFFFFF0,
387                 0xFFFFFF00,
388                 0xFFFFF000,
389                 0xFFFF0000,
390                 0
391         };
392
393         // we need bigendian data...
394         for (int i=0; i < 19; i++) {
395                         be32enc(&endiandata[i], pdata[i]);
396         }
397
398 #ifdef DEBUG_ALGO
399         printf("[%d] Htarg=%X\n", thr_id, Htarg);
400 #endif
401         for (int m=0; m < 6; m++) {
402                 if (Htarg <= htmax[m]) {
403                         uint32_t mask = masks[m];
404                         do {
405                                 pdata[19] = ++n;
406                                 be32enc(&endiandata[19], n);
407                                 sonoa_hash(hash32, endiandata);
408 #ifndef DEBUG_ALGO
409                                 if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) {
410                                         work_set_target_ratio(work, hash32);
411                                         *hashes_done = n - first_nonce + 1;
412                                         return 1;
413                                 }
414 #else
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;
421                                                 return 1;
422                                         }
423                                 }
424 #endif
425                         } while (n < max_nonce && !work_restart[thr_id].restart);
426                         // see blake.c if else to understand the loop on htmax => mask
427                         break;
428                 }
429         }
430
431         *hashes_done = n - first_nonce + 1;
432         pdata[19] = n;
433         return 0;
434 }
This page took 0.05086 seconds and 4 git commands to generate.