本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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
}
示例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;
}
示例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);
}
}
}
示例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
}
示例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);
}
}
示例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
);
}
}
示例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);
}
}
示例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;
}