Skip to content

Commit

Permalink
Merge pull request #256 from fancyIX/feature/#247
Browse files Browse the repository at this point in the history
Feature/#247
  • Loading branch information
fancyIX committed Dec 13, 2021
2 parents 6012382 + 8e695fa commit af34e4e
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 55 deletions.
4 changes: 2 additions & 2 deletions algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ static cl_int queue_heavyhash_kernel(_clState *clState, dev_blk_ctx *blk, __mayb
uint32_t edata[20];
uint32_t seed[8];

uint32_t matrix[64][64];
uint8_t matrix[64][64];
struct xoshiro_state state;

memcpy(edata, clState->cldata, 80);
Expand All @@ -1875,7 +1875,7 @@ static cl_int queue_heavyhash_kernel(_clState *clState, dev_blk_ctx *blk, __mayb

generate_matrix(matrix, &state);

status = clEnqueueWriteBuffer(clState->commandQueue, clState->padbuffer8, true, 0, 64 * 64 * 4, matrix, 0, NULL, NULL);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->padbuffer8, true, 0, 64 * 64, matrix, 0, NULL, NULL);

CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
Expand Down
20 changes: 10 additions & 10 deletions algorithm/heavyhash-gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static inline uint64_t xoshiro_gen(struct xoshiro_state *state) {
return result;
}

static int compute_rank(const uint32_t A[64][64])
static int compute_rank(const uint8_t A[64][64])
{
double B[64][64];
for (int i = 0; i < 64; ++i){
Expand Down Expand Up @@ -104,12 +104,12 @@ static int compute_rank(const uint32_t A[64][64])
return rank;
}

static inline bool is_full_rank(const uint32_t matrix[64][64])
static inline bool is_full_rank(const uint8_t matrix[64][64])
{
return compute_rank(matrix) == 64;
}

void generate_matrix(uint32_t matrix[64][64], struct xoshiro_state *state) {
void generate_matrix(uint8_t matrix[64][64], struct xoshiro_state *state) {
do {
for (int i = 0; i < 64; ++i) {
for (int j = 0; j < 64; j += 16) {
Expand All @@ -122,14 +122,14 @@ void generate_matrix(uint32_t matrix[64][64], struct xoshiro_state *state) {
} while (!is_full_rank(matrix));
}

void heavyhash(const uint32_t matrix[64][64], uint8_t* pdata, size_t pdata_len, uint8_t* output)
void heavyhash(const uint8_t matrix[64][64], uint8_t* pdata, size_t pdata_len, uint8_t* output)
{
uint8_t hash_first[32] __attribute__((aligned(64)));
uint8_t hash_second[32] __attribute__((aligned(64)));
uint8_t hash_xored[32] __attribute__((aligned(64)));

uint32_t vector[64] __attribute__((aligned(64)));
uint32_t product[64] __attribute__((aligned(64)));
uint16_t vector[64] __attribute__((aligned(64)));
uint16_t product[64] __attribute__((aligned(64)));

kt_sha3_256((uint8_t*) hash_first, 32, pdata, pdata_len);

Expand All @@ -139,7 +139,7 @@ void heavyhash(const uint32_t matrix[64][64], uint8_t* pdata, size_t pdata_len,
}

for (int i = 0; i < 64; ++i) {
uint32_t sum = 0;
uint16_t sum = 0;
for (int j = 0; j < 64; ++j) {
sum += matrix[i][j] * vector[j];
}
Expand Down Expand Up @@ -167,7 +167,7 @@ int heavyhash_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t

uint32_t seed[8];

uint32_t matrix[64][64];
uint8_t matrix[64][64];
struct xoshiro_state state;

kt_sha3_256((uint8_t *)seed, 32, (uint8_t *)(data+1), 32);
Expand Down Expand Up @@ -200,7 +200,7 @@ void heavyhash_regenhash(struct work *work)

uint32_t seed[8];

uint32_t matrix[64][64];
uint8_t matrix[64][64];
struct xoshiro_state state;

kt_sha3_256((uint8_t *)seed, 32, (uint8_t*) (data+1), 32);
Expand Down Expand Up @@ -228,7 +228,7 @@ bool scanhash_heavyhash(struct thr_info *thr, const unsigned char *pmidstate,

const uint32_t first_nonce = ((uint32_t *)pdata)[19];

uint32_t matrix[64][64] __attribute__((aligned(64)));
uint8_t matrix[64][64] __attribute__((aligned(64)));
struct xoshiro_state state;

mm128_bswap32_80( edata, pdata );
Expand Down
2 changes: 1 addition & 1 deletion algorithm/heavyhash-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct xoshiro_state {
};

extern uint64_t le64dec(const void *pp);
extern void generate_matrix(uint32_t matrix[64][64], struct xoshiro_state *state);
extern void generate_matrix(uint8_t matrix[64][64], struct xoshiro_state *state);
extern int heavyhash_test(unsigned char *pdata, const unsigned char *ptarget,
uint32_t nonce);
extern void heavyhash_regenhash(struct work *work);
Expand Down
Loading

0 comments on commit af34e4e

Please sign in to comment.