• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sha256_transform函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sha256_transform函数的典型用法代码示例。如果您正苦于以下问题:C++ sha256_transform函数的具体用法?C++ sha256_transform怎么用?C++ sha256_transform使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sha256_transform函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: HMAC_SHA256_80_init

static inline void HMAC_SHA256_80_init(const uint32_t *key,
	uint32_t *tstate, uint32_t *ostate)
{
	uint32_t ihash[8];
	uint32_t pad[16];
	int i;

	/* tstate is assumed to contain the midstate of key */
	memcpy(pad, key + 16, 16);
	memcpy(pad + 4, keypad, 48);
	sha256_transform(tstate, pad, 0);
	memcpy(ihash, tstate, 32);

	sha256_init(ostate);
	for (i = 0; i < 8; i++)
		pad[i] = ihash[i] ^ 0x5c5c5c5c;
	for (; i < 16; i++)
		pad[i] = 0x5c5c5c5c;
	sha256_transform(ostate, pad, 0);

	sha256_init(tstate);
	for (i = 0; i < 8; i++)
		pad[i] = ihash[i] ^ 0x36363636;
	for (; i < 16; i++)
		pad[i] = 0x36363636;
	sha256_transform(tstate, pad, 0);
}
开发者ID:FrBillyD,项目名称:cpuminer,代码行数:27,代码来源:scrypt.c


示例2: sha256_process

int sha256_process(sha256_state * md, const unsigned char *in,
		   unsigned long inlen)
{
  unsigned long n;
  int block_size = sizeof(md->buf);

  if (md->curlen > block_size)
    return FALSE;

  while (inlen > 0) {
    if (md->curlen == 0 && inlen >= block_size) {
      sha256_transform(md->state, (unsigned char *)in);
      md->length += block_size * 8;
      in             += block_size;
      inlen          -= block_size;
    } else {
      n = MIN(inlen, (block_size - md->curlen));
      memcpy(md->buf + md->curlen, in, (size_t)n);
      md->curlen += n;
      in             += n;
      inlen          -= n;
      if (md->curlen == block_size) {
	sha256_transform(md->state, md->buf);
	md->length += block_size * 8;
	md->curlen = 0;
      }
    }
  }
  return TRUE;
}
开发者ID:FabrizioFabbe,项目名称:crypto,代码行数:30,代码来源:sha256.c


示例3: akmos_sha2_256_update

void akmos_sha2_256_update(akmos_sha2_256_t *ctx, const uint8_t *input, size_t len)
{
    size_t nb, new_len, rem_len, tmp_len;
    const uint8_t *sfi;

    tmp_len = AKMOS_SHA2_256_BLKLEN - ctx->len;
    rem_len = len < tmp_len ? len : tmp_len;

    memcpy(&ctx->block[ctx->len], input, rem_len);

    if(ctx->len + len < AKMOS_SHA2_256_BLKLEN) {
        ctx->len += len;
        return;
    }

    new_len = len - rem_len;
    nb = new_len / AKMOS_SHA2_256_BLKLEN;

    sfi = input + rem_len;

    sha256_transform(ctx->h, ctx->w, ctx->block, 1 & SIZE_T_MAX);
    sha256_transform(ctx->h, ctx->w, sfi, nb);

    rem_len = new_len % AKMOS_SHA2_256_BLKLEN;

    memcpy(ctx->block, &sfi[nb * 64], rem_len);

    ctx->len = rem_len;
    ctx->total += (nb + 1);
}
开发者ID:melanhit,项目名称:akmos,代码行数:30,代码来源:sha2.c


示例4: PBKDF2_SHA256_80_128

static inline void PBKDF2_SHA256_80_128(const uint32_t *tstate,
	const uint32_t *ostate, const uint32_t *salt, uint32_t *output)
{
	uint32_t istate[8], ostate2[8];
	uint32_t ibuf[16], obuf[16];
	int i, j;

	memcpy(istate, tstate, 32);
	sha256_transform(istate, salt, 0);
	
	memcpy(ibuf, salt + 16, 16);
	memcpy(ibuf + 5, innerpad, 44);
	memcpy(obuf + 8, outerpad, 32);

	for (i = 0; i < 4; i++) {
		memcpy(obuf, istate, 32);
		ibuf[4] = i + 1;
		sha256_transform(obuf, ibuf, 0);

		memcpy(ostate2, ostate, 32);
		sha256_transform(ostate2, obuf, 0);
		for (j = 0; j < 8; j++)
			output[8 * i + j] = swab32(ostate2[j]);
	}
}
开发者ID:FrBillyD,项目名称:cpuminer,代码行数:25,代码来源:scrypt.c


