Commit 8abc24f4 authored by Michael Hamburg's avatar Michael Hamburg

montgomery aux step is defined; probably doesnt work

parent a412e7b5
......@@ -318,6 +318,30 @@ convert_tw_niels_to_tw_extensible (
field_copy ( &e->u, &e->y );
}
void
montgomery_aux_step (
struct montgomery_aux_t* a
) {
field_add ( &a->xs, &a->xa, &a->za );
field_subx ( &a->zs, &a->xa, &a->za );
field_add ( &a->xa, &a->xd, &a->zd );
field_subx ( &a->za, &a->xd, &a->zd );
field_mul ( &a->xd, &a->xa, &a->zs );
field_mul ( &a->zd, &a->xs, &a->za );
field_add ( &a->xs, &a->xd, &a->zd );
field_subx ( &a->zd, &a->zd, &a->xd );
field_mul ( &a->zs, &a->zd, &a->s0 );
field_sqr ( &a->zd, &a->xa ); // zd = AA
field_sqr ( &a->xa, &a->za ); // xa = BB
field_subx ( &a->za, &a->zd, &a->xa ); // za = E
field_mul ( &a->xd, &a->xa, &a->zd ); // xd final
field_mulw_scc_wr ( &a->zd, &a->xa, 1-EDWARDS_D );
field_add ( &a->xa, &a->za, &a->zd ); // BB + (1-d)*E
field_mul ( &a->zd, &a->xa, &a->za ); // zd final
field_sqr ( &a->xa, &a->xs );
field_sqr ( &a->za, &a->zs );
}
void
montgomery_step (
struct montgomery_t* a
......@@ -438,7 +462,6 @@ decaf_serialize_extensible (
struct field_t* b,
const struct extensible_t* a
) {
/* FIXME: IF32...? */
struct field_t L0, L1, L2, L3;
field_mulw_scc ( &L2, &a->y, EDWARDS_D ); // L2 = d*y
field_mul ( &L3, &L2, &a->t ); // L3 = d*y*t_
......@@ -466,7 +489,6 @@ decaf_serialize_tw_extensible (
struct field_t* b,
const struct tw_extensible_t* a
) {
/* FIXME: IF32...? */
struct field_t L0, L1, L2, L3;
field_mulw_scc ( &L2, &a->y, 1-EDWARDS_D ); // L2 = (1-d)*y
field_mul ( &L3, &L2, &a->t ); // L3 = (1-d)*y*t_
......
......@@ -38,6 +38,13 @@ struct montgomery_t {
struct field_t z0, xd, zd, xa, za;
};
/**
* Montgomery buffer, augmented version.
*/
struct montgomery_aux_t {
struct field_t s0, xd, zd, xa, za, xs, zs;
};
/**
* Extensible coordinates for Edwards curves, suitable for
* accumulators.
......@@ -270,6 +277,11 @@ montgomery_step (
struct montgomery_t* a
);
void
montgomery_aux_step (
struct montgomery_aux_t* a
);
void
deserialize_montgomery (
struct montgomery_t* a,
......
......@@ -86,6 +86,7 @@ int main(int argc, char **argv) {
struct tw_pniels_t pniels;
struct affine_t affine;
struct montgomery_t mb;
struct montgomery_aux_t mba;
struct field_t a,b,c,d;
......@@ -312,6 +313,14 @@ int main(int argc, char **argv) {
}
when = now() - when;
printf("monty step: %5.1fns\n", when * 1e9 / i);
memset(&mba,0,sizeof(mba));
when = now();
for (i=0; i<nbase*100; i++) {
montgomery_aux_step(&mba);
}
when = now() - when;
printf("monty aux: %5.1fns\n", when * 1e9 / i);
when = now();
for (i=0; i<nbase/10; i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment