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


C++ SHA512_Final函数代码示例

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


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

示例1: SHA512_File

static void SHA512_File(FILE *file, unsigned char **output, int *outlength)
{
	*output = new unsigned char[SHA512_DIGEST_LENGTH];
	*outlength = SHA512_DIGEST_LENGTH;

	SHA512_CTX c;
	int i;
	unsigned char buf[SHA384_FILE_BUFFER_SIZE];
	
	SHA512_Init(&c);
	for (;;)
	{
		i = fread(buf,1,SHA512_FILE_BUFFER_SIZE,file);
		if(i <= 0)
			break;
		SHA512_Update(&c,buf,(unsigned long)i);
	}
	SHA512_Final(*output, &c);
}
开发者ID:earlcochran,项目名称:sourcemod-curl-extension,代码行数:19,代码来源:opensslmanager.cpp

示例2: chk_sha512

static int chk_sha512(
	const struct berval *scheme, /* Scheme of hashed reference password */
	const struct berval *passwd, /* Hashed reference password to check against */
	const struct berval *cred, /* user-supplied password to check */
	const char **text )
{
	SHA512_CTX SHAcontext;
	unsigned char SHAdigest[SHA512_DIGEST_LENGTH];
	int rc;
	unsigned char *orig_pass = NULL;
	size_t decode_len = LUTIL_BASE64_DECODE_LEN(passwd->bv_len);

	/* safety check */
	if (decode_len < sizeof(SHAdigest)) {
		return LUTIL_PASSWD_ERR;
	}

	/* base64 un-encode password */
	orig_pass = (unsigned char *) ber_memalloc(decode_len + 1);

	if( orig_pass == NULL ) return LUTIL_PASSWD_ERR;

	rc = lutil_b64_pton(passwd->bv_val, orig_pass, decode_len);

	if( rc != sizeof(SHAdigest) ) {
		ber_memfree(orig_pass);
		return LUTIL_PASSWD_ERR;
	}

	/* hash credentials with salt */
	SHA512_Init(&SHAcontext);
	SHA512_Update(&SHAcontext,
		(const unsigned char *) cred->bv_val, cred->bv_len);
	SHA512_Final(SHAdigest, &SHAcontext);

	/* compare */
	rc = memcmp((char *)orig_pass, (char *)SHAdigest, sizeof(SHAdigest));
#ifdef SLAPD_SHA2_DEBUG
	chk_sha_debug(scheme, passwd, cred, (char *)SHAdigest, sizeof(SHAdigest), rc);
#endif
	ber_memfree(orig_pass);
	return rc ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
开发者ID:cptaffe,项目名称:openldap,代码行数:43,代码来源:slapd-sha2.c

示例3: SHA512_Init

/* -- Blinding -------------------------------------------------------------
//
//  Blinding is a measure to protect against side channel attacks. 
//  Blinding randomizes the scalar multiplier.
//
//  Instead of calculating a*P, calculate (a+b mod BPO)*P + B
//
//  Where b = random blinding and B = -b*P
//
// -------------------------------------------------------------------------
*/
void *ed25519_Blinding_Init(
    void *context,                      /* IO: null or ptr blinding context */
    const unsigned char *seed,          /* IN: [size bytes] random blinding seed */
    size_t size)                        /* IN: size of blinding seed */
{
    struct {
        Ext_POINT T;
        U_WORD t[K_WORDS];
        SHA512_CTX H;
        U8 digest[SHA512_DIGEST_LENGTH];
    } d;

    EDP_BLINDING_CTX *ctx = (EDP_BLINDING_CTX*)context;

    if (ctx == 0)
    {
        ctx = (EDP_BLINDING_CTX*)mem_alloc(sizeof(EDP_BLINDING_CTX));
        if (ctx == 0) return 0;
    }

    /* Use edp_custom_blinding to protect generation of the new blinder */

    SHA512_Init(&d.H);
    SHA512_Update(&d.H, edp_custom_blinding.zr, 32);
    SHA512_Update(&d.H, seed, size);
    SHA512_Final(d.digest, &d.H);

    ecp_BytesToWords(ctx->zr, d.digest+32);
    ecp_BytesToWords(d.t, d.digest);
    eco_Mod(d.t);
    ecp_Sub(ctx->bl, _w_BPO, d.t);

    eco_AddReduce(d.t, d.t, edp_custom_blinding.bl);
    edp_BasePointMult(&d.T, d.t, edp_custom_blinding.zr);
    edp_AddPoint(&d.T, &d.T, &edp_custom_blinding.BP);

    edp_ExtPoint2PE(&ctx->BP, &d.T);

    /* clear potentially sensitive data */
    mem_clear (&d, sizeof(d));

    return ctx;
}
开发者ID:EmuxEvans,项目名称:curve25519,代码行数:54,代码来源:ed25519_sign.c

示例4: sha_file

int sha_file(int md_alg, const char *filename, unsigned char *md)
{
	FILE *inFile;
	SHA256_CTX shaContext;
	SHA512_CTX sha512Context;
	int bytes;
	unsigned char data[BUFFER_SIZE];

	if ((filename == NULL) || (md == NULL)) {
		ERROR("%s(): NULL argument\n", __FUNCTION__);
		return 0;
	}

	inFile = fopen(filename, "rb");
	if (inFile == NULL) {
		ERROR("Cannot read %s\n", filename);
		return 0;
	}

	if (md_alg == HASH_ALG_SHA384) {
		SHA384_Init(&sha512Context);
		while ((bytes = fread(data, 1, BUFFER_SIZE, inFile)) != 0) {
			SHA384_Update(&sha512Context, data, bytes);
		}
		SHA384_Final(md, &sha512Context);
	} else if (md_alg == HASH_ALG_SHA512) {
		SHA512_Init(&sha512Context);
		while ((bytes = fread(data, 1, BUFFER_SIZE, inFile)) != 0) {
			SHA512_Update(&sha512Context, data, bytes);
		}
		SHA512_Final(md, &sha512Context);
	} else {
		SHA256_Init(&shaContext);
		while ((bytes = fread(data, 1, BUFFER_SIZE, inFile)) != 0) {
			SHA256_Update(&shaContext, data, bytes);
		}
		SHA256_Final(md, &shaContext);
	}

	fclose(inFile);
	return 1;
}
开发者ID:Summer-ARM,项目名称:arm-trusted-firmware,代码行数:42,代码来源:sha.c

示例5: sha512

static int32_t sha512(char *in, char **out)
{
    SHA512_CTX ctx;
    uint32_t i = 0;
    int32_t rtrn = 0;
    unsigned char hash[SHA512_DIGEST_LENGTH];

    rtrn = SHA512_Init(&ctx);
    if(rtrn < 0)
    {
        output->write(ERROR,"Sha init\n");
        return (-1);
    }

    rtrn = SHA512_Update(&ctx, in, strlen(in));
    if(rtrn < 0)
    {
        output->write(ERROR,"Can't update input string\n");
        return (-1);
    }

    rtrn = SHA512_Final(hash, &ctx);
    if(rtrn < 0)
    {
        output->write(ERROR,"Can't do this\n");
        return (-1);
    }

    (*out) = allocator->alloc((SHA512_DIGEST_LENGTH * 2) + 1);
    if((*out) == NULL)
    {
        output->write(ERROR,"Can't allocate output buf\n");
        return (-1);
    }

    for(i = 0; i < SHA512_DIGEST_LENGTH; i++)
        sprintf(*out + (i * 2), "%02x", hash[i]);

    (*out)[128] = '\0';

    return (0);
}
开发者ID:2trill2spill,项目名称:nextgen,代码行数:42,代码来源:hash.c

示例6: calc_hash

void calc_hash(const char *filename)
{
    int n;
    unsigned char data[BUFFSIZE];
    FILE *file = fopen(filename, "rb");
    if (file == NULL) {
        fprintf(stderr, "'%s' ", filename);
        perror("文件打开失败");
        return;
    }

    unsigned char md5[MD5_DIGEST_LENGTH];
    MD5_CTX md5_c;
    unsigned char sha1[SHA_DIGEST_LENGTH];
    SHA_CTX sha1_c;
    unsigned char sha512[SHA_DIGEST_LENGTH];
    SHA512_CTX sha512_c;

    MD5_Init(&md5_c);
    SHA1_Init(&sha1_c);
    SHA512_Init(&sha512_c);
    while ((n = fread(data, 1, BUFFSIZE, file)) != 0) {
        MD5_Update(&md5_c, data, n);
        SHA1_Update(&sha1_c, data, n);
        SHA512_Update(&sha512_c, data, n);
    }
    MD5_Final(md5, &md5_c);
    SHA1_Final(sha1, &sha1_c);
    SHA512_Final(sha512, &sha512_c);

    int i;
    printf("%s", filename);
    printf("\n%8s: ", "MD5");
    for (i = 0; i < MD5_DIGEST_LENGTH; i++) printf("%02x", md5[i]);
    printf("\n%8s: ", "SHA1");
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x", sha1[i]);
    printf("\n%8s: ", "SHA512");
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x", sha512[i]);
    printf("\n");

    fclose(file);
}
开发者ID:kingfree,项目名称:haut,代码行数:42,代码来源:md5.c

示例7: generate_ripe

static void
generate_ripe(struct ntb_ecc *ecc,
              struct ntb_key *key)
{
        SHA512_CTX sha_ctx;
        uint8_t public_key[NTB_ECC_PUBLIC_KEY_SIZE];
        uint8_t sha_hash[SHA512_DIGEST_LENGTH];

        SHA512_Init(&sha_ctx);

        ntb_ecc_get_pub_key(ecc, key->signing_key, public_key);
        SHA512_Update(&sha_ctx, public_key, NTB_ECC_PUBLIC_KEY_SIZE);

        ntb_ecc_get_pub_key(ecc, key->encryption_key, public_key);
        SHA512_Update(&sha_ctx, public_key, NTB_ECC_PUBLIC_KEY_SIZE);

        SHA512_Final(sha_hash, &sha_ctx);

        RIPEMD160(sha_hash, SHA512_DIGEST_LENGTH, key->address.ripe);
}
开发者ID:bpeel,项目名称:notbit,代码行数:20,代码来源:ntb-key.c

示例8: Md5str

std::string Digestor::HashPassword(const std::string& plain_pwd)
{
#if USE_SIMPLE_PWD_HASH
	return Md5str(plain_pwd);
#else
	uint8_t sha512[64] = {0};
	SHA512_CTX sha512_ctx;
	SHA512_Init(&sha512_ctx);
	SHA512_Update(&sha512_ctx, plain_pwd.c_str(), plain_pwd.size());
	SHA512_Final(sha512, &sha512_ctx);

	uint8_t md5[16] = {0};
	MD5_CTX md5_ctx;
	MD5_Init(&md5_ctx);
	MD5_Update(&md5_ctx, sha512, 64);
	MD5_Final(md5, &md5_ctx);

	return BinaryHashToHexString(md5, 16);
#endif
}
开发者ID:zjjfhqpl,项目名称:surbasic,代码行数:20,代码来源:Digestor.cpp

示例9: sha512_hex_hash

char * sha512_hex_hash(const char * passwd) {

	SHA512_CTX ct;
	unsigned char hash[SHA512_DIGEST_LENGTH];
	static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA512_DIGEST_LENGTH)+1]; // extra char for \0

	SHA512_Init(&ct);
	SHA512_Update(&ct, (const uint8_t*)passwd, strlen(passwd));
	SHA512_Final(hash, &ct);

        /* base64 encode it */
	lutil_b64_ntop(
			hash,
			SHA512_DIGEST_LENGTH,
			real_hash,
			LUTIL_BASE64_ENCODE_LEN(SHA512_DIGEST_LENGTH)+1
			);

	return real_hash;
}
开发者ID:1ack,项目名称:Impala,代码行数:20,代码来源:slapd-sha2.c

