Skip to content

Commit

Permalink
Port optimization to E(Fp²) too.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Sep 12, 2024
1 parent ecb5069 commit 6f3ba53
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/epx/relic_ep2_mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#if EP_MUL == LWNAF || !defined(STRIP)

static void ep2_mul_gls_imp(ep2_t r, const ep2_t p, const bn_t k) {
size_t l, _l[4];
size_t l, _l[4], w = RLC_WIDTH;
bn_t n, _k[4], u;
int8_t naf[4][RLC_FP_BITS + 1];
ep2_t q, t[4][1 << (RLC_WIDTH - 2)];
Expand All @@ -68,19 +68,27 @@ static void ep2_mul_gls_imp(ep2_t r, const ep2_t p, const bn_t k) {
bn_mod(_k[0], k, n);
bn_rec_frb(_k, 4, _k[0], u, n, ep_curve_is_pairf() == EP_BN);

l = 0;
for (size_t i = 0; i < 4; i++) {
l = RLC_MAX(l, bn_bits(_k[i]));
}
if (l < bn_bits(u) / 2) {
w = 2;
}

l = 0;
for (size_t i = 0; i < 4; i++) {
_l[i] = RLC_FP_BITS + 1;
bn_rec_naf(naf[i], &_l[i], _k[i], RLC_WIDTH);
bn_rec_naf(naf[i], &_l[i], _k[i], w);
l = RLC_MAX(l, _l[i]);
if (i == 0) {
ep2_norm(q, p);
if (bn_sign(_k[0]) == RLC_NEG) {
ep2_neg(q, q);
}
ep2_tab(t[0], q, RLC_WIDTH);
ep2_tab(t[0], q, w);
} else {
for (size_t j = 0; j < (1 << (RLC_WIDTH - 2)); j++) {
for (size_t j = 0; j < (1 << (w - 2)); j++) {
ep2_frb(t[i][j], t[i - 1][j], 1);
if (bn_sign(_k[i]) != bn_sign(_k[i - 1])) {
ep2_neg(t[i][j], t[i][j]);
Expand Down

0 comments on commit 6f3ba53

Please sign in to comment.