Skip to content

Commit

Permalink
Fix type promotion bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Aug 21, 2023
1 parent d9056df commit 1fc483f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/fp/relic_fp_smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,18 @@ int fp_smb_divst(const fp_t a) {
g[RLC_FP_DIGS - 1] |= (dig_t)gs << (RLC_DIG - 1);
}

k = 1 - ((2*k) % 4);
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);

r = RLC_SEL(r, k, dv_cmp_const(f, t, RLC_FP_DIGS) == RLC_EQ);
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, k, dv_cmp_const(f, t, RLC_FP_DIGS) == RLC_EQ);
r = RLC_SEL(r, k, fp_is_zero(f));
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));
} RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT)
} RLC_FINALLY {
Expand Down Expand Up @@ -340,14 +340,14 @@ int fp_smb_jmpds(const fp_t a) {

j = (j + k) % 4;
j = (j + ((j & 1) ^ (RLC_SIGN(f[precision])))) % 4;
j = 1 - ((j + (j & 1)) % 4);
j = (j + (j & 1)) % 4;

fp_zero(t0);
t0[0] = 1;
r = RLC_SEL(r, j, dv_cmp_const(f, t0, RLC_FP_DIGS) == RLC_EQ);
r = RLC_SEL(r, 1 - j, dv_cmp_const(f, t0, RLC_FP_DIGS) == RLC_EQ);
bn_negs_low(t0, t0, 1, RLC_FP_DIGS);
r = RLC_SEL(r, j, dv_cmp_const(f, t0, RLC_FP_DIGS) == RLC_EQ);
r = RLC_SEL(r, j, fp_is_zero(f));
r = RLC_SEL(r, 1 - j, dv_cmp_const(f, t0, RLC_FP_DIGS) == RLC_EQ);
r = RLC_SEL(r, 1 - j, fp_is_zero(f));
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
Expand Down

0 comments on commit 1fc483f

Please sign in to comment.