Skip to content

Commit

Permalink
Tagging for release 0.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Feb 18, 2013
1 parent e42cced commit 0af67f8
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 18 deletions.
58 changes: 41 additions & 17 deletions src/eb/relic_eb_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,10 @@ void eb_tab(eb_t *t, eb_t p, int w) {
t[i]->norm = 1;
}

eb_copy(t[0], p);
#if defined(EB_MIXED)
eb_norm(t[0], t[0]);
eb_norm(t[0], p);
#else
eb_copy(t[0], p);
#endif

switch (w) {
Expand Down Expand Up @@ -313,6 +314,9 @@ void eb_tab(eb_t *t, eb_t p, int w) {
eb_add(t[2], t[3], p);
eb_frb(t[3], t[3]);

eb_frb(t[7], t[3]);
eb_sub(t[7], t[7], p);

if (u == 1) {
eb_neg(t[3], t[3]);
}
Expand All @@ -321,11 +325,6 @@ void eb_tab(eb_t *t, eb_t p, int w) {
eb_frb(t[4], t[2]);
eb_frb(t[4], t[4]);

#if defined(EB_MIXED) && defined(STRIP)
eb_norm(t[2], t[2]);
#endif
eb_sub(t[7], t[4], t[2]);

eb_neg(t[4], t[4]);
eb_sub(t[5], t[4], p);
eb_add(t[6], t[4], p);
Expand All @@ -347,6 +346,7 @@ void eb_tab(eb_t *t, eb_t p, int w) {
eb_add(t[14], t[14], p);

eb_frb(t[0], t[0]);
eb_frb(t[8], t[0]);
if (u == -1) {
eb_neg(t[0], t[0]);
}
Expand All @@ -358,22 +358,19 @@ void eb_tab(eb_t *t, eb_t p, int w) {
eb_sub(t[1], t[0], p);
eb_add(t[2], t[0], p);

#if defined(EB_MIXED) && defined(STRIP)
eb_norm(t[13], t[13]);
#endif
eb_add(t[15], t[0], t[13]);
eb_frb(t[15], t[8]);
if (u == -1) {
eb_neg(t[15], t[15]);
}
eb_sub(t[15], t[15], p);

eb_frb(t[0], t[13]);
eb_frb(t[0], t[0]);
eb_sub(t[5], t[0], p);
eb_add(t[6], t[0], p);

eb_neg(t[8], t[0]);
eb_add(t[7], t[8], t[13]);
#if defined(EB_MIXED) && defined(STRIP)
eb_norm(t[14], t[14]);
#endif
eb_add(t[8], t[8], t[14]);
eb_sub(t[7], t[8], p);
eb_add(t[8], t[8], p);

eb_frb(t[0], t[0]);
if (u == -1) {
Expand Down Expand Up @@ -604,6 +601,33 @@ void eb_tab(eb_t *t, eb_t p, int w) {
*/
eb_mul_frb(t[_k], p, tnaf, len);
}

eb_frb(t[0], t[0]);
eb_frb(t[0], t[0]);
eb_sub(t[17], t[0], p);
eb_add(t[18], t[0], p);
eb_frb(t[0], t[0]);
if (u == 1) {
eb_neg(t[0], t[0]);
}
eb_sub(t[19], t[0], p);
eb_add(t[20], t[0], p);

eb_frb(t[0], t[19]);
eb_frb(t[0], t[0]);
eb_neg(t[0], t[0]);
eb_sub(t[1], t[0], p);
eb_add(t[2], t[0], p);

eb_frb(t[0], t[17]);
eb_frb(t[0], t[0]);
eb_frb(t[0], t[0]);
if (u == -1) {
eb_neg(t[0], t[0]);
}
eb_sub(t[3], t[0], p);


/*
signed char k1[] = {-1, 0, 1, 0, 0, -1, };
eb_mul_frb(t[1], p, k1, sizeof(k1));
Expand Down
76 changes: 75 additions & 1 deletion src/ep/relic_ep_mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void ep_mul_naf_imp(ep_t r, ep_t p, bn_t k) {
/* Compute the precomputation table. */
ep_tab(table, p, EP_WIDTH);

/* Compute the w-TNAF representation of k. */
/* Compute the w-NAF representation of k. */
bn_rec_naf(naf, &len, k, EP_WIDTH);

t = naf + len - 1;
Expand All @@ -186,7 +186,64 @@ static void ep_mul_naf_imp(ep_t r, ep_t p, bn_t k) {
}
/* Convert r to affine coordinates. */
ep_norm(r, r);
}
CATCH_ANY {
THROW(ERR_CAUGHT);
}
FINALLY {
/* Free the precomputation table. */
for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
ep_free(table[i]);
}
}
}

#endif /* EP_ORDIN || EP_SUPER */
#endif /* EP_MUL == LWNAF */

#if EP_MUL == LWREG || !defined(STRIP)

#if defined(EP_ORDIN) || defined(EP_SUPER)

static void ep_mul_reg_imp(ep_t r, ep_t p, bn_t k) {
int len, i, j, n;
signed char reg[FP_BITS + 1], *t;
ep_t table[1 << (EP_WIDTH - 2)];

for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
ep_null(table[i]);
}

TRY {
/* Prepare the precomputation table. */
for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
ep_new(table[i]);
}
/* Compute the precomputation table. */
ep_tab(table, p, EP_WIDTH);

/* Compute the w-NAF representation of k. */
bn_rec_reg(reg, &len, k, FP_BITS, EP_WIDTH);

t = reg + len - 1;

ep_set_infty(r);
for (i = len - 1; i >= 0; i--, t--) {
for (j = 0; j < EP_WIDTH - 1; j++) {
ep_dbl(r, r);
}

n = *t;
if (n > 0) {
ep_add(r, r, table[n / 2]);
}
if (n < 0) {
ep_sub(r, r, table[-n / 2]);
}
}

/* Convert r to affine coordinates. */
ep_norm(r, r);
}
CATCH_ANY {
THROW(ERR_CAUGHT);
Expand Down Expand Up @@ -380,6 +437,23 @@ void ep_mul_lwnaf(ep_t r, ep_t p, bn_t k) {

#endif

#if EP_MUL == LWREG || !defined(STRIP)

void ep_mul_lwreg(ep_t r, ep_t p, bn_t k) {
#if defined(EP_KBLTZ)
if (ep_curve_is_kbltz()) {
ep_mul_glv_imp(r, p, k);
return;
}
#endif

#if defined(EP_ORDIN) || defined(EP_SUPER)
ep_mul_reg_imp(r, p, k);
#endif
}

#endif

void ep_mul_gen(ep_t r, bn_t k) {
#ifdef EP_PRECO
ep_mul_fix(r, ep_curve_get_tab(), k);
Expand Down

0 comments on commit 0af67f8

Please sign in to comment.