]> Git Repo - cpuminer-multi.git/blame - x15.c
move compat defines in compat.h
[cpuminer-multi.git] / x15.c
CommitLineData
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 26void 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
0fcbea8e
TP
110int scanhash_x15(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
111 uint32_t max_nonce, uint64_t *hashes_done)
112{
113 uint32_t n = pdata[19] - 1;
114 const uint32_t first_nonce = pdata[19];
115 const uint32_t Htarg = ptarget[7];
116
588f5d90 117 uint32_t _ALIGN(32) hash64[8];
0fcbea8e
TP
118 uint32_t endiandata[32];
119
120 uint64_t htmax[] = {
121 0,
122 0xF,
123 0xFF,
124 0xFFF,
125 0xFFFF,
126 0x10000000
127 };
128 uint32_t masks[] = {
129 0xFFFFFFFF,
130 0xFFFFFFF0,
131 0xFFFFFF00,
132 0xFFFFF000,
133 0xFFFF0000,
134 0
135 };
136
137 // we need bigendian data...
138 for (int kk=0; kk < 32; kk++) {
139 be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
140 };
141#ifdef DEBUG_ALGO
142 if (Htarg != 0)
143 printf("[%d] Htarg=%X\n", thr_id, Htarg);
144#endif
14f0acf4 145 for (int m=0; m < 6; m++) {
0fcbea8e
TP
146 if (Htarg <= htmax[m]) {
147 uint32_t mask = masks[m];
148 do {
149 pdata[19] = ++n;
167960db 150 be32enc(&endiandata[19], n);
df0c0adb 151 x15hash(hash64, endiandata);
0fcbea8e
TP
152#ifndef DEBUG_ALGO
153 if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) {
154 *hashes_done = n - first_nonce + 1;
155 return true;
156 }
157#else
158 if (!(n % 0x1000) && !thr_id) printf(".");
159 if (!(hash64[7] & mask)) {
160 printf("[%d]",thr_id);
161 if (fulltest(hash64, ptarget)) {
162 *hashes_done = n - first_nonce + 1;
163 return true;
164 }
165 }
166#endif
167 } while (n < max_nonce && !work_restart[thr_id].restart);
168 // see blake.c if else to understand the loop on htmax => mask
169 break;
170 }
171 }
172
173 *hashes_done = n - first_nonce + 1;
174 pdata[19] = n;
175 return 0;
176}
This page took 0.037681 seconds and 4 git commands to generate.