示例10: ATF_TC_BODY

ATF_TC_BODY(t_sha512, tc)
{
	size_t i, j, len;
	SHA512_CTX ctx;
	unsigned char buf[512];
	unsigned char digest[8 + SHA512_DIGEST_LENGTH];
	char output[SHA512_DIGEST_STRING_LENGTH];

	for (i = 0; i < sizeof(test512) / sizeof(test512[0]); ++i) {
		len = strlen(test512[i].vector);
		for (j = 0; j < 8; ++j) {
			SHA512_Init(&ctx);
			memcpy(buf + j, test512[i].vector, len);
			SHA512_Update(&ctx, buf + j, len);
			SHA512_Final(digest + j, &ctx);
			digest2string(digest + j, output, SHA512_DIGEST_LENGTH);
			ATF_CHECK_STREQ(test512[i].hash, output);
		}
	}
}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:20,代码来源:t_sha2.c

示例11: _wi_sha2_ctx_final

static void _wi_sha2_ctx_final(unsigned char *buffer, _wi_sha2_ctx_t *ctx) {
#ifdef WI_SHA2_OPENSSL
    switch(ctx->bits) {
    case WI_SHA2_224:
        SHA224_Final(buffer, &ctx->openssl_256_ctx);
        break;

    case WI_SHA2_256:
        SHA256_Final(buffer, &ctx->openssl_256_ctx);
        break;

    case WI_SHA2_384:
        SHA384_Final(buffer, &ctx->openssl_512_ctx);
        break;

    case WI_SHA2_512:
        SHA512_Final(buffer, &ctx->openssl_512_ctx);
        break;
    }
#endif

#ifdef WI_SHA2_COMMONCRYPTO
    switch(ctx->bits) {
    case WI_SHA2_224:
        CC_SHA224_Final(buffer, &ctx->commondigest_256_ctx);
        break;

    case WI_SHA2_256:
        CC_SHA256_Final(buffer, &ctx->commondigest_256_ctx);
        break;

    case WI_SHA2_384:
        CC_SHA384_Final(buffer, &ctx->commondigest_512_ctx);
        break;

    case WI_SHA2_512:
        CC_SHA512_Final(buffer, &ctx->commondigest_512_ctx);
        break;
    }
#endif
}
开发者ID:haifenghuang,项目名称:libwired,代码行数:41,代码来源:wi-sha2.c

