static int crypt_2(int *pcount, struct db_salt *salt) { int count = *pcount; int index = 0; #ifdef _OPENMP #pragma omp parallel for for (index = 0; index < count; index++) #endif { #if (AC_BUILT && HAVE_WHIRLPOOL) || \ (!AC_BUILT && OPENSSL_VERSION_NUMBER >= 0x10000000 && !HAVE_NO_SSL_WHIRLPOOL) WHIRLPOOL_CTX ctx; WHIRLPOOL_Init(&ctx); WHIRLPOOL_Update(&ctx, saved_key[index], strlen(saved_key[index])); WHIRLPOOL_Final((unsigned char*)crypt_out[index], &ctx); #else sph_whirlpool_context ctx; sph_whirlpool_init(&ctx); sph_whirlpool(&ctx, saved_key[index], strlen(saved_key[index])); sph_whirlpool_close(&ctx, (unsigned char*)crypt_out[index]); #endif } return count; }
void whirlpoolx_hash(const char* input, char* output) { unsigned char hash[64]; memset(hash, 0, sizeof(hash)); sph_whirlpool_context ctx_whirlpool; sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool(&ctx_whirlpool, input, 80); sph_whirlpool_close(&ctx_whirlpool, hash); unsigned char hash_xored[sizeof(hash) / 2]; unsigned int i = 0; for (; i < (sizeof(hash) / 2); i++) { hash_xored[i] = hash[i] ^ hash[i + ((sizeof(hash) / 2) / 2)] ; } memcpy(output, hash_xored, 32); }
inline void bitblockhash(void *state, const void *input) { init_Bhash_contexts(); Xhash_context_holder ctx; uint32_t hashA[16], hashB[16]; memcpy(&ctx, &base_contexts, sizeof(base_contexts)); sph_blake512 (&ctx.blake1, input, 80); sph_blake512_close (&ctx.blake1, hashA); sph_bmw512 (&ctx.bmw1, hashA, 64); sph_bmw512_close(&ctx.bmw1, hashB); sph_groestl512 (&ctx.groestl1, hashB, 64); sph_groestl512_close(&ctx.groestl1, hashA); sph_skein512 (&ctx.skein1, hashA, 64); sph_skein512_close(&ctx.skein1, hashB); sph_jh512 (&ctx.jh1, hashB, 64); sph_jh512_close(&ctx.jh1, hashA); sph_keccak512 (&ctx.keccak1, hashA, 64); sph_keccak512_close(&ctx.keccak1, hashB); sph_luffa512 (&ctx.luffa1, hashB, 64); sph_luffa512_close (&ctx.luffa1, hashA); sph_cubehash512 (&ctx.cubehash1, hashA, 64); sph_cubehash512_close(&ctx.cubehash1, hashB); sph_shavite512 (&ctx.shavite1, hashB, 64); sph_shavite512_close(&ctx.shavite1, hashA); sph_simd512 (&ctx.simd1, hashA, 64); sph_simd512_close(&ctx.simd1, hashB); sph_echo512 (&ctx.echo1, hashB, 64); sph_echo512_close(&ctx.echo1, hashA); sph_hamsi512 (&ctx.hamsi1, hashA, 64); sph_hamsi512_close(&ctx.hamsi1, hashB); sph_fugue512 (&ctx.fugue1, hashB, 64); sph_fugue512_close(&ctx.fugue1, hashA); sph_shabal512 (&ctx.shabal1, (const unsigned char*)hashA, 64); sph_shabal512_close(&ctx.shabal1, hashB); sph_whirlpool (&ctx.whirlpool1, hashB, 64); sph_whirlpool_close(&ctx.whirlpool1, hashA); memcpy(state, hashA, 32); }
void x15hash(void *output, const void *input) { uint32_t hash[16]; memset(hash, 0, 16 * sizeof(uint32_t)); sph_blake512(&ctx.blake, input, 80); sph_blake512_close(&ctx.blake, hash); sph_bmw512(&ctx.bmw, hash, 64); sph_bmw512_close(&ctx.bmw, hash); sph_groestl512(&ctx.groestl, hash, 64); sph_groestl512_close(&ctx.groestl, hash); sph_skein512(&ctx.skein, hash, 64); sph_skein512_close(&ctx.skein, hash); sph_jh512(&ctx.jh, hash, 64); sph_jh512_close(&ctx.jh, hash); sph_keccak512(&ctx.keccak, hash, 64); sph_keccak512_close(&ctx.keccak, hash); sph_luffa512(&ctx.luffa, hash, 64); sph_luffa512_close(&ctx.luffa, hash); sph_cubehash512(&ctx.cubehash, hash, 64); sph_cubehash512_close(&ctx.cubehash, hash); sph_shavite512(&ctx.shavite, hash, 64); sph_shavite512_close(&ctx.shavite, hash); sph_simd512(&ctx.simd, hash, 64); sph_simd512_close(&ctx.simd, hash); sph_echo512(&ctx.echo, hash, 64); sph_echo512_close(&ctx.echo, hash); sph_hamsi512(&ctx.hamsi, hash, 64); sph_hamsi512_close(&ctx.hamsi, hash); sph_fugue512(&ctx.fugue, hash, 64); sph_fugue512_close(&ctx.fugue, hash); sph_shabal512(&ctx.shabal, hash, 64); sph_shabal512_close(&ctx.shabal, hash); sph_whirlpool(&ctx.whirlpool, hash, 64); sph_whirlpool_close(&ctx.whirlpool, hash); memcpy(output, hash, 32); }
void whirlpoolxhash(void *output, const void *input) { uint32_t hash[16]; memset(hash, 0, 16 * sizeof(uint32_t)); sph_whirlpool(&ctx.whirlpool, input, 80); sph_whirlpool_close(&ctx.whirlpool, hash); for (uint32_t i = 0; i < 8; i++) { hash[i] = hash[i] ^ hash[i + 4]; } memcpy(output, hash, 32); }
void x16r_hash(void* output, const void* input) { uint32_t _ALIGN(128) hash[64/4]; sph_blake512_context ctx_blake; sph_bmw512_context ctx_bmw; sph_groestl512_context ctx_groestl; sph_skein512_context ctx_skein; sph_jh512_context ctx_jh; sph_keccak512_context ctx_keccak; sph_luffa512_context ctx_luffa1; sph_cubehash512_context ctx_cubehash1; sph_shavite512_context ctx_shavite1; sph_simd512_context ctx_simd1; sph_echo512_context ctx_echo1; sph_hamsi512_context ctx_hamsi1; sph_fugue512_context ctx_fugue1; sph_shabal512_context ctx_shabal1; sph_whirlpool_context ctx_whirlpool1; sph_sha512_context ctx_sha512; void *in = (void*) input; int size = 80; if (s_ntime == UINT32_MAX) { const uint8_t* in8 = (uint8_t*) input; getAlgoString(&in8[4], hashOrder); } for (int i = 0; i < 16; i++) { const char elem = hashOrder[i]; const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0'; switch (algo) { case BLAKE: sph_blake512_init(&ctx_blake); sph_blake512(&ctx_blake, in, size); sph_blake512_close(&ctx_blake, hash); break; case BMW: sph_bmw512_init(&ctx_bmw); sph_bmw512(&ctx_bmw, in, size); sph_bmw512_close(&ctx_bmw, hash); break; case GROESTL: sph_groestl512_init(&ctx_groestl); sph_groestl512(&ctx_groestl, in, size); sph_groestl512_close(&ctx_groestl, hash); break; case SKEIN: sph_skein512_init(&ctx_skein); sph_skein512(&ctx_skein, in, size); sph_skein512_close(&ctx_skein, hash); break; case JH: sph_jh512_init(&ctx_jh); sph_jh512(&ctx_jh, in, size); sph_jh512_close(&ctx_jh, hash); break; case KECCAK: sph_keccak512_init(&ctx_keccak); sph_keccak512(&ctx_keccak, in, size); sph_keccak512_close(&ctx_keccak, hash); break; case LUFFA: sph_luffa512_init(&ctx_luffa1); sph_luffa512(&ctx_luffa1, in, size); sph_luffa512_close(&ctx_luffa1, hash); break; case CUBEHASH: sph_cubehash512_init(&ctx_cubehash1); sph_cubehash512(&ctx_cubehash1, in, size); sph_cubehash512_close(&ctx_cubehash1, hash); break; case SHAVITE: sph_shavite512_init(&ctx_shavite1); sph_shavite512(&ctx_shavite1, in, size); sph_shavite512_close(&ctx_shavite1, hash); break; case SIMD: sph_simd512_init(&ctx_simd1); sph_simd512(&ctx_simd1, in, size); sph_simd512_close(&ctx_simd1, hash); break; case ECHO: sph_echo512_init(&ctx_echo1); sph_echo512(&ctx_echo1, in, size); sph_echo512_close(&ctx_echo1, hash); break; case HAMSI: sph_hamsi512_init(&ctx_hamsi1); sph_hamsi512(&ctx_hamsi1, in, size); sph_hamsi512_close(&ctx_hamsi1, hash); break; case FUGUE: sph_fugue512_init(&ctx_fugue1); sph_fugue512(&ctx_fugue1, in, size); sph_fugue512_close(&ctx_fugue1, hash); break; case SHABAL: sph_shabal512_init(&ctx_shabal1); sph_shabal512(&ctx_shabal1, in, size); sph_shabal512_close(&ctx_shabal1, hash); break; case WHIRLPOOL: sph_whirlpool_init(&ctx_whirlpool1); sph_whirlpool(&ctx_whirlpool1, in, size); sph_whirlpool_close(&ctx_whirlpool1, hash); break; case SHA512: sph_sha512_init(&ctx_sha512); sph_sha512(&ctx_sha512,(const void*) in, size); sph_sha512_close(&ctx_sha512,(void*) hash); break; } in = (void*) hash; size = 64; } memcpy(output, hash, 32); }
static #endif inline void hmq1725hash(void *state, const void *input) { sph_blake512_context ctx_blake; sph_bmw512_context ctx_bmw; sph_groestl512_context ctx_groestl; sph_jh512_context ctx_jh; sph_keccak512_context ctx_keccak; sph_skein512_context ctx_skein; sph_luffa512_context ctx_luffa; sph_cubehash512_context ctx_cubehash; sph_shavite512_context ctx_shavite; sph_simd512_context ctx_simd; sph_echo512_context ctx_echo; sph_hamsi512_context ctx_hamsi; sph_fugue512_context ctx_fugue; sph_shabal512_context ctx_shabal; sph_whirlpool_context ctx_whirlpool; sph_sha512_context ctx_sha2; sph_haval256_5_context ctx_haval; uint32_t mask = 24; uint32_t zero = 0; uint32_t hashA[16], hashB[16]; sph_bmw512_init(&ctx_bmw); sph_bmw512 (&ctx_bmw, input, 80); sph_bmw512_close (&ctx_bmw, hashA); //0 sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool (&ctx_whirlpool, hashA, 64); //0 sph_whirlpool_close(&ctx_whirlpool, hashB); //1 if ((hashB[0] & mask) != zero) //1 { sph_groestl512_init(&ctx_groestl); sph_groestl512 (&ctx_groestl, hashB, 64); //1 sph_groestl512_close(&ctx_groestl, hashA); //2 } else { sph_skein512_init(&ctx_skein); sph_skein512 (&ctx_skein, hashB, 64); //1 sph_skein512_close(&ctx_skein, hashA); //2 } sph_jh512_init(&ctx_jh); sph_jh512 (&ctx_jh, hashA, 64); //2 sph_jh512_close(&ctx_jh, hashB); //3 sph_keccak512_init(&ctx_keccak); sph_keccak512 (&ctx_keccak, hashB, 64); //3 sph_keccak512_close(&ctx_keccak, hashA); //4 if ((hashA[0] & mask) != zero) //4 { sph_blake512_init(&ctx_blake); sph_blake512 (&ctx_blake, hashA, 64); // sph_blake512_close(&ctx_blake, hashB); //5 } else { sph_bmw512_init(&ctx_bmw); sph_bmw512 (&ctx_bmw, hashA, 64); //4 sph_bmw512_close(&ctx_bmw, hashB); //5 } sph_luffa512_init(&ctx_luffa); sph_luffa512 (&ctx_luffa,hashB, 64); //5 sph_luffa512_close(&ctx_luffa, hashA); //6 sph_cubehash512_init(&ctx_cubehash); sph_cubehash512 (&ctx_cubehash, hashA, 64); //6 sph_cubehash512_close(&ctx_cubehash, hashB); //7 if ((hashB[0] & mask) != zero) //7 { sph_keccak512_init(&ctx_keccak); sph_keccak512 (&ctx_keccak, hashB, 64); // sph_keccak512_close(&ctx_keccak, hashA); //8 } else { sph_jh512_init(&ctx_jh); sph_jh512 (&ctx_jh, hashB, 64); //7 sph_jh512_close(&ctx_jh, hashA); //8 } sph_shavite512_init(&ctx_shavite); sph_shavite512 (&ctx_shavite,hashA, 64); //5 sph_shavite512_close(&ctx_shavite, hashB); //6 sph_simd512_init(&ctx_simd); sph_simd512 (&ctx_simd, hashB, 64); //6 sph_simd512_close(&ctx_simd, hashA); //7 if ((hashA[0] & mask) != zero) //4 { sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool (&ctx_whirlpool, hashA, 64); // sph_whirlpool_close(&ctx_whirlpool, hashB); //5 } else { sph_haval256_5_init(&ctx_haval); sph_haval256_5 (&ctx_haval, hashA, 64); //4 sph_haval256_5_close(&ctx_haval, hashB); //5 memset(&hashB[8], 0, 32); } sph_echo512_init(&ctx_echo); sph_echo512 (&ctx_echo,hashB, 64); //5 sph_echo512_close(&ctx_echo, hashA); //6 sph_blake512_init(&ctx_blake); sph_blake512 (&ctx_blake, hashA, 64); //6 sph_blake512_close(&ctx_blake, hashB); //7 if ((hashB[0] & mask) != zero) //7 { sph_shavite512_init(&ctx_shavite); sph_shavite512 (&ctx_shavite, hashB, 64); // sph_shavite512_close(&ctx_shavite, hashA); //8 } else { sph_luffa512_init(&ctx_luffa); sph_luffa512 (&ctx_luffa, hashB, 64); //7 sph_luffa512_close(&ctx_luffa, hashA); //8 } sph_hamsi512_init(&ctx_hamsi); sph_hamsi512 (&ctx_hamsi,hashA, 64); //5 sph_hamsi512_close(&ctx_hamsi, hashB); //6 sph_fugue512_init(&ctx_fugue); sph_fugue512 (&ctx_fugue, hashB, 64); //6 sph_fugue512_close(&ctx_fugue, hashA); //7 if ((hashA[0] & mask) != zero) //4 { sph_echo512_init(&ctx_echo); sph_echo512 (&ctx_echo, hashA, 64); // sph_echo512_close(&ctx_echo, hashB); //5 } else { sph_simd512_init(&ctx_simd); sph_simd512 (&ctx_simd, hashA, 64); //4 sph_simd512_close(&ctx_simd, hashB); //5 } sph_shabal512_init(&ctx_shabal); sph_shabal512 (&ctx_shabal,hashB, 64); //5 sph_shabal512_close(&ctx_shabal, hashA); //6 sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool (&ctx_whirlpool, hashA, 64); //6 sph_whirlpool_close(&ctx_whirlpool, hashB); //7 if ((hashB[0] & mask) != zero) //7 { sph_fugue512_init(&ctx_fugue); sph_fugue512 (&ctx_fugue, hashB, 64); // sph_fugue512_close(&ctx_fugue, hashA); //8 } else { sph_sha512_init(&ctx_sha2); sph_sha512 (&ctx_sha2, hashB, 64); //7 sph_sha512_close(&ctx_sha2, hashA); //8 } sph_groestl512_init(&ctx_groestl); sph_groestl512 (&ctx_groestl,hashA, 64); //5 sph_groestl512_close(&ctx_groestl, hashB); //6 sph_sha512_init(&ctx_sha2); sph_sha512 (&ctx_sha2, hashB, 64); //6 sph_sha512_close(&ctx_sha2, hashA); //7 if ((hashA[0] & mask) != zero) //4 { sph_haval256_5_init(&ctx_haval); sph_haval256_5 (&ctx_haval, hashA, 64); // sph_haval256_5_close(&ctx_haval, hashB); //5 memset(&hashB[8], 0, 32); } else { sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool (&ctx_whirlpool, hashA, 64); //4 sph_whirlpool_close(&ctx_whirlpool, hashB); //5 } sph_bmw512_init(&ctx_bmw); sph_bmw512 (&ctx_bmw,hashB, 64); //5 sph_bmw512_close(&ctx_bmw, hashA); //6 memcpy(state, hashA, 32); }
void X15_hash(const char* input, char* output) { sph_blake512_context ctx_blake; sph_bmw512_context ctx_bmw; sph_groestl512_context ctx_groestl; sph_skein512_context ctx_skein; sph_jh512_context ctx_jh; sph_keccak512_context ctx_keccak; sph_luffa512_context ctx_luffa1; sph_cubehash512_context ctx_cubehash1; sph_shavite512_context ctx_shavite1; sph_simd512_context ctx_simd1; sph_echo512_context ctx_echo1; sph_hamsi512_context ctx_hamsi1; sph_fugue512_context ctx_fugue1; sph_shabal512_context ctx_shabal1; sph_whirlpool_context ctx_whirlpool1; //these uint512 in the c++ source of the client are backed by an array of uint32 uint32_t hashA[16], hashB[16]; sph_blake512_init(&ctx_blake); sph_blake512 (&ctx_blake, input, 80); sph_blake512_close (&ctx_blake, hashA); sph_bmw512_init(&ctx_bmw); sph_bmw512 (&ctx_bmw, hashA, 64); sph_bmw512_close(&ctx_bmw, hashB); sph_groestl512_init(&ctx_groestl); sph_groestl512 (&ctx_groestl, hashB, 64); sph_groestl512_close(&ctx_groestl, hashA); sph_skein512_init(&ctx_skein); sph_skein512 (&ctx_skein, hashA, 64); sph_skein512_close (&ctx_skein, hashB); sph_jh512_init(&ctx_jh); sph_jh512 (&ctx_jh, hashB, 64); sph_jh512_close(&ctx_jh, hashA); sph_keccak512_init(&ctx_keccak); sph_keccak512 (&ctx_keccak, hashA, 64); sph_keccak512_close(&ctx_keccak, hashB); sph_luffa512_init (&ctx_luffa1); sph_luffa512 (&ctx_luffa1, hashB, 64); sph_luffa512_close (&ctx_luffa1, hashA); sph_cubehash512_init (&ctx_cubehash1); sph_cubehash512 (&ctx_cubehash1, hashA, 64); sph_cubehash512_close(&ctx_cubehash1, hashB); sph_shavite512_init (&ctx_shavite1); sph_shavite512 (&ctx_shavite1, hashB, 64); sph_shavite512_close(&ctx_shavite1, hashA); sph_simd512_init (&ctx_simd1); sph_simd512 (&ctx_simd1, hashA, 64); sph_simd512_close(&ctx_simd1, hashB); sph_echo512_init (&ctx_echo1); sph_echo512 (&ctx_echo1, hashB, 64); sph_echo512_close(&ctx_echo1, hashA); sph_hamsi512_init (&ctx_hamsi1); sph_hamsi512 (&ctx_hamsi1, hashA, 64); sph_hamsi512_close(&ctx_hamsi1, hashB); sph_fugue512_init (&ctx_fugue1); sph_fugue512 (&ctx_fugue1, hashB, 64); sph_fugue512_close(&ctx_fugue1, hashA); sph_shabal512_init (&ctx_shabal1); sph_shabal512 (&ctx_shabal1, hashA, 64); sph_shabal512_close(&ctx_shabal1, hashB); sph_whirlpool_init (&ctx_whirlpool1); sph_whirlpool (&ctx_whirlpool1, hashB, 64); sph_whirlpool_close(&ctx_whirlpool1, hashA); memcpy(output, hashA, 32); }
int scanhash_m7m_hash(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint64_t max_nonce, unsigned long *hashes_done) { uint32_t data[32] __attribute__((aligned(128))); uint32_t *data_p64 = data + (M7_MIDSTATE_LEN / sizeof(data[0])); uint32_t hash[8] __attribute__((aligned(32))); uint8_t bhash[7][64] __attribute__((aligned(32))); uint32_t n = pdata[19] - 1; const uint32_t first_nonce = pdata[19]; char data_str[161], hash_str[65], target_str[65]; uint8_t *bdata = 0; mpz_t bns[8]; int rc = 0; int bytes, nnNonce2; mpz_t product; mpz_init(product); for(int i=0; i < 8; i++){ mpz_init(bns[i]); } memcpy(data, pdata, 80); sph_sha256_context ctx_final_sha256; sph_sha256_context ctx_sha256; sph_sha512_context ctx_sha512; sph_keccak512_context ctx_keccak; sph_whirlpool_context ctx_whirlpool; sph_haval256_5_context ctx_haval; sph_tiger_context ctx_tiger; sph_ripemd160_context ctx_ripemd; sph_sha256_init(&ctx_sha256); sph_sha256 (&ctx_sha256, data, M7_MIDSTATE_LEN); sph_sha512_init(&ctx_sha512); sph_sha512 (&ctx_sha512, data, M7_MIDSTATE_LEN); sph_keccak512_init(&ctx_keccak); sph_keccak512 (&ctx_keccak, data, M7_MIDSTATE_LEN); sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool (&ctx_whirlpool, data, M7_MIDSTATE_LEN); sph_haval256_5_init(&ctx_haval); sph_haval256_5 (&ctx_haval, data, M7_MIDSTATE_LEN); sph_tiger_init(&ctx_tiger); sph_tiger (&ctx_tiger, data, M7_MIDSTATE_LEN); sph_ripemd160_init(&ctx_ripemd); sph_ripemd160 (&ctx_ripemd, data, M7_MIDSTATE_LEN); sph_sha256_context ctx2_sha256; sph_sha512_context ctx2_sha512; sph_keccak512_context ctx2_keccak; sph_whirlpool_context ctx2_whirlpool; sph_haval256_5_context ctx2_haval; sph_tiger_context ctx2_tiger; sph_ripemd160_context ctx2_ripemd; do { data[19] = ++n; nnNonce2 = (int)(data[19]/2); memset(bhash, 0, 7 * 64); ctx2_sha256 = ctx_sha256; sph_sha256 (&ctx2_sha256, data_p64, 80 - M7_MIDSTATE_LEN); sph_sha256_close(&ctx2_sha256, (void*)(bhash[0])); ctx2_sha512 = ctx_sha512; sph_sha512 (&ctx2_sha512, data_p64, 80 - M7_MIDSTATE_LEN); sph_sha512_close(&ctx2_sha512, (void*)(bhash[1])); ctx2_keccak = ctx_keccak; sph_keccak512 (&ctx2_keccak, data_p64, 80 - M7_MIDSTATE_LEN); sph_keccak512_close(&ctx2_keccak, (void*)(bhash[2])); ctx2_whirlpool = ctx_whirlpool; sph_whirlpool (&ctx2_whirlpool, data_p64, 80 - M7_MIDSTATE_LEN); sph_whirlpool_close(&ctx2_whirlpool, (void*)(bhash[3])); ctx2_haval = ctx_haval; sph_haval256_5 (&ctx2_haval, data_p64, 80 - M7_MIDSTATE_LEN); sph_haval256_5_close(&ctx2_haval, (void*)(bhash[4])); ctx2_tiger = ctx_tiger; sph_tiger (&ctx2_tiger, data_p64, 80 - M7_MIDSTATE_LEN); sph_tiger_close(&ctx2_tiger, (void*)(bhash[5])); ctx2_ripemd = ctx_ripemd; sph_ripemd160 (&ctx2_ripemd, data_p64, 80 - M7_MIDSTATE_LEN); sph_ripemd160_close(&ctx2_ripemd, (void*)(bhash[6])); for(int i=0; i < 7; i++){ set_one_if_zero(bhash[i]); mpz_set_uint512(bns[i],bhash[i]); } mpz_set_ui(bns[7],0); for(int i=0; i < 7; i++){ mpz_add(bns[7], bns[7], bns[i]); } mpz_set_ui(product,1); for(int i=0; i < 8; i++){ mpz_mul(product,product,bns[i]); } mpz_pow_ui(product, product, 2); bytes = mpz_sizeinbase(product, 256); bdata = (uint8_t *)realloc(bdata, bytes); mpz_export((void *)bdata, NULL, -1, 1, 0, 0, product); sph_sha256_init(&ctx_final_sha256); sph_sha256 (&ctx_final_sha256, bdata, bytes); sph_sha256_close(&ctx_final_sha256, (void*)(hash)); int digits=(int)((sqrt((double)(nnNonce2))*(1.+EPS))/9000+75); int iterations=20; mpf_set_default_prec((long int)(digits*BITS_PER_DIGIT+16)); mpz_t magipi; mpz_t magisw; mpf_t magifpi; mpf_t mpa1, mpb1, mpt1, mpp1; mpf_t mpa2, mpb2, mpt2, mpp2; mpf_t mpsft; mpz_init(magipi); mpz_init(magisw); mpf_init(magifpi); mpf_init(mpsft); mpf_init(mpa1); mpf_init(mpb1); mpf_init(mpt1); mpf_init(mpp1); mpf_init(mpa2); mpf_init(mpb2); mpf_init(mpt2); mpf_init(mpp2); uint32_t usw_; usw_ = sw_(nnNonce2, SW_DIVS); if (usw_ < 1) usw_ = 1; mpz_set_ui(magisw, usw_); uint32_t mpzscale=mpz_size(magisw); for(int i=0; i < NM7M; i++){ if (mpzscale > 1000) { mpzscale = 1000; } else if (mpzscale < 1) { mpzscale = 1; } mpf_set_ui(mpa1, 1); mpf_set_ui(mpb1, 2); mpf_set_d(mpt1, 0.25*mpzscale); mpf_set_ui(mpp1, 1); mpf_sqrt(mpb1, mpb1); mpf_ui_div(mpb1, 1, mpb1); mpf_set_ui(mpsft, 10); for(int j=0; j <= iterations; j++){ mpf_add(mpa2, mpa1, mpb1); mpf_div_ui(mpa2, mpa2, 2); mpf_mul(mpb2, mpa1, mpb1); mpf_abs(mpb2, mpb2); mpf_sqrt(mpb2, mpb2); mpf_sub(mpt2, mpa1, mpa2); mpf_abs(mpt2, mpt2); mpf_sqrt(mpt2, mpt2); mpf_mul(mpt2, mpt2, mpp1); mpf_sub(mpt2, mpt1, mpt2); mpf_mul_ui(mpp2, mpp1, 2); mpf_swap(mpa1, mpa2); mpf_swap(mpb1, mpb2); mpf_swap(mpt1, mpt2); mpf_swap(mpp1, mpp2); } mpf_add(magifpi, mpa1, mpb1); mpf_pow_ui(magifpi, magifpi, 2); mpf_div_ui(magifpi, magifpi, 4); mpf_abs(mpt1, mpt1); mpf_div(magifpi, magifpi, mpt1); mpf_pow_ui(mpsft, mpsft, digits/2); mpf_mul(magifpi, magifpi, mpsft); mpz_set_f(magipi, magifpi); mpz_add(product,product,magipi); mpz_add(product,product,magisw); mpz_set_uint256(bns[0], (void*)(hash)); mpz_add(bns[7], bns[7], bns[0]); mpz_mul(product,product,bns[7]); mpz_cdiv_q (product, product, bns[0]); if (mpz_sgn(product) <= 0) mpz_set_ui(product,1); bytes = mpz_sizeinbase(product, 256); mpzscale=bytes; bdata = (uint8_t *)realloc(bdata, bytes); mpz_export(bdata, NULL, -1, 1, 0, 0, product); sph_sha256_init(&ctx_final_sha256); sph_sha256 (&ctx_final_sha256, bdata, bytes); sph_sha256_close(&ctx_final_sha256, (void*)(hash)); } mpz_clear(magipi); mpz_clear(magisw); mpf_clear(magifpi); mpf_clear(mpsft); mpf_clear(mpa1); mpf_clear(mpb1); mpf_clear(mpt1); mpf_clear(mpp1); mpf_clear(mpa2); mpf_clear(mpb2); mpf_clear(mpt2); mpf_clear(mpp2); rc = fulltest_m7hash(hash, ptarget); if (rc) { if (opt_debug) { bin2hex(hash_str, (unsigned char *)hash, 32); bin2hex(target_str, (unsigned char *)ptarget, 32); bin2hex(data_str, (unsigned char *)data, 80); applog(LOG_DEBUG, "DEBUG: [%d thread] Found share!\ndata %s\nhash %s\ntarget %s", thr_id, data_str, hash_str, target_str); } pdata[19] = data[19]; goto out; } } while (n < max_nonce && !work_restart[thr_id].restart); pdata[19] = n; out: for(int i=0; i < 8; i++){ mpz_clear(bns[i]); } mpz_clear(product); free(bdata); *hashes_done = n - first_nonce + 1; return rc; }
int scanhash_m7hash(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint64_t max_nonce, unsigned long *hashes_done) { uint32_t data[32] __attribute__((aligned(128))); uint32_t *data_p64 = data + (M7_MIDSTATE_LEN / sizeof(data[0])); uint32_t hash[8] __attribute__((aligned(32))); uint8_t bhash[7][64] __attribute__((aligned(32))); uint32_t hashtest[8] __attribute__((aligned(32))); uint32_t n = pdata[29] - 1; const uint32_t first_nonce = pdata[29]; char data_str[245], hash_str[65], target_str[65]; uint8_t *bdata = 0; mpz_t bns[7]; int rc = 0; for(int i=0; i < 7; i++){ mpz_init(bns[i]); } memcpy(data, pdata, 122); sph_sha256_context ctx_final_sha256; sph_sha256_context ctx_sha256; sph_sha512_context ctx_sha512; sph_keccak512_context ctx_keccak; sph_whirlpool_context ctx_whirlpool; sph_haval256_5_context ctx_haval; sph_tiger_context ctx_tiger; sph_ripemd160_context ctx_ripemd; sph_sha256_init(&ctx_sha256); sph_sha256 (&ctx_sha256, data, M7_MIDSTATE_LEN); sph_sha512_init(&ctx_sha512); sph_sha512 (&ctx_sha512, data, M7_MIDSTATE_LEN); sph_keccak512_init(&ctx_keccak); sph_keccak512 (&ctx_keccak, data, M7_MIDSTATE_LEN); sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool (&ctx_whirlpool, data, M7_MIDSTATE_LEN); sph_haval256_5_init(&ctx_haval); sph_haval256_5 (&ctx_haval, data, M7_MIDSTATE_LEN); sph_tiger_init(&ctx_tiger); sph_tiger (&ctx_tiger, data, M7_MIDSTATE_LEN); sph_ripemd160_init(&ctx_ripemd); sph_ripemd160 (&ctx_ripemd, data, M7_MIDSTATE_LEN); sph_sha256_context ctx2_sha256; sph_sha512_context ctx2_sha512; sph_keccak512_context ctx2_keccak; sph_whirlpool_context ctx2_whirlpool; sph_haval256_5_context ctx2_haval; sph_tiger_context ctx2_tiger; sph_ripemd160_context ctx2_ripemd; do { data[29] = ++n; memset(bhash, 0, 7 * 64); ctx2_sha256 = ctx_sha256; sph_sha256 (&ctx2_sha256, data_p64, 122 - M7_MIDSTATE_LEN); sph_sha256_close(&ctx2_sha256, (void*)(bhash[0])); ctx2_sha512 = ctx_sha512; sph_sha512 (&ctx2_sha512, data_p64, 122 - M7_MIDSTATE_LEN); sph_sha512_close(&ctx2_sha512, (void*)(bhash[1])); ctx2_keccak = ctx_keccak; sph_keccak512 (&ctx2_keccak, data_p64, 122 - M7_MIDSTATE_LEN); sph_keccak512_close(&ctx2_keccak, (void*)(bhash[2])); ctx2_whirlpool = ctx_whirlpool; sph_whirlpool (&ctx2_whirlpool, data_p64, 122 - M7_MIDSTATE_LEN); sph_whirlpool_close(&ctx2_whirlpool, (void*)(bhash[3])); ctx2_haval = ctx_haval; sph_haval256_5 (&ctx2_haval, data_p64, 122 - M7_MIDSTATE_LEN); sph_haval256_5_close(&ctx2_haval, (void*)(bhash[4])); ctx2_tiger = ctx_tiger; sph_tiger (&ctx2_tiger, data_p64, 122 - M7_MIDSTATE_LEN); sph_tiger_close(&ctx2_tiger, (void*)(bhash[5])); ctx2_ripemd = ctx_ripemd; sph_ripemd160 (&ctx2_ripemd, data_p64, 122 - M7_MIDSTATE_LEN); sph_ripemd160_close(&ctx2_ripemd, (void*)(bhash[6])); for(int i=0; i < 7; i++){ set_one_if_zero(bhash[i]); mpz_set_uint512(bns[i],bhash[i]); } for(int i=6; i > 0; i--){ mpz_mul(bns[i-1], bns[i-1], bns[i]); } int bytes = mpz_sizeinbase(bns[0], 256); bdata = (uint8_t *)realloc(bdata, bytes); mpz_export((void *)bdata, NULL, -1, 1, 0, 0, bns[0]); sph_sha256_init(&ctx_final_sha256); sph_sha256 (&ctx_final_sha256, bdata, bytes); sph_sha256_close(&ctx_final_sha256, (void*)(hash)); rc = fulltest_m7hash(hash, ptarget); if (rc) { if (opt_debug) { bin2hex(hash_str, (unsigned char *)hash, 32); bin2hex(target_str, (unsigned char *)ptarget, 32); bin2hex(data_str, (unsigned char *)data, 122); applog(LOG_DEBUG, "DEBUG: [%d thread] Found share!\ndata %s\nhash %s\ntarget %s", thr_id, data_str, hash_str, target_str); } pdata[29] = data[29]; goto out; } } while (n < max_nonce && !work_restart[thr_id].restart); pdata[29] = n; out: for(int i=0; i < 7; i++){ mpz_clear(bns[i]); } *hashes_done = n - first_nonce + 1; free(bdata); return rc; }
static void x15hash(void *output, const void *input) { unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; #define hashB hash+64 x15_ctx_holder ctx; memcpy( &ctx, &x15_ctx, sizeof(x15_ctx) ); #ifdef NO_AES_NI grsoState sts_grs; #endif unsigned char hashbuf[128]; size_t hashptr; sph_u64 hashctA; sph_u64 hashctB; //---blake1--- DECL_BLK; BLK_I; BLK_W; BLK_C; //---bmw2--- DECL_BMW; BMW_I; BMW_U; #define M(x) sph_dec64le_aligned(data + 8 * (x)) #define H(x) (h[x]) #define dH(x) (dh[x]) BMW_C; #undef M #undef H #undef dH //---groestl---- #ifdef NO_AES_NI GRS_I; GRS_U; GRS_C; // sph_groestl512(&ctx.groestl, hash, 64); // sph_groestl512_close(&ctx.groestl, hash); #else update_groestl( &ctx.groestl, (char*)hash,512); final_groestl( &ctx.groestl, (char*)hash); #endif //---skein4--- DECL_SKN; SKN_I; SKN_U; SKN_C; //---jh5------ DECL_JH; JH_H; //---keccak6--- DECL_KEC; KEC_I; KEC_U; KEC_C; //--- luffa7 update_luffa( &ctx.luffa, (const BitSequence*)hash,512); final_luffa( &ctx.luffa, (BitSequence*)hashB); // 8 Cube cubehashUpdate( &ctx.cubehash, (const byte*) hashB,64); cubehashDigest( &ctx.cubehash, (byte*)hash); // 9 Shavite sph_shavite512( &ctx.shavite, hash, 64); sph_shavite512_close( &ctx.shavite, hashB); // 10 Simd update_sd( &ctx.simd, (const BitSequence *)hashB,512); final_sd( &ctx.simd, (BitSequence *)hash); //11---echo--- #ifdef NO_AES_NI sph_echo512(&ctx.echo, hash, 64); sph_echo512_close(&ctx.echo, hashB); #else update_echo ( &ctx.echo, (const BitSequence *) hash, 512); final_echo( &ctx.echo, (BitSequence *) hashB); #endif // X13 algos // 12 Hamsi sph_hamsi512(&ctx.hamsi, hashB, 64); sph_hamsi512_close(&ctx.hamsi, hash); // 13 Fugue sph_fugue512(&ctx.fugue, hash, 64); sph_fugue512_close(&ctx.fugue, hashB); // X14 Shabal sph_shabal512(&ctx.shabal, hashB, 64); sph_shabal512_close(&ctx.shabal, hash); // X15 Whirlpool sph_whirlpool(&ctx.whirlpool, hash, 64); sph_whirlpool_close(&ctx.whirlpool, hashB); asm volatile ("emms"); memcpy(output, hashB, 32); }
void x15hash_alt(void *output, const void *input) { unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; #define hashB hash+64 sph_blake512_context ctx_blake; sph_bmw512_context ctx_bmw; sph_groestl512_context ctx_groestl; sph_jh512_context ctx_jh; sph_keccak512_context ctx_keccak; sph_skein512_context ctx_skein; sph_luffa512_context ctx_luffa; sph_cubehash512_context ctx_cubehash; sph_shavite512_context ctx_shavite; sph_simd512_context ctx_simd; sph_echo512_context ctx_echo; sph_hamsi512_context ctx_hamsi; sph_fugue512_context ctx_fugue; sph_shabal512_context ctx_shabal; sph_whirlpool_context ctx_whirlpool; sph_blake512_init(&ctx_blake); sph_blake512(&ctx_blake, input, 80); sph_blake512_close(&ctx_blake, hash); sph_bmw512_init(&ctx_bmw); sph_bmw512(&ctx_bmw, hash, 64); sph_bmw512_close(&ctx_bmw, hashB); sph_groestl512_init(&ctx_groestl); sph_groestl512(&ctx_groestl, hashB, 64); sph_groestl512_close(&ctx_groestl, hash); sph_skein512_init(&ctx_skein); sph_skein512(&ctx_skein, hash, 64); sph_skein512_close(&ctx_skein, hashB); sph_jh512_init(&ctx_jh); sph_jh512(&ctx_jh, hashB, 64); sph_jh512_close(&ctx_jh, hash); sph_keccak512_init(&ctx_keccak); sph_keccak512(&ctx_keccak, hash, 64); sph_keccak512_close(&ctx_keccak, hashB); sph_luffa512_init(&ctx_luffa); sph_luffa512(&ctx_luffa, hashB, 64); sph_luffa512_close(&ctx_luffa, hash); sph_cubehash512_init(&ctx_cubehash); sph_cubehash512(&ctx_cubehash, hash, 64); sph_cubehash512_close(&ctx_cubehash, hashB); sph_shavite512_init(&ctx_shavite); sph_shavite512(&ctx_shavite, hashB, 64); sph_shavite512_close(&ctx_shavite, hash); sph_simd512_init(&ctx_simd); sph_simd512(&ctx_simd, hash, 64); sph_simd512_close(&ctx_simd, hashB); sph_echo512_init(&ctx_echo); sph_echo512(&ctx_echo, hashB, 64); sph_echo512_close(&ctx_echo, hash); sph_hamsi512_init(&ctx_hamsi); sph_hamsi512(&ctx_hamsi, hash, 64); sph_hamsi512_close(&ctx_hamsi, hashB); sph_fugue512_init(&ctx_fugue); sph_fugue512(&ctx_fugue, hashB, 64); sph_fugue512_close(&ctx_fugue, hash); sph_shabal512_init(&ctx_shabal); sph_shabal512(&ctx_shabal, hash, 64); sph_shabal512_close(&ctx_shabal, hashB); sph_whirlpool_init(&ctx_whirlpool); sph_whirlpool(&ctx_whirlpool, hashB, 64); sph_whirlpool_close(&ctx_whirlpool, hash); memcpy(output, hash, 32); }
//#define SW_MAX 1000 void m7magi_hash(const char* input, char* output) { unsigned int nnNonce; uint32_t pdata[32]; memcpy(pdata, input, 80); // memcpy(&nnNonce, input+76, 4); int i, j, bytes, nnNonce2; nnNonce2 = (int)(pdata[19]/2); size_t sz = 80; uint8_t bhash[7][64]; uint32_t hash[8]; memset(bhash, 0, 7 * 64); sph_sha256_context ctx_final_sha256; sph_sha256_context ctx_sha256; sph_sha512_context ctx_sha512; sph_keccak512_context ctx_keccak; sph_whirlpool_context ctx_whirlpool; sph_haval256_5_context ctx_haval; sph_tiger_context ctx_tiger; sph_ripemd160_context ctx_ripemd; sph_sha256_init(&ctx_sha256); // ZSHA256; sph_sha256 (&ctx_sha256, input, sz); sph_sha256_close(&ctx_sha256, (void*)(bhash[0])); sph_sha512_init(&ctx_sha512); // ZSHA512; sph_sha512 (&ctx_sha512, input, sz); sph_sha512_close(&ctx_sha512, (void*)(bhash[1])); sph_keccak512_init(&ctx_keccak); // ZKECCAK; sph_keccak512 (&ctx_keccak, input, sz); sph_keccak512_close(&ctx_keccak, (void*)(bhash[2])); sph_whirlpool_init(&ctx_whirlpool); // ZWHIRLPOOL; sph_whirlpool (&ctx_whirlpool, input, sz); sph_whirlpool_close(&ctx_whirlpool, (void*)(bhash[3])); sph_haval256_5_init(&ctx_haval); // ZHAVAL; sph_haval256_5 (&ctx_haval, input, sz); sph_haval256_5_close(&ctx_haval, (void*)(bhash[4])); sph_tiger_init(&ctx_tiger); // ZTIGER; sph_tiger (&ctx_tiger, input, sz); sph_tiger_close(&ctx_tiger, (void*)(bhash[5])); sph_ripemd160_init(&ctx_ripemd); // ZRIPEMD; sph_ripemd160 (&ctx_ripemd, input, sz); sph_ripemd160_close(&ctx_ripemd, (void*)(bhash[6])); // printf("%s\n", hash[6].GetHex().c_str()); mpz_t bns[8]; for(i=0; i < 8; i++){ mpz_init(bns[i]); } //Take care of zeros and load gmp for(i=0; i < 7; i++){ set_one_if_zero(bhash[i]); mpz_set_uint512(bns[i],bhash[i]); } mpz_set_ui(bns[7],0); for(i=0; i < 7; i++) mpz_add(bns[7], bns[7], bns[i]); mpz_t product; mpz_init(product); mpz_set_ui(product,1); // mpz_pow_ui(bns[7], bns[7], 2); for(i=0; i < 8; i++){ mpz_mul(product,product,bns[i]); } mpz_pow_ui(product, product, 2); bytes = mpz_sizeinbase(product, 256); // printf("M7M data space: %iB\n", bytes); char *data = (char*)malloc(bytes); mpz_export(data, NULL, -1, 1, 0, 0, product); sph_sha256_init(&ctx_final_sha256); // ZSHA256; sph_sha256 (&ctx_final_sha256, data, bytes); sph_sha256_close(&ctx_final_sha256, (void*)(hash)); free(data); int digits=(int)((sqrt((double)(nnNonce2))*(1.+EPS))/9000+75); // int iterations=(int)((sqrt((double)(nnNonce2))+EPS)/500+350); // <= 500 // int digits=100; int iterations=20; // <= 500 mpf_set_default_prec((long int)(digits*BITS_PER_DIGIT+16)); mpz_t magipi; mpz_t magisw; mpf_t magifpi; mpf_t mpa1, mpb1, mpt1, mpp1; mpf_t mpa2, mpb2, mpt2, mpp2; mpf_t mpsft; mpz_init(magipi); mpz_init(magisw); mpf_init(magifpi); mpf_init(mpsft); mpf_init(mpa1); mpf_init(mpb1); mpf_init(mpt1); mpf_init(mpp1); mpf_init(mpa2); mpf_init(mpb2); mpf_init(mpt2); mpf_init(mpp2); uint32_t usw_; usw_ = sw_(nnNonce2, SW_DIVS); if (usw_ < 1) usw_ = 1; // if(fDebugMagi) printf("usw_: %d\n", usw_); mpz_set_ui(magisw, usw_); uint32_t mpzscale=mpz_size(magisw); for(i=0; i < NM7M; i++) { if (mpzscale > 1000) { mpzscale = 1000; } else if (mpzscale < 1) { mpzscale = 1; } // if(fDebugMagi) printf("mpzscale: %d\n", mpzscale); mpf_set_ui(mpa1, 1); mpf_set_ui(mpb1, 2); mpf_set_d(mpt1, 0.25*mpzscale); mpf_set_ui(mpp1, 1); mpf_sqrt(mpb1, mpb1); mpf_ui_div(mpb1, 1, mpb1); mpf_set_ui(mpsft, 10); for(j=0; j <= iterations; j++) { mpf_add(mpa2, mpa1, mpb1); mpf_div_ui(mpa2, mpa2, 2); mpf_mul(mpb2, mpa1, mpb1); mpf_abs(mpb2, mpb2); mpf_sqrt(mpb2, mpb2); mpf_sub(mpt2, mpa1, mpa2); mpf_abs(mpt2, mpt2); mpf_sqrt(mpt2, mpt2); mpf_mul(mpt2, mpt2, mpp1); mpf_sub(mpt2, mpt1, mpt2); mpf_mul_ui(mpp2, mpp1, 2); mpf_swap(mpa1, mpa2); mpf_swap(mpb1, mpb2); mpf_swap(mpt1, mpt2); mpf_swap(mpp1, mpp2); } mpf_add(magifpi, mpa1, mpb1); mpf_pow_ui(magifpi, magifpi, 2); mpf_div_ui(magifpi, magifpi, 4); mpf_abs(mpt1, mpt1); mpf_div(magifpi, magifpi, mpt1); // mpf_out_str(stdout, 10, digits+2, magifpi); mpf_pow_ui(mpsft, mpsft, digits/2); mpf_mul(magifpi, magifpi, mpsft); mpz_set_f(magipi, magifpi); //mpz_set_ui(magipi,1); mpz_add(product,product,magipi); mpz_add(product,product,magisw); mpz_set_uint256(bns[0], (void*)(hash)); mpz_add(bns[7], bns[7], bns[0]); mpz_mul(product,product,bns[7]); mpz_cdiv_q (product, product, bns[0]); if (mpz_sgn(product) <= 0) mpz_set_ui(product,1); bytes = mpz_sizeinbase(product, 256); mpzscale=bytes; // printf("M7M data space: %iB\n", bytes); char *bdata = (char*)malloc(bytes); mpz_export(bdata, NULL, -1, 1, 0, 0, product); sph_sha256_init(&ctx_final_sha256); // ZSHA256; sph_sha256 (&ctx_final_sha256, bdata, bytes); sph_sha256_close(&ctx_final_sha256, (void*)(hash)); free(bdata); } //Free the memory for(i=0; i < 8; i++){ mpz_clear(bns[i]); } // mpz_clear(dSpectralWeight); mpz_clear(product); mpz_clear(magipi); mpz_clear(magisw); mpf_clear(magifpi); mpf_clear(mpsft); mpf_clear(mpa1); mpf_clear(mpb1); mpf_clear(mpt1); mpf_clear(mpp1); mpf_clear(mpa2); mpf_clear(mpb2); mpf_clear(mpt2); mpf_clear(mpp2); memcpy(output, hash, 32); }