当前位置: 首页>>代码示例>>C++>>正文


C++ SHA256_Update函数代码示例

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


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

示例1: sha256_str

void
sha256_str(const char *string, char out[65])
{
	unsigned char hash[SHA256_DIGEST_LENGTH];
	SHA256_CTX sha256;

	SHA256_Init(&sha256);
	SHA256_Update(&sha256, string, strlen(string));
	SHA256_Final(hash, &sha256);

	sha256_hash(hash, out);
}
开发者ID:flz,项目名称:pkgng,代码行数:12,代码来源:pkg_util.c

示例2: scryptenc_setup

static int
scryptenc_setup(uint8_t header[96], uint8_t dk[64],
    const uint8_t * passwd, size_t passwdlen,
    size_t maxmem, double maxmemfrac, double maxtime)
{
	uint8_t salt[32];
	uint8_t hbuf[32];
	int logN;
	uint64_t N;
	uint32_t r;
	uint32_t p;
	SHA256_CTX ctx;
	uint8_t * key_hmac = &dk[32];
	HMAC_SHA256_CTX hctx;
	int rc;

	/* Pick values for N, r, p. */
	if ((rc = pickparams(maxmem, maxmemfrac, maxtime,
	    &logN, &r, &p)) != 0)
		return (rc);
	N = (uint64_t)(1) << logN;

	/* Get some salt. */
	if ((rc = getsalt(salt)) != 0)
		return (rc);

	/* Generate the derived keys. */
	if (crypto_scrypt(passwd, passwdlen, salt, 32, N, r, p, dk, 64))
		return (3);

	/* Construct the file header. */
	memcpy(header, "scrypt", 6);
	header[6] = 0;
	header[7] = logN;
	be32enc(&header[8], r);
	be32enc(&header[12], p);
	memcpy(&header[16], salt, 32);

	/* Add header checksum. */
	SHA256_Init(&ctx);
	SHA256_Update(&ctx, header, 48);
	SHA256_Final(hbuf, &ctx);
	memcpy(&header[48], hbuf, 16);

	/* Add header signature (used for verifying password). */
	HMAC_SHA256_Init(&hctx, key_hmac, 32);
	HMAC_SHA256_Update(&hctx, header, 64);
	HMAC_SHA256_Final(hbuf, &hctx);
	memcpy(&header[64], hbuf, 32);

	/* Success! */
	return (0);
}
开发者ID:jeremykohn,项目名称:scrypt,代码行数:53,代码来源:scryptenc.c

示例3: vdi_random_sha

/*
 * Applies sha256 using the given context and input/length, and returns
 * a double in the range [0...1[ based on the hash.
 */
static double
vdi_random_sha(const char *input, ssize_t len)
{
    struct SHA256Context ctx;
    uint8_t sign[SHA256_LEN];

    AN(input);
    SHA256_Init(&ctx);
    SHA256_Update(&ctx, input, len);
    SHA256_Final(sign, &ctx);
    return (vle32dec(sign) / exp2(32));
}
开发者ID:midnightskinhead,项目名称:Varnish-Cache,代码行数:16,代码来源:cache_dir_random.c

示例4: crypt_all

static void crypt_all(int count)
{
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
	for (index = 0; index < count; index++)
#endif
	{
		SHA256_CTX ctx;
		int i;
		SHA256_Init(&ctx);
		SHA256_Update(&ctx, saved_key[index], strlen(saved_key[index]));
		SHA256_Update(&ctx, cur_salt->salt, 32);
		SHA256_Final((unsigned char*)crypt_out[index], &ctx);
		for(i = 0; i <= cur_salt->iterations; i++)  {
			SHA256_Init(&ctx);
			SHA256_Update(&ctx, (unsigned char*)crypt_out[index], 32);
			SHA256_Final((unsigned char*)crypt_out[index], &ctx);
		}
	}
}
开发者ID:bhargavz,项目名称:pac4mac,代码行数:21,代码来源:pwsafe_fmt_plug.c

示例5: SHA224_Init

unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
  {
  SHA256_CTX c;
  static unsigned char m[SHA224_DIGEST_LENGTH];

  if (md == NULL) md=m;
  SHA224_Init(&c);
  SHA256_Update(&c,d,n);
  SHA256_Final(md,&c);
  OPENSSL_cleanse(&c,sizeof(c));
  return(md);
  }
