Пример #1
0
static void scrypt_1024_1_1_256_4way(const uint32_t *input,
	uint32_t *output, uint32_t *midstate, unsigned char *scratchpad, int N)
{
	uint32_t tstate[4 * 8] __attribute__((aligned(128)));
	uint32_t ostate[4 * 8] __attribute__((aligned(128)));
	uint32_t W[4 * 32] __attribute__((aligned(128)));
	uint32_t X[4 * 32] __attribute__((aligned(128)));
	uint32_t *V;
	int i, k;
	
	V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));

	for (i = 0; i < 20; i++)
		for (k = 0; k < 4; k++)
			W[4 * i + k] = input[k * 20 + i];
	for (i = 0; i < 8; i++)
		for (k = 0; k < 4; k++)
			tstate[4 * i + k] = midstate[i];
	HMAC_SHA256_80_init_4way(W, tstate, ostate);
	PBKDF2_SHA256_80_128_4way(tstate, ostate, W, W);
	for (i = 0; i < 32; i++)
		for (k = 0; k < 4; k++)
			X[k * 32 + i] = W[4 * i + k];
	scrypt_core(X + 0 * 32, V, N);
	scrypt_core(X + 1 * 32, V, N);
	scrypt_core(X + 2 * 32, V, N);
	scrypt_core(X + 3 * 32, V, N);
	for (i = 0; i < 32; i++)
		for (k = 0; k < 4; k++)
			W[4 * i + k] = X[k * 32 + i];
	PBKDF2_SHA256_128_32_4way(tstate, ostate, W, W);
	for (i = 0; i < 8; i++)
		for (k = 0; k < 4; k++)
			output[k * 8 + i] = W[4 * i + k];
}
Пример #2
0
static void scrypt_1024_1_1_256_4way(const uint32_t *input,
	uint32_t *output, uint32_t *midstate, unsigned char *scratchpad)
{
	uint32_t tstate[4 * 8];
	uint32_t ostate[4 * 8] ;
	uint32_t W[4 * 32] ;
	uint32_t X[4 * 32] ;
	uint32_t *V;
	int i;
	
	V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));

	for (i = 0; i < 20; i++) {
		W[4 * i + 0] = input[0 * 20 + i];
		W[4 * i + 1] = input[1 * 20 + i];
		W[4 * i + 2] = input[2 * 20 + i];
		W[4 * i + 3] = input[3 * 20 + i];
	}
	for (i = 0; i < 8; i++) {
		tstate[4 * i + 0] = midstate[i];
		tstate[4 * i + 1] = midstate[i];
		tstate[4 * i + 2] = midstate[i];
		tstate[4 * i + 3] = midstate[i];
	}
	HMAC_SHA256_80_init_4way(W, tstate, ostate);
	PBKDF2_SHA256_80_128_4way(tstate, ostate, W, W);
	for (i = 0; i < 32; i++) {
		X[0 * 32 + i] = W[4 * i + 0];
		X[1 * 32 + i] = W[4 * i + 1];
		X[2 * 32 + i] = W[4 * i + 2];
		X[3 * 32 + i] = W[4 * i + 3];
	}
	scrypt_core(X + 0 * 32, V);
	scrypt_core(X + 1 * 32, V);
	scrypt_core(X + 2 * 32, V);
	scrypt_core(X + 3 * 32, V);
	for (i = 0; i < 32; i++) {
		W[4 * i + 0] = X[0 * 32 + i];
		W[4 * i + 1] = X[1 * 32 + i];
		W[4 * i + 2] = X[2 * 32 + i];
		W[4 * i + 3] = X[3 * 32 + i];
	}
	PBKDF2_SHA256_128_32_4way(tstate, ostate, W, W);
	for (i = 0; i < 8; i++) {
		output[0 * 8 + i] = W[4 * i + 0];
		output[1 * 8 + i] = W[4 * i + 1];
		output[2 * 8 + i] = W[4 * i + 2];
		output[3 * 8 + i] = W[4 * i + 3];
	}
}
Пример #3
0
static void scrypt(const void* input, size_t inputlen, uint32_t *res, void *scratchpad)
{
    uint32_t *V;
    uint32_t X[32];
    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);

    scrypt_core(X, V);

    PBKDF2_SHA256((const uint8_t*)input, inputlen, (uint8_t *)X, 128, 1, (uint8_t*)res, 32);
}
Пример #4
0
uint256 scrypt(const void* data, size_t datalen, const void* salt, size_t saltlen, void *scratchpad)
{
    unsigned int *V;
    unsigned int X[32];
    uint256 result = 0;
    V = (unsigned int *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));

    PBKDF2_SHA256((const uint8_t*)data, datalen, (const uint8_t*)salt, saltlen, 1, (uint8_t *)X, 128);
    scrypt_core(X, V);
    PBKDF2_SHA256((const uint8_t*)data, datalen, (uint8_t *)X, 128, 1, (uint8_t*)&result, 32);

    return result;
}
Пример #5
0
uint256 scrypt_nosalt(const void* input, size_t inputlen, void *scratchpad)
{
    uint32_t *V;
    uint32_t X[32];
    uint256 result = 0;
    V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));

    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);

    return result;
}
Пример #6
0
uint256 scrypt_blockhash(const uint8_t* input)
{
    uint8_t scratchpad[SCRYPT_BUFFER_SIZE];
    ::uint32_t X[32];
    uint256 result = 0;

    ::uint32_t *V = (::uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));

    PBKDF2_SHA256(input, 80, input, 80, 1, (uint8_t *)X, 128);
    scrypt_core(X, V);
    PBKDF2_SHA256(input, 80, (uint8_t *)X, 128, 1, (uint8_t*)&result, 32);

    return result;
}
Пример #7
0
static void scrypt_1024_1_1_256(const uint32_t *input, uint32_t *output,
	uint32_t *midstate, unsigned char *scratchpad, int N)
{
	uint32_t tstate[8], ostate[8];
	uint32_t X[32] __attribute__((aligned(128)));
	uint32_t *V;
	
	V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));

	memcpy(tstate, midstate, 32);
	HMAC_SHA256_80_init(input, tstate, ostate);
	PBKDF2_SHA256_80_128(tstate, ostate, input, X);

	scrypt_core(X, V, N);

	PBKDF2_SHA256_128_32(tstate, ostate, X, output);
}