]> Git Repo - cpuminer-multi.git/blob - algo/x11.c
skein: cleanup
[cpuminer-multi.git] / algo / x11.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
20
21 void x11hash(void *output, const void *input)
22 {
23         sph_blake512_context     ctx_blake;
24         sph_bmw512_context       ctx_bmw;
25         sph_groestl512_context   ctx_groestl;
26         sph_skein512_context     ctx_skein;
27         sph_jh512_context        ctx_jh;
28         sph_keccak512_context    ctx_keccak;
29
30         sph_luffa512_context            ctx_luffa1;
31         sph_cubehash512_context         ctx_cubehash1;
32         sph_shavite512_context          ctx_shavite1;
33         sph_simd512_context             ctx_simd1;
34         sph_echo512_context             ctx_echo1;
35
36         //these uint512 in the c++ source of the client are backed by an array of uint32
37         uint32_t _ALIGN(64) hashA[16], hashB[16];
38
39         sph_blake512_init(&ctx_blake);
40         sph_blake512 (&ctx_blake, input, 80);
41         sph_blake512_close (&ctx_blake, hashA);
42
43         sph_bmw512_init(&ctx_bmw);
44         sph_bmw512 (&ctx_bmw, hashA, 64);
45         sph_bmw512_close(&ctx_bmw, hashB);
46
47         sph_groestl512_init(&ctx_groestl);
48         sph_groestl512 (&ctx_groestl, hashB, 64);
49         sph_groestl512_close(&ctx_groestl, hashA);
50
51         sph_skein512_init(&ctx_skein);
52         sph_skein512 (&ctx_skein, hashA, 64);
53         sph_skein512_close (&ctx_skein, hashB);
54
55         sph_jh512_init(&ctx_jh);
56         sph_jh512 (&ctx_jh, hashB, 64);
57         sph_jh512_close(&ctx_jh, hashA);
58
59         sph_keccak512_init(&ctx_keccak);
60         sph_keccak512 (&ctx_keccak, hashA, 64);
61         sph_keccak512_close(&ctx_keccak, hashB);
62
63         sph_luffa512_init (&ctx_luffa1);
64         sph_luffa512 (&ctx_luffa1, hashB, 64);
65         sph_luffa512_close (&ctx_luffa1, hashA);
66
67         sph_cubehash512_init (&ctx_cubehash1);
68         sph_cubehash512 (&ctx_cubehash1, hashA, 64);
69         sph_cubehash512_close(&ctx_cubehash1, hashB);
70
71         sph_shavite512_init (&ctx_shavite1);
72         sph_shavite512 (&ctx_shavite1, hashB, 64);
73         sph_shavite512_close(&ctx_shavite1, hashA);
74
75         sph_simd512_init (&ctx_simd1);
76         sph_simd512 (&ctx_simd1, hashA, 64);
77         sph_simd512_close(&ctx_simd1, hashB);
78
79         sph_echo512_init (&ctx_echo1);
80         sph_echo512 (&ctx_echo1, hashB, 64);
81         sph_echo512_close(&ctx_echo1, hashA);
82
83         memcpy(output, hashA, 32);
84 }
85
86 int scanhash_x11(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
87         uint32_t max_nonce,     uint64_t *hashes_done)
88 {
89         const uint32_t first_nonce = pdata[19];
90         uint32_t _ALIGN(64) endiandata[20];
91         uint32_t nonce = first_nonce;
92         volatile uint8_t *restart = &(work_restart[thr_id].restart);
93
94         if (opt_benchmark)
95                 ((uint32_t*)ptarget)[7] = 0x0cff;
96
97         for (int k=0; k < 19; k++)
98                 be32enc(&endiandata[k], pdata[k]);
99
100         const uint32_t Htarg = ptarget[7];
101         do {
102                 uint32_t hash[8];
103                 be32enc(&endiandata[19], nonce);
104                 x11hash(hash, endiandata);
105
106                 if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
107                         pdata[19] = nonce;
108                         *hashes_done = pdata[19] - first_nonce;
109                         return 1;
110                 }
111                 nonce++;
112
113         } while (nonce < max_nonce && !(*restart));
114
115         pdata[19] = nonce;
116         *hashes_done = pdata[19] - first_nonce + 1;
117         return 0;
118 }
This page took 0.029361 seconds and 4 git commands to generate.