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

C++ sha256函数代码示例

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

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



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

示例1: data

//------------------------------------------------------------------------------
// returns message signature generated from a URI path, a nonce 
// and postdata, message signature is created as a follows:
// 
//   hmac_sha512(path + sha256(nonce + postdata), b64decode(secret)) 
//
// and the result is converted in a base64 string: 
std::string KClient::signature(const std::string& path, 
			    const std::string& nonce, 
			    const std::string& postdata) const
{
   // add path to data to encrypt
   std::vector<unsigned char> data(path.begin(), path.end());

   // concatenate nonce and postdata and compute SHA256
   std::vector<unsigned char> nonce_postdata = sha256(nonce + postdata);

   // concatenate path and nonce_postdata (path + sha256(nonce + postdata))
   data.insert(data.end(), nonce_postdata.begin(), nonce_postdata.end());

   // and compute HMAC
   return b64_encode( hmac_sha512(data, b64_decode(secret_)) );
}
开发者ID:erdincay,项目名称:krakenapi,代码行数:23,代码来源:kclient.cpp


示例2: tag

	/**
	 * @brief        Add a matrix to workspace
	 *
	 * @param  name  Name
	 * @param  m     The added matrix
     *
	 * @return       Success
	 */
	template<class T> inline Matrix<T>&
	AddMatrix        (const std::string& name, boost::shared_ptr< Matrix<T> > m) {

	  std::vector<std::string> tag(2);
		boost::any value = m;
        
		tag[0] = sha256(name);
		tag[1] = typeid(T).name();
		assert (m_ref.find (name) == m_ref.end());
		m_ref.insert (refent(name, tag));
		m_store.insert (entry (tag[0], value));

        m->SetClassName(name.c_str());
        
		return *m;

	}
开发者ID:nomissretep,项目名称:codeare,代码行数:25,代码来源:Workspace.hpp


示例3: hmac_sha256_init

void hmac_sha256_init(hmac_sha256_ctx *ctx, unsigned char *key,
                      unsigned int key_size)
{
    unsigned int fill;
    unsigned int num;

    unsigned char *key_used;
    unsigned char key_temp[SHA256_DIGEST_SIZE];
    int i;

    if (key_size == SHA256_BLOCK_SIZE) {
        key_used = key;
        num = SHA256_BLOCK_SIZE;
    } else {
        if (key_size > SHA256_BLOCK_SIZE){
            key_used = key_temp;
            num = SHA256_DIGEST_SIZE;
            sha256(key, key_size, key_used);
        } else { /* key_size > SHA256_BLOCK_SIZE */
            key_used = key;
            num = key_size;
        }
        fill = SHA256_BLOCK_SIZE - num;

        memset(ctx->block_ipad + num, 0x36, fill);
        memset(ctx->block_opad + num, 0x5c, fill);
    }

    for (i = 0; i < num; i++) {
        ctx->block_ipad[i] = key_used[i] ^ 0x36;
        ctx->block_opad[i] = key_used[i] ^ 0x5c;
    }

    sha256_init(&ctx->ctx_inside);
    sha256_update(&ctx->ctx_inside, ctx->block_ipad, SHA256_BLOCK_SIZE);

    sha256_init(&ctx->ctx_outside);
    sha256_update(&ctx->ctx_outside, ctx->block_opad,
                  SHA256_BLOCK_SIZE);

    /* for hmac_reinit */
    memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside,
           sizeof(sha256_ctx));
    memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside,
           sizeof(sha256_ctx));
}
开发者ID:AlexeyProkhin,项目名称:ireen,代码行数:46,代码来源:hmac_sha2.c


示例4: essiv

static TEE_Result essiv(uint8_t iv[TEE_AES_BLOCK_SIZE],
			const uint8_t fek[TEE_FS_KM_FEK_SIZE],
			uint16_t blk_idx)
{
	TEE_Result res;
	uint8_t sha[TEE_SHA256_HASH_SIZE];
	uint8_t pad_blkid[TEE_AES_BLOCK_SIZE] = { 0, };

	res = sha256(sha, sizeof(sha), fek, TEE_FS_KM_FEK_SIZE);
	if (res != TEE_SUCCESS)
		return res;

	pad_blkid[0] = (blk_idx & 0xFF);
	pad_blkid[1] = (blk_idx & 0xFF00) >> 8;

	return aes_ecb(iv, pad_blkid, sha, 16);
}
开发者ID:pascal-brand-st-dev,项目名称:optee_os,代码行数:17,代码来源:tee_fs_key_manager.c