开发者ID:yyyyyao,项目名称:Slicer3-lib-mirrors,代码行数:12,代码来源:sha256.c

示例6: SHA256FromHash

char* SHA256FromHash(ArrayOfHash *array)
{
    unsigned char* hash = malloc(SHA256_DIGEST_LENGTH);
    SHA256_CTX sha256;
    SHA256_Init(&sha256);
    int i;
    for(i = 0; i < array->size; i++) {
        SHA256_Update(&sha256, array->arrayOfHash[i], array->sizeBlock);
    }
    SHA256_Final(hash, &sha256);
    return hash;
}
开发者ID:ddcleave,项目名称:HashDisk,代码行数:12,代码来源:hash.c

示例7: register_user

/*
 *Register
 */
int register_user(packet *in_pkt, int fd) {
   int i = 0;
   char *args[16];
   char cpy[BUFFERSIZE];
   char *tmp = cpy;
   strcpy(tmp, in_pkt->buf);

   args[i] = strsep(&tmp, " \t");
   while ((i < sizeof(args) - 1) && (args[i] != '\0')) {
       args[++i] = strsep(&tmp, " \t");
   }
   // Check there are enough arguements to safely inspect them
   if (i > 3) {
      // Ensure requested username is valid
      if (!validUsername(args[1], fd)) { return 0; }
      // Check if the requested username is unique
      if(strcmp(get_real_name(&registered_users_list, args[1], registered_users_mutex), "ERROR") !=0 || \
                              !(strcmp(SERVER_NAME, args[1])) || \
                              strcmp(args[2], args[3]) != 0) {
         sendError("Username unavailable.", fd);
         return 0;
      }
      // Ensure password requested is valid
      if (!validPassword(args[2], args[3], fd)) { return 0; }

      // Allocate memory space for new user node, populate node with new user data
      User *user = (User *)malloc(sizeof(User));
      strcpy(user->username, args[1]);
      strcpy(user->real_name, args[1]);
      // Hash password
      SHA256_CTX sha256;
      SHA256_Init(&sha256);
      SHA256_Update(&sha256, args[2], strlen(args[2]));
      SHA256_Final(user->password, &sha256);
      user->sock = fd;
      user->next = NULL;
      
      // Insert user as registered user, write new user data to file
      insertUser(&registered_users_list, user, registered_users_mutex);
      writeUserFile(&registered_users_list, USERS_FILE, registered_users_mutex);

      // Reform packet as valid login, pass new user data to login
      memset(&in_pkt->buf, 0, sizeof(in_pkt->buf));
      sprintf(in_pkt->buf, "/login %s %s", args[1], args[2]);
      return login(in_pkt, fd);
   }
   // There were not enough arguements received to correctly read them
   else {
      printf("%s --- %sError:%s Malformed reg packet received from %s on %d, ignoring.\n", \
             WHITE, RED, NORMAL, args[1], fd);
   }
   return 0;
}
开发者ID:mgeitz,项目名称:tbdchat,代码行数:56,代码来源:server_clients.c

示例8: read_bitcoin_transaction

void read_bitcoin_transaction(struct space *space,
			      struct bitcoin_transaction *trans,
			      struct file *f, off_t *poff)
{
	size_t i;
	off_t start = *poff;
	SHA256_CTX sha256;

	trans->version = pull_u32(f, poff);
	trans->input_count = pull_varint(f, poff);
	trans->input = space_alloc_arr(space,
				       struct bitcoin_transaction_input,
				       trans->input_count);
	for (i = 0; i < trans->input_count; i++)
		read_input(space, f, poff, trans->input + i);
	trans->output_count = pull_varint(f, poff);
	trans->output = space_alloc_arr(space,
					struct bitcoin_transaction_output,
					trans->output_count);
	for (i = 0; i < trans->output_count; i++)
               read_output(space, f, poff, trans->output + i);
	trans->lock_time = pull_u32(f, poff);

	/* Bitcoin uses double sha (it's not quite known why...) */
	SHA256_Init(&sha256);
	if (likely(f->mmap)) {
		SHA256_Update(&sha256, f->mmap + start, *poff - start);
	} else {
		u8 *buf = tal_arr(NULL, u8, *poff - start);
		file_read(f, start, *poff - start, buf);
		SHA256_Update(&sha256, buf, *poff - start);
		tal_free(buf);
	}
	SHA256_Final(trans->sha256, &sha256);

