Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/s3.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_simd.h"
11
12
void s3hash(void *output, const void *input)
13
{
14
sph_shavite512_context ctx_shavite;
15
sph_simd512_context ctx_simd;
16
sph_skein512_context ctx_skein;
17
18
unsigned char _ALIGN(128) hash[64];
19
20
sph_shavite512_init(&ctx_shavite);
21
sph_shavite512(&ctx_shavite, input, 80);
22
sph_shavite512_close(&ctx_shavite, (void*)hash);
23
24
sph_simd512_init(&ctx_simd);
25
sph_simd512(&ctx_simd, (const void*)hash, 64);
26
sph_simd512_close(&ctx_simd, (void*)hash);
27
28
sph_skein512_init(&ctx_skein);
29
sph_skein512(&ctx_skein, (const void*)hash, 64);
30
sph_skein512_close(&ctx_skein, (void*)hash);
31
32
memcpy(output, hash, 32);
33
}
34
35
int scanhash_s3(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
36
{
37
uint32_t _ALIGN(128) hash32[8];
38
uint32_t _ALIGN(128) endiandata[20];
39
uint32_t *pdata = work->data;
40
uint32_t *ptarget = work->target;
41
42
uint32_t n = pdata[19] - 1;
43
const uint32_t first_nonce = pdata[19];
44
const uint32_t Htarg = ptarget[7];
45
46
uint64_t htmax[] = {
47
0,
48
0xF,
49
0xFF,
50
0xFFF,
51
0xFFFF,
52
0x10000000
53
};
54
uint32_t masks[] = {
55
0xFFFFFFFF,
56
0xFFFFFFF0,
57
0xFFFFFF00,
58
0xFFFFF000,
59
0xFFFF0000,
60
0
61
};
62
63
// we need bigendian data...
64
for (int i=0; i < 19; i++) {
65
be32enc(&endiandata[i], pdata[i]);
66
}
67
68
#ifdef DEBUG_ALGO
69
printf("[%d] Htarg=%X\n", thr_id, Htarg);
70
#endif
71
for (int m=0; m < 6; m++) {
72
if (Htarg <= htmax[m]) {
73
uint32_t mask = masks[m];
74
do {
75
pdata[19] = ++n;
76
be32enc(&endiandata[19], n);
77
s3hash(hash32, endiandata);
78
#ifndef DEBUG_ALGO
79
if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) {
80
work_set_target_ratio(work, hash32);
81
*hashes_done = n - first_nonce + 1;
82
return true;
83
}
84
#else
85
if (!(n % 0x1000) && !thr_id) printf(".");
86
if (!(hash32[7] & mask)) {
87
printf("[%d]",thr_id);
88
if (fulltest(hash32, ptarget)) {
89
work_set_target_ratio(work, hash32);
90
*hashes_done = n - first_nonce + 1;
91
return true;
92
}
93
}
94
#endif
95
} while (n < max_nonce && !work_restart[thr_id].restart);
96
// see blake.c if else to understand the loop on htmax => mask
97
break;
98
}
99
}
100
101
*hashes_done = n - first_nonce + 1;
102
pdata[19] = n;
103
return 0;
104
}
105
106