private QueryPerformanceCounter ( long &lpPerformanceCount ) : bool | ||
lpPerformanceCount | long | |
Результат | bool |
void WorkThread() { long startTime, endTime, freq; Win32Wrapper.QueryPerformanceFrequency(out freq); double dfFreq = 1.0 / (double)freq; while (true) { if (mDoWork) { uint hashesRemaining = mHashCount - mHashesDone; uint numHashes = Math.Min(hashesRemaining, cHashChunk); uint start = mHashStart + mHashesDone; Win32Wrapper.QueryPerformanceCounter(out startTime); uint hashesDone = DoHashes(start, numHashes); Win32Wrapper.QueryPerformanceCounter(out endTime); double seconds = (double)(endTime - startTime) * dfFreq; mHashrate = (double)hashesDone / seconds; mHashesDone += hashesDone; if (mHashesDone >= mHashCount) { // Done, didnt find a solution SendWorkComplete(false, 0, mHashesDone); } } } }
public static void RandomSeed() { long counter; Win32Wrapper.QueryPerformanceCounter(out counter); MemoryStream stream = new MemoryStream(); BinaryWriter bw = new BinaryWriter(stream); bw.Write(counter); byte[] data = stream.ToArray(); //OpenSSL.RAND_add(data, data.Length, 1.5); OpenSSL.Core.Random.Add(data, 1.5); bw.Close(); }
void DoWork(WorkBlock work) { byte[] data = new byte[64]; Array.Copy(work.data, 64, data, 0, 64); uint[] midstate = ByteArrayToUIntArray(work.midstate, 0); uint[] targetA = ByteArrayToUIntArray(work.target, 0); uint[] targetSwapped = new uint[8]; for (int i = 0; i < 8; i++) { targetSwapped[i] = targetA[7 - i]; } uint max = 0xFFFFFFFF; long start, end, freq; Win32Wrapper.QueryPerformanceFrequency(out freq); Win32Wrapper.QueryPerformanceCounter(out start); for (uint n = 0; n < max; n++) { WriteUIntToByteArray(n, data, 12); uint[] output = new uint[8]; SHATransform(output, data, midstate); byte[] input = new byte[64]; Buffer.BlockCopy(output, 0, input, 0, 32); Buffer.BlockCopy(work.hash1, 32, input, 32, 32); SHATransform(output, input, staticData); if (output[7] == 0) { uint[] swapped = new uint[8]; for (int i = 0; i < 8; i++) { swapped[i] = Program.Byteswap(output[7 - i]); } for (int i = 1; i < 8; i++) { if (swapped[i] < targetSwapped[i]) { // Found a solution WriteUIntToByteArray(n, work.data, 76); // Write the nonce value into the data block return; } if (swapped[i] > targetSwapped[i]) { break; } } } } Win32Wrapper.QueryPerformanceCounter(out end); long clocks = end - start; double seconds = (double)clocks / (double)freq; double hashesPerSecond = max / seconds; Console.WriteLine(hashesPerSecond.ToString() + " hashes per second"); }