]>
Commit | Line | Data |
---|---|---|
0fcbea8e TP |
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 | ||
167960db | 24 | //#define DEBUG_ALGO |
4b5c6daf | 25 | |
f4ccad0e | 26 | void x15hash(void *output, const void *input) |
0fcbea8e TP |
27 | { |
28 | unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; | |
29 | #define hashB hash+64 | |
30 | ||
0fcbea8e TP |
31 | sph_blake512_context ctx_blake; |
32 | sph_bmw512_context ctx_bmw; | |
33 | sph_groestl512_context ctx_groestl; | |
34 | sph_jh512_context ctx_jh; | |
35 | sph_keccak512_context ctx_keccak; | |
36 | sph_skein512_context ctx_skein; | |
37 | sph_luffa512_context ctx_luffa; | |
38 | sph_cubehash512_context ctx_cubehash; | |
39 | sph_shavite512_context ctx_shavite; | |
40 | sph_simd512_context ctx_simd; | |
41 | sph_echo512_context ctx_echo; | |
42 | sph_hamsi512_context ctx_hamsi; | |
43 | sph_fugue512_context ctx_fugue; | |
44 | sph_shabal512_context ctx_shabal; | |
45 | sph_whirlpool_context ctx_whirlpool; | |
46 | ||
47 | sph_blake512_init(&ctx_blake); | |
48 | sph_blake512(&ctx_blake, input, 80); | |
49 | sph_blake512_close(&ctx_blake, hash); | |
167960db | 50 | |
0fcbea8e TP |
51 | sph_bmw512_init(&ctx_bmw); |
52 | sph_bmw512(&ctx_bmw, hash, 64); | |
53 | sph_bmw512_close(&ctx_bmw, hashB); | |
54 | ||
55 | sph_groestl512_init(&ctx_groestl); | |
56 | sph_groestl512(&ctx_groestl, hashB, 64); | |
57 | sph_groestl512_close(&ctx_groestl, hash); | |
58 | ||
59 | sph_skein512_init(&ctx_skein); | |
60 | sph_skein512(&ctx_skein, hash, 64); | |
61 | sph_skein512_close(&ctx_skein, hashB); | |
62 | ||
63 | sph_jh512_init(&ctx_jh); | |
64 | sph_jh512(&ctx_jh, hashB, 64); | |
65 | sph_jh512_close(&ctx_jh, hash); | |
66 | ||
67 | sph_keccak512_init(&ctx_keccak); | |
68 | sph_keccak512(&ctx_keccak, hash, 64); | |
69 | sph_keccak512_close(&ctx_keccak, hashB); | |
70 | ||
71 | sph_luffa512_init(&ctx_luffa); | |
72 | sph_luffa512(&ctx_luffa, hashB, 64); | |
73 | sph_luffa512_close(&ctx_luffa, hash); | |
74 | ||
75 | sph_cubehash512_init(&ctx_cubehash); | |
76 | sph_cubehash512(&ctx_cubehash, hash, 64); | |
77 | sph_cubehash512_close(&ctx_cubehash, hashB); | |
78 | ||
79 | sph_shavite512_init(&ctx_shavite); | |
80 | sph_shavite512(&ctx_shavite, hashB, 64); | |
81 | sph_shavite512_close(&ctx_shavite, hash); | |
82 | ||
83 | sph_simd512_init(&ctx_simd); | |
84 | sph_simd512(&ctx_simd, hash, 64); | |
85 | sph_simd512_close(&ctx_simd, hashB); | |
86 | ||
87 | sph_echo512_init(&ctx_echo); | |
88 | sph_echo512(&ctx_echo, hashB, 64); | |
89 | sph_echo512_close(&ctx_echo, hash); | |
90 | ||
91 | sph_hamsi512_init(&ctx_hamsi); | |
92 | sph_hamsi512(&ctx_hamsi, hash, 64); | |
93 | sph_hamsi512_close(&ctx_hamsi, hashB); | |
94 | ||
95 | sph_fugue512_init(&ctx_fugue); | |
96 | sph_fugue512(&ctx_fugue, hashB, 64); | |
97 | sph_fugue512_close(&ctx_fugue, hash); | |
98 | ||
99 | sph_shabal512_init(&ctx_shabal); | |
100 | sph_shabal512(&ctx_shabal, hash, 64); | |
101 | sph_shabal512_close(&ctx_shabal, hashB); | |
102 | ||
103 | sph_whirlpool_init(&ctx_whirlpool); | |
104 | sph_whirlpool(&ctx_whirlpool, hashB, 64); | |
105 | sph_whirlpool_close(&ctx_whirlpool, hash); | |
167960db | 106 | |
0fcbea8e TP |
107 | memcpy(output, hash, 32); |
108 | } | |
109 | ||
f7c584dc | 110 | int scanhash_x15(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) |
0fcbea8e | 111 | { |
f7c584dc TP |
112 | uint32_t _ALIGN(128) hash32[8]; |
113 | uint32_t _ALIGN(128) endiandata[20]; | |
114 | uint32_t *pdata = work->data; | |
115 | uint32_t *ptarget = work->target; | |
116 | ||
0fcbea8e TP |
117 | uint32_t n = pdata[19] - 1; |
118 | const uint32_t first_nonce = pdata[19]; | |
119 | const uint32_t Htarg = ptarget[7]; | |
120 | ||
0fcbea8e TP |
121 | uint64_t htmax[] = { |
122 | 0, | |
123 | 0xF, | |
124 | 0xFF, | |
125 | 0xFFF, | |
126 | 0xFFFF, | |
127 | 0x10000000 | |
128 | }; | |
129 | uint32_t masks[] = { | |
130 | 0xFFFFFFFF, | |
131 | 0xFFFFFFF0, | |
132 | 0xFFFFFF00, | |
133 | 0xFFFFF000, | |
134 | 0xFFFF0000, | |
135 | 0 | |
136 | }; | |
137 | ||
138 | // we need bigendian data... | |
f7c584dc TP |
139 | for (int k=0; k < 19; k++) |
140 | be32enc(&endiandata[k], pdata[k]); | |
141 | ||
0fcbea8e TP |
142 | #ifdef DEBUG_ALGO |
143 | if (Htarg != 0) | |
144 | printf("[%d] Htarg=%X\n", thr_id, Htarg); | |
145 | #endif | |
14f0acf4 | 146 | for (int m=0; m < 6; m++) { |
0fcbea8e TP |
147 | if (Htarg <= htmax[m]) { |
148 | uint32_t mask = masks[m]; | |
149 | do { | |
150 | pdata[19] = ++n; | |
167960db | 151 | be32enc(&endiandata[19], n); |
f7c584dc | 152 | x15hash(hash32, endiandata); |
0fcbea8e | 153 | #ifndef DEBUG_ALGO |
f7c584dc TP |
154 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { |
155 | work_set_target_ratio(work, hash32); | |
0fcbea8e | 156 | *hashes_done = n - first_nonce + 1; |
f7c584dc | 157 | return 1; |
0fcbea8e TP |
158 | } |
159 | #else | |
160 | if (!(n % 0x1000) && !thr_id) printf("."); | |
f7c584dc | 161 | if (!(hash32[7] & mask)) { |
0fcbea8e | 162 | printf("[%d]",thr_id); |
f7c584dc TP |
163 | if (fulltest(hash32, ptarget)) { |
164 | work_set_target_ratio(work, hash32); | |
0fcbea8e | 165 | *hashes_done = n - first_nonce + 1; |
f7c584dc | 166 | return 1; |
0fcbea8e TP |
167 | } |
168 | } | |
169 | #endif | |
170 | } while (n < max_nonce && !work_restart[thr_id].restart); | |
171 | // see blake.c if else to understand the loop on htmax => mask | |
172 | break; | |
173 | } | |
174 | } | |
175 | ||
176 | *hashes_done = n - first_nonce + 1; | |
177 | pdata[19] = n; | |
178 | return 0; | |
179 | } |