您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ DH_generate_key函数代码示例

51自学网 2021-06-01 20:21:44
  C++
这篇教程C++ DH_generate_key函数代码示例写得很实用,希望能帮到您。

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

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

示例1: openssl_dh_crypt

void openssl_dh_crypt(){	BIO *b;	DH *d1, *d2;	int i, len1, len2;	unsigned char skey1[COMM_LEN], skey2[COMM_LEN];	d1 = DH_new();	d2 = DH_new();	DH_generate_parameters_ex(d1, 64, DH_GENERATOR_2, NULL);	DH_check(d1, &i);	printf("/nDH key size: %d/n", DH_size(d1));	DH_generate_key(d1);	d2->p = BN_dup(d1->p);	d2->g = BN_dup(d1->g);	DH_generate_key(d2);	DH_check_pub_key(d1, d1->pub_key, &i);	len1 = DH_compute_key(skey1, d2->pub_key, d1);	len2 = DH_compute_key(skey2, d1->pub_key, d2);	if ((len1 != len2) || (memcmp(skey1, skey2, len1) != 0)) {		printf("DH_compute_key err!/n");		DH_free(d1);		DH_free(d2);		return;	}	b = BIO_new(BIO_s_file());	BIO_set_fp(b, stdout, BIO_NOCLOSE);	DHparams_print(b, d1);	BIO_free(b);	DH_free(d1);	DH_free(d2);}
开发者ID:beike2020,项目名称:source,代码行数:35,


示例2: mech_start

static int mech_start(sasl_session_t *p, char **out, int *out_len){	char *ptr;	if (!DH_generate_key(dh))		return ASASL_FAIL;	/* Serialize p, g, and pub_key */	*out = malloc(BN_num_bytes(dh->p) + BN_num_bytes(dh->g) + BN_num_bytes(dh->pub_key) + 6);	*out_len = BN_num_bytes(dh->p) + BN_num_bytes(dh->g) + BN_num_bytes(dh->pub_key) + 6;	ptr = *out;	/* p */	*((unsigned int *)ptr) = htons(BN_num_bytes(dh->p));	BN_bn2bin(dh->p, (unsigned char *)ptr + 2);	ptr += 2 + BN_num_bytes(dh->p);	/* g */	*((unsigned int *)ptr) = htons(BN_num_bytes(dh->g));	BN_bn2bin(dh->g, (unsigned char *)ptr + 2);	ptr += 2 + BN_num_bytes(dh->g);	/* pub_key */	*((unsigned int *)ptr) = htons(BN_num_bytes(dh->pub_key));	BN_bn2bin(dh->pub_key, (unsigned char *)ptr + 2);	ptr += 2 + BN_num_bytes(dh->pub_key);	p->mechdata = dh;	return ASASL_MORE;}
开发者ID:DrRenX,项目名称:atheme,代码行数:30,


示例3: tr_dh_make_key

booltr_dh_make_key (tr_dh_ctx_t   raw_handle,                size_t        private_key_length,                uint8_t     * public_key,                size_t      * public_key_length){  DH * handle = raw_handle;  int dh_size, my_public_key_length;  assert (handle != NULL);  assert (public_key != NULL);  handle->length = private_key_length * 8;  if (!check_result (DH_generate_key (handle)))    return false;  my_public_key_length = BN_bn2bin (handle->pub_key, public_key);  dh_size = DH_size (handle);  tr_dh_align_key (public_key, my_public_key_length, dh_size);  if (public_key_length != NULL)    *public_key_length = dh_size;  return true;}
开发者ID:NAStools,项目名称:transmission,代码行数:27,


示例4: dif_hel_setup

DH * dif_hel_setup(){    DH * new_dh = DH_new();    if ( !new_dh )    {	printf("%s /n","Error:Creating new dh");	error();    }    if ( !DH_generate_parameters_ex(new_dh,2,DH_GENERATOR_2,0))    {	printf("%s /n","Error:Generating paramters");	error();    }    int dh_code = 0;    if( !DH_check(new_dh,&dh_code))    {	printf("%s /n", "Error:Dh_check failed");	error();    }    if(!DH_generate_key(new_dh))    {	printf("%s /n", "Error:Generating key failed");	error();    }    return new_dh;}
开发者ID:mrpallyguy,项目名称:code1,代码行数:26,


示例5: DH_new

void avjackif::async_handshake(std::string login_username, std::string login_password, boost::asio::yield_context yield_context){	auto dh = DH_new();	DH_generate_parameters();	DH_generate_key(dh);}
开发者ID:xosdy,项目名称:avim,代码行数:7,


