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 }
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 }
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 }
void eb_curve_set_super(fb_t a, fb_t b, fb_t c, eb_t g, bn_t r, bn_t h) { curve_is_kbltz = 0; curve_is_super = 1; fb_copy(curve_a, a); fb_copy(curve_b, b); fb_copy(curve_c, c); detect_opt(&curve_opt_a, curve_a); detect_opt(&curve_opt_b, curve_b); detect_opt(&curve_opt_c, curve_c); 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 }
void ep_curve_set_super(const fp_t a, const fp_t b, const ep_t g, const bn_t r, const bn_t h) { ctx_t *ctx = core_get(); ctx->ep_is_endom = 0; ctx->ep_is_super = 1; fp_copy(ctx->ep_a, 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); 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 }
void eb_curve_set_kbltz(fb_t a, eb_t g, bn_t r, bn_t h) { curve_is_kbltz = 1; curve_is_super = 0; fb_copy(curve_a, a); fb_set_dig(curve_b, 1); detect_opt(&curve_opt_a, curve_a); detect_opt(&curve_opt_b, curve_b); #if EB_MUL == LWNAF || EB_FIX == LWNAF || EB_SIM == INTER || !defined(STRIP) 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 }
void eb_curve_set_super(const fb_t a, const fb_t b, const fb_t c, const eb_t g, const bn_t r, const bn_t h) { ctx_t *ctx = core_get(); ctx->eb_is_kbltz = 0; ctx->eb_is_super = 1; fb_copy(ctx->eb_a, a); fb_copy(ctx->eb_b, b); fb_copy(ctx->eb_c, c); detect_opt(&(ctx->eb_opt_a), ctx->eb_a); detect_opt(&(ctx->eb_opt_b), ctx->eb_b); detect_opt(&(ctx->eb_opt_c), ctx->eb_c); 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 }
void eb_curve_set_kbltz(const fb_t a, const eb_t g, const bn_t r, const bn_t h) { ctx_t *ctx = core_get(); ctx->eb_is_kbltz = 1; ctx->eb_is_super = 0; fb_copy(ctx->eb_a, a); fb_set_dig(ctx->eb_b, 1); detect_opt(&(ctx->eb_opt_a), ctx->eb_a); detect_opt(&(ctx->eb_opt_b), ctx->eb_b); #if EB_MUL == LWNAF || EB_FIX == LWNAF || EB_SIM == INTER || !defined(STRIP) 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 }