Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/bastion.c
1201 views
1
#include "miner.h"
2
3
#include <stdio.h>
4
#include <string.h>
5
#include <openssl/sha.h>
6
#include <stdint.h>
7
#include <stdlib.h>
8
9
#include "sha3/sph_hefty1.h"
10
11
#include "sha3/sph_luffa.h"
12
#include "sha3/sph_fugue.h"
13
#include "sha3/sph_skein.h"
14
#include "sha3/sph_whirlpool.h"
15
#include "sha3/sph_shabal.h"
16
#include "sha3/sph_echo.h"
17
#include "sha3/sph_hamsi.h"
18
19
void bastionhash(void *output, const void *input)
20
{
21
unsigned char _ALIGN(128) hash[64] = { 0 };
22
23
sph_echo512_context ctx_echo;
24
sph_luffa512_context ctx_luffa;
25
sph_fugue512_context ctx_fugue;
26
sph_whirlpool_context ctx_whirlpool;
27
sph_shabal512_context ctx_shabal;
28
sph_skein512_context ctx_skein;
29
sph_hamsi512_context ctx_hamsi;
30
31
HEFTY1(input, 80, hash);
32
33
sph_luffa512_init(&ctx_luffa);
34
sph_luffa512(&ctx_luffa, hash, 64);
35
sph_luffa512_close(&ctx_luffa, hash);
36
37
if (hash[0] & 0x8)
38
{
39
sph_fugue512_init(&ctx_fugue);
40
sph_fugue512(&ctx_fugue, hash, 64);
41
sph_fugue512_close(&ctx_fugue, hash);
42
} else {
43
sph_skein512_init(&ctx_skein);
44
sph_skein512(&ctx_skein, hash, 64);
45
sph_skein512_close(&ctx_skein, hash);
46
}
47
48
sph_whirlpool_init(&ctx_whirlpool);
49
sph_whirlpool(&ctx_whirlpool, hash, 64);
50
sph_whirlpool_close(&ctx_whirlpool, hash);
51
52
sph_fugue512_init(&ctx_fugue);
53
sph_fugue512(&ctx_fugue, hash, 64);
54
sph_fugue512_close(&ctx_fugue, hash);
55
56
if (hash[0] & 0x8)
57
{
58
sph_echo512_init(&ctx_echo);
59
sph_echo512(&ctx_echo, hash, 64);
60
sph_echo512_close(&ctx_echo, hash);
61
} else {
62
sph_luffa512_init(&ctx_luffa);
63
sph_luffa512(&ctx_luffa, hash, 64);
64
sph_luffa512_close(&ctx_luffa, hash);
65
}
66
67
sph_shabal512_init(&ctx_shabal);
68
sph_shabal512(&ctx_shabal, hash, 64);
69
sph_shabal512_close(&ctx_shabal, hash);
70
71
sph_skein512_init(&ctx_skein);
72
sph_skein512(&ctx_skein, hash, 64);
73
sph_skein512_close(&ctx_skein, hash);
74
75
if (hash[0] & 0x8)
76
{
77
sph_shabal512_init(&ctx_shabal);
78
sph_shabal512(&ctx_shabal, hash, 64);
79
sph_shabal512_close(&ctx_shabal, hash);
80
} else {
81
sph_whirlpool_init(&ctx_whirlpool);
82
sph_whirlpool(&ctx_whirlpool, hash, 64);
83
sph_whirlpool_close(&ctx_whirlpool, hash);
84
}
85
86
sph_shabal512_init(&ctx_shabal);
87
sph_shabal512(&ctx_shabal, hash, 64);
88
sph_shabal512_close(&ctx_shabal, hash);
89
90
if (hash[0] & 0x8)
91
{
92
sph_hamsi512_init(&ctx_hamsi);
93
sph_hamsi512(&ctx_hamsi, hash, 64);
94
sph_hamsi512_close(&ctx_hamsi, hash);
95
} else {
96
sph_luffa512_init(&ctx_luffa);
97
sph_luffa512(&ctx_luffa, hash, 64);
98
sph_luffa512_close(&ctx_luffa, hash);
99
}
100
101
memcpy(output, hash, 32);
102
}
103
104
int scanhash_bastion(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
105
{
106
uint32_t _ALIGN(64) hash32[8];
107
uint32_t _ALIGN(64) endiandata[20];
108
uint32_t *pdata = work->data;
109
uint32_t *ptarget = work->target;
110
111
const uint32_t Htarg = ptarget[7];
112
const uint32_t first_nonce = pdata[19];
113
114
uint32_t n = first_nonce;
115
116
for (int i=0; i < 19; i++) {
117
be32enc(&endiandata[i], pdata[i]);
118
}
119
120
do {
121
be32enc(&endiandata[19], n);
122
bastionhash(hash32, endiandata);
123
if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
124
work_set_target_ratio(work, hash32);
125
*hashes_done = n - first_nonce + 1;
126
pdata[19] = n;
127
return true;
128
}
129
n++;
130
131
} while (n < max_nonce && !work_restart[thr_id].restart);
132
133
*hashes_done = n - first_nonce + 1;
134
pdata[19] = n;
135
136
return 0;
137
}
138
139