Skip to content

Commit

Permalink
Simplify and fix bound problems with symbol.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Feb 4, 2024
1 parent fde494f commit 66d3a67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/fp/relic_fp_inv.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ void fp_inv_jmpds(fp_t c, const fp_t a) {
dv_zero(v0, 2 * RLC_FP_DIGS);
dv_zero(v1, 2 * RLC_FP_DIGS);
dv_copy(f, fp_prime_get(), RLC_FP_DIGS);
dv_copy(p + 1, fp_prime_get(), RLC_FP_DIGS);
#if FP_RDC == MONTY
/* Convert a from Montgomery form. */
fp_copy(t, a);
Expand Down Expand Up @@ -704,9 +703,9 @@ void fp_inv_jmpds(fp_t c, const fp_t a) {
j = i % RLC_FP_DIGS;
if (j == 0) {
fp_addd_low(t, u0, u1);
fp_rdcn_low(p11, t);
fp_rdc(p11, t);
fp_addd_low(t, v0, v1);
fp_rdcn_low(p01, t);
fp_rdc(p01, t);
dv_zero(v0, 2 * RLC_FP_DIGS);
dv_zero(v1, 2 * RLC_FP_DIGS);
} else {
Expand Down Expand Up @@ -735,9 +734,9 @@ void fp_inv_jmpds(fp_t c, const fp_t a) {
dv_copy_cond(u1, t, 2 * RLC_FP_DIGS, RLC_SIGN(m[3]));

fp_addc_low(t, u0, u1);
fp_rdcn_low(p11, t);
fp_rdc(p11, t);
fp_addc_low(t, v0, v1);
fp_rdcn_low(p01, t);
fp_rdc(p01, t);
#if FP_RDC == MONTY
fp_mulm_low(pre, pre, core_get()->conv.dp);
#endif
Expand Down Expand Up @@ -776,7 +775,7 @@ void fp_inv_jmpds(fp_t c, const fp_t a) {
dv_copy_cond(v1, t, RLC_FP_DIGS + j + 1, RLC_SIGN(m[1]));

fp_addd_low(t, v0, v1);
fp_rdcn_low(p01, t);
fp_rdc(p01, t);
#else
(void)j;
fp_zero(p);
Expand All @@ -792,12 +791,13 @@ void fp_inv_jmpds(fp_t c, const fp_t a) {
dv_copy_cond(v1, t, 2 * RLC_FP_DIGS, RLC_SIGN(m[1]));

fp_addc_low(t, v0, v1);
fp_rdcn_low(p01, t);
fp_rdc(p01, t);
#endif

/* Negate based on sign of f at the end. */
fp_negm_low(t, p01);
dv_copy_cond(p01, t, RLC_FP_DIGS, f[RLC_FP_DIGS] >> (RLC_DIG - 1));

/* Multiply by (precomp * R^j) % p, one for each iteration of the loop,
* one for the constant, one more to be removed by reduction. */
fp_mul(c, p01, pre);
Expand Down
6 changes: 5 additions & 1 deletion src/fp/relic_fp_smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ int fp_smb_divst(const fp_t a) {
#endif

k = 0;
dv_copy(f, fp_prime_get(), RLC_FP_DIGS);
#if FP_RDC == MONTY
/* Convert a from Montgomery form. */
dv_zero(t, 2 * RLC_FP_DIGS);
Expand All @@ -205,7 +206,10 @@ int fp_smb_divst(const fp_t a) {
#else
fp_copy(g, a);
#endif
dv_copy(f, fp_prime_get(), RLC_FP_DIGS);
r = dv_cmp(g, f, RLC_FP_DIGS);
fp_subn_low(t, g, f);
dv_copy_cond(g, t, RLC_FP_DIGS, r != RLC_LT);

fs = gs = RLC_POS;

for (int i = 0; i < d; i++) {
Expand Down

0 comments on commit 66d3a67

Please sign in to comment.