本文整理汇总了C++中BN_dup函数的典型用法代码示例。如果您正苦于以下问题:C++ BN_dup函数的具体用法?C++ BN_dup怎么用?C++ BN_dup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BN_dup函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pkey_rsa_copy
static int pkey_rsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
{
RSA_PKEY_CTX *dctx, *sctx;
if (!pkey_rsa_init(dst))
return 0;
sctx = src->data;
dctx = dst->data;
dctx->nbits = sctx->nbits;
if (sctx->pub_exp) {
dctx->pub_exp = BN_dup(sctx->pub_exp);
if (!dctx->pub_exp)
return 0;
}
dctx->pad_mode = sctx->pad_mode;
dctx->md = sctx->md;
dctx->mgf1md = sctx->mgf1md;
if (sctx->oaep_label) {
if (dctx->oaep_label)
OPENSSL_free(dctx->oaep_label);
dctx->oaep_label = BUF_memdup(sctx->oaep_label, sctx->oaep_labellen);
if (!dctx->oaep_label)
return 0;
dctx->oaep_labellen = sctx->oaep_labellen;
}
return 1;
}
开发者ID:5y,项目名称:node,代码行数:26,代码来源:rsa_pmeth.c
示例2: dupKeys
int dupKeys(paillierKeys *out, const paillierKeys *in)
{
out->n2 = BN_dup(in->n2);
out->n = BN_dup(in->n);
out->pub.g = BN_dup(in->pub.g);
out->pub.n = out->n;
out->pub.n2 = out->n2;
out->priv.lamda = BN_dup(in->priv.lamda);
out->priv.mu = BN_dup(in->priv.mu);
out->priv.n = out->n;
out->priv.n2 = out->n2;
return 0;
}
开发者ID:marshallnaito,项目名称:PaillierEncryptedDatabaseService,代码行数:16,代码来源:paillier.c
示例3: PSPAKE_Message_generate
void PSPAKE_Message_generate(PSPAKE_Message *message, PSPAKE_CTX *ctx)
{
BIGNUM *t1 = BN_new();
BIGNUM *t2 = BN_new();
/* just for debugging */
static int cnt = 0;
cnt++;
/* r belongs to [0, q) */
BN_rand_range(ctx->r, ctx->q);
/* t1 = g^r mod q */
BN_mod_exp(t1, ctx->g, ctx->r, ctx->q, ctx->ctx);
/* t2 = h^secret mod q */
BN_mod_exp(t2, ctx->h, ctx->secret, ctx->q, ctx->ctx);
/* ctx->y = t1 * t2 mod q */
BN_mod_mul(ctx->y, t1, t2, ctx->q, ctx->ctx);
/* message->y = ctx->y */
message->y = BN_dup(ctx->y);
/* print the random number r generated (just for debugging) */
if (cnt == 1)
{
print_bn("alice's r", ctx->r);
}
else
{
print_bn("bob's r", ctx->r);
}
}
开发者ID:qzhouayi,项目名称:New_graduation_thesis,代码行数:34,代码来源:pspake.c
示例4: EC_KEY_set_private_key
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
{
if (key->priv_key)
BN_clear_free(key->priv_key);
key->priv_key = BN_dup(priv_key);
return (key->priv_key == NULL) ? 0 : 1;
}
开发者ID:oss-forks,项目名称:openssl,代码行数:7,代码来源:ec_key.c
示例5: ec_GFp_mont_group_copy
int
ec_GFp_mont_group_copy(EC_GROUP * dest, const EC_GROUP * src)
{
BN_MONT_CTX_free(dest->field_data1);
dest->field_data1 = NULL;
BN_clear_free(dest->field_data2);
dest->field_data2 = NULL;
if (!ec_GFp_simple_group_copy(dest, src))
return 0;
if (src->field_data1 != NULL) {
dest->field_data1 = BN_MONT_CTX_new();
if (dest->field_data1 == NULL)
return 0;
if (!BN_MONT_CTX_copy(dest->field_data1, src->field_data1))
goto err;
}
if (src->field_data2 != NULL) {
dest->field_data2 = BN_dup(src->field_data2);
if (dest->field_data2 == NULL)
goto err;
}
return 1;
err:
if (dest->field_data1 != NULL) {
BN_MONT_CTX_free(dest->field_data1);
dest->field_data1 = NULL;
}
return 0;
}
开发者ID:libressl-portable,项目名称:openbsd,代码行数:32,代码来源:ecp_mont.c
示例6: YAK_CTX_init
static void YAK_CTX_init(YAK_CTX *ctx, const char *name,
const char *peer_name, const BIGNUM *p,
const EC_POINT *g, const BIGNUM *q,
const BIGNUM *secret)
{
ctx->p.name = OPENSSL_strdup(name);
ctx->p.peer_name = OPENSSL_strdup(peer_name);
ctx->p.p = BN_dup(p);
ctx->p.g = BN_dup(g);
ctx->p.q = BN_dup(q);
ctx->secret = BN_dup(secret);
ctx->xa = BN_new();
ctx->key = BN_new();
ctx->ctx = BN_CTX_new();
}
开发者ID:stonecoldpat,项目名称:Authenticated-Key-Exchange-Over-Bitcoin,代码行数:16,代码来源:yak.c
示例7: EVP_DecodeInit
BIGNUM * OpenSSLCryptoBase64::b642BN(char * b64in, unsigned int len) {
if (len > 1024)
return NULL;
int bufLen;
unsigned char buf[1024];
EVP_ENCODE_CTX m_dctx;
EVP_DecodeInit(&m_dctx);
int rc = EVP_DecodeUpdate(&m_dctx,
buf,
&bufLen,
(unsigned char *) b64in,
len);
if (rc < 0) {
throw XSECCryptoException(XSECCryptoException::Base64Error,
"OpenSSL:Base64 - Error during Base64 Decode of BIGNUMS");
}
int finalLen;
EVP_DecodeFinal(&m_dctx, &buf[bufLen], &finalLen);
bufLen += finalLen;
// Now translate to a bignum
return BN_dup(BN_bin2bn(buf, bufLen, NULL));
}
开发者ID:mvancompernolle,项目名称:ai_project,代码行数:31,代码来源:OpenSSLCryptoBase64.cpp
示例8: dh_compute_key_nif
ERL_NIF_TERM dh_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{/* (OthersPublicKey, MyPrivateKey, DHParams=[P,G]) */
BIGNUM *other_pub_key = NULL,
*dh_p = NULL,
*dh_g = NULL;
DH *dh_priv = DH_new();
/* Check the arguments and get
my private key (dh_priv),
the peer's public key (other_pub_key),
the parameters p & q
*/
{
BIGNUM *dummy_pub_key = NULL,
*priv_key = NULL;
ERL_NIF_TERM head, tail;
if (!get_bn_from_bin(env, argv[0], &other_pub_key)
|| !get_bn_from_bin(env, argv[1], &priv_key)
|| !enif_get_list_cell(env, argv[2], &head, &tail)
|| !get_bn_from_bin(env, head, &dh_p)
|| !enif_get_list_cell(env, tail, &head, &tail)
|| !get_bn_from_bin(env, head, &dh_g)
|| !enif_is_empty_list(env, tail)
/* Note: DH_set0_key() does not allow setting only the
* private key, although DH_compute_key() does not use the
* public key. Work around this limitation by setting
* the public key to a copy of the private key.
*/
|| !(dummy_pub_key = BN_dup(priv_key))
|| !DH_set0_key(dh_priv, dummy_pub_key, priv_key)
|| !DH_set0_pqg(dh_priv, dh_p, NULL, dh_g)
) {
if (dh_p) BN_free(dh_p);
if (dh_g) BN_free(dh_g);
if (other_pub_key) BN_free(other_pub_key);
if (dummy_pub_key) BN_free(dummy_pub_key);
if (priv_key) BN_free(priv_key);
return enif_make_badarg(env);
}
}
{
ErlNifBinary ret_bin;
int size;
enif_alloc_binary(DH_size(dh_priv), &ret_bin);
size = DH_compute_key(ret_bin.data, other_pub_key, dh_priv);
BN_free(other_pub_key);
DH_free(dh_priv);
if (size<=0) {
enif_release_binary(&ret_bin);
return atom_error;
}
if (size != ret_bin.size) enif_realloc_binary(&ret_bin, size);
return enif_make_binary(env, &ret_bin);
}
}
开发者ID:KennethL,项目名称:otp,代码行数:60,代码来源:dh.c
示例9: ec_GFp_mont_group_copy
int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) {
BN_MONT_CTX_free(dest->mont);
dest->mont = NULL;
BN_clear_free(dest->one);
dest->one = NULL;
if (!ec_GFp_simple_group_copy(dest, src)) {
return 0;
}
if (src->mont != NULL) {
dest->mont = BN_MONT_CTX_new();
if (dest->mont == NULL) {
return 0;
}
if (!BN_MONT_CTX_copy(dest->mont, src->mont)) {
goto err;
}
}
if (src->one != NULL) {
dest->one = BN_dup(src->one);
if (dest->one == NULL) {
goto err;
}
}
return 1;
err:
BN_MONT_CTX_free(dest->mont);
dest->mont = NULL;
return 0;
}
开发者ID:Crawping,项目名称:chromium_extract,代码行数:33,代码来源:ec_montgomery.c
示例10: gost_set_priv_key
static int gost_set_priv_key(EVP_PKEY *pkey,BIGNUM *priv)
{
switch (EVP_PKEY_base_id(pkey))
{
case NID_id_GostR3410_94:
{
DSA *dsa = (DSA*)EVP_PKEY_get0(pkey);
if (!dsa)
{
dsa = DSA_new();
EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),dsa);
}
dsa->priv_key = BN_dup(priv);
if (!EVP_PKEY_missing_parameters(pkey))
gost94_compute_public(dsa);
break;
}
case NID_id_GostR3410_2001:
{
EC_KEY *ec = (EC_KEY*)EVP_PKEY_get0(pkey);
if (!ec)
{
ec = EC_KEY_new();
EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),ec);
}
if (!EC_KEY_set_private_key(ec,priv)) return 0;
if (!EVP_PKEY_missing_parameters(pkey))
gost2001_compute_public(ec);
break;
}
}
return 1;
}
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:33,代码来源:gost_ameth.cpp
示例11: BN_new
//old
BIGNUM *Egcd(const BIGNUM *n, const BIGNUM *m, BIGNUM *x, BIGNUM *y)
{
//print_bn("n", n);
//print_bn("m", m);
BIGNUM *value = BN_new();
BIGNUM *temp = BN_new();
BIGNUM *t1 = BN_new();
BIGNUM *t2 = BN_new();
BIGNUM *new_m = BN_new();
BN_CTX *ctx = BN_CTX_new();
if (BN_is_zero(m))
{
BN_set_word(x, 1);
BN_set_word(y, 0);
value = BN_dup(n);
//print_bn("x", x);
//print_bn("y", y);
return value;
}
BN_mod(new_m, n, m, ctx);
//printf("called once\n");
value = BN_dup(Egcd(m, new_m, x, y));
print_bn("n", n);
print_bn("m", m);
print_bn("old_x", x);
print_bn("old_y", y);
temp = BN_dup(x);
x = BN_dup(y);
/* y = temp - (n/m) * y */
BN_div(t1, NULL, n, m, ctx);
BN_mul(t2, t1, y, ctx);
BN_sub(y, temp, t2);
print_bn("x", x);
print_bn("y", y);
return value;
}
开发者ID:qzhouayi,项目名称:New_graduation_thesis,代码行数:48,代码来源:test.c
示例12: DH_new
static DH *get_standard_parameters(const struct standard_parameters *params,
const ENGINE *engine) {
DH *dh = DH_new();
if (!dh) {
return NULL;
}
dh->p = BN_dup(¶ms->p);
dh->q = BN_dup(¶ms->q);
dh->g = BN_dup(¶ms->g);
if (!dh->p || !dh->q || !dh->g) {
DH_free(dh);
return NULL;
}
return dh;
}
开发者ID:aaapei,项目名称:libquic,代码行数:17,代码来源:params.c
示例13: dh_copy_parameters
static int
dh_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
{
BIGNUM *a;
if ((a = BN_dup(from->pkey.dh->p)) == NULL)
return 0;
BN_free(to->pkey.dh->p);
to->pkey.dh->p = a;
if ((a = BN_dup(from->pkey.dh->g)) == NULL)
return 0;
BN_free(to->pkey.dh->g);
to->pkey.dh->g = a;
return 1;
}
开发者ID:Basskrapfen,项目名称:openbsd,代码行数:17,代码来源:dh_ameth.c
示例14: EVP_PKEY_copy_parameters
int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
{
if (to->type != from->type)
{
EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
goto err;
}
if (EVP_PKEY_missing_parameters(from))
{
EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
goto err;
}
#ifndef OPENSSL_NO_DSA
if (to->type == EVP_PKEY_DSA)
{
BIGNUM *a;
if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
to->pkey.dsa->p=a;
if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
to->pkey.dsa->q=a;
if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
to->pkey.dsa->g=a;
}
#endif
#ifndef OPENSSL_NO_EC
if (to->type == EVP_PKEY_EC)
{
EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec));
if (group == NULL)
goto err;
if (EC_KEY_set_group(to->pkey.ec, group) == 0)
goto err;
EC_GROUP_free(group);
}
#endif
return(1);
err:
return(0);
}
开发者ID:1310701102,项目名称:sl4a,代码行数:46,代码来源:p_lib.c
示例15: SRP_user_pwd_set_gN
static SRP_user_pwd *srp_user_pwd_dup(SRP_user_pwd *src)
{
SRP_user_pwd *ret;
if (src == NULL)
return NULL;
if ((ret = SRP_user_pwd_new()) == NULL)
return NULL;
SRP_user_pwd_set_gN(ret, src->g, src->N);
if (!SRP_user_pwd_set_ids(ret, src->id, src->info)
|| !SRP_user_pwd_set_sv_BN(ret, BN_dup(src->s), BN_dup(src->v))) {
SRP_user_pwd_free(ret);
return NULL;
}
return ret;
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:17,代码来源:srp_vfy.c
示例16: tls_ctx_use_external_private_key
int
tls_ctx_use_external_private_key (struct tls_root_ctx *ctx, X509 *cert)
{
RSA *rsa = NULL;
RSA *pub_rsa;
RSA_METHOD *rsa_meth;
ASSERT (NULL != ctx);
ASSERT (NULL != cert);
/* allocate custom RSA method object */
ALLOC_OBJ_CLEAR (rsa_meth, RSA_METHOD);
rsa_meth->name = "OpenVPN external private key RSA Method";
rsa_meth->rsa_pub_enc = rsa_pub_enc;
rsa_meth->rsa_pub_dec = rsa_pub_dec;
rsa_meth->rsa_priv_enc = rsa_priv_enc;
rsa_meth->rsa_priv_dec = rsa_priv_dec;
rsa_meth->init = NULL;
rsa_meth->finish = rsa_finish;
rsa_meth->flags = RSA_METHOD_FLAG_NO_CHECK;
rsa_meth->app_data = NULL;
/* allocate RSA object */
rsa = RSA_new();
if (rsa == NULL)
{
SSLerr(SSL_F_SSL_USE_PRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
/* get the public key */
ASSERT(cert->cert_info->key->pkey); /* NULL before SSL_CTX_use_certificate() is called */
pub_rsa = cert->cert_info->key->pkey->pkey.rsa;
/* initialize RSA object */
rsa->n = BN_dup(pub_rsa->n);
rsa->flags |= RSA_FLAG_EXT_PKEY;
if (!RSA_set_method(rsa, rsa_meth))
goto err;
/* bind our custom RSA object to ssl_ctx */
if (!SSL_CTX_use_RSAPrivateKey(ctx->ctx, rsa))
goto err;
RSA_free(rsa); /* doesn't necessarily free, just decrements refcount */
return 1;
err:
if (rsa)
RSA_free(rsa);
else
{
if (rsa_meth)
free(rsa_meth);
}
msg (M_SSLERR, "Cannot enable SSL external private key capability");
return 0;
}
开发者ID:LordZEDith,项目名称:russia_vpn,代码行数:58,代码来源:ssl_openssl.c
示例17: init_crypto
Result<RSA> RSA::from_pem(Slice pem) {
init_crypto();
auto *bio =
BIO_new_mem_buf(const_cast<void *>(static_cast<const void *>(pem.ubegin())), narrow_cast<int32>(pem.size()));
if (bio == nullptr) {
return Status::Error("Cannot create BIO");
}
SCOPE_EXIT {
BIO_free(bio);
};
auto *rsa = RSA_new();
if (rsa == nullptr) {
return Status::Error("Cannot create RSA");
}
SCOPE_EXIT {
RSA_free(rsa);
};
if (!PEM_read_bio_RSAPublicKey(bio, &rsa, nullptr, nullptr)) {
return Status::Error("Error while reading rsa pubkey");
}
if (RSA_size(rsa) != 256) {
return Status::Error("RSA_size != 256");
}
const BIGNUM *n_num;
const BIGNUM *e_num;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
n_num = rsa->n;
e_num = rsa->e;
#else
RSA_get0_key(rsa, &n_num, &e_num, nullptr);
#endif
auto n = static_cast<void *>(BN_dup(n_num));
auto e = static_cast<void *>(BN_dup(e_num));
if (n == nullptr || e == nullptr) {
return Status::Error("Cannot dup BIGNUM");
}
return RSA(BigNum::from_raw(n), BigNum::from_raw(e));
}
开发者ID:anhdocphys,项目名称:td,代码行数:45,代码来源:crypto.cpp
示例18: test_seckey
static void
test_seckey(const __ops_seckey_t *seckey)
{
RSA *test = RSA_new();
test->n = BN_dup(seckey->pubkey.key.rsa.n);
test->e = BN_dup(seckey->pubkey.key.rsa.e);
test->d = BN_dup(seckey->key.rsa.d);
test->p = BN_dup(seckey->key.rsa.p);
test->q = BN_dup(seckey->key.rsa.q);
if (RSA_check_key(test) != 1) {
(void) fprintf(stderr,
"test_seckey: RSA_check_key failed\n");
}
RSA_free(test);
}
开发者ID:Mynigma,项目名称:MCryptoLib,代码行数:18,代码来源:openssl_crypto.c
示例19: TRY
QUADRATIC *QD_dup(QUADRATIC *a) {
QUADRATIC *b = NULL;
int code;
code = LIBLESS_ERROR;
TRY(b = (QUADRATIC *)malloc(sizeof(QUADRATIC)), return NULL);
TRY(b->x = BN_dup(a->x), goto end);
TRY(b->y = BN_dup(a->y), goto end);
code = LIBLESS_OK;
end:
if (code != LIBLESS_OK) {
QD_free(b);
b = NULL;
}
return b;
}
开发者ID:BackupTheBerlios,项目名称:kurupira-svn,代码行数:18,代码来源:libless_quadratic.c
示例20: EC_KEY_set_private_key
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
{
if (key->meth->set_private != NULL
&& key->meth->set_private(key, priv_key) == 0)
return 0;
BN_clear_free(key->priv_key);
key->priv_key = BN_dup(priv_key);
return (key->priv_key == NULL) ? 0 : 1;
}
开发者ID:AndreV84,项目名称:openssl,代码行数:9,代码来源:ec_key.c
注:本文中的BN_dup函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论