示例5: hmac_sha256_init

void hmac_sha256_init(struct hmac_sha256_ctx *ctx,
		      const void *k, size_t ksize)
{
	struct sha256 hashed_key;
	/* We use k_opad as k_ipad temporarily. */
	uint64_t *k_ipad = ctx->k_opad;

	/* (keys longer than B bytes are first hashed using H) */
	if (ksize > HMAC_SHA256_BLOCKSIZE) {
		sha256(&hashed_key, k, ksize);
		k = &hashed_key;
		ksize = sizeof(hashed_key);
	}

	/* From RFC2104:
	 *
	 * (1) append zeros to the end of K to create a B byte string
	 *  (e.g., if K is of length 20 bytes and B=64, then K will be
	 *   appended with 44 zero bytes 0x00)
	 */
	memcpy(k_ipad, k, ksize);
	memset((char *)k_ipad + ksize, 0, HMAC_SHA256_BLOCKSIZE - ksize);

	/*
	 * (2) XOR (bitwise exclusive-OR) the B byte string computed
	 * in step (1) with ipad
	 */
	xor_block(k_ipad, IPAD);

	/*
	 * We start (4) here, appending text later:
	 *
	 * (3) append the stream of data 'text' to the B byte string resulting
	 * from step (2)
	 * (4) apply H to the stream generated in step (3)
	 */
	sha256_init(&ctx->sha);
	sha256_update(&ctx->sha, k_ipad, HMAC_SHA256_BLOCKSIZE);

	/*
	 * (5) XOR (bitwise exclusive-OR) the B byte string computed in
	 * step (1) with opad
	 */
	xor_block(ctx->k_opad, IPAD^OPAD);
}
开发者ID:cdecker,项目名称:lightning,代码行数:45,代码来源:hmac_sha256.c


示例6: __64bit_generator

int WorkerThread::insert_query(void)
{
    struct row_data data;

    data.num =  __64bit_generator();
    data.string_a = __generate_rand_string(256);
    data.string_b = __generate_rand_string(256);
    data.sha_digest = sha256(data.string_a + data.string_b + std::to_string(data.num));

    // uint64_t num = __64bit_generator();
    // std::string str1 = __generate_rand_string(256);
    // std::string str2 = __generate_rand_string(256);
    // std::string sha_digest = sha256(str1+str2+std::to_string(num));
    //insert_entry(connection_string, num, str1, str2, sha_digest);
    insert_entry(connection_string, data);

    return 0;
}
开发者ID:spapageo0x01,项目名称:barrageDB,代码行数:18,代码来源:worker_thread.cpp


示例7: do_test

static bool do_test(const struct test *t)
{
	struct sha256 h, expected;

	if (t->repetitions == 1)
		sha256(&h, t->test, strlen(t->test));
	else {
		struct sha256_ctx ctx = SHA256_INIT;
		size_t i;

		for (i = 0; i < t->repetitions; i++)
			sha256_update(&ctx, t->test, strlen(t->test));
		sha256_done(&ctx, &h);
	}

	hex_decode(t->result, strlen(t->result), &expected, sizeof(expected));
	return memcmp(&h, &expected, sizeof(h)) == 0;
}
开发者ID:cdecker,项目名称:lightning,代码行数:18,代码来源:run-test-vectors.c


示例8: sha256

bool
Floodgate::addRecord(StellarMessage const& msg, Peer::pointer peer)
{
    Hash index = sha256(xdr::xdr_to_opaque(msg));
    auto result = mFloodMap.find(index);
    if (result == mFloodMap.end())
    { // we have never seen this message
        mFloodMap[index] = std::make_shared<FloodRecord>(
            msg, mApp.getLedgerManager().getLedgerNum(), peer);
        mFloodMapSize.set_count(mFloodMap.size());
        return true;
    }
    else
    {
        result->second->mPeersTold.push_back(peer);
        return false;
    }
}
开发者ID:brttstl,项目名称:stellar-core,代码行数:18,代码来源:Floodgate.cpp