示例5: sha256d_80_swap

void sha256d_80_swap(uint32_t *hash, const uint32_t *data)
{
	uint32_t S[16];
	int i;

	sha256_init(S);
	sha256_transform(S, data, 0);
	sha256_transform(S, data + 16, 0);
	memcpy(S + 8, sha256d_hash1 + 8, 32);
	sha256_init(hash);
	sha256_transform(hash, S, 0);
	for (i = 0; i < 8; i++)
		hash[i] = swab32(hash[i]);
}
开发者ID:afsheenb,项目名称:cpuminer-rminerd,代码行数:14,代码来源:sha2.c


示例6: sha256func

void sha256func(unsigned char *hash, const unsigned char *data, int len)
{
    uint32_t S[16], T[16];
    int i, r;

    sha256_init(S);
    for (r = len; r > -9; r -= 64) {
        if (r < 64)
            memset(T, 0, 64);
        memcpy(T, data + len - r, r > 64 ? 64 : (r < 0 ? 0 : r));
        if (r >= 0 && r < 64)
            ((unsigned char *)T)[r] = 0x80;
        for (i = 0; i < 16; i++)
            T[i] = be32dec(T + i);
        if (r < 56)
            T[15] = 8 * len;
        sha256_transform(S, T, 0);
    }
    /*
    memcpy(S + 8, sha256d_hash1 + 8, 32);
    sha256_init(T);
    sha256_transform(T, S, 0);
    */
    for (i = 0; i < 8; i++)
        be32enc((uint32_t *)hash + i, T[i]);
}
开发者ID:2082615,项目名称:ccminer,代码行数:26,代码来源:groestlcoin.cpp


示例7: sha256_update

static int sha256_update(struct shash_desc *desc, const u8 *data,
			  unsigned int len)
{
	struct sha256_state *sctx = shash_desc_ctx(desc);
	unsigned int partial, done;
	const u8 *src;

	partial = sctx->count & 0x3f;
	sctx->count += len;
	done = 0;
	src = data;

	if ((partial + len) > 63) {
		if (partial) {
			done = -partial;
			memcpy(sctx->buf + partial, data, done + 64);
			src = sctx->buf;
		}

		do {
			sha256_transform(sctx->state, src);
			done += 64;
			src = data + done;
		} while (done + 63 < len);

		partial = 0;
	}
	memcpy(sctx->buf + partial, src, len - done);

	return 0;
}
开发者ID:andi34,项目名称:Dhollmen_Kernel,代码行数:31,代码来源:sha256_generic.c


示例8: sha256

void sha256(unsigned char input[32], int rounds, unsigned char output[32])
{
    GET_UINT32_BE( W[0],  input,  0 );
    GET_UINT32_BE( W[1],  input,  4 );
    GET_UINT32_BE( W[2],  input,  8 );
    GET_UINT32_BE( W[3],  input, 12 );
    GET_UINT32_BE( W[4],  input, 16 );
    GET_UINT32_BE( W[5],  input, 20 );
    GET_UINT32_BE( W[6],  input, 24 );
    GET_UINT32_BE( W[7],  input, 28 );
    

    int i;
    for(i=0;i<rounds;++i)
        sha256_transform();
    
    
    PUT_UINT32_BE( W[0], output,  0 );
    PUT_UINT32_BE( W[1], output,  4 );
    PUT_UINT32_BE( W[2], output,  8 );
    PUT_UINT32_BE( W[3], output, 12 );
    PUT_UINT32_BE( W[4], output, 16 );
    PUT_UINT32_BE( W[5], output, 20 );
    PUT_UINT32_BE( W[6], output, 24 );
    PUT_UINT32_BE( W[7], output, 28 );
  
    
}
开发者ID:Reaper38,项目名称:Crypto.NET,代码行数:28,代码来源:sha256.c


示例9: fio_sha256_update

void fio_sha256_update(struct fio_sha256_ctx *sctx, const uint8_t *data,
		       unsigned int len)
{
	unsigned int partial, done;
	const uint8_t *src;

	partial = sctx->count & 0x3f;
	sctx->count += len;
	done = 0;
	src = data;

	if ((partial + len) > 63) {
		if (partial) {
			done = -partial;
			memcpy(sctx->buf + partial, data, done + 64);
			src = sctx->buf;
		}

		do {
			sha256_transform(sctx->state, src);
			done += 64;
			src = data + done;
		} while (done + 63 < len);

		partial = 0;
	}
	memcpy(sctx->buf + partial, src, len - done);
}
开发者ID:Andiry,项目名称:fio,代码行数:28,代码来源:sha256.c


