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


C++ EVP_md5函数代码示例

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


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

示例1: imap_state_cram_md5_auth

/* CRAM-MD5 auth state. */
int
imap_state_cram_md5_auth(struct account *a, struct fetch_ctx *fctx)
{
	struct fetch_imap_data	*data = a->data;
	char			*line, *ptr, *src, *b64;
	char			 out[EVP_MAX_MD_SIZE * 2 + 1];
	u_char			 digest[EVP_MAX_MD_SIZE];
	u_int			 i, n;

	if (imap_getln(a, fctx, IMAP_CONTINUE, &line) != 0)
		return (FETCH_ERROR);
	if (line == NULL)
		return (FETCH_BLOCK);

	ptr = line + 1;
	while (isspace((u_char) *ptr))
		ptr++;
	if (*ptr == '\0')
		return (imap_invalid(a, line));

	b64 = imap_base64_decode(ptr);
	HMAC(EVP_md5(),
	    data->pass, strlen(data->pass), b64, strlen(b64), digest, &n);
	xfree(b64);

	for (i = 0; i < n; i++)
		xsnprintf(out + i * 2, 3, "%02hhx", digest[i]);
	xasprintf(&src, "%s %s", data->user, out);
	b64 = imap_base64_encode(src);
	xfree(src);

	if (imap_putln(a, "%s", b64) != 0) {
		xfree(b64);
		return (FETCH_ERROR);
	}
	xfree(b64);

	fctx->state = imap_state_pass;
	return (FETCH_BLOCK);
}
开发者ID:avkrotov,项目名称:fdm,代码行数:41,代码来源:imap-common.c

示例2: ntlm_compute_lm_v2_response

void ntlm_compute_lm_v2_response(NTLM_CONTEXT* context)
{
    char* response;
    char value[16];
    char ntlm_v2_hash[16];

    /* Compute the NTLMv2 hash */
    ntlm_compute_ntlm_v2_hash(context, ntlm_v2_hash);

    /* Concatenate the server and client challenges */
    CopyMemory(value, context->ServerChallenge, 8);
    CopyMemory(&value[8], context->ClientChallenge, 8);

    sspi_SecBufferAlloc(&context->LmChallengeResponse, 24);
    response = (char*) context->LmChallengeResponse.pvBuffer;

    /* Compute the HMAC-MD5 hash of the resulting value using the NTLMv2 hash as the key */
    HMAC(EVP_md5(), (void*) ntlm_v2_hash, 16, (void*) value, 16, (void*) response, NULL);

    /* Concatenate the resulting HMAC-MD5 hash and the client challenge, giving us the LMv2 response (24 bytes) */
    CopyMemory(&response[16], context->ClientChallenge, 8);
}
开发者ID:resumejayaraj,项目名称:FreeRDP,代码行数:22,代码来源:ntlm_compute.c

示例3: X509_issuer_and_serial_hash

unsigned long X509_issuer_and_serial_hash(X509 *a)
	{
	unsigned long ret=0;
	EVP_MD_CTX ctx;
	unsigned char md[16];
	char *f;

	EVP_MD_CTX_init(&ctx);
	f=X509_NAME_oneline(a->cert_info->issuer,NULL,0);
	ret=strlen(f);
	EVP_DigestInit_ex(&ctx, EVP_md5(), NULL);
	EVP_DigestUpdate(&ctx,(unsigned char *)f,ret);
	OPENSSL_free(f);
	EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data,
		(unsigned long)a->cert_info->serialNumber->length);
	EVP_DigestFinal_ex(&ctx,&(md[0]),NULL);
	ret=(	((unsigned long)md[0]     )|((unsigned long)md[1]<<8L)|
		((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
		)&0xffffffffL;
	EVP_MD_CTX_cleanup(&ctx);
	return(ret);
	}
开发者ID:hackshields,项目名称:antivirus,代码行数:22,代码来源:x509_cmp.c

示例4: _md_init_subsystem

static void
_md_init_subsystem (void)
{
    int i;

    for (i = 0; i < MUNGE_MAC_LAST_ITEM; i++) {
        _md_map [i] = NULL;
    }
    _md_map [MUNGE_MAC_MD5] = EVP_md5 ();
    _md_map [MUNGE_MAC_SHA1] = EVP_sha1 ();
    _md_map [MUNGE_MAC_RIPEMD160] = EVP_ripemd160 ();

#if HAVE_EVP_SHA256
    _md_map [MUNGE_MAC_SHA256] = EVP_sha256 ();
#endif /* HAVE_EVP_SHA256 */

#if HAVE_EVP_SHA512
    _md_map [MUNGE_MAC_SHA512] = EVP_sha512 ();
#endif /* HAVE_EVP_SHA512 */

    return;
}
开发者ID:dun,项目名称:munge,代码行数:22,代码来源:md.c

示例5: irssi_ssl_verify

static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, X509 *cert)
{
	long result;

	result = SSL_get_verify_result(ssl);
	if (result != X509_V_OK) {
		unsigned char md[EVP_MAX_MD_SIZE];
		unsigned int n;
		char *str;

		g_warning("Could not verify SSL servers certificate: %s",
				X509_verify_cert_error_string(result));
		if ((str = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0)) == NULL)
			g_warning("  Could not get subject-name from peer certificate");
		else {
			g_warning("  Subject : %s", str);
			free(str);
		}
		if ((str = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0)) == NULL)
			g_warning("  Could not get issuer-name from peer certificate");
		else {
			g_warning("  Issuer  : %s", str);
			free(str);
		}
		if (! X509_digest(cert, EVP_md5(), md, &n))
			g_warning("  Could not get fingerprint from peer certificate");
		else {
			char hex[] = "0123456789ABCDEF";
			char fp[EVP_MAX_MD_SIZE*3];
			if (n < sizeof(fp)) {
				unsigned int i;
				for (i = 0; i < n; i++) {
					fp[i*3+0] = hex[(md[i] >> 4) & 0xF];
					fp[i*3+1] = hex[(md[i] >> 0) & 0xF];
					fp[i*3+2] = i == n - 1 ? '\0' : ':';
				}
				g_warning("  MD5 Fingerprint : %s", fp);
			}
		}
