Skip to content

Commit fb181f5

Browse files
committed
Add Pascal algo for PascalCoin
1 parent 673dc79 commit fb181f5

File tree

9 files changed

+425
-2
lines changed

9 files changed

+425
-2
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ sgminer_SOURCES += algorithm/yescrypt.h algorithm/yescrypt.c algorithm/yescrypt_
8282
sgminer_SOURCES += algorithm/blake256.c algorithm/blake256.h
8383
sgminer_SOURCES += algorithm/blakecoin.c algorithm/blakecoin.h
8484
sgminer_SOURCES += algorithm/decred.c algorithm/decred.h
85+
sgminer_SOURCES += algorithm/pascal.c algorithm/pascal.h
8586
sgminer_SOURCES += algorithm/lbry.c algorithm/lbry.h
8687

8788
bin_SCRIPTS = $(top_srcdir)/kernel/*.cl

algorithm.c

+23
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "algorithm/blakecoin.h"
4242
#include "algorithm/sia.h"
4343
#include "algorithm/decred.h"
44+
#include "algorithm/pascal.h"
4445
#include "algorithm/lbry.h"
4546
#include "algorithm/sibcoin.h"
4647

@@ -54,6 +55,7 @@ const char *algorithm_type_str[] = {
5455
"Credits",
5556
"Scrypt",
5657
"NScrypt",
58+
"Pascal",
5759
"X11",
5860
"X13",
5961
"X14",
@@ -204,6 +206,25 @@ static cl_int queue_scrypt_kernel(struct __clState *clState, struct _dev_blk_ctx
204206
return status;
205207
}
206208

209+
static cl_int queue_pascal_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
210+
{
211+
cl_kernel *kernel = &clState->kernel;
212+
unsigned int num = 0;
213+
cl_ulong le_target;
214+
cl_int status = 0;
215+
216+
le_target = *(cl_ulong *)(blk->work->device_target + 24);
217+
flip196(clState->cldata, blk->work->data);
218+
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 196, clState->cldata, 0, NULL, NULL);
219+
220+
CL_SET_ARG(clState->CLbuffer0);
221+
CL_SET_ARG(clState->outputBuffer);
222+
CL_SET_ARG(le_target);
223+
CL_SET_ARG(blk->work->midstate);
224+
225+
return status;
226+
}
227+
207228
static cl_int queue_neoscrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
208229
{
209230
cl_kernel *kernel = &clState->kernel;
@@ -1206,6 +1227,8 @@ static algorithm_settings_t algos[] = {
12061227

12071228
{ "lbry", ALGO_LBRY, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 2, 4 * 8 * 4194304, 0, lbry_regenhash, NULL, NULL, queue_lbry_kernel, gen_hash, NULL },
12081229

1230+
{ "pascal", ALGO_PASCAL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, pascal_regenhash, pascal_midstate, NULL, queue_pascal_kernel, NULL, NULL },
1231+
12091232
// Terminator (do not remove)
12101233
{ NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
12111234
};

algorithm.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef enum {
1616
ALGO_CRE,
1717
ALGO_SCRYPT,
1818
ALGO_NSCRYPT,
19+
ALGO_PASCAL,
1920
ALGO_X11,
2021
ALGO_X13,
2122
ALGO_X14,

algorithm/pascal.c

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* BLAKE implementation.
3+
*
4+
* ==========================(LICENSE BEGIN)============================
5+
*
6+
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining
9+
* a copy of this software and associated documentation files (the
10+
* "Software"), to deal in the Software without restriction, including
11+
* without limitation the rights to use, copy, modify, merge, publish,
12+
* distribute, sublicense, and/or sell copies of the Software, and to
13+
* permit persons to whom the Software is furnished to do so, subject to
14+
* the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be
17+
* included in all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*
27+
* ===========================(LICENSE END)=============================
28+
*
29+
* @author Thomas Pornin <[email protected]>
30+
*
31+
* Modified for more speed by BlueDragon747 for the Blakecoin project
32+
*/
33+
34+
#include <stddef.h>
35+
#include <string.h>
36+
#include <limits.h>
37+
#include <stdint.h>
38+
39+
#include "sph/sph_sha2.h"
40+
#include "algorithm/pascal.h"
41+
42+
static const uint32_t diff1targ_pascal = 0x000000ff;
43+
44+
void pascalhash(void *state, const void *input)
45+
{
46+
sph_sha256_context ctx_sha;
47+
uint32_t hash[16];
48+
49+
sph_sha256_init(&ctx_sha);
50+
sph_sha256(&ctx_sha, input, 200);
51+
sph_sha256_close(&ctx_sha, hash);
52+
53+
sph_sha256_init(&ctx_sha);
54+
sph_sha256(&ctx_sha, hash, 32);
55+
sph_sha256_close(&ctx_sha, hash);
56+
57+
memcpy(state, hash, 32);
58+
59+
}
60+
61+
void pascal_midstate(struct work *work)
62+
{
63+
sph_sha256_context ctx_sha;
64+
uint32_t data[48];
65+
66+
memcpy(data, work->data, 192);
67+
68+
sph_sha256_init(&ctx_sha);
69+
sph_sha256 (&ctx_sha, (unsigned char *)data, 192);
70+
71+
memcpy(work->midstate, ctx_sha.val, 32);
72+
endian_flip32(work->midstate, work->midstate);
73+
74+
/*
75+
char *strdata, *strmidstate;
76+
strdata = bin2hex(work->data, 192);
77+
strmidstate = bin2hex(work->midstate, 32);
78+
applog(LOG_DEBUG, "data %s midstate %s", strdata, strmidstate);
79+
*/
80+
}
81+
82+
static const uint32_t diff1targ = 0x0000ffff;
83+
84+
/* Used externally as confirmation of correct OCL code */
85+
int pascal_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
86+
{
87+
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
88+
uint32_t data[50], ohash[8];
89+
90+
memcpy(data, pdata, 200);
91+
data[49] = htobe32(nonce);
92+
pascalhash(ohash, data);
93+
tmp_hash7 = be32toh(ohash[7]);
94+
95+
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
96+
(long unsigned int)Htarg,
97+
(long unsigned int)diff1targ,
98+
(long unsigned int)tmp_hash7);
99+
if (tmp_hash7 > diff1targ)
100+
return -1;
101+
if (tmp_hash7 > Htarg)
102+
return 0;
103+
return 1;
104+
}
105+
106+
void pascal_regenhash(struct work *work)
107+
{
108+
uint32_t data[64];
109+
uint32_t hash[16];
110+
uint32_t *nonce = (uint32_t *)(work->data + 196);
111+
uint32_t *ohash = (uint32_t *)(work->hash);
112+
113+
memcpy(data, work->data, 200);
114+
data[49] = htole32(*nonce);
115+
pascalhash(hash, data);
116+
swab256(ohash, hash);
117+
}

algorithm/pascal.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef PASCAL_H
2+
#define PASCAL_H
3+
4+
#include "miner.h"
5+
6+
extern int pascal_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce);
7+
extern void pascal_prepare_work(dev_blk_ctx *blk, uint32_t *state, uint32_t *pdata);
8+
extern void pascal_midstate(struct work *work);
9+
extern void pascal_regenhash(struct work *work);
10+
11+
#endif /* PASCAL_H */

0 commit comments

Comments
 (0)