	SHA256_Init(&sha256);
	SHA256_Update(&sha256, trans->sha256, sizeof(trans->sha256));
	SHA256_Final(trans->sha256, &sha256);
	trans->len = *poff - start;
}
开发者ID:jkauffman1,项目名称:bitcoin-iterate,代码行数:40,代码来源:parse.c

示例9: EllipticCurveKeyPair

void Identity::generate()
{
	delete [] _keyPair;

	// Generate key pair and derive address
	do {
		_keyPair = new EllipticCurveKeyPair();
		_keyPair->generate();
		_address = deriveAddress(_keyPair->pub().data(),_keyPair->pub().size());
	} while (_address.isReserved());
	_publicKey = _keyPair->pub();

	// Sign address, key type, and public key with private key (with a zero
	// byte between each field). Including this extra data means simply editing
	// the address of an identity will be detected as its signature will be
	// invalid. Of course, deep verification of address/key relationship is
	// required to cover the more elaborate address claim jump attempt case.
	SHA256_CTX sha;
	unsigned char dig[32];
	unsigned char idtype = IDENTITY_TYPE_NIST_P_521,zero = 0;
	SHA256_Init(&sha);
	SHA256_Update(&sha,_address.data(),ZT_ADDRESS_LENGTH);
	SHA256_Update(&sha,&zero,1);
	SHA256_Update(&sha,&idtype,1);
	SHA256_Update(&sha,&zero,1);
	SHA256_Update(&sha,_publicKey.data(),_publicKey.size());
	SHA256_Update(&sha,&zero,1);
	SHA256_Final(dig,&sha);
	_signature = _keyPair->sign(dig);
}
开发者ID:Audiarto,项目名称:ZeroTierOne,代码行数:30,代码来源:Identity.cpp

示例10: transform_key

transform_key(char *PASSWORD, final_key)
{
     // First, hash the PASSWORD
    SHA256_CTX ctx;
    AES_KEY akey;
    SHA256_Init(&ctx);
    SHA256_Update(&ctx, PASSWORD, strlen(PASSWORD));
    SHA256_Final(hash, &ctx);
    if(version == 2) { /* 2.x database */
        SHA256_Init(&ctx);
        SHA256_Update(&ctx, hash, 32);
        SHA256_Final(hash, &ctx);
    }
    AES_set_encrypt_key(TRS, 256, &akey);    
    // Next, encrypt the created hash
    for(i = 0; i < ITERATIONSl; i++) {
        AES_encrypt(hash, hash, &akey);
        AES_encrypt(hash+16, hash+16, &akey);
    }
    // Finally, hash it again...
    SHA256_Init(&ctx);
    SHA256_Update(&ctx, hash, 32);
    SHA256_Final(hash, &ctx);
    // and hash the result together with the Final Random Seed
    SHA256_Init(&ctx);
    if(version == 1) {
        SHA256_Update(&ctx, FRS, 16);
    }
    else {
        SHA256_Update(&ctx, FRS, 32);
    }
    SHA256_Update(&ctx, hash, 32);
    SHA256_Final(final_key, &ctx);
}
开发者ID:kholia,项目名称:thesis,代码行数:34,代码来源:keepass_kdf.c

示例11: scryptdec_setup

static int
scryptdec_setup(const uint8_t header[96], uint8_t dk[64],
    const uint8_t * passwd, size_t passwdlen,
    size_t maxmem, double maxmemfrac, double maxtime)
{
	uint8_t salt[32];
	uint8_t hbuf[32];
	int logN;
	uint32_t r;
	uint32_t p;
	uint64_t N;
	SHA256_CTX ctx;
	uint8_t * key_hmac = &dk[32];
	HMAC_SHA256_CTX hctx;
	int rc;

	/* Parse N, r, p, salt. */
	logN = header[7];
	r = be32dec(&header[8]);
	p = be32dec(&header[12]);
	memcpy(salt, &header[16], 32);

	/* Verify header checksum. */
	SHA256_Init(&ctx);
	SHA256_Update(&ctx, header, 48);
	SHA256_Final(hbuf, &ctx);
	if (memcmp(&header[48], hbuf, 16))
		return (7);

	/*
	 * Check whether the provided parameters are valid and whether the
	 * key derivation function can be computed within the allowed memory
	 * and CPU time.
	 */
	if ((rc = checkparams(maxmem, maxmemfrac, maxtime, logN, r, p)) != 0)
		return (rc);

	/* Compute the derived keys. */
	N = (uint64_t)(1) << logN;
	if (crypto_scrypt(passwd, passwdlen, salt, 32, N, r, p, dk, 64))
		return (3);

	/* Check header signature (i.e., verify password). */
	HMAC_SHA256_Init(&hctx, key_hmac, 32);
	HMAC_SHA256_Update(&hctx, header, 64);
	HMAC_SHA256_Final(hbuf, &hctx);
	if (memcmp(hbuf, &header[64], 32))
		return (11);

	/* Success! */
	return (0);
}
开发者ID:AVVS,项目名称:node-scrypt,代码行数:52,代码来源:scryptenc.c