开发者ID:mauke,项目名称:irssi-hax,代码行数:39,代码来源:network-openssl.c

示例6: X509_NAME_hash_old

unsigned long
X509_NAME_hash_old(X509_NAME *x)
{
	EVP_MD_CTX md_ctx;
	unsigned long ret = 0;
	unsigned char md[16];

	/* Make sure X509_NAME structure contains valid cached encoding */
	i2d_X509_NAME(x, NULL);
	EVP_MD_CTX_init(&md_ctx);
	if (EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL) &&
	    EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length) &&
	    EVP_DigestFinal_ex(&md_ctx, md, NULL))
		ret = (((unsigned long)md[0]) |
		    ((unsigned long)md[1] << 8L) |
		    ((unsigned long)md[2] << 16L) |
		    ((unsigned long)md[3] << 24L)) &
		    0xffffffffL;
	EVP_MD_CTX_cleanup(&md_ctx);

	return (ret);
}
开发者ID:LucaBongiorni,项目名称:nextgen,代码行数:22,代码来源:x509_cmp.c

示例7: X509_NAME_hash_old

unsigned long X509_NAME_hash_old(X509_NAME *x)
{
    EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
    unsigned long ret = 0;
    unsigned char md[16];

    if (md_ctx == NULL)
        return ret;

    /* Make sure X509_NAME structure contains valid cached encoding */
    i2d_X509_NAME(x, NULL);
    EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
    if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL)
        && EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length)
        && EVP_DigestFinal_ex(md_ctx, md, NULL))
        ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |
               ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)
            ) & 0xffffffffL;
    EVP_MD_CTX_free(md_ctx);

    return (ret);
}
开发者ID:1234-,项目名称:openssl,代码行数:22,代码来源:x509_cmp.c

示例8: main

int main(int argc, char *argv[])
	{
#ifndef OPENSSL_NO_MD5
	int i;
	char *p;
#endif
	int err=0;

#ifdef OPENSSL_NO_MD5
	printf("test skipped: MD5 disabled\n");
#else

#ifdef CHARSET_EBCDIC
	ebcdic2ascii(test[0].data, test[0].data, test[0].data_len);
	ebcdic2ascii(test[1].data, test[1].data, test[1].data_len);
	ebcdic2ascii(test[2].key,  test[2].key,  test[2].key_len);
	ebcdic2ascii(test[2].data, test[2].data, test[2].data_len);
#endif

	for (i=0; i<4; i++)
		{
		p=pt(HMAC(EVP_md5(),
			test[i].key, test[i].key_len,
			test[i].data, test[i].data_len,
			NULL,NULL));

		if (strcmp(p,(char *)test[i].digest) != 0)
			{
			printf("error calculating HMAC on %d entry'\n",i);
			printf("got %s instead of %s\n",p,test[i].digest);
			err++;
			}
		else
			printf("test %d ok\n",i);
		}
#endif /* OPENSSL_NO_MD5 */
	EXIT(err);
	return(0);
	}
