本文整理汇总了C++中bn_copy函数的典型用法代码示例。如果您正苦于以下问题:C++ bn_copy函数的具体用法?C++ bn_copy怎么用?C++ bn_copy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bn_copy函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: eb_curve_set_ordin
void eb_curve_set_ordin(fb_t a, fb_t b, eb_t g, bn_t r, bn_t h) {
fb_copy(curve_a, a);
fb_copy(curve_b, b);
detect_opt(&curve_opt_a, curve_a);
detect_opt(&curve_opt_b, curve_b);
curve_is_super = 0;
if (fb_cmp_dig(curve_b, 1) == CMP_EQ) {
curve_is_kbltz = 1;
} else {
curve_is_kbltz = 0;
}
#if defined(EB_KBLTZ) && (EB_MUL == LWNAF || EB_FIX == LWNAF || EB_SIM == INTER || !defined(STRIP))
if (curve_is_kbltz) {
compute_kbltz();
}
#endif
eb_norm(g, g);
eb_copy(&curve_g, g);
bn_copy(&curve_r, r);
bn_copy(&curve_h, h);
#if defined(EB_PRECO)
eb_mul_pre(eb_curve_get_tab(), &curve_g);
#endif
}
开发者ID:0x64616E69656C,项目名称:supercop,代码行数:27,代码来源:relic_eb_curve.c
示例2: eb_curve_set_ordin
void eb_curve_set_ordin(const fb_t a, const fb_t b, const eb_t g, const bn_t r,
const bn_t h) {
ctx_t *ctx = core_get();
fb_copy(ctx->eb_a, a);
fb_copy(ctx->eb_b, b);
detect_opt(&(ctx->eb_opt_a), ctx->eb_a);
detect_opt(&(ctx->eb_opt_b), ctx->eb_b);
ctx->eb_is_super = 0;
if (fb_cmp_dig(ctx->eb_b, 1) == CMP_EQ) {
ctx->eb_is_kbltz = 1;
} else {
ctx->eb_is_kbltz = 0;
}
#if defined(EB_KBLTZ) && (EB_MUL == LWNAF || EB_FIX == LWNAF || EB_SIM == INTER || !defined(STRIP))
if (ctx->eb_is_kbltz) {
compute_kbltz();
}
#endif
eb_norm(&(ctx->eb_g), g);
bn_copy(&(ctx->eb_r), r);
bn_copy(&(ctx->eb_h), h);
#if defined(EB_PRECO)
eb_mul_pre((eb_t *)eb_curve_get_tab(), &(ctx->eb_g));
#endif
}
开发者ID:ekr,项目名称:hacrypto,代码行数:28,代码来源:relic_eb_curve.c
示例3: bn_exp
/**
* Computes c = a ^ b mod m.
*
* @param c - the result.
* @param a - the basis.
* @param b - the exponent.
* @param m - the modulus.
*/
static void bn_exp(bn_t c, const bn_t a, const bn_t b, const bn_t m) {
int i, l;
bn_t t;
bn_null(t);
TRY {
bn_new(t);
l = bn_bits(b);
bn_copy(t, a);
for (i = l - 2; i >= 0; i--) {
bn_sqr(t, t);
bn_mod(t, t, m);
if (bn_get_bit(b, i)) {
bn_mul(t, t, a);
bn_mod(t, t, m);
}
}
bn_copy(c, t);
}
CATCH_ANY {
THROW(ERR_CAUGHT);
}
FINALLY {
bn_free(t);
}
}
开发者ID:enascimento,项目名称:relic-git-avr,代码行数:39,代码来源:relic_bn_prime.c
示例4: cp_rsa_gen_basic
int cp_rsa_gen_basic(rsa_t pub, rsa_t prv, int bits) {
bn_t t, r;
int result = STS_OK;
if (pub == NULL || prv == NULL || bits == 0) {
return STS_ERR;
}
bn_null(t);
bn_null(r);
TRY {
bn_new(t);
bn_new(r);
/* Generate different primes p and q. */
do {
bn_gen_prime(prv->p, bits / 2);
bn_gen_prime(prv->q, bits / 2);
} while (bn_cmp(prv->p, prv->q) == CMP_EQ);
/* Swap p and q so that p is smaller. */
if (bn_cmp(prv->p, prv->q) == CMP_LT) {
bn_copy(t, prv->p);
bn_copy(prv->p, prv->q);
bn_copy(prv->q, t);
}
bn_mul(pub->n, prv->p, prv->q);
bn_copy(prv->n, pub->n);
bn_sub_dig(prv->p, prv->p, 1);
bn_sub_dig(prv->q, prv->q, 1);
bn_mul(t, prv->p, prv->q);
bn_set_2b(pub->e, 16);
bn_add_dig(pub->e, pub->e, 1);
bn_gcd_ext(r, prv->d, NULL, pub->e, t);
if (bn_sign(prv->d) == BN_NEG) {
bn_add(prv->d, prv->d, t);
}
if (bn_cmp_dig(r, 1) == CMP_EQ) {
bn_add_dig(prv->p, prv->p, 1);
bn_add_dig(prv->q, prv->q, 1);
}
}
CATCH_ANY {
result = STS_ERR;
}
FINALLY {
bn_free(t);
bn_free(r);
}
return result;
}
开发者ID:Gesine,项目名称:relic,代码行数:58,代码来源:relic_cp_rsa.c
示例5: bn_mxp_monty
void bn_mxp_monty(bn_t c, const bn_t a, const bn_t b, const bn_t m) {
bn_t tab[2], u;
dig_t mask;
int t;
bn_null(tab[0]);
bn_null(tab[1]);
bn_null(u);
TRY {
bn_new(u);
bn_mod_pre(u, m);
bn_new(tab[0]);
bn_new(tab[1]);
#if BN_MOD == MONTY
bn_set_dig(tab[0], 1);
bn_mod_monty_conv(tab[0], tab[0], m);
bn_mod_monty_conv(tab[1], a, m);
#else
bn_set_dig(tab[0], 1);
bn_copy(tab[1], a);
#endif
for (int i = bn_bits(b) - 1; i >= 0; i--) {
int j = bn_get_bit(b, i);
dv_swap_cond(tab[0]->dp, tab[1]->dp, BN_DIGS, j ^ 1);
mask = -(j ^ 1);
t = (tab[0]->used ^ tab[1]->used) & mask;
tab[0]->used ^= t;
tab[1]->used ^= t;
bn_mul(tab[0], tab[0], tab[1]);
bn_mod(tab[0], tab[0], m, u);
bn_sqr(tab[1], tab[1]);
bn_mod(tab[1], tab[1], m, u);
dv_swap_cond(tab[0]->dp, tab[1]->dp, BN_DIGS, j ^ 1);
mask = -(j ^ 1);
t = (tab[0]->used ^ tab[1]->used) & mask;
tab[0]->used ^= t;
tab[1]->used ^= t;
}
#if BN_MOD == MONTY
bn_mod_monty_back(c, tab[0], m);
#else
bn_copy(c, tab[0]);
#endif
} CATCH_ANY {
THROW(ERR_CAUGHT);
}
FINALLY {
bn_free(tab[1]);
bn_free(tab[0]);
bn_free(u);
}
}
开发者ID:Gesine,项目名称:relic,代码行数:58,代码来源:relic_bn_mxp.c
示例6: ep_curve_set_endom
void ep_curve_set_endom(const fp_t b, const ep_t g, const bn_t r, const bn_t h,
const fp_t beta, const bn_t l) {
int bits = bn_bits(r);
ctx_t *ctx = core_get();
ctx->ep_is_endom = 1;
ctx->ep_is_super = 0;
fp_zero(ctx->ep_a);
fp_copy(ctx->ep_b, b);
detect_opt(&(ctx->ep_opt_a), ctx->ep_a);
detect_opt(&(ctx->ep_opt_b), ctx->ep_b);
#if EP_MUL == LWNAF || EP_FIX == COMBS || EP_FIX == LWNAF || EP_SIM == INTER || !defined(STRIP)
fp_copy(ctx->beta, beta);
bn_gcd_ext_mid(&(ctx->ep_v1[1]), &(ctx->ep_v1[2]), &(ctx->ep_v2[1]),
&(ctx->ep_v2[2]), l, r);
/* l = v1[1] * v2[2] - v1[2] * v2[1], r = l / 2. */
bn_mul(&(ctx->ep_v1[0]), &(ctx->ep_v1[1]), &(ctx->ep_v2[2]));
bn_mul(&(ctx->ep_v2[0]), &(ctx->ep_v1[2]), &(ctx->ep_v2[1]));
bn_sub(&(ctx->ep_r), &(ctx->ep_v1[0]), &(ctx->ep_v2[0]));
bn_hlv(&(ctx->ep_r), &(ctx->ep_r));
/* v1[0] = round(v2[2] * 2^|n| / l). */
bn_lsh(&(ctx->ep_v1[0]), &(ctx->ep_v2[2]), bits + 1);
if (bn_sign(&(ctx->ep_v1[0])) == BN_POS) {
bn_add(&(ctx->ep_v1[0]), &(ctx->ep_v1[0]), &(ctx->ep_r));
} else {
bn_sub(&(ctx->ep_v1[0]), &(ctx->ep_v1[0]), &(ctx->ep_r));
}
bn_dbl(&(ctx->ep_r), &(ctx->ep_r));
bn_div(&(ctx->ep_v1[0]), &(ctx->ep_v1[0]), &(ctx->ep_r));
if (bn_sign(&ctx->ep_v1[0]) == BN_NEG) {
bn_add_dig(&(ctx->ep_v1[0]), &(ctx->ep_v1[0]), 1);
}
/* v2[0] = round(v1[2] * 2^|n| / l). */
bn_lsh(&(ctx->ep_v2[0]), &(ctx->ep_v1[2]), bits + 1);
if (bn_sign(&(ctx->ep_v2[0])) == BN_POS) {
bn_add(&(ctx->ep_v2[0]), &(ctx->ep_v2[0]), &(ctx->ep_r));
} else {
bn_sub(&(ctx->ep_v2[0]), &(ctx->ep_v2[0]), &(ctx->ep_r));
}
bn_div(&(ctx->ep_v2[0]), &(ctx->ep_v2[0]), &(ctx->ep_r));
if (bn_sign(&ctx->ep_v2[0]) == BN_NEG) {
bn_add_dig(&(ctx->ep_v2[0]), &(ctx->ep_v2[0]), 1);
}
bn_neg(&(ctx->ep_v2[0]), &(ctx->ep_v2[0]));
#endif
ep_norm(&(ctx->ep_g), g);
bn_copy(&(ctx->ep_r), r);
bn_copy(&(ctx->ep_h), h);
#if defined(EP_PRECO)
ep_mul_pre((ep_t *)ep_curve_get_tab(), &(ctx->ep_g));
#endif
}
开发者ID:cryptobiu,项目名称:libscapi,代码行数:56,代码来源:relic_ep_curve.c
示例7: eccutils_affine_to_projective
uint32_t eccutils_affine_to_projective(bn_uint_t *ax, bn_uint_t *ay,
bn_uint_t *px, bn_uint_t *py,
bn_uint_t *pz, ecc_curve_t *curve) {
(void)(curve);
//trying to create (X,Y,Z) => (X,Y,1) from (x,y)
bn_copy(ax, px, ax->length);
bn_copy(ay, py, ay->length);
bn_zero(pz);
pz->number[0] = 1;
return 0;
}
开发者ID:kl-cruz,项目名称:cecc,代码行数:11,代码来源:ecc_utils.c
示例8: bn_mxp_basic
void bn_mxp_basic(bn_t c, const bn_t a, const bn_t b, const bn_t m) {
int i, l;
bn_t t, u, r;
if (bn_is_zero(b)) {
bn_set_dig(c, 1);
return;
}
bn_null(t);
bn_null(u);
bn_null(r);
TRY {
bn_new(t);
bn_new(u);
bn_new(r);
bn_mod_pre(u, m);
l = bn_bits(b);
#if BN_MOD == MONTY
bn_mod_monty_conv(t, a, m);
#else
bn_copy(t, a);
#endif
bn_copy(r, t);
for (i = l - 2; i >= 0; i--) {
bn_sqr(r, r);
bn_mod(r, r, m, u);
if (bn_get_bit(b, i)) {
bn_mul(r, r, t);
bn_mod(r, r, m, u);
}
}
#if BN_MOD == MONTY
bn_mod_monty_back(c, r, m);
#else
bn_copy(c, r);
#endif
}
CATCH_ANY {
THROW(ERR_CAUGHT);
}
FINALLY {
bn_free(t);
bn_free(u);
bn_free(r);
}
}
开发者ID:Gesine,项目名称:relic,代码行数:54,代码来源:relic_bn_mxp.c
示例9: ep2_curve_set
void ep2_curve_set(fp2_t a, fp2_t b, ep2_t g, bn_t r, bn_t h) {
ctx_t *ctx = core_get();
ctx->ep2_is_twist = 0;
fp2_copy(ctx->ep2_a, a);
fp2_copy(ctx->ep2_b, b);
ep2_norm(&(ctx->ep2_g), g);
bn_copy(&(ctx->ep2_r), r);
bn_copy(&(ctx->ep2_h), h);
#if defined(EP_PRECO)
ep2_mul_pre((ep2_t *)ep2_curve_get_tab(), &(ctx->ep2_g));
#endif
}
开发者ID:enascimento,项目名称:relic-git-avr,代码行数:15,代码来源:relic_ep2_curve.c
示例10: eb_curve_get_s1
void eb_curve_get_s1(bn_t s1) {
if (core_get()->eb_is_kbltz) {
bn_copy(s1, &(core_get()->eb_s1));
} else {
bn_zero(s1);
}
}
开发者ID:ekr,项目名称:hacrypto,代码行数:7,代码来源:relic_eb_curve.c
示例11: eb_curve_get_s0
void eb_curve_get_s0(bn_t s0) {
if (core_get()->eb_is_kbltz) {
bn_copy(s0, &(core_get()->eb_s0));
} else {
bn_zero(s0);
}
}
开发者ID:ekr,项目名称:hacrypto,代码行数:7,代码来源:relic_eb_curve.c
示例12: eb_curve_get_vm
void eb_curve_get_vm(bn_t vm) {
if (core_get()->eb_is_kbltz) {
bn_copy(vm, &(core_get()->eb_vm));
} else {
bn_zero(vm);
}
}
开发者ID:ekr,项目名称:hacrypto,代码行数:7,代码来源:relic_eb_curve.c
示例13: bn_sqr_comba
void bn_sqr_comba(bn_t c, const bn_t a) {
int digits;
bn_t t;
bn_null(t);
digits = 2 * a->used;
TRY {
/* We need a temporary variable so that c can be a or b. */
bn_new_size(t, digits);
t->used = digits;
bn_sqrn_low(t->dp, a->dp, a->used);
t->sign = BN_POS;
bn_trim(t);
bn_copy(c, t);
} CATCH_ANY {
THROW(ERR_CAUGHT);
}
FINALLY {
bn_free(t);
}
}
开发者ID:lucamelis,项目名称:relic,代码行数:25,代码来源:relic_bn_sqr.c
示例14: bn_sqr_basic
void bn_sqr_basic(bn_t c, const bn_t a) {
int i, digits;
bn_t t;
bn_null(t);
digits = 2 * a->used;
TRY {
bn_new_size(t, digits);
bn_zero(t);
t->used = digits;
for (i = 0; i < a->used; i++) {
bn_sqra_low(t->dp + (2 * i), a->dp + i, a->used - i);
}
t->sign = BN_POS;
bn_trim(t);
bn_copy(c, t);
}
CATCH_ANY {
THROW(ERR_CAUGHT);
}
FINALLY {
bn_free(t);
}
}
开发者ID:lucamelis,项目名称:relic,代码行数:28,代码来源:relic_bn_sqr.c
示例15: bn_rsh
void bn_rsh(bn_t c, bn_t a, int bits) {
int digits = 0;
if (bits <= 0) {
bn_copy(c, a);
return;
}
SPLIT(bits, digits, bits, BN_DIG_LOG);
if (digits > 0) {
bn_rshd_low(c->dp, a->dp, a->used, digits);
}
c->used = a->used - digits;
c->sign = a->sign;
if (c->used > 0 && bits > 0) {
if (digits == 0 && c != a) {
bn_rshb_low(c->dp, a->dp + digits, a->used - digits, bits);
} else {
bn_rshb_low(c->dp, c->dp, c->used, bits);
}
}
bn_trim(c);
}
开发者ID:0x64616E69656C,项目名称:supercop,代码行数:25,代码来源:relic_bn_shift.c
示例16: test_gen_proj_key
uint32_t test_gen_proj_key(bn_uint_t *d, bn_uint_t *exp_pub_k_x, bn_uint_t *exp_pub_k_y, ecc_curve_t *curve)
{
BN_CREATE_VARIABLE(dtmp, d->length);
void prgn(bn_uint_t *output)
{
bn_copy(d, output, output->length);
}
开发者ID:kl-cruz,项目名称:cecc,代码行数:7,代码来源:test_ecc_proj_coords.c
示例17: eb_curve_get_s1
void eb_curve_get_s1(bn_t s1) {
if (curve_is_kbltz) {
bn_copy(s1, &curve_s1);
} else {
bn_zero(s1);
}
}
开发者ID:0x64616E69656C,项目名称:supercop,代码行数:7,代码来源:relic_eb_curve.c
示例18: eb_curve_get_s0
void eb_curve_get_s0(bn_t s0) {
if (curve_is_kbltz) {
bn_copy(s0, &curve_s0);
} else {
bn_zero(s0);
}
}
开发者ID:0x64616E69656C,项目名称:supercop,代码行数:7,代码来源:relic_eb_curve.c
示例19: eb_curve_get_vm
void eb_curve_get_vm(bn_t vm) {
if (curve_is_kbltz) {
bn_copy(vm, &curve_vm);
} else {
bn_zero(vm);
}
}
开发者ID:0x64616E69656C,项目名称:supercop,代码行数:7,代码来源:relic_eb_curve.c
示例20: ep2_curve_get_ord
void ep2_curve_get_ord(bn_t n) {
ctx_t *ctx = core_get();
if (ctx->ep2_is_twist) {
ep_curve_get_ord(n);
} else {
bn_copy(n, &(ctx->ep2_r));
}
}
开发者ID:enascimento,项目名称:relic-git-avr,代码行数:8,代码来源:relic_ep2_curve.c
注:本文中的bn_copy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论