diff --git a/include/decaf_255.h b/include/decaf_255.h index 3ef4c88..f01f1b7 100644 --- a/include/decaf_255.h +++ b/include/decaf_255.h @@ -486,7 +486,7 @@ decaf_bool_t decaf_255_point_valid ( * @param [out] q The point to torque. * @param [in] p The point to torque. */ -void decaf_255_point_debugging_2torque ( +void decaf_255_point_debugging_torque ( decaf_255_point_t q, const decaf_255_point_t p ) API_VIS NONNULL2 NOINLINE; diff --git a/include/decaf_255.hxx b/include/decaf_255.hxx index 2613130..23ea568 100644 --- a/include/decaf_255.hxx +++ b/include/decaf_255.hxx @@ -580,7 +580,7 @@ public: } inline Point& debugging_torque_in_place() { - decaf_255_point_debugging_2torque(p,p); + decaf_255_point_debugging_torque(p,p); return *this; } diff --git a/include/decaf_448.h b/include/decaf_448.h index b9143a8..45deff8 100644 --- a/include/decaf_448.h +++ b/include/decaf_448.h @@ -486,7 +486,7 @@ decaf_bool_t decaf_448_point_valid ( * @param [out] q The point to torque. * @param [in] p The point to torque. */ -void decaf_448_point_debugging_2torque ( +void decaf_448_point_debugging_torque ( decaf_448_point_t q, const decaf_448_point_t p ) API_VIS NONNULL2 NOINLINE; diff --git a/include/decaf_448.hxx b/include/decaf_448.hxx index 4fc7008..1b239ed 100644 --- a/include/decaf_448.hxx +++ b/include/decaf_448.hxx @@ -580,7 +580,7 @@ public: } inline Point& debugging_torque_in_place() { - decaf_448_point_debugging_2torque(p,p); + decaf_448_point_debugging_torque(p,p); return *this; } diff --git a/src/decaf.c b/src/decaf.c index 068ced1..d5c9e6e 100644 --- a/src/decaf.c +++ b/src/decaf.c @@ -891,7 +891,7 @@ decaf_448_invert_elligator_nonuniform ( return succ; } -void decaf_448_point_debugging_2torque ( +void decaf_448_point_debugging_torque ( decaf_448_point_t q, const decaf_448_point_t p ) { diff --git a/src/decaf_fast.c b/src/decaf_fast.c index ea85bf6..d1b6a01 100644 --- a/src/decaf_fast.c +++ b/src/decaf_fast.c @@ -481,7 +481,8 @@ static void deisogenize ( gf_s *__restrict__ minus_t_over_s, const point_t p, decaf_bool_t toggle_hibit_s, - decaf_bool_t toggle_hibit_t_over_s + decaf_bool_t toggle_hibit_t_over_s, + decaf_bool_t toggle_rotation ) { gf c, d, x, t; gf_s *b = s, *a = minus_t_over_s; @@ -514,7 +515,7 @@ static void deisogenize ( * Pink bike shed: frob = zx * 1/tz */ gf_mul ( a, b, c ); /* this is the case for PinkBikeShed */ - cond_sel ( a, a, SQRT_ONE_MINUS_D, rotate ); + cond_sel ( a, a, SQRT_ONE_MINUS_D, rotate^toggle_rotation ); gf_sub ( e, ZERO, x ); cond_sel ( x, p->y, e, rotate ); } @@ -534,7 +535,7 @@ static void deisogenize ( void API_NS(point_encode)( unsigned char ser[SER_BYTES], const point_t p ) { gf s, mtos; - deisogenize(s,mtos,p,0,0); + deisogenize(s,mtos,p,0,0,0); gf_encode ( ser, s ); } @@ -1165,7 +1166,7 @@ uint16_t API_NS(point_from_hash_nonuniform) ( assert(API_NS(point_valid)(p)); - return (~square & 1) | (sgn_t_over_s & 2) | (sgn_r0 & 4) | (over & 8); + return (~square & 1) | (sgn_t_over_s & 2) | (sgn_r0 & 4) | (over & 16); } decaf_bool_t @@ -1176,9 +1177,10 @@ API_NS(invert_elligator_nonuniform) ( ) { decaf_bool_t sgn_s = -(hint & 1), sgn_t_over_s = -(hint>>1 & 1), - sgn_r0 = -(hint>>2 & 1); + sgn_r0 = -(hint>>2 & 1), + sgn_ed_T = -(hint>>3 & 1); gf a, b, c, d; - deisogenize(a,c,p,sgn_s,sgn_t_over_s); + deisogenize(a,c,p,sgn_s,sgn_t_over_s,sgn_ed_T); /* ok, a = s; c = -t/s */ gf_mul(b,c,a); @@ -1254,14 +1256,23 @@ decaf_bool_t API_NS(point_valid) ( return out; } -void API_NS(point_debugging_2torque) ( +void API_NS(point_debugging_torque) ( point_t q, const point_t p ) { +#if 0 gf_sub(q->x,ZERO,p->x); gf_sub(q->y,ZERO,p->y); gf_cpy(q->z,p->z); gf_cpy(q->t,p->t); +#else + gf tmp; + gf_mul(tmp,p->x,SQRT_MINUS_ONE); + gf_mul(q->x,p->y,SQRT_MINUS_ONE); + gf_cpy(q->y,tmp); + gf_cpy(q->z,p->z); + gf_sub(q->t,ZERO,p->t); +#endif } static void gf_batch_invert ( diff --git a/test/test_decaf.cxx b/test/test_decaf.cxx index 8779b24..bc83ea2 100644 --- a/test/test_decaf.cxx +++ b/test/test_decaf.cxx @@ -156,10 +156,10 @@ static void test_elligator() { decaf::SpongeRng rng(decaf::Block("test_elligator")); Test test("Elligator"); - for (int i=0; i<16; i++) { + for (int i=0; i<32; i++) { decaf::SecureBuffer b1(Point::HASH_BYTES); Point p = Point::identity(); - if (i>=8) p.debugging_torque_in_place(); + for (int j=0; j