本文整理汇总了C++中sha256_init函数的典型用法代码示例。如果您正苦于以下问题:C++ sha256_init函数的具体用法?C++ sha256_init怎么用?C++ sha256_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sha256_init函数的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: testHash
void testHash()
{
unsigned char Digest[32];
sha256_context ctx;
sha256_init( &ctx );
sha256_starts( &ctx, 0 );
sha256_update( &ctx, sha256_test_buf[0], sha256_test_buflen[0] );
sha256_finish( &ctx, Digest );
print_buffer(Digest, sizeof(Digest));
memset(Digest, 0, sizeof(Digest));
uint8 buffer[1];
sha256_init( &ctx );
sha256_starts( &ctx, 0 );
buffer[0] = 'a';
sha256_update( &ctx, buffer, 1 );
buffer[0] = 'b';
sha256_update( &ctx, buffer, 1 );
buffer[0] = 'c';
sha256_update( &ctx, buffer, 1 );
buffer[0] = '\0';
sha256_update( &ctx, buffer, 1 );
sha256_finish( &ctx, Digest );
print_buffer(Digest, sizeof(Digest));
}
开发者ID:dileepkella85,项目名称:trunk,代码行数:35,代码来源:crypto.c
示例3: yarrow256_init
void
yarrow256_init(struct yarrow256_ctx *ctx,
unsigned n,
struct yarrow_source *s)
{
unsigned i;
sha256_init(&ctx->pools[0]);
sha256_init(&ctx->pools[1]);
ctx->seeded = 0;
/* Not strictly necessary, but it makes it easier to see if the
* values are sane. */
memset(ctx->counter, 0, sizeof(ctx->counter));
ctx->nsources = n;
ctx->sources = s;
for (i = 0; i<n; i++)
{
ctx->sources[i].estimate[YARROW_FAST] = 0;
ctx->sources[i].estimate[YARROW_SLOW] = 0;
ctx->sources[i].next = YARROW_FAST;
}
}
开发者ID:Distrotech,项目名称:nettle,代码行数:26,代码来源:yarrow256.c
示例4: 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
示例5: hmac_sha256_init
void hmac_sha256_init(hmac_sha256_ctx_t *s, const void* key, uint16_t keylength_b){
uint8_t buffer[HMAC_SHA256_BLOCK_BYTES];
uint8_t i;
memset(buffer, 0, HMAC_SHA256_BLOCK_BYTES);
if (keylength_b > HMAC_SHA256_BLOCK_BITS){
sha256((void*)buffer, key, keylength_b);
} else {
memcpy(buffer, key, (keylength_b+7)/8);
}
for (i=0; i<HMAC_SHA256_BLOCK_BYTES; ++i){
buffer[i] ^= IPAD;
}
sha256_init(&(s->a));
sha256_nextBlock(&(s->a), buffer);
for (i=0; i<HMAC_SHA256_BLOCK_BYTES; ++i){
buffer[i] ^= IPAD^OPAD;
}
sha256_init(&(s->b));
sha256_nextBlock(&(s->b), buffer);
#if defined SECURE_WIPE_BUFFER
memset(buffer, 0, SHA256_BLOCK_BYTES);
#endif
}
开发者ID:WayWingsDev,项目名称:LightweightCryptography,代码行数:28,代码来源:hmac-sha256.cpp
示例6: 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
示例7: hmac_sha256_init
void
hmac_sha256_init(hmac_sha256_ctx *ctx, const void *key, size_t keylen)
{
uint8_t keybuf[SHA256_BLOCK_LEN], pad[SHA256_BLOCK_LEN];
/* prepare key */
memset(keybuf, 0, sizeof keybuf);
if (keylen > sizeof keybuf)
sha256_complete(key, keylen, keybuf);
else
memcpy(keybuf, key, keylen);
/* input pad */
for (unsigned int i = 0; i < sizeof pad; ++i)
pad[i] = 0x36 ^ keybuf[i];
sha256_init(&ctx->ictx);
sha256_update(&ctx->ictx, pad, sizeof pad);
/* output pad */
for (unsigned int i = 0; i < sizeof pad; ++i)
pad[i] = 0x5c ^ keybuf[i];
sha256_init(&ctx->octx);
sha256_update(&ctx->octx, pad, sizeof pad);
/* hide the evidence */
memset(keybuf, 0, sizeof keybuf);
memset(pad, 0, sizeof pad);
}
开发者ID:cryb-to,项目名称:cryb-to,代码行数:28,代码来源:cryb_hmac_sha256.c
示例8: 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
示例9: hmac_sha256
/*
* keylength in bits!
* message length in bits!
*/
void hmac_sha256(void* dest, void* key, uint16_t keylength_b, void* msg, uint64_t msglength_b){ /* a one-shot*/
sha256_ctx_t s;
uint8_t i;
uint8_t buffer[SHA256_HASH_BYTES];
memset(buffer, 0, SHA256_HASH_BYTES);
/* if key is larger than a block we have to hash it*/
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);
while (msglength_b >= SHA256_BLOCK_BITS){
sha256_nextBlock(&s, msg);
msg = (uint8_t*)msg + SHA256_HASH_BYTES;
msglength_b -= SHA256_BLOCK_BITS;
}
sha256_lastBlock(&s, msg, msglength_b);
/* since buffer still contains key xor ipad we can do ... */
for (i=0; i<SHA256_HASH_BYTES; ++i){
buffer[i] ^= IPAD ^ OPAD;
}
sha256_ctx2hash(dest, &s); /* save inner hash temporary to dest */
sha256_init(&s);
sha256_nextBlock(&s, buffer);
sha256_lastBlock(&s, dest, SHA256_HASH_BITS);
sha256_ctx2hash(dest, &s);
}
开发者ID:azilly-de,项目名称:openkubus,代码行数:39,代码来源:hmac-sha256.c
示例10: 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
示例11: hmac_sha256
/* Direct mapping from MD5 example in RFC2104 */
void hmac_sha256(struct hmac_sha256 *hmac,
const void *key, size_t key_len,
const void *text, size_t text_len)
{
struct sha256_ctx context;
unsigned char k_ipad[65]; /* inner padding -
* key XORd with ipad
*/
unsigned char k_opad[65]; /* outer padding -
* key XORd with opad
*//* start out by storing key in pads */
unsigned char tk[32];
int i;
/* if key is longer than 64 bytes reset it to key=MD5(key) */
if (key_len > 64) {
struct sha256_ctx tctx;
sha256_init(&tctx);
sha256_update(&tctx, key, key_len);
sha256_done(&tctx, tk);
key = tk;
key_len = 32;
}
bzero( k_ipad, sizeof k_ipad);
bzero( k_opad, sizeof k_opad);
bcopy( key, k_ipad, key_len);
bcopy( key, k_opad, key_len);
/* XOR key with ipad and opad values */
for (i=0; i<64; i++) {
k_ipad[i] ^= 0x36;
k_opad[i] ^= 0x5c;
}
/*
* perform inner MD5
*/
sha256_init(&context); /* init context for 1st
* pass */
sha256_update(&context, k_ipad, 64); /* start with inner pad */
sha256_update(&context, text, text_len); /* then text of datagram */
sha256_done(&context, &hmac->sha); /* finish up 1st pass */
/*
* perform outer MD5
*/
sha256_init(&context); /* init context for 2nd
* pass */
sha256_update(&context, k_opad, 64); /* start with outer pad */
sha256_update(&context, &hmac->sha, 32); /* then results of 1st
* hash */
sha256_done(&context, &hmac->sha); /* finish up 2nd pass */
}
开发者ID:cdecker,项目名称:lightning,代码行数:55,代码来源:hmac_sha256.c
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: _sol_message_digest_sha256_init
static void
_sol_message_digest_sha256_init(struct sol_message_digest *handle)
{
sha256_context_t *ctx = sol_message_digest_common_get_context(handle);
sha256_init(ctx);
}
开发者ID:amandawrcoelho,项目名称:soletta,代码行数:7,代码来源:sol-message-digest-impl-riot.c
示例17: sha256
void sha256(unsigned char* in, size_t in_size, unsigned char* out)
{
hash_state h;
sha256_init(&h);
sha256_process(&h, in, (unsigned long)in_size);
sha256_done(&h, out);
}
开发者ID:chaind,项目名称:chaind,代码行数:7,代码来源:hashes.c
示例18: 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
示例19: 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
示例20: 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
注:本文中的sha256_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论