示例10: PBKDF2_SHA256_128_32

static inline void PBKDF2_SHA256_128_32(uint32_t *tstate, uint32_t *ostate,
	const uint32_t *salt, uint32_t *output)
{
	uint32_t buf[16];
	int i;
	
	sha256_transform(tstate, salt, 1);
	sha256_transform(tstate, salt + 16, 1);
	sha256_transform(tstate, finalblk, 0);
	memcpy(buf, tstate, 32);
	memcpy(buf + 8, outerpad, 32);

	sha256_transform(ostate, buf, 0);
	for (i = 0; i < 8; i++)
		output[i] = swab32(ostate[i]);
}
开发者ID:FrBillyD,项目名称:cpuminer,代码行数:16,代码来源:scrypt.c


示例11: scanhash_scrypt

int scanhash_scrypt(int thr_id, uint32_t *pdata,
	unsigned char *scratchbuf, const uint32_t *ptarget,
	uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t data[SCRYPT_MAX_WAYS * 20], hash[SCRYPT_MAX_WAYS * 8];
	uint32_t midstate[8];
	uint32_t n = pdata[19] - 1;
	const uint32_t Htarg = ptarget[7];
	int throughput = scrypt_best_throughput();
	int i;
	
#ifdef HAVE_SHA256_4WAY
	if (sha256_use_4way())
		throughput *= 4;
#endif
	
	for (i = 0; i < throughput; i++)
		memcpy(data + i * 20, pdata, 80);
	
	sha256_init(midstate);
	sha256_transform(midstate, data, 0);
	
	do {
		for (i = 0; i < throughput; i++)
			data[i * 20 + 19] = ++n;
		
#if defined(HAVE_SHA256_4WAY)
		if (throughput == 4)
			scrypt_1024_1_1_256_4way(data, hash, midstate, scratchbuf);
		else
#endif
#if defined(HAVE_SCRYPT_3WAY) && defined(HAVE_SHA256_4WAY)
		if (throughput == 12)
			scrypt_1024_1_1_256_12way(data, hash, midstate, scratchbuf);
		else
#endif
#if defined(HAVE_SCRYPT_3WAY)
		if (throughput == 3)
			scrypt_1024_1_1_256_3way(data, hash, midstate, scratchbuf);
		else
#endif
		scrypt_1024_1_1_256(data, hash, midstate, scratchbuf);
		
		for (i = 0; i < throughput; i++) {
			if (hash[i * 8 + 7] <= Htarg && fulltest(hash + i * 8, ptarget)) {
				*hashes_done = n - pdata[19] + 1;
				pdata[19] = data[i * 20 + 19];
				return 1;
			}
		}
	} while (n < max_nonce && !work_restart[thr_id].restart);
	
	*hashes_done = n - pdata[19] + 1;
	pdata[19] = n;
	return 0;
}
开发者ID:xxrforone,项目名称:miner,代码行数:56,代码来源:scrypt.c


示例12: scanhash_sha256d_4way

