Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/x11.c
1201 views
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, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
87
{
88
uint32_t _ALIGN(128) hash[8];
89
uint32_t _ALIGN(128) endiandata[20];
90
uint32_t *pdata = work->data;
91
uint32_t *ptarget = work->target;
92
93
const uint32_t Htarg = ptarget[7];
94
const uint32_t first_nonce = pdata[19];
95
uint32_t nonce = first_nonce;
96
volatile uint8_t *restart = &(work_restart[thr_id].restart);
97
98
if (opt_benchmark)
99
ptarget[7] = 0x0cff;
100
101
for (int k=0; k < 19; k++)
102
be32enc(&endiandata[k], pdata[k]);
103
104
do {
105
be32enc(&endiandata[19], nonce);
106
x11hash(hash, endiandata);
107
108
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
109
work_set_target_ratio(work, hash);
110
pdata[19] = nonce;
111
*hashes_done = pdata[19] - first_nonce;
112
return 1;
113
}
114
nonce++;
115
116
} while (nonce < max_nonce && !(*restart));
117
118
pdata[19] = nonce;
119
*hashes_done = pdata[19] - first_nonce + 1;
120
return 0;
121
}
122
123