开发者ID:002301,项目名称:node,代码行数:39,代码来源:hmactest.c

示例9: EVP_cipher

int EVP_cipher(const char *passw, int cbpass, char *strin, int cbstr, int op, const char *cipher)
{
	const EVP_CIPHER * enc;
	if (cipher && *cipher) {
		if (!myEvpMap.Find(cipher,enc))
			return CIPHER_INVALID;
	} else 
		enc = EVP_des_ede_cbc();

	unsigned char key[EVP_MAX_KEY_LENGTH];
	unsigned char iv[EVP_MAX_IV_LENGTH];
	EVP_CIPHER_CTX ctx;

	EVP_BytesToKey(enc,EVP_md5(),NULL,(unsigned char *)passw,cbpass,1,key,iv);
	EVP_CIPHER_CTX_init(&ctx);
	EVP_CipherInit(&ctx,enc,key,iv,op);
	
	unsigned char out[CIPHER_BLOCK+EVP_MAX_IV_LENGTH];
	int outl;

	unsigned char *in = (unsigned char *) strin;
	unsigned char *endp = in + cbstr - CIPHER_BLOCK;
	unsigned char *outp = in;

	while (in < endp)	{
		EVP_CipherUpdate(&ctx,out,&outl,in,CIPHER_BLOCK);
		memcpy(outp, out, outl); outp += outl;
		in += CIPHER_BLOCK;
	}
	EVP_CipherUpdate(&ctx,out,&outl,in,endp+CIPHER_BLOCK-in);
	memcpy(outp, out, outl); outp += outl;

	EVP_CipherFinal(&ctx,out,&outl);
	memcpy(outp, out, outl); outp += outl;

	EVP_CIPHER_CTX_cleanup(&ctx);
	return (char *)outp-strin;
}
开发者ID:BackupTheBerlios,项目名称:smx-svn,代码行数:38,代码来源:open-enc.cpp

示例10: fr_hmac_md5

/** Calculate HMAC using OpenSSL's MD5 implementation
 *
 * @param digest Caller digest to be filled in.
 * @param in Pointer to data stream.
 * @param inlen length of data stream.
 * @param key Pointer to authentication key.
 * @param key_len Length of authentication key.
 *
 */
void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
		 uint8_t const *key, size_t key_len)
{
	HMAC_CTX *ctx;

	if (unlikely(!md5_hmac_ctx)) {
		ctx = HMAC_CTX_new();
		if (unlikely(!ctx)) return;
		fr_thread_local_set_destructor(md5_hmac_ctx, _hmac_md5_ctx_free_on_exit, ctx);
	} else {
		ctx = md5_hmac_ctx;
	}

#ifdef EVP_MD_CTX_FLAG_NON_FIPS_ALLOW
	/* Since MD5 is not allowed by FIPS, explicitly allow it. */
	HMAC_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
#endif /* EVP_MD_CTX_FLAG_NON_FIPS_ALLOW */

	HMAC_Init_ex(ctx, key, key_len, EVP_md5(), NULL);
	HMAC_Update(ctx, in, inlen);
	HMAC_Final(ctx, digest, NULL);
	HMAC_CTX_reset(ctx);
}
开发者ID:FreeRADIUS,项目名称:freeradius-server,代码行数:32,代码来源:hmac_md5.c

示例11: snmp_digest_init

static int32_t
snmp_digest_init(const struct snmp_user *user, EVP_MD_CTX *ctx,
    const EVP_MD **dtype, uint32_t *keylen)
{
	if (user->auth_proto == SNMP_AUTH_HMAC_MD5) {
		*dtype = EVP_md5();
		*keylen = SNMP_AUTH_HMACMD5_KEY_SIZ;
	} else if (user->auth_proto == SNMP_AUTH_HMAC_SHA) {
		*dtype = EVP_sha1();
		*keylen = SNMP_AUTH_HMACSHA_KEY_SIZ;
	} else if (user->auth_proto == SNMP_AUTH_NOAUTH)
		return (0);
	else {
		snmp_error("unknown authentication option - %d",
		    user->auth_proto);
		return (-1);
	}

	if (EVP_DigestInit(ctx, *dtype) != 1)
		return (-1);

	return (1);
}
开发者ID:2014-class,项目名称:freerouter,代码行数:23,代码来源:snmpcrypto.c

示例12: switch

/*!
 * \brief Get message digest type for a given algorithm.
 *
 * \param algorithm  Algorithm number.
 *
 * \return Pointer to digest type specification, NULL if not implemented.
 */
