11 // MSVC 64bit is unable to use inline asm
14 // GCC Linux or i686-w64-mingw32
19 extern "C" void scrypt_core(uint32_t *X, uint32_t *V);
21 extern uint256 scrypt_blockhash__sse2(const uint8_t* input);
23 /* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
24 scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
25 r = 1, p = 1, N = 1024
28 uint256 scrypt_blockhash_generic(const uint8_t* input)
30 uint8_t scratchpad[SCRYPT_BUFFER_SIZE];
34 uint32_t *V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
36 PBKDF2_SHA256(input, 80, input, 80, 1, (uint8_t *)X, 128);
38 PBKDF2_SHA256(input, 80, (uint8_t *)X, 128, 1, (uint8_t*)&result, 32);
43 // By default, set to generic scrypt function. This will prevent crash in case when scrypt_detect_sse2() wasn't called
44 uint256 (*scrypt_blockhash_detected)(const uint8_t* input) = &scrypt_blockhash_generic;
47 void scrypt_detect_sse2()
49 // 32bit x86 Linux or Windows, detect cpuid features
50 unsigned int cpuid_edx=0;
55 cpuid_edx = (unsigned int)x86cpuid[3];
57 // Linux or i686-w64-mingw32 (gcc-4.6.3)
58 unsigned int eax, ebx, ecx;
59 __get_cpuid(1, &eax, &ebx, &ecx, &cpuid_edx);
62 if (cpuid_edx & 1<<26)
64 scrypt_blockhash_detected = &scrypt_blockhash__sse2;
65 printf("scrypt: using scrypt-sse2 as detected.\n");
69 scrypt_blockhash_detected = &scrypt_blockhash_generic;
70 printf("scrypt: using scrypt-generic, SSE2 unavailable.\n");
75 uint256 scrypt_blockhash(const uint8_t* input)
77 return scrypt_blockhash_detected(input);