extern uint64 nLastBlockSize;
extern int64 nLastCoinStakeSearchInterval;
extern const std::string strMessageMagic;
-extern double dHashesPerSec;
-extern int64 nHPSTimerStart;
extern int64 nTimeBestReceived;
extern CCriticalSection cs_setpwalletRegistered;
extern std::set<CWallet*> setpwalletRegistered;
uint256 GetHash() const
{
- uint256 thash;
- void * scratchbuff = scrypt_buffer_alloc();
-
- scrypt_hash(CVOIDBEGIN(nVersion), sizeof(block_header), UINTBEGIN(thash), scratchbuff);
-
- scrypt_buffer_free(scratchbuff);
-
- return thash;
+ return scrypt_blockhash(CVOIDBEGIN(nVersion));
}
int64 GetBlockTime() const
#include <stdlib.h>
#include <stdint.h>
-#include <xmmintrin.h>
#include "scrypt_mine.h"
#include "pbkdf2.h"
#include "util.h"
#include "net.h"
-#if defined (__x86_64__) || defined (__i386__)
#define SCRYPT_BUFFER_SIZE (131072 + 63)
+
+#if defined (__x86_64__) || defined (__i386__)
extern "C" void scrypt_core(uint32_t *X, uint32_t *V);
+#else
+// TODO: Add cross-platform scrypt_core implementation
#endif
-void *scrypt_buffer_alloc() {
- return malloc(SCRYPT_BUFFER_SIZE);
-}
-
-void scrypt_buffer_free(void *scratchpad)
-{
- free(scratchpad);
-}
-
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
r = 1, p = 1, N = 1024
*/
-static void scrypt(const void* input, size_t inputlen, uint32_t *res, void *scratchpad)
+static uint256 scrypt(const void* input, size_t inputlen, void *scratchpad)
{
uint32_t *V;
uint32_t X[32];
+ uint256 result;
V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
- PBKDF2_SHA256((const uint8_t*)input, inputlen, (const uint8_t*)input, sizeof(block_header), 1, (uint8_t *)X, 128);
-
+ PBKDF2_SHA256((const uint8_t*)input, inputlen, (const uint8_t*)input, inputlen, 1, (uint8_t *)X, 128);
scrypt_core(X, V);
+ PBKDF2_SHA256((const uint8_t*)input, inputlen, (uint8_t *)X, 128, 1, (uint8_t*)&result, 32);
- PBKDF2_SHA256((const uint8_t*)input, inputlen, (uint8_t *)X, 128, 1, (uint8_t*)res, 32);
+ return result;
+}
+
+uint256 scrypt_hash(const void* input, size_t inputlen)
+{
+ unsigned char scratchpad[SCRYPT_BUFFER_SIZE];
+ return scrypt(input, inputlen, scratchpad);
}
-void scrypt_hash(const void* input, size_t inputlen, uint32_t *res, void *scratchpad)
+uint256 scrypt_blockhash(const void* input)
{
- return scrypt(input, inputlen, res, scratchpad);
+ unsigned char scratchpad[SCRYPT_BUFFER_SIZE];
+ return scrypt(input, 80, scratchpad);
}
#include "util.h"
#include "net.h"
-typedef struct
-{
- unsigned int version;
- uint256 prev_block;
- uint256 merkle_root;
- unsigned int timestamp;
- unsigned int bits;
- unsigned int nonce;
-} block_header;
-
-void *scrypt_buffer_alloc();
-void scrypt_buffer_free(void *scratchpad);
-void scrypt_hash(const void* input, size_t inputlen, uint32_t *res, void *scratchpad);
+uint256 scrypt_hash(const void* input, size_t inputlen);
+uint256 scrypt_blockhash(const void* input);
#endif // SCRYPT_MINE_H