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


C++ sha256函数代码示例

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


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


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