示例9: create_key

        /**
          *   keys for basic authentication;
          *   result is: sha256( s2 + sha256( s1 + key ) );
          *   s1 and s2 are open information
         **/
        void create_key( const std::string &key,
                         const std::string &s1, const std::string &s2,
                               std::string &result )
        {
            std::string tkey(key);
            std::string ts1 (s1 );
            std::string ts2 (s2 );

            vtrc::unique_ptr<hash_iface> sha256( hash::sha2::create256( ) );

            ts1.append( tkey.begin( ), tkey.end( ) );
            ts1.assign( sha256->get_data_hash( ts1.c_str( ), ts1.size( ) ) );

            ts2.append( ts1.begin( ), ts1.end( ) );
            ts2.assign( sha256->get_data_hash( ts2.c_str( ), ts2.size( ) ) );

            result.swap( ts2 );

        }
开发者ID:malchemist,项目名称:vtrc,代码行数:24,代码来源:vtrc-transformer-create.cpp


示例10: sha256

QString sha256( QString in )
{
    unsigned char digest[ SHA512_DIGEST_SIZE];
    unsigned char* toHash = (unsigned char*)in.toUtf8().data();
    
    sha256( toHash , qstrlen( ( char* )toHash ), digest );

    // this part copied from main() in sha256.cpp
    unsigned char output[2 * SHA512_DIGEST_SIZE + 1];
    int i;

    output[2 * SHA256_DIGEST_SIZE ] = '\0';

    for (i = 0; i < SHA256_DIGEST_SIZE ; i++) {
       sprintf((char *) output + 2*i, "%02x", digest[i]);
    }
    
    return QString::fromAscii( (const char*)output );
}
开发者ID:weiligang512,项目名称:apue-test,代码行数:19,代码来源:AmpacheService.cpp


示例11: sha256

// send message to anyone you haven't gotten it from
void
Floodgate::broadcast(StellarMessage const& msg, bool force)
{
    if (mShuttingDown)
    {
        return;
    }
    Hash index = sha256(xdr::xdr_to_opaque(msg));
    auto result = mFloodMap.find(index);
    if (result == mFloodMap.end() || force)
    { // no one has sent us this message
        FloodRecord::pointer record = std::make_shared<FloodRecord>(
            msg, mApp.getHerder().getCurrentLedgerSeq(), Peer::pointer());
        record->mPeersTold = mApp.getOverlayManager().getPeers();

        mFloodMap[index] = record;
        mFloodMapSize.set_count(mFloodMap.size());
        for (auto peer : mApp.getOverlayManager().getPeers())
        {
            if (peer->isAuthenticated())
            {
                peer->sendMessage(msg);
                record->mPeersTold.push_back(peer);
            }
        }
    }
    else
    { // send it to people that haven't sent it to us
        std::vector<Peer::pointer>& peersTold = result->second->mPeersTold;
        for (auto peer : mApp.getOverlayManager().getPeers())
        {
            if (find(peersTold.begin(), peersTold.end(), peer) ==
                peersTold.end())
            {
                if (peer->isAuthenticated())
                {
                    peer->sendMessage(msg);
                    peersTold.push_back(peer);
                }
            }
        }
    }
}
开发者ID:nullstyle,项目名称:stellar-core,代码行数:44,代码来源:Floodgate.cpp


示例12: sha256

string Utility::importMedia(string pathname) {
  string container;
  
  if(file::exists(pathname) && file::size(pathname) <= 0x10000) {
    // Check if it's one of the system ROMs
    if(auto manifest = program->getUserResource("Nintendo DS.sys/manifest.bml")) {
      auto elem     = Markup::Document(vectorstream(manifest()).text());
      auto contents = file::read(pathname);
      auto hash     = sha256(contents.data(), contents.size());
      auto sysfolder = program->savePath("Nintendo DS.sys/");
      
      if(hash == elem["system/memory/arm9/sha256"].text()) {
        string dest = {sysfolder, elem["system/memory/arm9/data"].text()};
        file::write(dest, contents);
        return "<system>";
      }
      else if(hash == elem["system/memory/arm7/sha256"].text()) {
        string dest = {sysfolder, elem["system/memory/arm7/data"].text()};
        file::write(dest, contents);
        return "<system>";
      }
    }
  }
  
  if(!NintendoDS::validateHeader(filestream(pathname, file::mode::read))) {
    MessageWindow().setTitle("Import failed").setText(
      {"Couldn't import ",pathname,".\n"
       "\n"
       "This file doesn't look like a Nintendo DS title.\n"})
      .error();
    return "";
  }
  else if(!NintendoDS::importROMImage(container, libraryPath(), pathname)) {
    MessageWindow().setTitle("Import failed").setText(
      {"Couldn't import ",pathname,".\n"
       "\n"
       "Check to see if you've got sufficient permissions and disk space."})
      .error();
    return "";
  }
  return container;
}
开发者ID:Cydrak,项目名称:dasShiny,代码行数:42,代码来源:utility.cpp


