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