本文整理匯總了C++中EVP_DigestInit函數的典型用法代碼示例。如果您正苦於以下問題:C++ EVP_DigestInit函數的具體用法?C++ EVP_DigestInit怎麽用?C++ EVP_DigestInit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EVP_DigestInit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: md5
void md5(
const void *content, ssize_t content_len,
char *result, ssize_t result_len)
{
assert(result_len==33); // md5+1 length
int i, j;
EVP_MD_CTX mdctx;
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len;
EVP_DigestInit(&mdctx, EVP_md5());
EVP_DigestUpdate(&mdctx, content, (size_t) content_len);
EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(&mdctx);
char byte[3];
j=0;
for(i=0; i<md_len; i++)
{
snprintf(byte, sizeof(byte), "%02x", md_value[i]);
result[j++]=byte[0];
result[j++]=byte[1];
}
result[j]=0;
}
示例2: digest_calculate
static char *
digest_calculate(char *filename,
char **digest_type, char *digest_string, unsigned *md_len_p,
file_offset_t *filesizep)
{
int fd, i, rv;
EVP_MD_CTX md_ctx;
unsigned char md_value[EVP_MAX_MD_SIZE];
char buffer[GFS_FILE_BUFSIZE];
if ((fd = open(filename, O_RDONLY)) == -1)
return (gfarm_errno_to_error(errno));
EVP_DigestInit(&md_ctx, GFS_DEFAULT_DIGEST_MODE);
rv = gfs_digest_calculate_local(
fd, buffer, GFS_FILE_BUFSIZE,
GFS_DEFAULT_DIGEST_MODE,
&md_ctx, md_len_p, md_value, filesizep);
close(fd);
if (rv != 0)
return (gfarm_errno_to_error(rv));
for (i = 0; i < *md_len_p; i++)
sprintf(&digest_string[i + i], "%02x",
md_value[i]);
*digest_type = GFS_DEFAULT_DIGEST_NAME;
return (NULL);
}
示例3: DECLCALLBACK
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
static DECLCALLBACK(int) rtCrDigestOsslEvp_Init(void *pvState, void *pvOpaque, bool fReInit)
{
EVP_MD_CTX *pThis = (EVP_MD_CTX *)pvState;
EVP_MD const *pEvpType = (EVP_MD const *)pvOpaque;
if (fReInit)
{
pEvpType = EVP_MD_CTX_md(pThis);
# if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER)
EVP_MD_CTX_reset(pThis);
# else
EVP_MD_CTX_cleanup(pThis);
# endif
}
AssertPtrReturn(pEvpType, VERR_INVALID_PARAMETER);
# if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER)
Assert(EVP_MD_block_size(pEvpType));
# else
Assert(pEvpType->md_size);
# endif
if (EVP_DigestInit(pThis, pEvpType))
return VINF_SUCCESS;
return VERR_CR_DIGEST_OSSL_DIGEST_INIT_ERROR;
}
示例4: px_find_digest
int
px_find_digest(const char *name, PX_MD ** res)
{
const EVP_MD *md;
EVP_MD_CTX *ctx;
PX_MD *h;
if (!px_openssl_initialized)
{
px_openssl_initialized = 1;
OpenSSL_add_all_algorithms();
}
md = EVP_get_digestbyname(name);
if (md == NULL)
return PXE_NO_HASH;
ctx = px_alloc(sizeof(*ctx));
EVP_DigestInit(ctx, md);
h = px_alloc(sizeof(*h));
h->result_size = digest_result_size;
h->block_size = digest_block_size;
h->reset = digest_reset;
h->update = digest_update;
h->finish = digest_finish;
h->free = digest_free;
h->p.ptr = (void *) ctx;
*res = h;
return 0;
}
示例5: HashFile
void HashFile(char *filename, unsigned char digest[EVP_MAX_MD_SIZE + 1], HashMethod type)
{
FILE *file;
EVP_MD_CTX context;
int len, md_len;
unsigned char buffer[1024];
const EVP_MD *md = NULL;
CfDebug("HashFile(%d,%s)\n", type, filename);
if ((file = fopen(filename, "rb")) == NULL)
{
CfOut(OUTPUT_LEVEL_INFORM, "fopen", "%s can't be opened\n", filename);
}
else
{
md = EVP_get_digestbyname(FileHashName(type));
EVP_DigestInit(&context, md);
while ((len = fread(buffer, 1, 1024, file)))
{
EVP_DigestUpdate(&context, buffer, len);
}
EVP_DigestFinal(&context, digest, &md_len);
/* Digest length stored in md_len */
fclose(file);
}
}
示例6: create_digest
static int create_digest(BIO *input, char *digest, const EVP_MD *md,
unsigned char **md_value)
{
int md_value_len;
md_value_len = EVP_MD_size(md);
if (md_value_len < 0)
return 0;
if (input) {
EVP_MD_CTX md_ctx;
unsigned char buffer[4096];
int length;
*md_value = app_malloc(md_value_len, "digest buffer");
EVP_DigestInit(&md_ctx, md);
while ((length = BIO_read(input, buffer, sizeof(buffer))) > 0) {
EVP_DigestUpdate(&md_ctx, buffer, length);
}
if (!EVP_DigestFinal(&md_ctx, *md_value, NULL))
return 0;
} else {
long digest_len;
*md_value = string_to_hex(digest, &digest_len);
if (!*md_value || md_value_len != digest_len) {
OPENSSL_free(*md_value);
*md_value = NULL;
BIO_printf(bio_err, "bad digest, %d bytes "
"must be specified\n", md_value_len);
return 0;
}
}
return md_value_len;
}
示例7: debug_printf
char *do_sha1(char *tohash, int size)
{
EVP_MD_CTX ctx;
char *hash_ret;
int evp_ret_len;
if (!tohash)
{
debug_printf(DEBUG_NORMAL, "Invalid value passed to do_sha1()!\n");
return NULL;
}
hash_ret = (char *)malloc(21); // We should get 20 bytes returned.
if (hash_ret == NULL)
{
printf("There was a malloc() error in eapsim.c with hash_ret!\n");
return NULL;
}
EVP_DigestInit(&ctx, EVP_sha1());
EVP_DigestUpdate(&ctx, tohash, size);
EVP_DigestFinal(&ctx, hash_ret, (int *)&evp_ret_len);
if (evp_ret_len != 20) printf("SHA1 returned something other than what it should have!\n");
return hash_ret;
}
示例8: HashString
void HashString(const char *buffer, int len, unsigned char digest[EVP_MAX_MD_SIZE + 1], HashMethod type)
{
EVP_MD_CTX context;
const EVP_MD *md = NULL;
int md_len;
CfDebug("HashString(%c)\n", type);
switch (type)
{
case HASH_METHOD_CRYPT:
CfOut(OUTPUT_LEVEL_ERROR, "", "The crypt support is not presently implemented, please use another algorithm instead");
memset(digest, 0, EVP_MAX_MD_SIZE + 1);
break;
default:
md = EVP_get_digestbyname(FileHashName(type));
if (md == NULL)
{
CfOut(OUTPUT_LEVEL_INFORM, "", " !! Digest type %s not supported by OpenSSL library", CF_DIGEST_TYPES[type][0]);
}
EVP_DigestInit(&context, md);
EVP_DigestUpdate(&context, (unsigned char *) buffer, (size_t) len);
EVP_DigestFinal(&context, digest, &md_len);
break;
}
}
示例9: MD5authencrypt
/*
* MD5authencrypt - generate message digest
*
* Returns length of MAC including key ID and digest.
*/
int
MD5authencrypt(
int type, /* hash algorithm */
u_char *key, /* key pointer */
u_int32 *pkt, /* packet pointer */
int length /* packet length */
)
{
u_char digest[EVP_MAX_MD_SIZE];
u_int len;
EVP_MD_CTX ctx;
/*
* Compute digest of key concatenated with packet. Note: the
* key type and digest type have been verified when the key
* was creaded.
*/
INIT_SSL();
EVP_DigestInit(&ctx, EVP_get_digestbynid(type));
EVP_DigestUpdate(&ctx, key, (u_int)cache_keylen);
EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length);
EVP_DigestFinal(&ctx, digest, &len);
memmove((u_char *)pkt + length + 4, digest, len);
return (len + 4);
}
示例10: _ldapfull_chk_hashed
int _ldapfull_chk_hashed(moddata_t data, const char *scheme, int salted, const char *hash, const char *passwd) {
char *bhash; // binary hash, will get it from base64
EVP_MD_CTX mdctx;
const EVP_MD *md;
unsigned char digest[EVP_MAX_MD_SIZE];
int bhlen, rc;
md = EVP_get_digestbyname(scheme);
if (!md) {
return 0;
}
if( ! _ldapfull_base64_decode(hash, &bhash, &bhlen) ) {
return 0;
}
EVP_DigestInit(&mdctx, md);
EVP_DigestUpdate(&mdctx, passwd, strlen(passwd));
if (salted) {
EVP_DigestUpdate(&mdctx, &bhash[EVP_MD_size(md)],
bhlen - EVP_MD_size(md));
}
EVP_DigestFinal(&mdctx, digest, NULL);
rc = memcmp((char *)bhash, (char *)digest, EVP_MD_size(md));
free(bhash);
return !rc;
}
示例11: calculate_new_key
/*
* Caclulate a new key after a reconnect
*/
void
calculate_new_key(u_int64_t *key, u_int64_t cookie, u_int64_t challenge)
{
int r;
const EVP_MD *md = EVP_sha1();
EVP_MD_CTX ctx;
char hash[EVP_MAX_MD_SIZE];
struct sshbuf *b;
if ((b = sshbuf_new()) == NULL)
fatal("%s: sshbuf_new failed", __func__);
if ((r = sshbuf_put_u64(b, *key)) != 0 ||
(r = sshbuf_put_u64(b, cookie)) != 0 ||
(r = sshbuf_put_u64(b, challenge)) != 0)
fatal("%s: buffer error: %s", __func__, ssh_err(r));
EVP_DigestInit(&ctx, md);
EVP_DigestUpdate(&ctx, sshbuf_ptr(b), sshbuf_len(b));
EVP_DigestFinal(&ctx, hash, NULL);
sshbuf_reset(b);
if ((r = sshbuf_put(b, hash, EVP_MD_size(md))) != 0 ||
(r = sshbuf_get_u64(b, key)) != 0)
fatal("%s: buffer error: %s", __func__, ssh_err(r));
sshbuf_free(b);
}
示例12: abort
QString pki_evp::sha512passwd(QString pass, QString salt)
{
EVP_MD_CTX mdctx;
QString str;
int n;
int j;
unsigned char m[EVP_MAX_MD_SIZE];
if (salt.length() <5)
abort();
str = salt.left(5);
pass = str + pass;
EVP_DigestInit(&mdctx, EVP_sha512());
EVP_DigestUpdate(&mdctx, CCHAR(pass), pass.size());
EVP_DigestFinal(&mdctx, m, (unsigned*)&n);
for (j=0; j<n; j++) {
char zs[4];
sprintf(zs, "%02X",m[j]);
str += zs;
}
return str;
}
示例13: EVP_CIPHER_iv_length
bool _IDB_XCH::new_msgiv( IDB_PH1 * ph1 )
{
if( ph1->evp_cipher == NULL )
return false;
unsigned char iv_data[ EVP_MAX_MD_SIZE ];
unsigned long iv_size = EVP_CIPHER_iv_length( ph1->evp_cipher );
EVP_MD_CTX ctx_hash;
EVP_DigestInit( &ctx_hash, ph1->evp_hash );
EVP_DigestUpdate( &ctx_hash, ph1->iv.buff(), ph1->iv.size() );
EVP_DigestUpdate( &ctx_hash, &msgid, 4 );
EVP_DigestFinal( &ctx_hash, iv_data, NULL );
EVP_MD_CTX_cleanup( &ctx_hash );
iv.set( iv_data, iv_size );
iked.log.bin(
LLOG_DEBUG,
LLOG_DECODE,
iv.buff(),
iv.size(),
"== : new %s iv",
name() );
return true;
}
示例14: send_chal_reply
bool send_chal_reply(connection_t *c) {
char hash[EVP_MAX_MD_SIZE * 2 + 1];
EVP_MD_CTX *ctx;
/* Calculate the hash from the challenge we received */
ctx = EVP_MD_CTX_create();
if(!ctx) {
abort();
}
if(!EVP_DigestInit(ctx, c->indigest)
|| !EVP_DigestUpdate(ctx, c->mychallenge, RSA_size(myself->connection->rsa_key))
|| !EVP_DigestFinal(ctx, (unsigned char *)hash, NULL)) {
EVP_MD_CTX_destroy(ctx);
logger(LOG_ERR, "Error during calculation of response for %s (%s): %s",
c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
return false;
}
EVP_MD_CTX_destroy(ctx);
/* Convert the hash to a hexadecimal formatted string */
bin2hex(hash, hash, EVP_MD_size(c->indigest));
hash[EVP_MD_size(c->indigest) * 2] = '\0';
/* Send the reply */
return send_request(c, "%d %s", CHAL_REPLY, hash);
}
示例15: derive_ssh1_session_id
void
derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus,
u_int8_t cookie[8], u_int8_t id[16])
{
const EVP_MD *evp_md = EVP_md5();
EVP_MD_CTX md;
u_int8_t nbuf[2048], obuf[EVP_MAX_MD_SIZE];
int len;
EVP_DigestInit(&md, evp_md);
len = BN_num_bytes(host_modulus);
if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
fatal("%s: bad host modulus (len %d)", __func__, len);
BN_bn2bin(host_modulus, nbuf);
EVP_DigestUpdate(&md, nbuf, len);
len = BN_num_bytes(server_modulus);
if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
fatal("%s: bad server modulus (len %d)", __func__, len);
BN_bn2bin(server_modulus, nbuf);
EVP_DigestUpdate(&md, nbuf, len);
EVP_DigestUpdate(&md, cookie, 8);
EVP_DigestFinal(&md, obuf, NULL);
memcpy(id, obuf, 16);
memset(nbuf, 0, sizeof(nbuf));
memset(obuf, 0, sizeof(obuf));
memset(&md, 0, sizeof(md));
}