]>
Commit | Line | Data |
---|---|---|
7495361e 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_jh.h" | |
9 | #include "sha3/sph_keccak.h" | |
10 | #include "sha3/sph_echo.h" | |
11 | ||
12 | void tribus_hash(void *state, const void *input) | |
13 | { | |
14 | uint8_t _ALIGN(128) hash[64]; | |
15 | ||
16 | sph_jh512_context ctx_jh; | |
17 | sph_keccak512_context ctx_keccak; | |
18 | sph_echo512_context ctx_echo; | |
19 | ||
20 | sph_jh512_init(&ctx_jh); | |
21 | sph_jh512(&ctx_jh, input, 80); | |
22 | sph_jh512_close(&ctx_jh, (void*) hash); | |
23 | ||
24 | sph_keccak512_init(&ctx_keccak); | |
25 | sph_keccak512(&ctx_keccak, (const void*) hash, 64); | |
26 | sph_keccak512_close(&ctx_keccak, (void*) hash); | |
27 | ||
28 | sph_echo512_init(&ctx_echo); | |
29 | sph_echo512(&ctx_echo, (const void*) hash, 64); | |
30 | sph_echo512_close(&ctx_echo, (void*) hash); | |
31 | ||
32 | memcpy(state, hash, 32); | |
33 | } | |
34 | ||
35 | int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) | |
36 | { | |
37 | uint32_t _ALIGN(128) hash32[8]; | |
38 | uint32_t _ALIGN(128) endiandata[20]; | |
39 | uint32_t *pdata = work->data; | |
40 | uint32_t *ptarget = work->target; | |
41 | const uint32_t first_nonce = pdata[19]; | |
42 | const uint32_t Htarg = ptarget[7]; | |
43 | uint32_t n = pdata[19] - 1; | |
44 | ||
45 | uint64_t htmax[] = { | |
46 | 0, | |
47 | 0xF, | |
48 | 0xFF, | |
49 | 0xFFF, | |
50 | 0xFFFF, | |
51 | 0x10000000 | |
52 | }; | |
53 | uint32_t masks[] = { | |
54 | 0xFFFFFFFF, | |
55 | 0xFFFFFFF0, | |
56 | 0xFFFFFF00, | |
57 | 0xFFFFF000, | |
58 | 0xFFFF0000, | |
59 | 0 | |
60 | }; | |
61 | ||
62 | // we need bigendian data... | |
63 | for (int i=0; i < 19; i++) { | |
64 | be32enc(&endiandata[i], pdata[i]); | |
65 | } | |
66 | ||
67 | #ifdef DEBUG_ALGO | |
68 | printf("[%d] Htarg=%X\n", thr_id, Htarg); | |
69 | #endif | |
70 | for (int m=0; m < 6; m++) { | |
71 | if (Htarg <= htmax[m]) { | |
72 | uint32_t mask = masks[m]; | |
73 | do { | |
74 | pdata[19] = ++n; | |
75 | be32enc(&endiandata[19], n); | |
76 | tribus_hash(hash32, endiandata); | |
77 | #ifndef DEBUG_ALGO | |
78 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { | |
79 | work_set_target_ratio(work, hash32); | |
80 | *hashes_done = n - first_nonce + 1; | |
81 | return 1; | |
82 | } | |
83 | #else | |
84 | if (!(n % 0x1000) && !thr_id) printf("."); | |
85 | if (!(hash32[7] & mask)) { | |
86 | printf("[%d]",thr_id); | |
87 | if (fulltest(hash32, ptarget)) { | |
88 | work_set_target_ratio(work, hash32); | |
89 | *hashes_done = n - first_nonce + 1; | |
90 | return 1; | |
91 | } | |
92 | } | |
93 | #endif | |
94 | } while (n < max_nonce && !work_restart[thr_id].restart); | |
95 | // see blake.c if else to understand the loop on htmax => mask | |
96 | break; | |
97 | } | |
98 | } | |
99 | ||
100 | *hashes_done = n - first_nonce + 1; | |
101 | pdata[19] = n; | |
102 | return 0; | |
103 | } |