示例13: validate_response

static int validate_response(connection *c) {
    char *source, *ret_hash, *nonce, *freeme;
    char scratch[512];

    unsigned char vhash[SHA_LENGTH];
    int valid = 0;

    /* printf("c->buf = %s.\n", c->buf); */
    freeme = source = strdup(c->buf);
    ret_hash = strsep(&source, ":");
    nonce = source;
    /* printf("nonce = %s.\n", nonce); */

    /* no colon: nope */
    if (nonce != NULL) {
        /* returned hash != sent hash: nope */
        if (memcmp(ret_hash, c->hash, SHA_LENGTH * 2) == 0) {
            strcpy(scratch, ret_hash);
            strcat(scratch, nonce);
            sha256(scratch, strlen(scratch), vhash);

            /* is the work proved? */
            if (vhash[SHA_LENGTH - 1] == 0) {
                valid = 1;
                strcpy(c->last_hash, c->hash);
                hexillate(vhash, c->hash, SHA_LENGTH);
            }
            else {
                printf("%s is not a valid proof of work.\n", c->buf);
            }
        }
        else {
            printf("received payload %s doesn't match sent payload %s.\n", ret_hash, c->hash);
        }
    }
    else {
        printf("input %s is missing a nonce.\n", c->buf);
    }

    free(freeme);
    return valid;
}
开发者ID:othiym23,项目名称:nonsense-wrk,代码行数:42,代码来源:wrk.c


示例14: tag

	/**
	 * @brief        Add a matrix to workspace
	 *
	 * @param  name  Name
	 * @param  m     The added matrix
     *
	 * @return       Success
	 */
	template<class T> inline Matrix<T>&
	AddMatrix        (const std::string& name) {

		shrd_ptr<Matrix<T> > m = mk_shared<Matrix<T> >();
		std::vector<std::string> tag(2);
		boost::any value = m;
        
		tag[0] = sha256(name);
		tag[1] = typeid(T).name();
		reflist::iterator ri = m_ref.find (name);
		if (ri != m_ref.end())
			Free (name);
		m_ref.insert (refent(name, tag));
		m_store.insert (entry (tag[0], value));

        m->SetClassName(name.c_str());
        
		return *m;

	}
开发者ID:kvahed,项目名称:codeare,代码行数:28,代码来源:Workspace.hpp


示例15: main

int main(int argc, char *argv[])
{
	const tal_t *ctx = tal_arr(NULL, char, 0);
	struct sha256 seed, revocation_hash, rval;
	struct pkt *pkt;
	unsigned update_num;

	err_set_progname(argv[0]);

	opt_register_noarg("--help|-h", opt_usage_and_exit,
			   "<seed> <update-number> <r-value>\n"
			   "Create a new HTLC complete message",
			   "Print this message.");
	opt_register_version();

 	opt_parse(&argc, argv, opt_log_stderr_exit);

	if (argc != 4)
		opt_usage_exit_fail("Expected 3 arguments");

	if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed)))
		errx(1, "Invalid seed '%s' - need 256 hex bits", argv[1]);
	update_num = atoi(argv[2]);
	if (!update_num)
		errx(1, "Update number %s invalid", argv[2]);

	if (!hex_decode(argv[3], strlen(argv[3]), &rval, sizeof(rval)))
		errx(1, "Invalid rvalue '%s' - need 256 hex bits", argv[3]);

	/* Get next revocation hash. */
	shachain_from_seed(&seed, update_num, &revocation_hash);
	sha256(&revocation_hash,
	       revocation_hash.u.u8, sizeof(revocation_hash.u.u8));

	pkt = update_htlc_complete_pkt(ctx, &revocation_hash, &rval);
	if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
		err(1, "Writing out packet");

	tal_free(ctx);
	return 0;
}
开发者ID:bitcredit-currency,项目名称:lightning,代码行数:41,代码来源:update-channel-htlc-complete.c


