本文整理汇总了C++中sha256_final函数的典型用法代码示例。如果您正苦于以下问题:C++ sha256_final函数的具体用法?C++ sha256_final怎么用?C++ sha256_final使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sha256_final函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: xdag_hash_final_multi
uint64_t xdag_hash_final_multi(void *ctxv, uint64_t *nonce, int attempts, int step, xdag_hash_t hash)
{
SHA256REF_CTX ctx;
xdag_hash_t hash0;
uint64_t min_nonce = 0;
int i;
for (i = 0; i < attempts; ++i) {
memcpy(&ctx, ctxv, sizeof(ctx));
sha256_update(&ctx, (uint8_t*)nonce, sizeof(uint64_t));
sha256_final(&ctx, (uint8_t*)hash0);
sha256_init(&ctx);
sha256_update(&ctx, (uint8_t*)hash0, sizeof(xdag_hash_t));
sha256_final(&ctx, (uint8_t*)hash0);
if (!i || xdag_cmphash(hash0, hash) < 0) {
memcpy(hash, hash0, sizeof(xdag_hash_t));
min_nonce = *nonce;
}
*nonce += step;
}
return min_nonce;
}
开发者ID:xrdavies,项目名称:android-wallet,代码行数:25,代码来源:hash.c
示例2: sha256_test
/*********************** FUNCTION DEFINITIONS ***********************/
void sha256_test()
{
BYTE text1[] = {"abc"};
BYTE text2[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
BYTE text3[] = {"aaaaaaaaaa"};
BYTE hash1[SHA256_BLOCK_SIZE] = {0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea,0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23,
0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c,0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad};
BYTE hash2[SHA256_BLOCK_SIZE] = {0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8,0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39,
0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67,0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1};
BYTE hash3[SHA256_BLOCK_SIZE] = {0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92,0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67,
0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e,0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0};
BYTE buf[SHA256_BLOCK_SIZE];
SHA256_CTX ctx;
int idx;
sha256_init(&ctx);
sha256_update(&ctx, text1, strlen((char *)text1));
sha256_final(&ctx, buf);
ok (!memcmp(hash1, buf, SHA256_BLOCK_SIZE),
"text1 OK");
sha256_init(&ctx);
sha256_update(&ctx, text2, strlen((char *)text2));
sha256_final(&ctx, buf);
ok (!memcmp(hash2, buf, SHA256_BLOCK_SIZE),
"text2 OK");
sha256_init(&ctx);
for (idx = 0; idx < 100000; ++idx)
sha256_update(&ctx, text3, strlen((char *)text3));
sha256_final(&ctx, buf);
ok (!memcmp(hash3, buf, SHA256_BLOCK_SIZE),
"text3 OK");
}
开发者ID:flux-framework,项目名称:flux-core,代码行数:35,代码来源:sha256.c
示例3: main
int main()
{
unsigned char text1[]={"abc"},
text2[]={"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"},
text3[]={"aaaaaaaaaa"},
hash[32];
int idx;
SHA256_CTX ctx;
// Hash one
sha256_init(&ctx);
sha256_update(&ctx,text1,strlen(text1));
sha256_final(&ctx,hash);
print_hash(hash);
// Hash two
sha256_init(&ctx);
sha256_update(&ctx,text2,strlen(text2));
sha256_final(&ctx,hash);
print_hash(hash);
// Hash three
sha256_init(&ctx);
for (idx=0; idx < 100000; ++idx)
sha256_update(&ctx,text3,strlen(text3));
sha256_final(&ctx,hash);
print_hash(hash);
getchar();
return 0;
}
开发者ID:aignacio,项目名称:homestark,代码行数:31,代码来源:sha256_example.c
示例4: hmac
void hmac(char* key,char* m,char len,char* buf){
SHA256_CTX ctx;
BYTE concat[130];
BYTE o_key_pad[65];
BYTE i_key_pad[65];
memset(o_key_pad,0,sizeof o_key_pad);
memset(i_key_pad,0,sizeof i_key_pad);
memcpy(o_key_pad,key,SHA256_BLOCK_SIZE);
memcpy(i_key_pad,key,SHA256_BLOCK_SIZE);
for(char i=0;i<64;i++){
o_key_pad[i]^=0x5c;
i_key_pad[i]^=0x36;
}
memset(concat,0,sizeof concat);
memcpy(concat,i_key_pad,64);
memcpy(concat+64,m,len);
sha256_init(&ctx);
sha256_update(&ctx, concat, 64+len);
sha256_final(&ctx, buf);
memset(concat,0,sizeof concat);
memcpy(concat,o_key_pad,64);
memcpy(concat+64,buf,SHA256_BLOCK_SIZE);
sha256_init(&ctx);
sha256_update(&ctx, concat, 64+SHA256_BLOCK_SIZE);
sha256_final(&ctx, buf);
}
开发者ID:AdrianPata,项目名称:crono.ski,代码行数:33,代码来源:crypto_hmac.c
示例5: hmac_sha256_final
void
hmac_sha256_final(hmac_sha256_ctx *ctx, uint8_t *mac)
{
uint8_t digest[SHA256_DIGEST_LEN];
sha256_final(&ctx->ictx, digest);
sha256_update(&ctx->octx, digest, sizeof digest);
sha256_final(&ctx->octx, mac);
memset(ctx, 0, sizeof *ctx);
}
开发者ID:cryb-to,项目名称:cryb-to,代码行数:10,代码来源:cryb_hmac_sha256.c
示例6: protoshares_process_8
void protoshares_process_8(minerProtosharesBlock_t* block)
{
// generate mid hash using sha256 (header hash)
uint8 midHash[32];
sha256_ctx c256;
sha256_init(&c256);
sha256_update(&c256, (unsigned char*)block, 80);
sha256_final(&c256, midHash);
sha256_init(&c256);
sha256_update(&c256, (unsigned char*)midHash, 32);
sha256_final(&c256, midHash);
// init collision map
if( __collisionMap == NULL )
__collisionMap = (uint32*)malloc(sizeof(uint32)*COLLISION_TABLE_SIZE);
uint32* collisionIndices = __collisionMap;
memset(collisionIndices, 0x00, sizeof(uint32)*COLLISION_TABLE_SIZE);
// start search
// uint8 midHash[64];
uint8 tempHash[32+4];
sha512_ctx c512;
uint64 resultHashStorage[8*CACHED_HASHES];
memcpy(tempHash+4, midHash, 32);
for(uint32 n=0; n<MAX_MOMENTUM_NONCE; n += BIRTHDAYS_PER_HASH * CACHED_HASHES)
{
if( block->height != monitorCurrentBlockHeight )
break;
for(uint32 m=0; m<CACHED_HASHES; m++)
{
sha512_init(&c512);
*(uint32*)tempHash = n+m*8;
sha512_update_final(&c512, tempHash, 32+4, (unsigned char*)(resultHashStorage+8*m));
}
for(uint32 m=0; m<CACHED_HASHES; m++)
{
uint64* resultHash = resultHashStorage + 8*m;
uint32 i = n + m*8;
for(uint32 f=0; f<8; f++)
{
uint64 birthday = resultHash[f] >> (64ULL-SEARCH_SPACE_BITS);
uint32 collisionKey = (uint32)((birthday>>18) & COLLISION_KEY_MASK);
birthday %= COLLISION_TABLE_SIZE;
if( collisionIndices[birthday] )
{
if( ((collisionIndices[birthday]&COLLISION_KEY_MASK) != collisionKey) || protoshares_revalidateCollision(block, midHash, collisionIndices[birthday]&~COLLISION_KEY_MASK, i+f) == false )
{
// invalid collision -> ignore
}
}
collisionIndices[birthday] = i+f | collisionKey; // we have 6 bits available for validation
}
}
}
}
开发者ID:COOLBGT,项目名称:fastrie,代码行数:55,代码来源:protosharesMiner.cpp
示例7: xdag_hash_final
void xdag_hash_final(void *ctxv, void *data, size_t size, xdag_hash_t hash)
{
SHA256REF_CTX ctx;
memcpy(&ctx, ctxv, sizeof(ctx));
sha256_update(&ctx, (uint8_t*)data, size);
sha256_final(&ctx, (uint8_t*)hash);
sha256_init(&ctx);
sha256_update(&ctx, (uint8_t*)hash, sizeof(xdag_hash_t));
sha256_final(&ctx, (uint8_t*)hash);
}
开发者ID:xrdavies,项目名称:android-wallet,代码行数:11,代码来源:hash.c
示例8: xdag_hash
void xdag_hash(void *data, size_t size, xdag_hash_t hash)
{
SHA256REF_CTX ctx;
sha256_init(&ctx);
sha256_update(&ctx, data, size);
sha256_final(&ctx, (uint8_t*)hash);
sha256_init(&ctx);
sha256_update(&ctx, (uint8_t*)hash, sizeof(xdag_hash_t));
sha256_final(&ctx, (uint8_t*)hash);
}
开发者ID:xrdavies,项目名称:android-wallet,代码行数:11,代码来源:hash.c
示例9: hmac_sha256_final
void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac,
unsigned int mac_size)
{
unsigned char digest_inside[SHA256_DIGEST_SIZE];
unsigned char mac_temp[SHA256_DIGEST_SIZE];
sha256_final(&ctx->ctx_inside, digest_inside);
sha256_update(&ctx->ctx_outside, digest_inside, SHA256_DIGEST_SIZE);
sha256_final(&ctx->ctx_outside, mac_temp);
memcpy(mac, mac_temp, mac_size);
}
开发者ID:AlexeyProkhin,项目名称:ireen,代码行数:11,代码来源:hmac_sha2.c
示例10: main
int main(void) {
uint32_t err_code;
uint32_t time0, time1;
LOG("Starting LFCLK");
err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
nrf_drv_clock_lfclk_request(NULL);
LOG("Starting RTC");
err_code = nrf_drv_rtc_init(&rtc, NULL, &rtc_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_rtc_tick_enable(&rtc, false);
nrf_drv_rtc_enable(&rtc);
LOG("Starting RNG");
err_code = nrf_drv_rng_init(NULL);
APP_ERROR_CHECK(err_code);
while (1) {
/* get a random key */
time0 = nrf_drv_rtc_counter_get(&rtc);
uECC_make_key(public_key, private_key);
time1 = nrf_drv_rtc_counter_get(&rtc);
LOG("Key time was %u ", time1 - time0);
/* use the key to sign the hash */
time0 = nrf_drv_rtc_counter_get(&rtc);
uECC_sign(private_key, hash, signature);
time1 = nrf_drv_rtc_counter_get(&rtc);
LOG("Sig Time was %u ", time1 - time0);
/* verify the signature */
time0 = nrf_drv_rtc_counter_get(&rtc);
uECC_verify(public_key, hash, signature);
time1 = nrf_drv_rtc_counter_get(&rtc);
LOG("Verify Time was %u ", time1 - time0);
time0 = nrf_drv_rtc_counter_get(&rtc);
uECC_shared_secret(public_key, private_key, secret);
time1 = nrf_drv_rtc_counter_get(&rtc);
LOG("SS Time was %u ", time1 - time0);
time0 = nrf_drv_rtc_counter_get(&rtc);
sha256_init(&context);
sha256_update(&context, message, 20);
sha256_final(&context, shahash);
time1 = nrf_drv_rtc_counter_get(&rtc);
LOG("SHA Time was %u ", time1 - time0);
}
return 0;
}
开发者ID:kkiningh,项目名称:nrf-crypto-tests,代码行数:60,代码来源:test.c
示例11: exit
QString Cache::hashFile(QString path) {
sha256_ctx ctx;
FILE *inFile;
char buffer[BUFFER_SIZE], output[2 * SHA256_DIGEST_SIZE + 1];
unsigned char digest[SHA256_DIGEST_SIZE];
int bytes;
if (!(inFile = fopen(path.toStdString().c_str(), "rb"))) {
cerr << "\x1b[31m[Medusa Error]: Couldn't read " + path.toStdString() + ". Please check if it exists and is readable.\x1b[0m" << endl;
exit(-1);
}
sha256_init(&ctx);
while ((bytes = fread(buffer, 1, BUFFER_SIZE, inFile)) != 0)
sha256_update(&ctx, (const unsigned char *) buffer, bytes);
sha256_final(&ctx, digest);
fclose(inFile);
output[2 * SHA256_DIGEST_SIZE] = 0;
for (int i = 0; i < SHA256_DIGEST_SIZE ; i++)
sprintf(output + 2 * i, "%02X", digest[i]);
return QString(output);
}
开发者ID:kaendfinger,项目名称:medusa,代码行数:25,代码来源:cache.cpp
示例12: compute_master_secret
/*
* \brief Computes the master secret.
*
* \param ps The premaster secret.
* \param client_random The random value from the client hello.
* \param server_random The random value from the server hello.
* \param master_secret A pointer to the final value of the master secret.
* Write the end result here.
*/
void
compute_master_secret(int ps, int client_random, int server_random, char *master_secret)
{
SHA256_CTX ctx;
sha256_init(&ctx);
unsigned char data[sizeof(int)];
unsigned char data1[sizeof(int)];
unsigned char data2[sizeof(int)];
unsigned char data3[sizeof(int)];
char master_secret0[16], master_secret1[16], master_secret2[16], master_secret3[16];
memcpy(data, &ps, sizeof(ps));
sha256_update(&ctx, data, (int) sizeof(data));
memcpy(data1, &client_random, sizeof(client_random));
sha256_update(&ctx, data1, (int) sizeof(data1));
memcpy(data2, &server_random, sizeof(server_random));
sha256_update(&ctx, data2, (int) sizeof(data2));
memcpy(data3, &ps, sizeof(ps));
sha256_update(&ctx, data3, (int) sizeof(data3));
sha256_final(&ctx, (unsigned char*) master_secret);
}
开发者ID:Garyguo2011,项目名称:TLS-Implementation,代码行数:34,代码来源:client_test.c
示例13: ota_package_verify
static uint32_t ota_package_verify(struct ota *ota)
{
uint32_t err_code;
uint32_t offset;
uint8_t buffer[32];
sha256_context_t c __attribute__((aligned(4)));
unsigned char md[SHA256_DIGEST_LENGTH] __attribute__((aligned(4)));
size_t len;
sha256_init(&c);
len = sizeof(buffer);
for (offset = 0; offset < ota->sig.size; offset += sizeof(buffer)) {
if (offset + len >= ota->sig.size)
{
len = ota->sig.size - offset;
}
err_code = ota_read_bytes(ota_get_cache_offset(ota) * ERASE_PAGE_SIZE
+ OTA_HEADER_OFFSET + offset,
buffer, len);
if (err_code)
return err_code;
sha256_update(&c, buffer, len);
}
sha256_final(md, &c);
uint8_t *buf;
buf = (uint8_t *) (ota_get_cache_offset(ota) * ERASE_PAGE_SIZE + OTA_HEADER_OFFSET);
ota->payload = buf + ota->header.hdr_length;
return !secure_update(& (ota->sig), md);
}
开发者ID:pafcndg,项目名称:ndgIqSoftwareKit,代码行数:34,代码来源:ota.c
示例14: mgf1_sha256
void mgf1_sha256(uint8_t *seed, size_t seedLen, size_t maskLen, uint8_t *out) {
SHA256_CTX base, ctrhash;
sha256_init(&base);
sha256_update(&base, seed, seedLen);
uint8_t ctrbuf[4];
uint8_t hashbuf[32];
uint64_t ctr;
for(ctr = 0; ctr < maskLen; ctr+=32) {
memcpy(&ctrhash, &base, sizeof(SHA256_CTX));
encbe32(ctr / 32, ctrbuf);
sha256_update(&ctrhash, ctrbuf, 4);
sha256_final(&ctrhash, hashbuf);
if(maskLen - ctr < 32) {
memcpy(&out[ctr], hashbuf, maskLen - ctr);
} else {
memcpy(&out[ctr], hashbuf, 32);
}
}
memsets(&base, 0, sizeof(SHA256_CTX));
memsets(&ctrhash, 0, sizeof(SHA256_CTX));
memsets(ctrbuf, 0, 4);
memsets(hashbuf, 0, 32);
}
开发者ID:iburinoc,项目名称:ibcrypt,代码行数:27,代码来源:rsa.c
示例15: make_sha256
static void make_sha256(const void *buf, size_t bufLen, BYTE *tmpHash)
{
SHA256_CONTEXT tmp;
sha256_init(&tmp);
sha256_write(&tmp, buf, bufLen);
sha256_final(&tmp, tmpHash);
}
开发者ID:martok,项目名称:miranda-ng,代码行数:7,代码来源:utils.cpp
示例16: create_passphrase_digest
int create_passphrase_digest(const unsigned char* passphrase, unsigned char* digest)
{
int was_successful = 0;
do{
if(!passphrase)
break;
SHA256_CTX ctx;
size_t passphrase_len = strlen((char*)passphrase);
sha256_init(&ctx);
sha256_update(&ctx, passphrase, passphrase_len);
sha256_final(&ctx, digest);
was_successful = 1;
}while(0);
if(!was_successful)
{
}
return was_successful;
}
开发者ID:sepisoad,项目名称:samples,代码行数:25,代码来源:protection.c
示例17: get_cookie
/*
* Generate a cookie (aka SPI)
* First argument is true if we're to create an Initiator cookie.
* Length SHOULD be a multiple of sizeof(u_int32_t).
*
* As responder, we use a hashing method to get a pseudo random
* value instead of using our own random pool. It will prevent
* an attacker from gaining raw data from our random pool and
* it will prevent an attacker from depleting our random pool
* or entropy.
*/
void get_cookie(bool initiator, u_int8_t cookie[COOKIE_SIZE],
const ip_address *addr)
{
do {
if (initiator) {
get_rnd_bytes(cookie, COOKIE_SIZE);
} else {
static u_int32_t counter = 0; /* STATIC */
unsigned char addr_buff[
sizeof(union { struct in_addr A;
struct in6_addr B;
})];
u_char buffer[SHA2_256_DIGEST_SIZE];
sha256_context ctx;
size_t addr_length =
addrbytesof(addr, addr_buff,
sizeof(addr_buff));
sha256_init(&ctx);
sha256_write(&ctx, addr_buff, addr_length);
sha256_write(&ctx, secret_of_the_day,
sizeof(secret_of_the_day));
counter++;
sha256_write(&ctx, (const void *) &counter,
sizeof(counter));
sha256_final(buffer, &ctx);
/* cookie size is smaller than any hash output sizes */
memcpy(cookie, buffer, COOKIE_SIZE);
}
} while (is_zero_cookie(cookie)); /* probably never loops */
}
开发者ID:doctaweeks,项目名称:libreswan,代码行数:43,代码来源:cookie.c
示例18: sha256
void sha256(unsigned char *digest, int len, unsigned char *hash)
{
SHA256CTX c = sha256_init();
if (c != NULL) {
sha256_update(c, digest, len);
sha256_final(hash, c);
}
}
开发者ID:cedral,项目名称:libssh,代码行数:8,代码来源:libcrypto.c
示例19: sha256
void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
{
sha256_ctx ctx;
sha256_init(&ctx);
sha256_update(&ctx, message, len);
sha256_final(&ctx, digest);
}
开发者ID:Asterios,项目名称:contiki-tls-dtls,代码行数:8,代码来源:sha2.c
示例20: SHA256
void SHA256(const void *data, size_t len, uint8_t *hash)
{
SHA256_CTX ctx;
sha256_init(&ctx);
sha256_update(&ctx, data, len);
sha256_final(&ctx, hash);
}
开发者ID:S010,项目名称:test,代码行数:8,代码来源:protocol.c
注:本文中的sha256_final函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论