示例12: sha256

// Deprecated on OSX... figure out the proper thing with their internal lib later...
// Using technique from http://stackoverflow.com/questions/13784434/gcc-use-openssls-sha256-functions
inline std::string sha256(std::string str)
{
  unsigned char hbuf[SHA256_DIGEST_LENGTH];
  std::stringstream ss;
  SHA256_CTX h;
  SHA256_Init(&h);
  SHA256_Update(&h, str.c_str(), str.size());
  SHA256_Final(hbuf, &h);
  for(int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
    ss << std::hex << std::setw(2) << std::setfill('0') << (int)hbuf[i];
    }
  return ss.str();
};
开发者ID:OortConsensus,项目名称:SCP,代码行数:15,代码来源:hash.hpp

示例13: hash

void hash(char *string, char *result) {
	unsigned char hash[SHA256_DIGEST_LENGTH];
	int i = 0;
	SHA256_CTX handler;

	SHA256_Init(&handler);
	SHA256_Update(&handler, string, strlen(string));
	SHA256_Final(hash, &handler);
	memset(result, '\0', strlen(result));
	for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
		sprintf(result, "%s%02x", result, hash[i]);
	};
}
开发者ID:serega6531,项目名称:NTLauncher-authserver,代码行数:13,代码来源:hash.c

示例14: heavy_hash

void heavy_hash(void* output, const void* input, int len)
{
	uint32_t hash1[16], hash2[16], hash3[16], hash4[16], hash5[16];

	HEFTY1(input, len, (unsigned char *)hash1);

	/* HEFTY1 is new, so take an extra security measure to eliminate
	 * the possiblity of collisions:
	 *
	 *	 Hash(x) = SHA256(x + HEFTY1(x))
	 *
	 * N.B. '+' is concatenation.
	 */
	SHA256_CTX sha256;
	SHA256_Init(&sha256);
	SHA256_Update(&sha256, input, len);
	SHA256_Update(&sha256, hash1, sizeof(hash1));
	SHA256_Final((unsigned char*)hash2, &sha256);

	/* Additional security: Do not rely on a single cryptographic hash
	 * function.  Instead, combine the outputs of 4 of the most secure
	 * cryptographic hash functions-- SHA256, KECCAK512, GROESTL512
	 * and BLAKE512.
	 */

	sph_keccak512(&ctx.keccak, input, len);
	sph_keccak512(&ctx.keccak, hash1, sizeof(hash1));
	sph_keccak512_close(&ctx.keccak, hash3);

	sph_groestl512(&ctx.groestl, input, len);
	sph_groestl512(&ctx.groestl, hash1, sizeof(hash1));
	sph_groestl512_close(&ctx.groestl, hash4);

	sph_blake512(&ctx.blake, input, len);
	sph_blake512(&ctx.blake, hash1, sizeof(hash1));
	sph_blake512_close(&ctx.blake, hash5);

	combine_hashes((uint32_t *)output, hash2, hash3, hash4, hash5);
}
开发者ID:bitbandi,项目名称:cpuminer-multi,代码行数:39,代码来源:heavy.c

示例15: sha

int sha(void* input, unsigned long length, unsigned char* md)
{
    SHA256_CTX context;
    if(!SHA256_Init(&context))
        return 0;

    if(!SHA256_Update(&context, (unsigned char*)input, length))
        return 0;

    if(!SHA256_Final(md, &context))
        return 0;
    return 1;
}
开发者ID:cn-uofbasel,项目名称:ccn-lite,代码行数:13,代码来源:ccnl-crypto.c


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