├── clientamd
├── clientnvidia
├── Makefile
├── README.md
├── sha256.h
├── sha256.c
├── amoveo.cl
└── client.c
/clientamd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zack-bitcoin/VeoCL/master/clientamd
--------------------------------------------------------------------------------
/clientnvidia:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zack-bitcoin/VeoCL/master/clientnvidia
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | compileOptions = -O3 -lOpenCL -lpthread -Wno-unused-result -Wno-int-conversion -Wno-deprecated-declarations -Wno-incompatible-pointer-types
2 | inputFiles = client.c sha256.c
3 | dependencies = client.c Makefile sha256.c sha256.h
4 |
5 | all: clientnvidia clientamd
6 |
7 | clientnvidia: $(dependencies)
8 | gcc -o clientnvidia $(inputFiles) -D'CLWAIT=1' $(compileOptions)
9 |
10 | clientamd: $(dependencies)
11 | gcc -o clientamd $(inputFiles) $(compileOptions)
12 |
13 | clean:
14 | rm clientnvidia clientamd
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VeoCL
2 | Amoveo OpenCL miner
3 |
4 | for AMD & Nvidia GPU´s
5 |
6 | Donations:
7 | BONJmlU2FUqYgUY60LTIumsYrW/c6MHte64y5KlDzXk5toyEMaBzWm8dHmdMfJmXnqvbYmlwim0hiFmYCCn3Rm0=
8 |
9 | # Usage
10 | Compile with "make"
11 |
12 | run
13 | ./clientnvidia
14 |
15 | or
16 | ./clientamd
17 |
18 | Make sure amoveo.cl is in current directory
19 |
20 | # Compile errors
21 |
22 | client.c:18:19: fatal error: CL/cl.h: No such file or directory
23 |
24 | sudo apt install opencl-headers
25 |
26 |
27 | Could not find libOpenCL.so
28 |
29 | sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/lib/x86_64-linux-gnu/libOpenCL.so
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sha256.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Filename: sha256.h
3 | * Author: Brad Conte (brad AT bradconte.com)
4 | * Copyright:
5 | * Disclaimer: This code is presented "as is" without any guarantees.
6 | * Details: Defines the API for the corresponding SHA1 implementation.
7 | *********************************************************************/
8 |
9 | #ifndef SHA256_H
10 | #define SHA256_H
11 |
12 | /*************************** HEADER FILES ***************************/
13 | #include
14 |
15 | /****************************** MACROS ******************************/
16 | #define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
17 |
18 | /**************************** DATA TYPES ****************************/
19 | typedef unsigned char BYTE; // 8-bit byte
20 | typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
21 |
22 | typedef struct {
23 | BYTE data[64];
24 | WORD datalen;
25 | unsigned long long bitlen;
26 | WORD state[8];
27 | } SHA256_CTX;
28 |
29 | /*********************** FUNCTION DECLARATIONS **********************/
30 | void sha256_init(SHA256_CTX *ctx);
31 | void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
32 | void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
33 |
34 | #endif // SHA256_H
35 |
--------------------------------------------------------------------------------
/sha256.c:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Filename: sha256.c
3 | * Author: Brad Conte (brad AT bradconte.com)
4 | * Copyright:
5 | * Disclaimer: This code is presented "as is" without any guarantees.
6 | * Details: Implementation of the SHA-256 hashing algorithm.
7 | SHA-256 is one of the three algorithms in the SHA2
8 | specification. The others, SHA-384 and SHA-512, are not
9 | offered in this implementation.
10 | Algorithm specification can be found here:
11 | * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
12 | This implementation uses little endian byte order.
13 | *********************************************************************/
14 |
15 | /*************************** HEADER FILES ***************************/
16 | #include
17 | #include
18 | #include
19 | #include "sha256.h"
20 |
21 | /****************************** MACROS ******************************/
22 | #define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b))))
23 | #define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))
24 |
25 | #define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z)))
26 | #define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
27 | #define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22))
28 | #define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
29 | #define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
30 | #define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
31 |
32 | /**************************** VARIABLES *****************************/
33 | static const WORD k[64] = {
34 | 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
35 | 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
36 | 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
37 | 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
38 | 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
39 | 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
40 | 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
41 | 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
42 | };
43 |
44 | static inline void phex(void *mem, int len) {
45 | int i;
46 | unsigned char *p = (unsigned char *)mem;
47 | for (i=0;istate[0];
71 | b = ctx->state[1];
72 | c = ctx->state[2];
73 | d = ctx->state[3];
74 | e = ctx->state[4];
75 | f = ctx->state[5];
76 | g = ctx->state[6];
77 | h = ctx->state[7];
78 |
79 | for (i = 0; i < 64; ++i) {
80 | t1 = h + EP1(e) + CH(e,f,g) + k[i] + m[i];
81 | t2 = EP0(a) + MAJ(a,b,c);
82 | h = g;
83 | g = f;
84 | f = e;
85 | e = d + t1;
86 | d = c;
87 | c = b;
88 | b = a;
89 | a = t1 + t2;
90 | }
91 |
92 | ctx->state[0] += a;
93 | ctx->state[1] += b;
94 | ctx->state[2] += c;
95 | ctx->state[3] += d;
96 | ctx->state[4] += e;
97 | ctx->state[5] += f;
98 | ctx->state[6] += g;
99 | ctx->state[7] += h;
100 | }
101 |
102 | void sha256_init(SHA256_CTX *ctx) {
103 | ctx->datalen = 0;
104 | ctx->bitlen = 0;
105 | ctx->state[0] = 0x6a09e667;
106 | ctx->state[1] = 0xbb67ae85;
107 | ctx->state[2] = 0x3c6ef372;
108 | ctx->state[3] = 0xa54ff53a;
109 | ctx->state[4] = 0x510e527f;
110 | ctx->state[5] = 0x9b05688c;
111 | ctx->state[6] = 0x1f83d9ab;
112 | ctx->state[7] = 0x5be0cd19;
113 | }
114 |
115 | void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len) {
116 | WORD i;
117 |
118 | for (i = 0; i < len; ++i) {
119 | ctx->data[ctx->datalen] = data[i];
120 | ctx->datalen++;
121 | if (ctx->datalen == 64) {
122 | sha256_transform(ctx, ctx->data);
123 | ctx->bitlen += 512;
124 | ctx->datalen = 0;
125 | }
126 | }
127 | }
128 |
129 | void sha256_final(SHA256_CTX *ctx, BYTE hash[]) {
130 | WORD i;
131 |
132 | i = ctx->datalen;
133 |
134 | // Pad whatever data is left in the buffer.
135 | if (ctx->datalen < 56) {
136 | ctx->data[i++] = 0x80;
137 | while (i < 56)
138 | ctx->data[i++] = 0x00;
139 | }
140 | else {
141 | ctx->data[i++] = 0x80;
142 | while (i < 64)
143 | ctx->data[i++] = 0x00;
144 | sha256_transform(ctx, ctx->data);
145 | memset(ctx->data, 0, 56);
146 | }
147 |
148 | // Append to the padding the total message's length in bits and transform.
149 | ctx->bitlen += ctx->datalen * 8;
150 | ctx->data[63] = ctx->bitlen;
151 | ctx->data[62] = ctx->bitlen >> 8;
152 | ctx->data[61] = ctx->bitlen >> 16;
153 | ctx->data[60] = ctx->bitlen >> 24;
154 | ctx->data[59] = ctx->bitlen >> 32;
155 | ctx->data[58] = ctx->bitlen >> 40;
156 | ctx->data[57] = ctx->bitlen >> 48;
157 | ctx->data[56] = ctx->bitlen >> 56;
158 | sha256_transform(ctx, ctx->data);
159 |
160 | // Since this implementation uses little endian byte ordering and SHA uses big endian,
161 | // reverse all the bytes when copying the final state to the output hash.
162 | for (i = 0; i < 4; ++i) {
163 | hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
164 | hash[i + 4] = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
165 | hash[i + 8] = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
166 | hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
167 | hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
168 | hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff;
169 | hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff;
170 | hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff;
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/amoveo.cl:
--------------------------------------------------------------------------------
1 | #define ROTRIGHT(a,b) (rotate((a),(uint)(32-b)))
2 |
3 | #define EP0(x) (ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22))
4 | #define EP1(x) (ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25))
5 | #define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
6 | #define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
7 |
8 | #define SHA256_F0o(x,y,z) (bitselect ((x), (y), ((x) ^ (z))))
9 | #define SHA256_F1o(x,y,z) (bitselect ((z), (y), (x)))
10 |
11 | #define FALTE(x,y,z,w) (SIG1(x) + y + SIG0(z) + w)
12 |
13 | #define RUNDE_INNEN(a,b,c,d,e,f,g,h,x) { \
14 | h += x + EP1(e) + SHA256_F1o(e,f,g); \
15 | d += h; \
16 | h = h + EP0(a) + SHA256_F0o(a,b,c); \
17 | }
18 |
19 | __kernel void amoveo(__global unsigned char *in, __global unsigned char *out) {
20 | __private int ii = get_global_id(0);
21 | __private unsigned char *iic = (unsigned char*)ⅈ
22 | __private uint m[14];
23 |
24 | for(int i=0; i<8; i++)
25 | out[ii * 8 + i] = 0;
26 |
27 | // 55 Byte vorgabe einpflegen:
28 | m[0] = (in[ 0] << 24) | (in[ 1] << 16) | (in[ 2] << 8) | (in[ 3]);
29 | m[1] = (in[ 4] << 24) | (in[ 5] << 16) | (in[ 6] << 8) | (in[ 7]);
30 | m[2] = (in[ 8] << 24) | (in[ 9] << 16) | (in[10] << 8) | (in[11]);
31 | m[3] = (in[12] << 24) | (in[13] << 16) | (in[14] << 8) | (in[15]);
32 | m[4] = (in[16] << 24) | (in[17] << 16) | (in[18] << 8) | (in[19]);
33 | m[5] = (in[20] << 24) | (in[21] << 16) | (in[22] << 8) | (in[23]);
34 | m[6] = (in[24] << 24) | (in[25] << 16) | (in[26] << 8) | (in[27]);
35 | m[7] = (in[28] << 24) | (in[29] << 16) | (in[30] << 8) | (in[31]);
36 | m[8] = (in[32] << 24) | (in[33] << 16) | (in[34] << 8) | (in[35]);
37 | m[9] = 0;
38 | m[10] = (in[40] << 24) | (in[41] << 16) | (in[42] << 8) | (in[43]);
39 | m[11] = 0;
40 | m[12] = ii << 8; // m13 kann optimal vorberechnet werden
41 |
42 | __private uint a, b, c, d, e, f, g, h, i, j;
43 | __private uint ap, bp, cp, dp, ep, fp, gp, hp;
44 |
45 | a = 0x6a09e667;
46 | b = 0xbb67ae85;
47 | c = 0x3c6ef372;
48 | d = 0xa54ff53a;
49 | e = 0x510e527f;
50 | f = 0x9b05688c;
51 | g = 0x1f83d9ab;
52 | h = 0x5be0cd19;
53 |
54 | RUNDE_INNEN(a, b, c, d, e, f, g, h, m[0] + 0x428a2f98);
55 | RUNDE_INNEN(h, a, b, c, d, e, f, g, m[1] + 0x71374491);
56 | RUNDE_INNEN(g, h, a, b, c, d, e, f, m[2] + 0xb5c0fbcf);
57 | RUNDE_INNEN(f, g, h, a, b, c, d, e, m[3] + 0xe9b5dba5);
58 | RUNDE_INNEN(e, f, g, h, a, b, c, d, m[4] + 0x3956c25b);
59 | RUNDE_INNEN(d, e, f, g, h, a, b, c, m[5] + 0x59f111f1);
60 | RUNDE_INNEN(c, d, e, f, g, h, a, b, m[6] + 0x923f82a4);
61 | RUNDE_INNEN(b, c, d, e, f, g, h, a, m[7] + 0xab1c5ed5);
62 | RUNDE_INNEN(a, b, c, d, e, f, g, h, m[8] + 0xd807aa98);
63 | RUNDE_INNEN(h, a, b, c, d, e, f, g, m[9] + 0x12835b01);
64 | RUNDE_INNEN(g, h, a, b, c, d, e, f, m[10] + 0x243185be);
65 | RUNDE_INNEN(f, g, h, a, b, c, d, e, m[11] + 0x550c7dc3);
66 | RUNDE_INNEN(e, f, g, h, a, b, c, d, m[12] + 0x72be5d74);
67 |
68 | // Verschieben: Phase 1
69 | ap = a;
70 | cp = c + 0x80deb1fe + EP1(h) + SHA256_F1o(h,a,b);
71 | dp = d;
72 | ep = e;
73 | fp = f;
74 | gp = g + cp;
75 | hp = h;
76 | cp += EP0(d) + SHA256_F0o(d,e,f);
77 |
78 | // Verschieben: Phase 2
79 | bp = b + 0x9bdc06a7;
80 |
81 | __private uint w0p, w1p, w2p, w3p, w4pp, w5p, w7p, w9p;
82 |
83 | // Verschieben: Phase 3
84 | w0p = FALTE((uint)0, m[9], m[1], m[0]);
85 | w1p = FALTE((uint)0x000001b8, m[10], m[2], m[1]);
86 | w2p = FALTE(w0p, m[11], m[3], m[2]);
87 | w3p = FALTE(w1p, m[12], m[4], m[3]);
88 | w4pp = SIG1(w2p) + SIG0(m[5]) + m[4];
89 | w5p = FALTE(w3p, (uint)0, m[6], m[5]);
90 | w7p = FALTE(w5p, w0p, m[8], m[7]);
91 | w9p = FALTE(w7p, w2p, m[10], m[9]);
92 |
93 | // Verschieben: Phase 4
94 | m[6] += 0x000001b8 + SIG0(m[7]);
95 | m[8] += w1p;
96 | m[10]+= w3p;
97 |
98 | __private uint mx = SIG1(w9p) + SIG0(m[12]);
99 |
100 | for(m[13] = 0x80; m[13] < (1 << 23); m[13]+= 0x100) {
101 | __private uint w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, wa, wb, wc, wd, we, wf;
102 |
103 | c = cp + m[13];
104 | g = gp + m[13];
105 |
106 | b = bp + EP1(g) + SHA256_F1o(g,hp,ap);
107 | f = fp + b;
108 | b += EP0(c) + SHA256_F0o(c,dp,ep);
109 |
110 | a = ap + 0xc19bf32c + EP1(f) + SHA256_F1o(f,g,hp);
111 | e = ep + a;
112 | a += EP0(b) + SHA256_F0o(b,c,dp);
113 |
114 | h = hp + 0xe49b69c1 + w0p + EP1(e) + SHA256_F1o(e,f,g);
115 | d = dp + h;
116 | h += EP0(a) + SHA256_F0o(a,b,c);
117 |
118 | RUNDE_INNEN(h, a, b, c, d, e, f, g, w1p + 0xefbe4786 );
119 | RUNDE_INNEN(g, h, a, b, c, d, e, f, w2p + 0x0fc19dc6 );
120 | RUNDE_INNEN(f, g, h, a, b, c, d, e, w3p + 0x240ca1cc );
121 | w4 = w4pp + m[13];
122 | RUNDE_INNEN(e, f, g, h, a, b, c, d, w4 + 0x2de92c6f );
123 | RUNDE_INNEN(d, e, f, g, h, a, b, c, w5p + 0x4a7484aa );
124 | w6 = SIG1(w4) + m[6];
125 | RUNDE_INNEN(c, d, e, f, g, h, a, b, w6 + 0x5cb0a9dc );
126 | RUNDE_INNEN(b, c, d, e, f, g, h, a, w7p + 0x76f988da );
127 | w8 = SIG1(w6) + m[8];
128 | RUNDE_INNEN(a, b, c, d, e, f, g, h, w8 + 0x983e5152 );
129 | RUNDE_INNEN(h, a, b, c, d, e, f, g, w9p + 0xa831c66d );
130 | wa = SIG1(w8) + m[10];
131 | RUNDE_INNEN(g, h, a, b, c, d, e, f, wa + 0xb00327c8 );
132 | wb = w4 + mx;
133 | RUNDE_INNEN(f, g, h, a, b, c, d, e, wb + 0xbf597fc7 );
134 | wc = SIG1(wa) + w5p + SIG0(m[13]) + m[12];
135 | RUNDE_INNEN(e, f, g, h, a, b, c, d, wc + 0xc6e00bf3 );
136 | wd = SIG1(wb) + w6 + m[13];
137 | RUNDE_INNEN(d, e, f, g, h, a, b, c, wd + 0xd5a79147 );
138 | we = SIG1(wc) + w7p + 0x706e0034;
139 | RUNDE_INNEN(c, d, e, f, g, h, a, b, we + 0x06ca6351 );
140 | wf = SIG1(wd) + w8 + SIG0(w0p) + 0x000001b8;
141 | RUNDE_INNEN(b, c, d, e, f, g, h, a, wf + 0x14292967 );
142 | w0 = FALTE(we, w9p, w1p, w0p);
143 | RUNDE_INNEN(a, b, c, d, e, f, g, h, w0 + 0x27b70a85 );
144 | w1 = FALTE(wf, wa, w2p, w1p);
145 | RUNDE_INNEN(h, a, b, c, d, e, f, g, w1 + 0x2e1b2138 );
146 | w2 = FALTE(w0, wb, w3p, w2p);
147 | RUNDE_INNEN(g, h, a, b, c, d, e, f, w2 + 0x4d2c6dfc );
148 | w3 = FALTE(w1, wc, w4, w3p);
149 | RUNDE_INNEN(f, g, h, a, b, c, d, e, w3 + 0x53380d13 );
150 | w4 = FALTE(w2, wd, w5p, w4);
151 | RUNDE_INNEN(e, f, g, h, a, b, c, d, w4 + 0x650a7354 );
152 | w5 = FALTE(w3, we, w6, w5p);
153 | RUNDE_INNEN(d, e, f, g, h, a, b, c, w5 + 0x766a0abb );
154 | w6 = FALTE(w4, wf, w7p, w6);
155 | RUNDE_INNEN(c, d, e, f, g, h, a, b, w6 + 0x81c2c92e );
156 | w7 = FALTE(w5, w0, w8, w7p);
157 | RUNDE_INNEN(b, c, d, e, f, g, h, a, w7 + 0x92722c85 );
158 | w8 = FALTE(w6, w1, w9p, w8);
159 | RUNDE_INNEN(a, b, c, d, e, f, g, h, w8 + 0xa2bfe8a1 );
160 | w9 = FALTE(w7, w2, wa, w9p);
161 | RUNDE_INNEN(h, a, b, c, d, e, f, g, w9 + 0xa81a664b );
162 | wa = FALTE(w8, w3, wb, wa);
163 | RUNDE_INNEN(g, h, a, b, c, d, e, f, wa + 0xc24b8b70 );
164 | wb = FALTE(w9, w4, wc, wb);
165 | RUNDE_INNEN(f, g, h, a, b, c, d, e, wb + 0xc76c51a3 );
166 | wc = FALTE(wa, w5, wd, wc);
167 | RUNDE_INNEN(e, f, g, h, a, b, c, d, wc + 0xd192e819 );
168 | wd = FALTE(wb, w6, we, wd);
169 | RUNDE_INNEN(d, e, f, g, h, a, b, c, wd + 0xd6990624 );
170 | we = FALTE(wc, w7, wf, we);
171 | RUNDE_INNEN(c, d, e, f, g, h, a, b, we + 0xf40e3585 );
172 | wf = FALTE(wd, w8, w0, wf);
173 | RUNDE_INNEN(b, c, d, e, f, g, h, a, wf + 0x106aa070 );
174 | w0 = FALTE(we, w9, w1, w0);
175 | RUNDE_INNEN(a, b, c, d, e, f, g, h, w0 + 0x19a4c116 );
176 | w1 = FALTE(wf, wa, w2, w1);
177 | RUNDE_INNEN(h, a, b, c, d, e, f, g, w1 + 0x1e376c08 );
178 | w2 = FALTE(w0, wb, w3, w2);
179 | RUNDE_INNEN(g, h, a, b, c, d, e, f, w2 + 0x2748774c );
180 | w3 = FALTE(w1, wc, w4, w3);
181 | RUNDE_INNEN(f, g, h, a, b, c, d, e, w3 + 0x34b0bcb5 );
182 | w4 = FALTE(w2, wd, w5, w4);
183 | RUNDE_INNEN(e, f, g, h, a, b, c, d, w4 + 0x391c0cb3 );
184 | w5 = FALTE(w3, we, w6, w5);
185 | RUNDE_INNEN(d, e, f, g, h, a, b, c, w5 + 0x4ed8aa4a );
186 | w6 = FALTE(w4, wf, w7, w6);
187 | RUNDE_INNEN(c, d, e, f, g, h, a, b, w6 + 0x5b9cca4f );
188 | w7 = FALTE(w5, w0, w8, w7);
189 | RUNDE_INNEN(b, c, d, e, f, g, h, a, w7 + 0x682e6ff3 );
190 | w8 = FALTE(w6, w1, w9, w8);
191 | RUNDE_INNEN(a, b, c, d, e, f, g, h, w8 + 0x748f82ee );
192 | w9 = FALTE(w7, w2, wa, w9);
193 | RUNDE_INNEN(h, a, b, c, d, e, f, g, w9 + 0x78a5636f );
194 | wa = FALTE(w8, w3, wb, wa);
195 | RUNDE_INNEN(g, h, a, b, c, d, e, f, wa + 0x84c87814 );
196 | wb = FALTE(w9, w4, wc, wb);
197 | RUNDE_INNEN(f, g, h, a, b, c, d, e, wb + 0x8cc70208 );
198 | wc = FALTE(wa, w5, wd, wc);
199 | RUNDE_INNEN(e, f, g, h, a, b, c, d, wc + 0x90befffa );
200 | wd = FALTE(wb, w6, we, wd);
201 |
202 | c += 0xa4506ceb + wd + EP1(h) + SHA256_F1o(h,a,b);
203 | g += c;
204 | c += EP0(d) + SHA256_F0o(d,e,f);
205 | b += 0xbef9a3f7 + FALTE(wc, w7, wf, we) + EP1(g) + SHA256_F1o(g,h,a);
206 | f += b;
207 | b += EP0(c) + SHA256_F0o(c,d,e);
208 | a += FALTE(wd, w8, w0, wf) + EP1(f) + SHA256_F1o(f,g,h) + EP0(b) + SHA256_F0o(b,c,d);
209 |
210 | if(a == 0xcf84a0a7) {
211 | unsigned char *mv = (unsigned char*)&m[12];
212 |
213 | out[ii * 8 + 0] = mv[3];
214 | out[ii * 8 + 1] = mv[2];
215 | out[ii * 8 + 2] = mv[1];
216 | out[ii * 8 + 3] = mv[0];
217 |
218 | mv = (unsigned char*)&m[13];
219 |
220 | out[ii * 8 + 4] = mv[3];
221 | out[ii * 8 + 5] = mv[2];
222 | out[ii * 8 + 6] = mv[1];
223 |
224 | mem_fence(CLK_GLOBAL_MEM_FENCE);
225 | return;
226 | }
227 | }
228 | }
229 |
230 |
--------------------------------------------------------------------------------
/client.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Open Source Amoveo OpenCL Miner
4 |
5 | for AMD & Nvidia GPU´s
6 |
7 | Donations:
8 | BONJmlU2FUqYgUY60LTIumsYrW/c6MHte64y5KlDzXk5toyEMaBzWm8dHmdMfJmXnqvbYmlwim0hiFmYCCn3Rm0=
9 |
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #include "sha256.h"
28 |
29 | #define MAXGPU 32
30 | #define NONCESIZE 23
31 |
32 | cl_device_id device_id[32];
33 |
34 | int randfd;
35 | pthread_mutex_t mutex;
36 |
37 | int diff;
38 | int sharediff = 0;
39 |
40 | unsigned char data[32];
41 |
42 | unsigned int poolport;
43 | unsigned char *workPath;
44 | unsigned char *address;
45 | unsigned char *hostname;
46 | struct in_addr *poolip;
47 | int pollcount = 0;
48 |
49 | static char encoding_table[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
50 | static char *decoding_table = NULL;
51 | static int mod_table[] = {0, 2, 1};
52 |
53 | void build_decoding_table() {
54 | decoding_table = malloc(256);
55 |
56 | for (int i = 0; i < 64; i++)
57 | decoding_table[(unsigned char) encoding_table[i]] = i;
58 | }
59 |
60 | char *base64_encode(const unsigned char *data, size_t input_length, size_t *output_length) {
61 |
62 | *output_length = 4 * ((input_length + 2) / 3);
63 |
64 | char *encoded_data = malloc(*output_length);
65 | if (encoded_data == NULL) return NULL;
66 |
67 | for (int i = 0, j = 0; i < input_length;) {
68 |
69 | uint32_t octet_a = i < input_length ? (unsigned char)data[i++] : 0;
70 | uint32_t octet_b = i < input_length ? (unsigned char)data[i++] : 0;
71 | uint32_t octet_c = i < input_length ? (unsigned char)data[i++] : 0;
72 |
73 | uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
74 |
75 | encoded_data[j++] = encoding_table[(triple >> 3 * 6) & 0x3F];
76 | encoded_data[j++] = encoding_table[(triple >> 2 * 6) & 0x3F];
77 | encoded_data[j++] = encoding_table[(triple >> 1 * 6) & 0x3F];
78 | encoded_data[j++] = encoding_table[(triple >> 0 * 6) & 0x3F];
79 | }
80 |
81 | for (int i = 0; i < mod_table[input_length % 3]; i++)
82 | encoded_data[*output_length - 1 - i] = '=';
83 |
84 | return encoded_data;
85 | }
86 |
87 |
88 | unsigned char *base64_decode(const char *data, size_t input_length, size_t *output_length) {
89 | if (decoding_table == NULL) build_decoding_table();
90 |
91 | if (input_length % 4 != 0) return NULL;
92 |
93 | *output_length = input_length / 4 * 3;
94 | if (data[input_length - 1] == '=') (*output_length)--;
95 | if (data[input_length - 2] == '=') (*output_length)--;
96 |
97 | unsigned char *decoded_data = malloc(*output_length);
98 | if (decoded_data == NULL) return NULL;
99 |
100 | for (int i = 0, j = 0; i < input_length;) {
101 |
102 | uint32_t sextet_a = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
103 | uint32_t sextet_b = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
104 | uint32_t sextet_c = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
105 | uint32_t sextet_d = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
106 |
107 | uint32_t triple = (sextet_a << 3 * 6)
108 | + (sextet_b << 2 * 6)
109 | + (sextet_c << 1 * 6)
110 | + (sextet_d << 0 * 6);
111 |
112 | if (j < *output_length) decoded_data[j++] = (triple >> 2 * 8) & 0xFF;
113 | if (j < *output_length) decoded_data[j++] = (triple >> 1 * 8) & 0xFF;
114 | if (j < *output_length) decoded_data[j++] = (triple >> 0 * 8) & 0xFF;
115 | }
116 |
117 | return decoded_data;
118 | }
119 |
120 | void base64_cleanup() {
121 | free(decoding_table);
122 | }
123 |
124 | void nonblock(int sock) {
125 | int flags = fcntl(sock, F_GETFL, 0);
126 | flags = flags | O_NONBLOCK;
127 | fcntl(sock, F_SETFL, flags);
128 | }
129 |
130 | int pool() {
131 | int sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
132 |
133 | nonblock(sd);
134 |
135 | struct sockaddr_in servaddr;
136 |
137 | memset(&servaddr, 0, sizeof(servaddr));
138 |
139 | servaddr.sin_family = AF_INET;
140 | servaddr.sin_port = htons(poolport);
141 | memcpy(&servaddr.sin_addr, poolip, sizeof(poolip));
142 |
143 | pollcount++;
144 |
145 | connect(sd, (struct sockaddr *)&servaddr, sizeof(servaddr));
146 |
147 | char buffer[1000];
148 |
149 | /* if(strlen(workPath) > 3) {
150 | sprintf(buffer, "POST %s HTTP/1.1\r\ncontent-type: application/octet-stream\r\ncontent-length: %i\r\nhost: %s:%i\r\nconnection: close\r\n\r\n[\"mining_data\", \"%s\"]",
151 | workPath,
152 | (19 + (int)strlen(address)),
153 | hostname,
154 | poolport,
155 | address
156 | );
157 | } else {
158 | sprintf(buffer, "POST %s HTTP/1.1\r\ncontent-type: application/octet-stream\r\ncontent-length: %i\r\nhost: %s:%i\r\nconnection: close\r\n\r\n[\"mining_data\",8080]",
159 | workPath,
160 | 20,
161 | hostname,
162 | poolport
163 | );
164 | } */
165 | sprintf(buffer, "POST %s HTTP/1.1\r\ncontent-type: application/octet-stream\r\ncontent-length: %i\r\nhost: %s:%i\r\nconnection: close\r\n\r\n[\"mining_data\", \"%s\"]",
166 | workPath,
167 | (19 + (int)strlen(address)),
168 | hostname,
169 | poolport,
170 | address
171 | );
172 |
173 |
174 | struct timeval tv;
175 | tv.tv_sec = 4;
176 | tv.tv_usec = 0;
177 |
178 | fd_set my;
179 | FD_ZERO(&my);
180 | FD_SET(sd, &my);
181 | select(sd+1, NULL, &my, NULL, &tv);
182 |
183 | if(!FD_ISSET(sd, &my)) {
184 | close(sd);
185 | usleep(500000);
186 | return -1;
187 | }
188 |
189 | send(sd, buffer, strlen(buffer), MSG_NOSIGNAL);
190 |
191 | tv.tv_sec = 4;
192 | tv.tv_usec = 0;
193 |
194 | FD_ZERO(&my);
195 | FD_SET(sd, &my);
196 |
197 | select(sd+1, &my, NULL, NULL, &tv);
198 |
199 | if(!FD_ISSET(sd, &my)) {
200 | close(sd);
201 | usleep(500000);
202 | return -1;
203 | }
204 |
205 | int bytes = read(sd, buffer, 1000);
206 | close(sd);
207 |
208 | for(int i=0; iload;
392 |
393 | char *in = (char*)malloc(55);
394 | char *out = (char*)malloc(NONCESIZE * gc->load);
395 |
396 | for(;;) {
397 | pthread_mutex_lock(&gc->gpulock);
398 |
399 | read(randfd, nonces, NONCESIZE);
400 |
401 | for (int i = 0; i < 32; i++)
402 | in[i] = data[i];
403 |
404 | nonces[4] = 0; nonces[5] = 0; nonces[6] = 0; nonces[7] = 0;
405 | nonces[12] = 0; nonces[13] = 0; nonces[14] = 0; nonces[15] = 0;
406 |
407 | for(int i = 0; i < NONCESIZE; i++)
408 | in[i+32] = nonces[i];
409 |
410 | err = clEnqueueWriteBuffer(gc->commands, gc->input, CL_TRUE, 0, 55, in, 0, NULL, NULL);
411 | if (err != CL_SUCCESS) {
412 | exit(1);
413 | }
414 |
415 | err = clEnqueueNDRangeKernel(gc->commands, gc->kernel, 1, NULL, &global, NULL, 0, NULL, NULL);
416 | if (err) {
417 | exit(1);
418 | }
419 |
420 | struct timeval kernelStart, kernelEnd;
421 | gettimeofday(&kernelStart,NULL);
422 | #ifdef CLWAIT
423 | usleep(gc->waitus * 0.95);
424 | #endif
425 |
426 | clFinish(gc->commands);
427 |
428 | gettimeofday(&kernelEnd,NULL);
429 | unsigned long time_in_micros = 1000000 * (kernelEnd.tv_sec - kernelStart.tv_sec) + (kernelEnd.tv_usec - kernelStart.tv_usec);
430 | gc->waitus = time_in_micros;
431 |
432 | err = clEnqueueReadBuffer( gc->commands, gc->output, CL_TRUE, 0, 8 * gc->load, out, 0, NULL, NULL );
433 | if (err != CL_SUCCESS) {
434 | printf("Error: Failed to read output array! %d\n", err);
435 | exit(1);
436 | }
437 | gc->blocksdone++;
438 |
439 | pthread_mutex_unlock(&gc->gpulock);
440 |
441 | char hash0[32];
442 | SHA256_CTX ctx;
443 |
444 | for(int i=0; iload; i++) {
445 | if(
446 | out[i * 8 + 0] == 0 && out[i * 8 + 1] == 0 &&
447 | out[i * 8 + 2] == 0 && out[i * 8 + 3] == 0 &&
448 | out[i * 8 + 4] == 0 && out[i * 8 + 5] == 0 &&
449 | out[i * 8 + 6] == 0 && out[i * 8 + 7] == 0
450 | ) continue;
451 |
452 | char submit[23];
453 | memcpy(submit, &in[32], 16);
454 | memcpy(&submit[16], &out[i * 8], 7);
455 |
456 | sha256_init(&ctx);
457 | sha256_update(&ctx, data, 32);
458 | sha256_update(&ctx, submit, 23);
459 | sha256_final(&ctx, hash0);
460 |
461 | int xxx = hash2integer(hash0);
462 |
463 | if(xxx >= sharediff) {
464 | printf("Share with difficulty %d found. Submitting ...\n", xxx);
465 | while(submitnonce(submit) == -1);
466 | }
467 | }
468 | }
469 | }
470 |
471 | int main(int argc, char **argv) {
472 | // Default-pool:
473 | poolport = 8880;
474 | hostname = "veopool.pw";
475 | workPath = "/work";
476 |
477 | if (argc > 1) {
478 | size_t lengthAddress = strlen(argv[1])+1;
479 |
480 | if(argc > 2) {
481 | for(int i=0;ih_addr_list == NULL) {
515 | printf("Could not connect to pool.\n");
516 | return -1;
517 | }
518 |
519 | memcpy(&poolip, &host->h_addr_list[0], sizeof(poolip));
520 |
521 | int err;
522 |
523 | pthread_mutex_init(&mutex, NULL);
524 |
525 | randfd = open("/dev/urandom", O_RDONLY);
526 |
527 | unsigned char pad[32];
528 | SHA256_CTX ctx;
529 |
530 | unsigned char *ccd = malloc(20000);
531 |
532 | int fd = open("amoveo.cl", O_RDONLY);
533 | ccd[read(fd, ccd, 20000)] = 0;
534 | close(fd);
535 |
536 | cl_platform_id platform_id = NULL;
537 | cl_uint ret_num_platforms;
538 | cl_uint ret_num_devices;
539 |
540 | clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
541 | err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, MAXGPU, &device_id, &ret_num_devices);
542 | if (err != CL_SUCCESS) {
543 | printf("Error: Failed to create a device group!\n");
544 | return EXIT_FAILURE;
545 | }
546 |
547 | struct gpuContext *c = (struct gpuContext*) malloc(sizeof(struct gpuContext) * ret_num_devices);
548 |
549 | printf("Getting work from Pool...\n");
550 | while(pool() == -1);
551 | printf("Got work. Starting miner...\n");
552 |
553 | for(int i=0; i