Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/veltor.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_skein.h>
9
#include <sha3/sph_shavite.h>
10
#include <sha3/sph_shabal.h>
11
#include <sha3/gost_streebog.h>
12
13
/* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
14
typedef struct {
15
sph_skein512_context skein1;
16
sph_shavite512_context shavite1;
17
sph_shabal512_context shabal1;
18
sph_gost512_context gost1;
19
} Xhash_context_holder;
20
21
static __thread Xhash_context_holder base_contexts;
22
static __thread bool init = false;
23
24
static void init_Xhash_contexts()
25
{
26
sph_skein512_init(&base_contexts.skein1);
27
sph_shavite512_init(&base_contexts.shavite1);
28
sph_shabal512_init(&base_contexts.shabal1);
29
sph_gost512_init(&base_contexts.gost1);
30
init = true;
31
}
32
33
void veltor_hash(void *output, const void *input)
34
{
35
Xhash_context_holder ctx;
36
37
uint32_t hashA[16];
38
39
if (!init) init_Xhash_contexts();
40
41
memcpy(&ctx, &base_contexts, sizeof(base_contexts));
42
43
sph_skein512(&ctx.skein1, input, 80);
44
sph_skein512_close(&ctx.skein1, hashA);
45
46
sph_shavite512(&ctx.shavite1, hashA, 64);
47
sph_shavite512_close(&ctx.shavite1, hashA);
48
49
sph_shabal512(&ctx.shabal1, hashA, 64);
50
sph_shabal512_close(&ctx.shabal1, hashA);
51
52
sph_gost512(&ctx.gost1, hashA, 64);
53
sph_gost512_close(&ctx.gost1, hashA);
54
55
memcpy(output, hashA, 32);
56
}
57
58
int scanhash_veltor(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
59
{
60
uint32_t _ALIGN(128) hash[8];
61
uint32_t _ALIGN(128) endiandata[20];
62
uint32_t *pdata = work->data;
63
uint32_t *ptarget = work->target;
64
65
const uint32_t Htarg = ptarget[7];
66
const uint32_t first_nonce = pdata[19];
67
uint32_t nonce = first_nonce;
68
volatile uint8_t *restart = &(work_restart[thr_id].restart);
69
70
if (opt_benchmark)
71
ptarget[7] = 0x0cff;
72
73
// we need bigendian data...
74
for (int i=0; i < 19; i++) {
75
be32enc(&endiandata[i], pdata[i]);
76
}
77
do {
78
be32enc(&endiandata[19], nonce);
79
veltor_hash(hash, endiandata);
80
81
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
82
work_set_target_ratio(work, hash);
83
pdata[19] = nonce;
84
*hashes_done = pdata[19] - first_nonce;
85
return 1;
86
}
87
nonce++;
88
89
} while (nonce < max_nonce && !(*restart));
90
91
pdata[19] = nonce;
92
*hashes_done = pdata[19] - first_nonce + 1;
93
return 0;
94
}
95
96