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