示例16: test_sha256

void test_sha256() {
	const char * tests[4] = {
		"", "A", "0123456789", "abcdefghijklmnopqrstuvwxyz"
	};
	const char * oks[4] = {
		"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
		"559aead08264d5795d3909718cdd05abd49572e84fe55590eef31a88a08fdffd",
		"84d89877f0d4041efb6bf91a16f0248f2fd573e6af05c19f96bedb9f882f7882",
		"71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73"
	};
	uint8_t hash[SHA256_HASH_SIZE];
	char string[SHA256_STRING_HASH_SIZE];
	int i;
	puts("\n\nTesting SHA256...\n");
	for (i = 0; i < 4; i++) {
		sha256(tests[i], strlen(tests[i]), hash);
		sha256_hash_to_string(hash, string);
		printf("%s\n%s\n--> %s\n\n", tests[i], string, strcmp(string, oks[i]) == 0 ? "OK" : "FAIL");
	}
	puts("\nTest done.\n");
}
开发者ID:zdone,项目名称:libhash,代码行数:21,代码来源:tests.c


示例17: hmac_sha256_init

void hmac_sha256_init(hmac_sha256_ctx_t *s, void* key, uint16_t keylength_b){
	uint8_t buffer[SHA256_HASH_BYTES];
	uint8_t i;
	
	memset(buffer, 0, SHA256_HASH_BYTES);
	if (keylength_b > SHA256_BLOCK_BITS){
		sha256((void*)buffer, key, keylength_b);
	} else {
		memcpy(buffer, key, (keylength_b+7)/8);
	}
	
	for (i=0; i<SHA256_HASH_BYTES; ++i){
		buffer[i] ^= IPAD;
	}
	
	sha256_init(s);
	sha256_nextBlock(s, buffer);
#if defined SECURE_WIPE_BUFFER
	memset(buffer, 0, SHA256_HASH_BYTES);
#endif
}
开发者ID:azilly-de,项目名称:openkubus,代码行数:21,代码来源:hmac-sha256.c


示例18: sqliteTx

void CoinQKeychainSqlite3::insertMultiSigRedeemScript(const std::vector<uchar_vector>& pubKeys, int type, int status, const std::string& label, int minHeight, int maxHeight)
{
    if (type < 1 || type > 2) {
        throw CoinQ::Exception("Invalid type.", CoinQ::Exception::INVALID_PARAMETERS);
    }

    if (status < 1 || status > 2) {
        throw CoinQ::Exception("Invalid status.", CoinQ::Exception::INVALID_PARAMETERS);
    }

    Coin::MultiSigRedeemScript multiSig;
    for (auto& pubKey: pubKeys) {
        multiSig.addPubKey(pubKey);
    }

    SQLite3Tx sqliteTx(db, SQLite3Tx::IMMEDIATE);
    SQLite3Stmt stmt;
    stmt.prepare(db, "INSERT INTO `redeemscripts` (`hash`, `type`, `status`, `minheight`, `maxheight`, `label`) VALUES (?,?,?,?,?,?)");
    stmt.bindText(1, ripemd160(sha256(multiSig.getRedeemScript())).getHex());
    stmt.bindInt (2, type);
    stmt.bindInt (3, status);
    stmt.bindInt (4, minHeight);
    stmt.bindInt (5, maxHeight);
    stmt.bindText(6, label);
    stmt.step();
    stmt.finalize();

    std::stringstream sql;
    sql << "INSERT INTO `multisigs` (`redeemscript_id`, `pubkey`, `index`) VALUES (" << db.lastInsertRowId() << ",?,?)";
    stmt.prepare(db, sql.str());

    int i = 0;
    for (auto& pubKey: pubKeys) {
        stmt.reset();
        stmt.bindText(1, pubKey.getHex());
        stmt.bindInt (2, i++);
        stmt.step();
    }
}
开发者ID:AndreV84,项目名称:mSIGNA,代码行数:39,代码来源:CoinQ_sqlite3.cpp


示例19: parse_partitions

