本文整理汇总了C++中BN_dup函数的典型用法代码示例。如果您正苦于以下问题:C++ BN_dup函数的具体用法?C++ BN_dup怎么用?C++ BN_dup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BN_dup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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));
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}