Skip to content

Commit

Permalink
Refactor divstep symbol computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Feb 4, 2024
1 parent 35fc0b3 commit fde494f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/fp/relic_fp_smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,14 @@ int fp_smb_divst(const fp_t a) {
#endif

k = 0;
fp_prime_back(_t, a);
dv_zero(g, RLC_FP_DIGS);
dv_copy(g, _t->dp, _t->used);
#if FP_RDC == MONTY
/* Convert a from Montgomery form. */
dv_zero(t, 2 * RLC_FP_DIGS);
fp_copy(t, a);
fp_rdcn_low(g, t);
#else
fp_copy(g, a);
#endif
dv_copy(f, fp_prime_get(), RLC_FP_DIGS);
fs = gs = RLC_POS;

Expand Down Expand Up @@ -240,15 +245,13 @@ int fp_smb_divst(const fp_t a) {
k = (2*k) % 4;
fp_zero(t);
t[0] = 1;
for (int j = 0; j < RLC_FP_DIGS; j++) {
f[j] ^= -fs;
}
fp_add1_low(f, f, fs);

bn_negs_low(f, f, fs, RLC_FP_DIGS);

r = RLC_SEL(r, 1 - k, dv_cmp_const(f, t, RLC_FP_DIGS) == RLC_EQ);
bn_negs_low(t, t, 1, RLC_FP_DIGS);
r = RLC_SEL(r, 1 - k, dv_cmp_const(f, t, RLC_FP_DIGS) == RLC_EQ);
r = RLC_SEL(r, 1 - k, fp_is_zero(f));
r = RLC_SEL(r, 0, fp_is_zero(a));
} RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT)
} RLC_FINALLY {
Expand Down

0 comments on commit fde494f

Please sign in to comment.