Path: blob/master/algo/pentablake.c
1299 views
#include "miner.h"12#include <stdlib.h>3#include <stdint.h>4#include <string.h>5#include <stdio.h>67#include "sha3/sph_blake.h"89//#define DEBUG_ALGO1011extern void pentablakehash(void *output, const void *input)12{13unsigned char _ALIGN(32) hash[128];14// same as uint32_t hashA[16], hashB[16];15#define hashB hash+641617sph_blake512_context ctx_blake;1819sph_blake512_init(&ctx_blake);20sph_blake512(&ctx_blake, input, 80);21sph_blake512_close(&ctx_blake, hash);2223sph_blake512(&ctx_blake, hash, 64);24sph_blake512_close(&ctx_blake, hashB);2526sph_blake512(&ctx_blake, hashB, 64);27sph_blake512_close(&ctx_blake, hash);2829sph_blake512(&ctx_blake, hash, 64);30sph_blake512_close(&ctx_blake, hashB);3132sph_blake512(&ctx_blake, hashB, 64);33sph_blake512_close(&ctx_blake, hash);3435memcpy(output, hash, 32);36}3738int scanhash_pentablake(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)39{40uint32_t _ALIGN(128) hash32[8];41uint32_t _ALIGN(128) endiandata[20];42uint32_t *pdata = work->data;43uint32_t *ptarget = work->target;4445uint32_t n = pdata[19] - 1;46const uint32_t first_nonce = pdata[19];47const uint32_t Htarg = ptarget[7];4849uint64_t htmax[] = {500,510xF,520xFF,530xFFF,540xFFFF,550x1000000056};57uint32_t masks[] = {580xFFFFFFFF,590xFFFFFFF0,600xFFFFFF00,610xFFFFF000,620xFFFF0000,63064};6566// we need bigendian data...67for (int i=0; i < 19; i++) {68be32enc(&endiandata[i], pdata[i]);69}7071#ifdef DEBUG_ALGO72if (Htarg != 0)73printf("[%d] Htarg=%X\n", thr_id, Htarg);74#endif75for (int m=0; m < 6; m++) {76if (Htarg <= htmax[m]) {77uint32_t mask = masks[m];78do {79pdata[19] = ++n;80be32enc(&endiandata[19], n);81pentablakehash(hash32, endiandata);82#ifndef DEBUG_ALGO83if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) {84work_set_target_ratio(work, hash32);85*hashes_done = n - first_nonce + 1;86return 1;87}88#else89if (!(n % 0x1000) && !thr_id) printf(".");90if (!(hash32[7] & mask)) {91printf("[%d]",thr_id);92if (fulltest(hash32, ptarget)) {93work_set_target_ratio(work, hash32);94*hashes_done = n - first_nonce + 1;95return 1;96}97}98#endif99} while (n < max_nonce && !work_restart[thr_id].restart);100// see blake.c if else to understand the loop on htmax => mask101break;102}103}104105*hashes_done = n - first_nonce + 1;106pdata[19] = n;107return 0;108}109110111