示例6: __openssl_initialize_dh

 int __openssl_initialize_dh(DH* pdh, int32_t bits_count){     int ret = ERROR_SUCCESS;      //2. Create his internal p and g     if ((pdh->p = BN_new()) == NULL) {         ret = ERROR_OpenSslCreateP;          return ret;     }     if ((pdh->g = BN_new()) == NULL) {         ret = ERROR_OpenSslCreateG;          return ret;     }      //3. initialize p and g     if (BN_hex2bn(&pdh->p, RFC2409_PRIME_1024) == 0) {         ret = ERROR_OpenSslParseP1024;          return ret;     }     if (BN_set_word(pdh->g, 2) != 1) {         ret = ERROR_OpenSslSetG;         return ret;     }      //4. Set the key length     pdh->length = bits_count;      //5. Generate private and public key     if (DH_generate_key(pdh) != 1) {         ret = ERROR_OpenSslGenerateDHKeys;         return ret;     }          return ret; }
开发者ID:yejingyang,项目名称:simple-rtmp-server,代码行数:34,


示例7: dh_gen_key

intdh_gen_key(DH *dh, int need){	int pbits;	const BIGNUM *p, *pub_key, *priv_key;	DH_get0_pqg(dh, &p, NULL, NULL);	if (need < 0 || p == NULL ||	    (pbits = BN_num_bits(p)) <= 0 ||	    need > INT_MAX / 2 || 2 * need > pbits)		return SSH_ERR_INVALID_ARGUMENT;	if (need < 256)		need = 256;	/*	 * Pollard Rho, Big step/Little Step attacks are O(sqrt(n)),	 * so double requested need here.	 */	DH_set_length(dh, MIN(need * 2, pbits - 1));	if (DH_generate_key(dh) == 0) {		return SSH_ERR_LIBCRYPTO_ERROR;	}	DH_get0_key(dh, &pub_key, &priv_key);	if (!dh_pub_is_valid(dh, pub_key)) {#if 0		BN_clear(priv_key);#endif		return SSH_ERR_LIBCRYPTO_ERROR;	}	return 0;}
开发者ID:ozaki-r,项目名称:netbsd-src,代码行数:31,


示例8: DH_new

	// Set the prime P and the generator, generate local public key	DH_key_exchange::DH_key_exchange ()	{		m_DH = DH_new ();		m_DH->p = BN_bin2bn (m_dh_prime, sizeof(m_dh_prime), NULL);		m_DH->g = BN_bin2bn (m_dh_generator, sizeof(m_dh_generator), NULL);		assert (sizeof(m_dh_prime) == DH_size(m_DH));				DH_generate_key (m_DH); // TODO Check != 0		assert (m_DH->pub_key);		// DH can generate key sizes that are smaller than the size of		// P with exponentially decreasing probability, in which case		// the msb's of m_dh_local_key need to be zeroed		// appropriately.		int key_size = get_local_key_size();		int len_dh = sizeof(m_dh_prime); // must equal DH_size(m_DH)		if (key_size != len_dh)		{			assert(key_size > 0 && key_size < len_dh);			int pad_zero_size = len_dh - key_size;			std::fill(m_dh_local_key, m_dh_local_key + pad_zero_size, 0);			BN_bn2bin(m_DH->pub_key, (unsigned char*)m_dh_local_key + pad_zero_size);		}		else			BN_bn2bin(m_DH->pub_key, (unsigned char*)m_dh_local_key); // TODO Check return value	}
开发者ID:codeboost,项目名称:libertv,代码行数:31,


示例9: dh_gen_key

voiddh_gen_key(DH *dh, int need){	int i, bits_set, tries = 0;	if (dh->p == NULL)		fatal("dh_gen_key: dh->p == NULL");	if (need > INT_MAX / 2 || 2 * need >= BN_num_bits(dh->p))		fatal("dh_gen_key: group too small: %d (2*need %d)",		    BN_num_bits(dh->p), 2*need);	do {		if (dh->priv_key != NULL)			BN_clear_free(dh->priv_key);		if ((dh->priv_key = BN_new()) == NULL)			fatal("dh_gen_key: BN_new failed");		/* generate a 2*need bits random private exponent */		if (!BN_rand(dh->priv_key, 2*need, 0, 0))			fatal("dh_gen_key: BN_rand failed");		if (DH_generate_key(dh) == 0)			fatal("DH_generate_key");		for (i = 0, bits_set = 0; i <= BN_num_bits(dh->priv_key); i++)			if (BN_is_bit_set(dh->priv_key, i))				bits_set++;		debug2("dh_gen_key: priv key bits set: %d/%d",		    bits_set, BN_num_bits(dh->priv_key));		if (tries++ > 10)			fatal("dh_gen_key: too many bad keys: giving up");	} while (!dh_pub_is_valid(dh, dh->pub_key));}
开发者ID:gnusec,项目名称:baoleiji,代码行数:29,


万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。