static inline int scanhash_sha256d_4way(int thr_id, uint32_t *pdata,
	const uint32_t *ptarget, uint32_t max_nonce, struct timeval *tv_start, struct timeval *tv_end, unsigned long *hashes_done)
{
		gettimeofday(tv_start, NULL);

	uint32_t data[4 * 64] __attribute__((aligned(128)));
	uint32_t hash[4 * 8] __attribute__((aligned(32)));
	uint32_t midstate[4 * 8] __attribute__((aligned(32)));
	uint32_t prehash[4 * 8] __attribute__((aligned(32)));
	uint32_t n = pdata[19] - 1;
	const uint32_t first_nonce = pdata[19];
	const uint32_t Htarg = ptarget[7];
	int i, j;

	memcpy(data, pdata + 16, 64);
	sha256d_preextend(data);
	for (i = 31; i >= 0; i--)
		for (j = 0; j < 4; j++)
			data[i * 4 + j] = data[i];

	sha256_init(midstate);
	sha256_transform(midstate, pdata, 0);
	memcpy(prehash, midstate, 32);
	sha256d_prehash(prehash, pdata + 16);
	for (i = 7; i >= 0; i--) {
		for (j = 0; j < 4; j++) {
			midstate[i * 4 + j] = midstate[i];
			prehash[i * 4 + j] = prehash[i];
		}
	}

	do {
		for (i = 0; i < 4; i++)
			data[4 * 3 + i] = ++n;

		sha256d_ms_4way(hash, data, midstate, prehash);

		for (i = 0; i < 4; i++) {
			if (swab32(hash[4 * 7 + i]) <= Htarg) {
				pdata[19] = data[4 * 3 + i];
				sha256d_80_swap(hash, pdata);
				if (fulltest(hash, ptarget)) {
					*hashes_done = n - first_nonce + 1;
					gettimeofday(&tv_end, NULL);
					return 1;
				}
			}
		}
	} while (n < max_nonce && !scan_abort_flag && !work_restart[thr_id].restart);

	*hashes_done = n - first_nonce + 1;
	pdata[19] = n;
	gettimeofday(&tv_end, NULL);
	return 0;
}
开发者ID:nicehash,项目名称:ccminer-sp,代码行数:55,代码来源:sha2.c


示例13: sha256_done

int sha256_done(sha256_state * md, unsigned char *out)
{
  int i;

  if (md->curlen >= sizeof(md->buf))
    return FALSE;

  /* increase the length of the message */
  md->length += md->curlen * 8;

  /* append the '1' bit */
  md->buf[md->curlen++] = (unsigned char)0x80;

  /* if the length is currently above 56 bytes we append zeros
   * then compress.  Then we can fall back to padding zeros and length
   * encoding like normal.
   */
  if (md->curlen > 56) {
    while (md->curlen < 64) {
      md->buf[md->curlen++] = (unsigned char)0;
    }
    sha256_transform(md->state, md->buf);
    md->curlen = 0;
  }

  /* pad upto 56 bytes of zeroes */
  while (md->curlen < 56) {
    md->buf[md->curlen++] = (unsigned char)0;
  }

  /* store length */
  SILC_PUT64_MSB(md->length, md->buf + 56);
  sha256_transform(md->state, md->buf);

  /* copy output */
  for (i = 0; i < 8; i += 2) {
    SILC_PUT32_MSB(md->state[i], out + (4 * i));
    SILC_PUT32_MSB(md->state[i + 1], out + (4 * (i + 1)));
  }

  return TRUE;
}
开发者ID:FabrizioFabbe,项目名称:crypto,代码行数:42,代码来源:sha256.c


示例14: sha256_write_byte_block

PRIVATE static void sha256_write_byte_block(sha256_t *p)
{
  uint32_t data32[16];
  unsigned i;
  for (i = 0; i < 16; i++)
    data32[i] =
      ((uint32_t)(p->buffer[i * 4    ]) << 24) +
      ((uint32_t)(p->buffer[i * 4 + 1]) << 16) +
      ((uint32_t)(p->buffer[i * 4 + 2]) <<  8) +
      ((uint32_t)(p->buffer[i * 4 + 3]));
  sha256_transform(p->state, data32);
}
开发者ID:tehmaze,项目名称:libcommon,代码行数:12,代码来源:sha256.c


示例15: scanhash_sha256d

int scanhash_sha256d(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
	uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t data[64] __attribute__((aligned(128)));
	uint32_t hash[8] __attribute__((aligned(32)));
	uint32_t midstate[8] __attribute__((aligned(32)));
	uint32_t prehash[8] __attribute__((aligned(32)));
	uint32_t n = pdata[19] - 1;
	const uint32_t first_nonce = pdata[19];
	const uint32_t Htarg = ptarget[7];
	
#ifdef HAVE_SHA256_16WAY
	if (sha256_use_16way())
		return scanhash_sha256d_16way(thr_id, pdata, ptarget,
			max_nonce, hashes_done);
#endif
#ifdef HAVE_SHA256_8WAY
	if (sha256_use_8way())
		return scanhash_sha256d_8way(thr_id, pdata, ptarget,
			max_nonce, hashes_done);
#endif
#ifdef HAVE_SHA256_4WAY
	if (sha256_use_4way())
		return scanhash_sha256d_4way(thr_id, pdata, ptarget,
			max_nonce, hashes_done);
#endif
	
	memcpy(data, pdata + 16, 64);
	sha256d_preextend(data);
	
	sha256_init(midstate);
	sha256_transform(midstate, pdata, 0);
	memcpy(prehash, midstate, 32);
	sha256d_prehash(prehash, pdata + 16);
	
	do {
		data[3] = ++n;
		sha256d_ms(hash, data, midstate, prehash);
		if (swab32(hash[7]) <= Htarg) {
			pdata[19] = data[3];
			sha256d_80_swap(hash, pdata);
			if (fulltest(hash, ptarget)) {
				*hashes_done = n - first_nonce + 1;
				return 1;
			}
		}
	} while (n < max_nonce && !work_restart[thr_id].restart);
	
	*hashes_done = n - first_nonce + 1;
	pdata[19] = n;
	return 0;
}
开发者ID:kiyominer,项目名称:cpuminer,代码行数:52,代码来源:sha2.c