static const EVP_MD *get_digest_type(knot_dnssec_algorithm_t algorithm)
{
	// EVP_<digest>() functions should not fail (return NULL)

	switch (algorithm) {
	case KNOT_DNSSEC_ALG_RSASHA1:
	case KNOT_DNSSEC_ALG_RSASHA1_NSEC3_SHA1:
	case KNOT_DNSSEC_ALG_DSA:
	case KNOT_DNSSEC_ALG_DSA_NSEC3_SHA1:
		return EVP_sha1();
	case KNOT_DNSSEC_ALG_RSAMD5:
		return EVP_md5();
	case KNOT_DNSSEC_ALG_RSASHA256:
	case KNOT_DNSSEC_ALG_ECDSAP256SHA256:
		return EVP_sha256();
	case KNOT_DNSSEC_ALG_ECDSAP384SHA384:
		return EVP_sha384();
	case KNOT_DNSSEC_ALG_RSASHA512:
		return EVP_sha512();
	default:
		return NULL;
	}
}
开发者ID:stribika,项目名称:curveprotect,代码行数:30,代码来源:dnssec.c

示例13: EVP_BytesToKey

       bool AESCipher::init2(unsigned char *key_data, int key_data_len)
    {
        int i, nrounds = 1;
        unsigned char key[32], iv[32];

        /*
        * Gen key & IV for AES 256 CBC mode. A SHA1 digest is used to hash the supplied key material.
        * nrounds is the number of times the we hash the material. More rounds are more secure but
        * slower.
        */
        i = EVP_BytesToKey(EVP_aes_256_cfb(), EVP_md5(), NULL, key_data, key_data_len, nrounds, key, iv);
        if (i != 32) {
            //printf("Key size is %d bits - should be 256 bits/n", i);
            return false;
        }

        EVP_CIPHER_CTX_init(&m_ectx);
        EVP_EncryptInit_ex(&m_ectx, EVP_aes_256_cfb(), NULL, key, iv);

        EVP_CIPHER_CTX_init(&m_dctx);
        EVP_DecryptInit_ex(&m_dctx, EVP_aes_256_cfb(), NULL, key, iv);
        return true;
    }
开发者ID:levyhoo,项目名称:mynet,代码行数:23,代码来源:Cipher.cpp

示例14: HmacMd5Init

/**
  Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for
  subsequent use.

  If HmacMd5Context is NULL, then return FALSE.

  @param[out]  HmacMd5Context  Pointer to HMAC-MD5 context being initialized.
  @param[in]   Key             Pointer to the user-supplied key.
  @param[in]   KeySize         Key size in bytes.

  @retval TRUE   HMAC-MD5 context initialization succeeded.
  @retval FALSE  HMAC-MD5 context initialization failed.

**/
BOOLEAN
EFIAPI
HmacMd5Init (
  OUT  VOID         *HmacMd5Context,
  IN   CONST UINT8  *Key,
  IN   UINTN        KeySize
  )
{
  //
  // Check input parameters.
  //
  if (HmacMd5Context == NULL || KeySize > INT_MAX) {
    return FALSE;
  }

  //
  // OpenSSL HMAC-MD5 Context Initialization
  //
  HMAC_CTX_init (HmacMd5Context);
  HMAC_Init_ex (HmacMd5Context, Key, (UINT32) KeySize, EVP_md5(), NULL);

  return TRUE;
}
开发者ID:Acidburn0zzz,项目名称:shim,代码行数:37,代码来源:CryptHmacMd5.c

示例15: cipher_new

cipher_t * cipher_new(const char * pass)
{
  OpenSSL_add_all_algorithms();
  
//  const char * name;
//  name = "aes-128-cfb";
//  name = "bf-cfb";
  
  cipher_t *
  cipher       = calloc(1, sizeof(cipher_t));
  cipher->type = EVP_get_cipherbyname(conf.method);
  cipher->keyl = EVP_CIPHER_key_length(cipher->type);
  cipher->key  = malloc(cipher->keyl);
  
  EVP_CIPHER_CTX_init(&cipher->encrypt.ctx);
  EVP_CIPHER_CTX_init(&cipher->decrypt.ctx);
  
  EVP_BytesToKey(cipher->type, EVP_md5(), NULL,
                 (uint8_t *)conf.pass, (int)strlen(conf.pass), 1,
                 cipher->key, NULL);
  
  return cipher;
}
开发者ID:cuber,项目名称:shadowsocks-libuv,代码行数:23,代码来源:crypt.c


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