void parse_partitions(void* buf, char* target_dir){
	char part_dir[256];
	uint8_t hash[SHA256_DIGEST_LENGTH];
	uint8_t* buffer = (uint8_t*)buf + 0x200;
	uint32_t cur_part = PART_BASE;
	uint32_t part_length = 0;
	uint32_t hash_tbl_length = 0;

	if(mkdir(target_dir, 0766) < 0){
		fprintf(stderr, "Couldn't create dir %s\n", target_dir);
		return;
	}

	chdir(target_dir);
	while(!strncmp((char*)buffer, "DIFI", 4)){
		snprintf(part_dir, sizeof(part_dir), "part-%d", buffer[FS_INDEX_OFF]);
		hash_tbl_length = *((uint32_t*)&buffer[HASH_TBL_LEN_OFF]);
		part_length = *((uint32_t*)&buffer[PARTITION_LEN_OFF]);
		for(int i = 0; i < hash_tbl_length; i += SHA256_DIGEST_LENGTH){
			for(int j = 0; j < part_length; j += SECTOR_SIZE){
				sha256(buf + j + cur_part + hash_tbl_length, (part_length - j > SECTOR_SIZE) ? SECTOR_SIZE : part_length - j, hash);
				if(!memcmp(buf + i + cur_part, hash, sizeof(hash))){
					printf("Block (%08X) matches entry %d (", j + cur_part + hash_tbl_length, i / SHA256_DIGEST_LENGTH);
					for(int x = 0; x < SHA256_DIGEST_LENGTH; x++)
						printf("%02x", hash[x]);
					printf(")\n");
				}
			}
		}
#ifdef DEBUG
		printf("Partition @ %06X (%06X)\n", cur_part, part_length + hash_tbl_length);
#endif /* DEBUG */
		cur_part += hash_tbl_length;
		parse_fs(buf + cur_part, part_dir);
		cur_part += part_length;
		buffer += DIFI_LENGTH;
	}	
}
开发者ID:3dshax,项目名称:3ds,代码行数:38,代码来源:decrypt.c


示例20: hmac_sha256

void hmac_sha256( const unsigned char *key, size_t keyLen,
                  const unsigned char *msg, size_t msgLen,
                  unsigned char hash[] )
{
    unsigned char	pad[ HMAC_SHA256_BLOCK_SIZE ];
    unsigned char	normalizedKey[ HMAC_SHA256_BLOCK_SIZE ];
    unsigned char	intermediateHash[ HMAC_SHA256_HASH_SIZE ];
    size_t		i;
    sha256_ctx	ctx;

    memset( normalizedKey, 0, HMAC_SHA256_BLOCK_SIZE );
    if ( keyLen > HMAC_SHA256_BLOCK_SIZE )
        sha256( key, keyLen, normalizedKey );
    else	{
        for ( i = 0; i < keyLen; i++ )
            normalizedKey[ i ] = key[ i ];
    }

    memset( pad, 0x36, HMAC_SHA256_BLOCK_SIZE );
    for ( i = 0; i < HMAC_SHA256_BLOCK_SIZE; i++ )
        pad[ i ] ^= normalizedKey[ i ];
    sha256_init( &ctx );
    sha256_update( &ctx, pad, HMAC_SHA256_BLOCK_SIZE );
    sha256_update( &ctx, msg, msgLen );
    sha256_final( &ctx, intermediateHash );

    memset( pad, 0x5c, HMAC_SHA256_BLOCK_SIZE );
    for ( i = 0; i < HMAC_SHA256_BLOCK_SIZE; i++ )
        pad[ i ] ^= normalizedKey[ i ];
    sha256_init( &ctx );
    sha256_update( &ctx, pad, HMAC_SHA256_BLOCK_SIZE );
    sha256_update( &ctx, intermediateHash, HMAC_SHA256_HASH_SIZE );
    sha256_final( &ctx, hash );

    memset( pad, 0, sizeof( pad ));
    memset( normalizedKey, 0, sizeof( normalizedKey ));
    memset( intermediateHash, 0, sizeof( intermediateHash ));
}
开发者ID:ProjectTegano,项目名称:Tegano,代码行数:38,代码来源:hmac_sha256.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ sha256_final函数代码示例发布时间:2022-05-30
下一篇:
C++ sha1_update函数代码示例发布时间: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