mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
fix zr5 algo
This commit is contained in:
parent
f249ec0140
commit
9fad62357b
2 changed files with 78 additions and 6 deletions
|
@ -1,8 +1,7 @@
|
|||
#include "x15.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
|
@ -10,6 +9,8 @@
|
|||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
|
||||
//#define TEST_VERBOSELY
|
||||
|
||||
#define ZR_BLAKE 0
|
||||
#define ZR_GROESTL 1
|
||||
#define ZR_JH 2
|
||||
|
@ -47,7 +48,7 @@ static const int permut[][4] = {
|
|||
{3, 2, 1, 0}
|
||||
};
|
||||
|
||||
void zr5_hash(const char* input, char* output, uint32_t len)
|
||||
static void zr5_hash_512(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_blake512_context ctx_blake;
|
||||
|
@ -65,15 +66,16 @@ void zr5_hash(const char* input, char* output, uint32_t len)
|
|||
unsigned int norder = hash[0][0] % ARRAY_SIZE(permut); /* % 24 */
|
||||
int i;
|
||||
|
||||
#ifdef TEST_VERBOSELY
|
||||
for(i=0; i<len; i++) printf("%02x", (unsigned char)input[i]); printf("\n");
|
||||
for(i=0; i<32; i++) printf("%02x", (unsigned char)ph[i]); printf("\n");
|
||||
|
||||
#endif
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
void* phash = (void*) &(hash[i][0]);
|
||||
void* pdest = (void*) &(hash[i+1][0]);
|
||||
|
||||
printf("permut %d\n", permut[norder][i]);
|
||||
//printf("permut %d\n", permut[norder][i]);
|
||||
switch (permut[norder][i]) {
|
||||
case ZR_BLAKE:
|
||||
sph_blake512_init(&ctx_blake);
|
||||
|
@ -102,3 +104,72 @@ void zr5_hash(const char* input, char* output, uint32_t len)
|
|||
memcpy(output, &hash[4], 32);
|
||||
}
|
||||
|
||||
|
||||
void zr5_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
uint8_t *input512; // writeable copy of input
|
||||
uint8_t output512[64]; // output of both zr5 hashes
|
||||
uint32_t version; // writeable copy of version
|
||||
uint32_t nPoK = 0; // integer copy of PoK state
|
||||
#ifdef TEST_VERBOSELY
|
||||
char buffer[512] = { 0 };
|
||||
char *buf = buffer;
|
||||
uint32_t i = 0;
|
||||
#endif
|
||||
|
||||
// copy the input buffer at input to a modifiable location at input512,
|
||||
input512 = (uint8_t*)malloc(len); // allocate space for the copy
|
||||
memcpy((uint8_t*)input512, (uint8_t*)input, len);
|
||||
|
||||
#ifdef TEST_VERBOSELY
|
||||
fprintf(stderr, "zr5 input: ");
|
||||
for (i=0; i<len; i++) sprintf(stderr, "%02x", input512[i]);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
|
||||
// store the version bytes
|
||||
memcpy((uint8_t *)&version, (uint8_t *)input, 4);
|
||||
|
||||
// apply the first hash, yielding 512bits = 64 bytes
|
||||
zr5_hash_512(input512, output512, len);
|
||||
|
||||
// Now begins Proof of Knowledge
|
||||
//
|
||||
// Pull the data from the result for the Proof of Knowledge
|
||||
// (this is the 3rd and 4th of the first four bytes of the result)
|
||||
memcpy(&nPoK, (uint8_t *)output512, 4); // yields big or little endian uint
|
||||
// keep only the two least significant bytes
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
nPoK &= 0xFFFF0000; // bytes 3&4 of big endian are 1&2 of little endian
|
||||
#else
|
||||
nPoK &= 0x0000FFFF; // bytes 1&2 of big endian are 3&4 of little endian
|
||||
#endif
|
||||
//
|
||||
// PoK part 2:
|
||||
// update the version variable with the masks and PoK value
|
||||
// according to the Proof of Knowledge setting
|
||||
version &= (~POK_BOOL_MASK);
|
||||
version |= (POK_DATA_MASK & nPoK);
|
||||
#ifdef TEST_VERBOSELY
|
||||
fprintf(stderr, "new version field: %x\n", version);
|
||||
#endif
|
||||
|
||||
// and now write it back out to our copy of the input buffer
|
||||
memcpy((uint8_t *)input512, (uint8_t *)&version, 4);
|
||||
|
||||
// apply a second ZR5 hash of the modified input, 512 bits in and out,
|
||||
// to the input modified with PoK. Length is still the original length
|
||||
zr5_hash_512(input512, output512, len);
|
||||
|
||||
// copy the left-most 256 bits (32 bytes) of the last hash into the output buffer
|
||||
memcpy((uint8_t *)output, (uint8_t *)output512, sizeof(output512)/2);
|
||||
|
||||
#ifdef TEST_VERBOSELY
|
||||
buf += sprintf(buf, "zr5 hash: ");
|
||||
for (i=0; i<32; i++) { buf += sprintf(buf, "%02x", output512[i]); }
|
||||
fprintf(stderr, "%s\n", buffer); buf = buffer;
|
||||
#endif
|
||||
|
||||
free(input512);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -263,7 +263,8 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params)
|
|||
memset(&submitvalues, 0, sizeof(submitvalues));
|
||||
|
||||
build_submit_values(&submitvalues, templ, client->extranonce1, extranonce2, ntime, nonce);
|
||||
if(submitvalues.hash_bin[30] || submitvalues.hash_bin[31])
|
||||
// zr5 has data here, ignore it... reversed endian ?
|
||||
if((submitvalues.hash_bin[30] || submitvalues.hash_bin[31]) && g_current_algo && strcmp(g_current_algo->name, "zr5"))
|
||||
{
|
||||
client_submit_error(client, job, 25, "Invalid share", extranonce2, ntime, nonce);
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue