Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/sibcoin.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/gost_streebog.h"
16
#include "sha3/sph_cubehash.h"
17
#include "sha3/sph_shavite.h"
18
#include "sha3/sph_simd.h"
19
#include "sha3/sph_echo.h"
20
21
/* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
22
void sibhash(void *output, const void *input)
23
{
24
sph_blake512_context ctx_blake;
25
sph_bmw512_context ctx_bmw;
26
sph_groestl512_context ctx_groestl;
27
sph_skein512_context ctx_skein;
28
sph_jh512_context ctx_jh;
29
sph_keccak512_context ctx_keccak;
30
sph_gost512_context ctx_gost;
31
sph_luffa512_context ctx_luffa;
32
sph_cubehash512_context ctx_cubehash;
33
sph_shavite512_context ctx_shavite;
34
sph_simd512_context ctx_simd;
35
sph_echo512_context ctx_echo;
36
37
//these uint512 in the c++ source of the client are backed by an array of uint32
38
uint32_t _ALIGN(64) hashA[16], hashB[16];
39
40
sph_blake512_init(&ctx_blake);
41
sph_blake512(&ctx_blake, input, 80);
42
sph_blake512_close(&ctx_blake, hashA);
43
44
sph_bmw512_init(&ctx_bmw);
45
sph_bmw512(&ctx_bmw, hashA, 64);
46
sph_bmw512_close(&ctx_bmw, hashB);
47
48
sph_groestl512_init(&ctx_groestl);
49
sph_groestl512(&ctx_groestl, hashB, 64);
50
sph_groestl512_close(&ctx_groestl, hashA);
51
52
sph_skein512_init(&ctx_skein);
53
sph_skein512(&ctx_skein, hashA, 64);
54
sph_skein512_close(&ctx_skein, hashB);
55
56
sph_jh512_init(&ctx_jh);
57
sph_jh512(&ctx_jh, hashB, 64);
58
sph_jh512_close(&ctx_jh, hashA);
59
60
sph_keccak512_init(&ctx_keccak);
61
sph_keccak512(&ctx_keccak, hashA, 64);
62
sph_keccak512_close(&ctx_keccak, hashB);
63
64
sph_gost512_init(&ctx_gost);
65
sph_gost512(&ctx_gost, hashB, 64);
66
sph_gost512_close(&ctx_gost, hashA);
67
68
sph_luffa512_init(&ctx_luffa);
69
sph_luffa512(&ctx_luffa, hashA, 64);
70
sph_luffa512_close(&ctx_luffa, hashB);
71
72
sph_cubehash512_init(&ctx_cubehash);
73
sph_cubehash512(&ctx_cubehash, hashB, 64);
74
sph_cubehash512_close(&ctx_cubehash, hashA);
75
76
sph_shavite512_init(&ctx_shavite);
77
sph_shavite512(&ctx_shavite, hashA, 64);
78
sph_shavite512_close(&ctx_shavite, hashB);
79
80
sph_simd512_init(&ctx_simd);
81
sph_simd512(&ctx_simd, hashB, 64);
82
sph_simd512_close(&ctx_simd, hashA);
83
84
sph_echo512_init(&ctx_echo);
85
sph_echo512(&ctx_echo, hashA, 64);
86
sph_echo512_close(&ctx_echo, hashB);
87
88
memcpy(output, hashB, 32);
89
}
90
91
int scanhash_sib(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
92
{
93
uint32_t _ALIGN(128) hash[8];
94
uint32_t _ALIGN(128) endiandata[20];
95
uint32_t *pdata = work->data;
96
uint32_t *ptarget = work->target;
97
98
const uint32_t Htarg = ptarget[7];
99
const uint32_t first_nonce = pdata[19];
100
uint32_t nonce = first_nonce;
101
volatile uint8_t *restart = &(work_restart[thr_id].restart);
102
103
if (opt_benchmark)
104
ptarget[7] = 0x0cff;
105
106
// we need bigendian data...
107
for (int i=0; i < 19; i++) {
108
be32enc(&endiandata[i], pdata[i]);
109
}
110
do {
111
be32enc(&endiandata[19], nonce);
112
sibhash(hash, endiandata);
113
114
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
115
work_set_target_ratio(work, hash);
116
pdata[19] = nonce;
117
*hashes_done = pdata[19] - first_nonce;
118
return 1;
119
}
120
nonce++;
121
122
} while (nonce < max_nonce && !(*restart));
123
124
pdata[19] = nonce;
125
*hashes_done = pdata[19] - first_nonce + 1;
126
return 0;
127
}
128
129