示例16: scanhash_sha256d_16way

static inline int scanhash_sha256d_16way(int thr_id, uint32_t *pdata,
	const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t data[16 * 64] __attribute__((aligned(128)));
	uint32_t hash[16 * 8] __attribute__((aligned(64)));
	uint32_t midstate[16 * 8] __attribute__((aligned(64)));
	uint32_t prehash[16 * 8] __attribute__((aligned(64)));
	uint32_t n = pdata[19] - 1;
	const uint32_t first_nonce = pdata[19];
	const uint32_t Htarg = ptarget[7];
	int i, j;
	
	memcpy(data, pdata + 16, 64);
	sha256d_preextend(data);
	for (i = 63; i >= 0; i--)
		for (j = 0; j < 16; j++)
			data[i * 16 + j] = data[i];
	
	sha256_init(midstate);
	sha256_transform(midstate, pdata, 0);
	memcpy(prehash, midstate, 32);
	sha256d_prehash(prehash, pdata + 16);
	for (i = 7; i >= 0; i--) {
		for (j = 0; j < 16; j++) {
			midstate[i * 16 + j] = midstate[i];
			prehash[i * 16 + j] = prehash[i];
		}
	}
	
	do {
		for (i = 0; i < 16; i++)
			data[16 * 3 + i] = ++n;
		
		sha256d_ms_16way(hash, data, midstate, prehash);
		
		for (i = 0; i < 16; i++) {
			if (swab32(hash[16 * 7 + i]) <= Htarg) {
				pdata[19] = data[16 * 3 + i];
				sha256d_80_swap(hash, pdata);
				if (fulltest(hash, ptarget)) {
					*hashes_done = n - first_nonce + 1;
					return 1;
				}
			}
		}
	} while (n < max_nonce && !work_restart[thr_id].restart);
	*hashes_done = n - first_nonce + 1;
	pdata[19] = n;
	return 0;
}
开发者ID:kiyominer,项目名称:cpuminer,代码行数:50,代码来源:sha2.c


示例17: sha256_finish

// Update hash with the remaining portion of the message and finalise it.
// Total length of the entire message must be provided, as it will be appended
// at the end according to the specification.
// Input: hash[8] is the accumulated internal state in native byte order.
// Output: hash[8] is the resulting hash that can be considered a byte sequence
// (i.e. in big endian).
void sha256_finish(uint32_t hash[8], const uint8_t *data, int len, int total)
{
    union {
        uint8_t  b[SHA256_BLOCK_SIZE];      // 64 bytes
        uint32_t w[SHA256_BLOCK_SIZE / 4];
    } buf;
    int i;

    for (i = 0; i + (int) sizeof buf <= len; i += sizeof buf) {
        memcpy(buf.b, data + i, sizeof buf);
        sha256_transform(hash, buf.w);
    }

    int l = len - i;
    memcpy(buf.b, data + i, l);
    buf.b[l]=0x80;
    if (l > 55) {
        for (i = l + 1; i != sizeof buf; i++)
            buf.b[i]=0;
        sha256_transform(hash, buf.w);
        l = 0;
        buf.b[l] = 0;
    }

    for (i = l + 1; i <= 55; i++)
        buf.b[i]=0;
    buf.w[14] = 0; // high 4 bytes of bit length
    buf.w[15] = cpu_to_be32(total * 8);   // bit length

    sha256_transform(hash, buf.w);

#if __BYTE_ORDER == __LITTLE_ENDIAN
    for (i = 0; i < 8; i++)
        hash[i] = cpu_to_be32(hash[i]);
#endif
}
开发者ID:biddyweb,项目名称:entropy,代码行数:42,代码来源:sha256.c


示例18: akmos_sha2_256_done

