Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/c11.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 c11hash(void *output, const void *input)
22
{
23
uint32_t _ALIGN(64) hash[16];
24
25
sph_blake512_context ctx_blake;
26
sph_bmw512_context ctx_bmw;
27
sph_groestl512_context ctx_groestl;
28
sph_skein512_context ctx_skein;
29
sph_jh512_context ctx_jh;
30
sph_keccak512_context ctx_keccak;
31
32
sph_luffa512_context ctx_luffa1;
33
sph_cubehash512_context ctx_cubehash1;
34
sph_shavite512_context ctx_shavite1;
35
sph_simd512_context ctx_simd1;
36
sph_echo512_context ctx_echo1;
37
38
sph_blake512_init(&ctx_blake);
39
sph_blake512 (&ctx_blake, input, 80);
40
sph_blake512_close (&ctx_blake, hash);
41
42
sph_bmw512_init(&ctx_bmw);
43
sph_bmw512 (&ctx_bmw, hash, 64);
44
sph_bmw512_close(&ctx_bmw, hash);
45
46
sph_groestl512_init(&ctx_groestl);
47
sph_groestl512 (&ctx_groestl, hash, 64);
48
sph_groestl512_close(&ctx_groestl, hash);
49
50
sph_jh512_init(&ctx_jh);
51
sph_jh512 (&ctx_jh, hash, 64);
52
sph_jh512_close(&ctx_jh, hash);
53
54
sph_keccak512_init(&ctx_keccak);
55
sph_keccak512 (&ctx_keccak, hash, 64);
56
sph_keccak512_close(&ctx_keccak, hash);
57
58
sph_skein512_init(&ctx_skein);
59
sph_skein512 (&ctx_skein, hash, 64);
60
sph_skein512_close (&ctx_skein, hash);
61
62
sph_luffa512_init (&ctx_luffa1);
63
sph_luffa512 (&ctx_luffa1, hash, 64);
64
sph_luffa512_close (&ctx_luffa1, hash);
65
66
sph_cubehash512_init (&ctx_cubehash1);
67
sph_cubehash512 (&ctx_cubehash1, hash, 64);
68
sph_cubehash512_close(&ctx_cubehash1, hash);
69
70
sph_shavite512_init (&ctx_shavite1);
71
sph_shavite512 (&ctx_shavite1, hash, 64);
72
sph_shavite512_close(&ctx_shavite1, hash);
73
74
sph_simd512_init (&ctx_simd1);
75
sph_simd512 (&ctx_simd1, hash, 64);
76
sph_simd512_close(&ctx_simd1, hash);
77
78
sph_echo512_init (&ctx_echo1);
79
sph_echo512 (&ctx_echo1, hash, 64);
80
sph_echo512_close(&ctx_echo1, hash);
81
82
memcpy(output, hash, 32);
83
}
84
85
int scanhash_c11(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
86
{
87
uint32_t _ALIGN(128) hash32[8];
88
uint32_t _ALIGN(128) endiandata[20];
89
uint32_t *pdata = work->data;
90
uint32_t *ptarget = work->target;
91
92
const uint32_t Htarg = ptarget[7];
93
const uint32_t first_nonce = pdata[19];
94
uint32_t nonce = first_nonce;
95
volatile uint8_t *restart = &(work_restart[thr_id].restart);
96
97
if (opt_benchmark)
98
ptarget[7] = 0x0cff;
99
100
for (int k=0; k < 19; k++)
101
be32enc(&endiandata[k], pdata[k]);
102
103
do {
104
be32enc(&endiandata[19], nonce);
105
c11hash(hash32, endiandata);
106
107
if (hash32[7] <= Htarg && fulltest(hash32, ptarget)) {
108
work_set_target_ratio(work, hash32);
109
pdata[19] = nonce;
110
*hashes_done = pdata[19] - first_nonce;
111
return 1;
112
}
113
nonce++;
114
115
} while (nonce < max_nonce && !(*restart));
116
117
pdata[19] = nonce;
118
*hashes_done = pdata[19] - first_nonce + 1;
119
return 0;
120
}
121
122