Skip to content

Commit

Permalink
Another big refactoring to include more coords for ep2.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Mar 29, 2024
1 parent 1ffffb0 commit b5e5a7c
Show file tree
Hide file tree
Showing 12 changed files with 679 additions and 505 deletions.
67 changes: 57 additions & 10 deletions bench/bench_epx.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ static void arith2(void) {
ep2_rand(p);
ep2_add_projc(q, q, p);
BENCH_ADD(ep2_add_projc(r, p, q));
}
BENCH_END;
} BENCH_END;

BENCH_RUN("ep2_add_projc (z2 = 1)") {
ep2_rand(p);
Expand All @@ -250,17 +249,44 @@ static void arith2(void) {
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_projc(r, p, q));
}
BENCH_END;
} BENCH_END;

BENCH_RUN("ep2_add_projc (z1,z2 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_projc(r, p, q));
}
BENCH_END;
} BENCH_END;
#endif

#if EP_ADD == JACOB || !defined(STRIP)
BENCH_RUN("ep2_add_jacob") {
ep2_rand(p);
ep2_rand(q);
ep2_add_jacob(p, p, q);
ep2_rand(q);
ep2_rand(p);
ep2_add_jacob(q, q, p);
BENCH_ADD(ep2_add_jacob(r, p, q));
} BENCH_END;

BENCH_RUN("ep2_add_jacob (z2 = 1)") {
ep2_rand(p);
ep2_rand(q);
ep2_add_jacob(p, p, q);
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_jacob(r, p, q));
} BENCH_END;

BENCH_RUN("ep2_add_jacob (z1,z2 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_jacob(r, p, q));
} BENCH_END;
#endif

BENCH_RUN("ep2_sub") {
Expand Down Expand Up @@ -302,15 +328,28 @@ static void arith2(void) {
ep2_rand(q);
ep2_add_projc(p, p, q);
BENCH_ADD(ep2_dbl_projc(r, p));
}
BENCH_END;
} BENCH_END;

BENCH_RUN("ep2_dbl_projc (z1 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
BENCH_ADD(ep2_dbl_projc(r, p));
}
BENCH_END;
} BENCH_END;
#endif

#if EP_ADD == JACOB || !defined(STRIP)
BENCH_RUN("ep2_dbl_jacob") {
ep2_rand(p);
ep2_rand(q);
ep2_add_jacob(p, p, q);
BENCH_ADD(ep2_dbl_jacob(r, p));
} BENCH_END;

BENCH_RUN("ep2_dbl_jacob (z1 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
BENCH_ADD(ep2_dbl_jacob(r, p));
} BENCH_END;
#endif

BENCH_RUN("ep2_neg") {
Expand Down Expand Up @@ -357,6 +396,14 @@ static void arith2(void) {
} BENCH_END;
#endif

#if EP_MUL == LWREG || !defined(STRIP)
BENCH_RUN("ep2_mul_lwreg") {
bn_rand_mod(k, n);
ep2_rand(p);
BENCH_ADD(ep2_mul_lwreg(q, p, k));
} BENCH_END;
#endif

BENCH_RUN("ep2_mul_gen") {
bn_rand_mod(k, n);
BENCH_ADD(ep2_mul_gen(q, k));
Expand Down
24 changes: 10 additions & 14 deletions include/relic_ep.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,16 @@ typedef iso_st *iso_t;
#define ep_mul_sim(R, P, K, Q, M) ep_mul_sim_joint(R, P, K, Q, M)
#endif

/**
* Multiplies a point in an elliptic curve over by an unrestricted scalar.
* Computes R = [k]P.
*
* @param[out] R - the result.
* @param[in] P - the point to multiply.
* @param[in] K - the integer.
*/
#define ep_mul_big(R, P, K) ep_mul_basic(R, P, K)

/**
* Hashes a byte string to a prime elliptic point or the right order.
* Computes R = H(s).
Expand Down Expand Up @@ -547,13 +557,6 @@ int ep_curve_opt_a(void);
*/
int ep_curve_opt_b(void);

/**
* Returns a optimization identifier based on the b-coefficient of the curve.
*
* @return the optimization identifier.
*/
int ep_curve_opt_b3(void);

/**
* Multiplies a field element by the a-coefficient of the curve.
*
Expand All @@ -570,13 +573,6 @@ void ep_curve_mul_a(fp_t c, const fp_t a);
*/
void ep_curve_mul_b(fp_t c, const fp_t a);

/**
* Multiplies a field element by the b3 value of the curve.
*
* @param[out] c - the result.
* @param[in] a - the field element to multiply.
*/
void ep_curve_mul_b3(fp_t c, const fp_t a);
/**
* Tests if the configured prime elliptic curve is a Koblitz curve.
*
Expand Down
Loading

0 comments on commit b5e5a7c

Please sign in to comment.