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 }
/** * Detects an optimization based on the curve coefficients. * * @param opt - the resulting optimization. * @param a - the curve coefficient. */ static void detect_opt(int *opt, fb_t a) { if (fb_is_zero(a)) { *opt = OPT_ZERO; } else { if (fb_cmp_dig(a, 1) == CMP_EQ) { *opt = OPT_ONE; } else { if (fb_bits(a) <= FB_DIGIT) { *opt = OPT_DIGIT; } else { *opt = OPT_NONE; } } } }