void akmos_sha2_256_done(akmos_sha2_256_t *ctx, uint8_t *digest)
{
    size_t i, nb, pm_len;
    uint64_t len_b;

    nb = (1 + ((AKMOS_SHA2_256_BLKLEN - 9) < (ctx->len % AKMOS_SHA2_256_BLKLEN)));

    len_b = ((ctx->total * 64) + ctx->len) * 8;
    pm_len = nb * 64;

    memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
    ctx->block[ctx->len] = 0x80;
    UNPACK64LE(ctx->block + pm_len - 8, len_b);

    if(nb > 0)
        sha256_transform(ctx->h, ctx->w, ctx->block, nb);

    for(i = 0; i < ctx->diglen / (sizeof(uint32_t)); i++)
        UNPACK32LE(digest + (i * sizeof(uint32_t)), ctx->h[i]);
}
开发者ID:melanhit,项目名称:akmos,代码行数:20,代码来源:sha2.c


示例19: run_cpu_new

uint32_t* run_cpu_new(bc_work_t work, uint64_t nscrypt){
	uint32_t word_per_scrypt = 20;
	uint32_t word_per_hash = 8;
	//get starting nonce from the data. (last 4 bytes in data)

	uint32_t* data_32bit = (uint32_t*) work.result.data;

	uint32_t start_nonce = data_32bit[word_per_scrypt-1];

	uint32_t midstate[8];

	sha256_init(midstate);
	sha256_transform(midstate, data_32bit, 0);


	//Initialise input and outputs - 80 bytes per scrypt for inputs, 32bytes outputs
	uint32_t *input = calloc(nscrypt, word_per_scrypt*sizeof(uint32_t));
	uint32_t *output = calloc(nscrypt, word_per_hash*sizeof(uint32_t));

	if(NULL == input || NULL == output){
		LOG_FATAL("Cannot allocate memory for input/output buffers.\n");
	}

	for(uint32_t i = 0; i < nscrypt; i++){
		uint64_t index = i*word_per_scrypt;
		memcpy(input + index, data_32bit, sizeof(uint32_t)*word_per_scrypt);
	}

	for(uint32_t i = 0; i < nscrypt; i++){
		uint64_t index = i*word_per_scrypt;
		input[index+word_per_scrypt-1] = start_nonce + i;
	}

	dfescrypt_cpu(nscrypt, input, output, midstate);


	free(input);
	return output;

}
开发者ID:maxeler,项目名称:HybridMiner,代码行数:40,代码来源:scrypt.c


示例20: scrypt_prepare_run

/**
 * \brief   Prepare the data and run the Scrypt kernel.
 * \param   work  data received from getwork.
 * \return	boolean - if nonce has been found.
 */
void scrypt_prepare_run(scrypt_worker_t *worker, bc_work_t work){
	uint32_t word_per_scrypt = 20;
	uint32_t start_nonce = 0;
	//get starting nonce from the data. (last 4 bytes in data)
	uint32_t* data_32bit = (uint32_t*) work.result.data;

	uint32_t nscrypt = dfe_get_num_scrypt(worker->dfe);


	uint32_t midstate[8];

	sha256_init(midstate);
	sha256_transform(midstate, data_32bit, 0);

	uint32_t *input = calloc(nscrypt, word_per_scrypt*sizeof(uint32_t));

	for(uint32_t i = 0; i < nscrypt; i++){
		uint64_t index = i*word_per_scrypt;
		memcpy(input + index, data_32bit, sizeof(uint32_t)*word_per_scrypt);
	}

	for(uint32_t i = 0; i < nscrypt; i++){
		uint64_t index = i*word_per_scrypt;
		input[index+word_per_scrypt-1] = start_nonce + i;
	}

	uint32_t* X = worker->dfe_buffer;
	uint32_t* tstates = worker->tstate_buffer;
	uint32_t* ostates = worker->ostate_buffer;

#pragma omp parallel for
	for (int64_t i = 0; i < (int64_t)nscrypt; i++) {
		memcpy(&tstates[i*8], midstate, 32);
		SHA256_before(&tstates[i*8], &ostates[i*8], &input[20*i], &X[i*32]);
	}

	free(input);
}
开发者ID:maxeler,项目名称:HybridMiner,代码行数:43,代码来源:scrypt.c



注:本文中的sha256_transform函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sha256_vector函数代码示例发布时间:2022-05-30
下一篇:
C++ sha256_init函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap