Skip to content

Commit

Permalink
Handle more cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Dec 29, 2024
1 parent 0d1ec62 commit 0133791
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/bn/relic_bn_rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,13 +825,12 @@ void bn_rec_glv(bn_t k0, bn_t k1, const bn_t k, const bn_t n, const bn_st *v1,
size_t bits = bn_bits(n), d = bits >> RLC_DIG_LOG, b = bits % RLC_DIG;
dig_t r, b1[2 * RLC_FP_DIGS + 1] = { 0 }, b2[2 * RLC_FP_DIGS + 1] = { 0 };
dig_t _k[2 * RLC_FP_DIGS + 1] = { 0 }, _v[2 * RLC_FP_DIGS] = { 0 };
bn_t t, u;
bn_t t;

bn_null(t);

RLC_TRY {
bn_new(t);
bn_new(u);

bn_abs(t, k);

Expand Down Expand Up @@ -859,56 +858,52 @@ void bn_rec_glv(bn_t k0, bn_t k1, const bn_t k, const bn_t n, const bn_st *v1,
dv_zero(_v, 2 * RLC_FP_DIGS);
dv_copy(_v, v1[1].dp, v1[1].used);
bn_muln_low(k0->dp, b1, _v, RLC_FP_DIGS);
k0->used = 2 * RLC_FP_DIGS;
k0->dp[2 * RLC_FP_DIGS] = 0;
k0->sign = v1[0].sign ^ v1[1].sign;
bn_trim(k0);

/* k1 = b2 * v21 */
dv_zero(_v, 2 * RLC_FP_DIGS);
dv_copy(_v, v2[1].dp, v2[1].used);
bn_muln_low(k1->dp, b2, _v, RLC_FP_DIGS);
k1->used = 2 * RLC_FP_DIGS;
k1->dp[2 * RLC_FP_DIGS] = 0;
k1->sign = v2[0].sign ^ v2[1].sign;
bn_trim(k1);

k0->sign ^= 1;
bn_negs_low(k0->dp, k0->dp, k0->sign, 2 * RLC_FP_DIGS);
bn_addn_low(k0->dp, k0->dp, _k, 2 * RLC_FP_DIGS);
k0->sign = k0->dp[2 * RLC_FP_DIGS - 1] & 1;
k0->used = 2 * RLC_FP_DIGS;
bn_trim(k0);
k1->sign ^= 1;
k1->used = 2 * RLC_FP_DIGS;
bn_negs_low(k1->dp, k1->dp, k1->sign, 2 * RLC_FP_DIGS);
bn_addn_low(k0->dp, k0->dp, k1->dp, 2 * RLC_FP_DIGS);
k0->sign = k0->dp[2 * RLC_FP_DIGS - 1] & 1;
bn_negs_low(k0->dp, k0->dp, k0->sign, 2 * RLC_FP_DIGS);
/* k0 = k - k0 - k1. */
bn_negs_low(k0->dp, k0->dp, k0->sign ^ 1, 2 * RLC_FP_DIGS + 1);
bn_negs_low(k1->dp, k1->dp, k1->sign ^ 1, 2 * RLC_FP_DIGS + 1);
bn_addn_low(k0->dp, k0->dp, k1->dp, 2 * RLC_FP_DIGS + 1);
bn_addn_low(k0->dp, k0->dp, _k, 2 * RLC_FP_DIGS + 1);
k0->sign = k0->dp[2 * RLC_FP_DIGS] & 1;
bn_negs_low(k0->dp, k0->dp, k0->sign, 2 * RLC_FP_DIGS + 1);
k0->used = 2 * RLC_FP_DIGS;
bn_trim(k0);

/* k1 = 0 - b1 * v21 - b2 * v21. */
dv_zero(_v, 2 * RLC_FP_DIGS);
dv_copy(_v, v1[2].dp, v1[2].used);
bn_muln_low(k1->dp, b1, _v, RLC_FP_DIGS);
k1->used = 2 * RLC_FP_DIGS;
k1->dp[2 * RLC_FP_DIGS] = 0;
k1->sign = v1[0].sign ^ v1[2].sign;
bn_trim(k1);

dv_zero(_v, 2 * RLC_FP_DIGS);
dv_copy(_v, v2[2].dp, v2[2].used);
bn_muln_low(t->dp, b2, _v, RLC_FP_DIGS);
t->used = 2 * RLC_FP_DIGS;
t->dp[2 * RLC_FP_DIGS] = 0;
t->sign = v2[0].sign ^ v2[2].sign;
bn_trim(t);

bn_add(k1, k1, t);
k1->sign ^= 1;
bn_negs_low(t->dp, t->dp, t->sign ^ 1, 2 * RLC_FP_DIGS + 1);
bn_negs_low(k1->dp, k1->dp, k1->sign ^ 1, 2 * RLC_FP_DIGS + 1);
bn_addn_low(k1->dp, k1->dp, t->dp, 2 * RLC_FP_DIGS + 1);
k1->sign = k1->dp[2 * RLC_FP_DIGS] & 1;
bn_negs_low(k1->dp, k1->dp, k1->sign, 2 * RLC_FP_DIGS + 1);
k1->used = 2 * RLC_FP_DIGS;
bn_trim(k1);
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(t);
bn_free(u);
}
}

Expand Down

0 comments on commit 0133791

Please sign in to comment.