示例12: crypt_all

static void crypt_all(int count)
{
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
	for (index = 0; index < count; index++)
#endif
	{
		SHA512_CTX ctx;

		SHA512_Init(&ctx);

		/* First the password */
		SHA512_Update(&ctx, saved_key[index], saved_key_length[index]);

		/* Then the salt, including the $4$ magic */
		SHA512_Update(&ctx, cur_salt, salt_len);

		SHA512_Final((unsigned char*)crypt_out[index], &ctx);
	}
}
开发者ID:Sayantan2048,项目名称:myrice-JtR,代码行数:21,代码来源:dragonfly4_fmt.c

示例13: test_sha512

static void test_sha512(void)
{
  size_t i;

  printf("test SHA512\n");

  for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) {
    SHA512_CTX ctx;
    unsigned char r[64];
    const char *s = test_vectors[i];

    SHA512_Init(&ctx);
    SHA512_Update(&ctx, s, strlen(s));
    SHA512_Final(r, &ctx);

    print_result(&r[0], sizeof(r));

    rtems_test_assert(
      memcmp(&r[0], &test_sha512_results[i][0], sizeof(r)) == 0
    );
  }
}
开发者ID:Avanznow,项目名称:rtems,代码行数:22,代码来源:init.c

示例14: genkey

		void genkey(const Memblock &string, uint8_t *key, uint32_t length) const
		{
			SHA512_CTX ctx;
			uint32_t numHashes = (length + SHA512_DIGEST_LENGTH - 1) / SHA512_DIGEST_LENGTH;

			// TODO: This is not very efficient with multiple hashes
			for (uint32_t i = 0; i < numHashes; i++) {
				SHA512_Init(&ctx);
				for (uint32_t j = 0; j < i; j++) {
					SHA512_Update(&ctx, "\0", 1);
				}

				// Find multiplicator
				int32_t tl = string.length + 8;
				int32_t mul = 1;
				while (mul < tl && ((64 * mul) % tl)) {
					++mul;
				}

				// Try to feed the hash function with 64-byte blocks
				const int32_t bs = mul * 64;
				assert(bs <= KEYBUFFER_LENGTH);
				uint8_t *bptr = m_keybuf + tl;
				int32_t n = bs / tl;
				memcpy(m_keybuf + 8, string.data, string.length);
				while (n-- > 1) {
					memcpy(bptr, m_keybuf, tl);
					bptr += tl;
				}
				n = m_count / bs;
				while (n-- > 0) {
					SHA512_Update(&ctx, m_keybuf, bs);
				}
				SHA512_Update(&ctx, m_keybuf, m_count % bs);

				SHA512_Final(key + (i * SHA512_DIGEST_LENGTH), &ctx);
			}
		}
开发者ID:kholia,项目名称:gpg2john-deprecated,代码行数:38,代码来源:string2key.cpp

示例15: __get_patch_file_key

static int __get_patch_file_key(struct itg2_file *file)
{
	unsigned char hash[SHA512_DIGEST_LENGTH];
	SHA512_CTX ctx;

	if (SHA512_Init(&ctx) == 0)
		return -1;

	if (SHA512_Update(&ctx, file->header.subkey,
	                  file->header.subkey_size) == 0)
		return -1;

	if (SHA512_Update(&ctx, ITG2_PATCH_KEY,
	                  sizeof(ITG2_PATCH_KEY) - 1) == 0)
		return -1;

	if (SHA512_Final(hash, &ctx) == 0)
		return -1;

	memcpy(file->aes_key, hash, sizeof(file->aes_key));

	return 0;
}
开发者ID:scrippie,项目名称:itg2-utils,代码行数:23,代码来源:itg2-file.c


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