Blob PBKDF2(PseudoRandomFunction& prf, const ConstBuf& password, const ConstBuf& salt, uint32_t c, size_t dkLen) { size_t hlen = prf.HashSize(); if (dkLen > uint64_t(hlen) * uint32_t(0xFFFFFFFF)) Throw(ExtErr::DerivedKeyTooLong); uint32_t iBe = 0; Blob salt_i = salt + ConstBuf(&iBe, 4); Blob r(nullptr, dkLen); for (uint32_t i=1, n=uint32_t((dkLen + hlen - 1) / hlen); i<=n; ++i) { memcpy(salt_i.data()+salt.Size, &(iBe = htobe(i)), 4); hashval u = prf(password, salt_i), rh = u; for (uint32_t j=1; j<c; ++j) VectorXor(rh.data(), (u = prf(password, u)).data(), hlen); memcpy(r.data() + (i-1)*hlen, rh.data(), (min)(hlen, r.Size - (i-1)*hlen)); } return r; }
int main(int argc, char** argv) { const uint32_t v = 134480385; std::cout << std::hex << v << std::endl; std::cout << htole(v) << std::endl; std::cout << htobe(v) << std::endl; return 0; }
void MineNparNonces(BitcoinMiner& miner, BitcoinWorkData& wd, UInt32 *buf, UInt32 nonce) override { for (int i=0; i<UCFG_BITCOIN_NPAR; i+=3, nonce+=3) { SetNonce(buf, nonce); array<array<UInt32, 8>, 3> res3 = CalcSCryptHash_80_3way(buf); for (int j=0; j<3; ++j) { if (HashValue(ConstBuf(res3[j].data(), 32)) <= wd.HashTarget) { if (!miner.TestAndSubmit(&wd, htobe(nonce+j))) *miner.m_pTraceStream << "Found NONCE not accepted by Target" << endl; } } } }