Skip to content

Commit

Permalink
Change API for GLV-SAC recoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Aug 14, 2024
1 parent 2db28d5 commit 454d055
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion include/relic_bn.h
Original file line number Diff line number Diff line change
Expand Up @@ -1547,11 +1547,12 @@ void bn_rec_frb(bn_t *ki, int sub, const bn_t k, const bn_t x, const bn_t n,
* @param[out] b - the recoded subscalars.
* @param[in] len - the length in bytes of the recoding.
* @param[in] k - the subscalars to recode.
* @param[in] c - the splitting factor.
* @param[in] m - the number of subscalars to recode.
* @param[in] n - the bit length of the group order.
* @throw ERR_NO_BUFFER - if the buffer capacity is insufficient.
*/
void bn_rec_sac(int8_t *b, size_t *len, bn_t *k, size_t m, size_t n);
void bn_rec_sac(int8_t *b, size_t *len, bn_t *k, size_t c, size_t m, size_t n);

/**
* Computes the coefficients of the polynomial representing the Lagrange
Expand Down
4 changes: 2 additions & 2 deletions src/bn/relic_bn_rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,10 @@ void bn_rec_glv(bn_t k0, bn_t k1, const bn_t k, const bn_t n, const bn_t *v1,
}
}

void bn_rec_sac(int8_t *b, size_t *len, bn_t *k, size_t m, size_t n) {
void bn_rec_sac(int8_t *b, size_t *len, bn_t *k, size_t c, size_t m, size_t n) {
/* Assume k0 is the sign-aligner. */
bn_t *t = RLC_ALLOCA(bn_t, m);
size_t l = RLC_CEIL(n, m) + 1;
size_t l = RLC_CEIL(n, c * m) + 1;
int8_t bji;

if (t == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/epx/relic_ep2_mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static void ep2_mul_reg_gls(ep2_t r, const ep2_t p, const bn_t k) {
}

l = RLC_FP_BITS;
bn_rec_sac(sac, &l, _k, 4, bn_bits(n));
bn_rec_sac(sac, &l, _k, 1, 4, bn_bits(n));

#if defined(EP_MIXED)
ep2_norm_sim(t + 1, t + 1, (1 << 3) - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/epx/relic_ep3_mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void ep3_mul_gls_imp(ep3_t r, const ep3_t p, const bn_t k) {
}

l = RLC_FP_BITS + 1;
bn_rec_sac(sac, &l, _k, 6, bn_bits(n));
bn_rec_sac(sac, &l, _k, 1, 6, bn_bits(n));

#if defined(EP_MIXED)
ep3_norm_sim(t + 1, t + 1, (1 << 5) - 1);
Expand Down Expand Up @@ -245,7 +245,7 @@ static void ep3_mul_reg_gls(ep3_t r, const ep3_t p, const bn_t k) {
}

l = RLC_FP_BITS + 1;
bn_rec_sac(sac, &l, _k, 6, bn_bits(n));
bn_rec_sac(sac, &l, _k, 1, 6, bn_bits(n));

#if defined(EP_MIXED)
ep3_norm_sim(t + 1, t + 1, (1 << 5) - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/epx/relic_ep4_mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static void ep4_mul_reg_gls(ep4_t r, const ep4_t p, const bn_t k) {
ep4_add(t[i][j], t[i][j ^ (1 << (l - 1))], q[l + i * m / c]);
}
l = RLC_FP_BITS + 1;
bn_rec_sac(sac[i], &l, _k + i * m / c, m / c, bn_bits(n));
bn_rec_sac(sac[i], &l, _k + i * m / c, c, m / c, bn_bits(n));
}

#if defined(EP_MIXED)
Expand Down Expand Up @@ -293,7 +293,7 @@ static void ep4_mul_reg_gls(ep4_t r, const ep4_t p, const bn_t k) {
}

/* Convert r to affine coordinates. */
ep4_norm(r, r);
//ep4_norm(r, r);
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
Expand Down
2 changes: 1 addition & 1 deletion src/epx/relic_ep8_mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void ep8_mul_reg_gls(ep8_t r, const ep8_t p, const bn_t k) {
ep8_add(t[i][j], t[i][j ^ (1 << (l - 1))], q[l + i * m / c]);
}
l = RLC_FP_BITS + 1;
bn_rec_sac(sac[i], &l, _k + i * m / c, m / c, bn_bits(n));
bn_rec_sac(sac[i], &l, _k + i * m / c, c, m / c, bn_bits(n));
}

#if defined(EP_MIXED)
Expand Down
4 changes: 2 additions & 2 deletions src/pc/relic_pc_exp.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static void gt_exp_gls_sac(gt_t c, const gt_t a, const bn_t b, size_t d,
gt_mul(t[i * s + j], t[i * s + (j ^ (1 << (l - 1)))], q[l + i * f / d]);
}
l = RLC_FP_BITS;
bn_rec_sac(sac + i * f * RLC_FP_BITS, &l, _b + i * f / d, f / d, bn_bits(n));
bn_rec_sac(sac + i * f * RLC_FP_BITS, &l, _b + i * f / d, d, f / d, bn_bits(n));
}

gt_set_unity(c);
Expand Down Expand Up @@ -453,7 +453,7 @@ static void gt_exp_reg_sac(gt_t c, const gt_t a, const bn_t b, size_t d,
gt_mul(t[i * s + j], t[i * s + (j ^ (1 << (l - 1)))], q[l + i * f / d]);
}
l = RLC_FP_BITS;
bn_rec_sac(sac + i * f * RLC_FP_BITS, &l, _b + i * f / d, f / d, bn_bits(n));
bn_rec_sac(sac + i * f * RLC_FP_BITS, &l, _b + i * f / d, d, f / d, bn_bits(n));
}

gt_set_unity(c);
Expand Down
2 changes: 1 addition & 1 deletion test/test_bn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,7 @@ static int recoding(void) {
bn_rand_mod(a, b);
bn_rec_glv(b, c, a, b, (const bn_t *)v1, (const bn_t *)v2);
ep_curve_get_ord(v2[0]);
bn_rec_sac(ptr, &l, v1, 2, bn_bits(v2[0]));
bn_rec_sac(ptr, &l, v1, 1, 2, bn_bits(v2[0]));
if (bn_is_even(b)) {
bn_add_dig(b, b, 1);
}
Expand Down

0 comments on commit 454d055

Please sign in to comment.