From cfdddb2a57ad77f485eb4be1a52efe5ffe19a220 Mon Sep 17 00:00:00 2001 From: J08nY Date: Fri, 19 Jan 2018 23:34:17 +0100 Subject: Compute twist order, as it is obviously known. --- src/math/twists.c | 11 ++++++++++- src/math/twists.h | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/math') diff --git a/src/math/twists.c b/src/math/twists.c index 3f1296d..043594f 100644 --- a/src/math/twists.c +++ b/src/math/twists.c @@ -13,16 +13,25 @@ void twist_rand_to(curve_t *to, const curve_t *of) { if (typ(of->field) == t_INT) { to->a = ell_get_a4(to->curve); to->b = ell_get_a6(to->curve); + if (of->order != NULL) { + GEN q = addis(mulis(of->field, 2), 2); + to->order = subii(q, of->order); + obj_insert_shallow(to->curve, 1, to->order); + } } else if (typ(of->field) == t_FFELT) { to->a = ell_get_a2(to->curve); to->b = ell_get_a6(to->curve); + if (of->order != NULL) { + GEN q = addis(mulis(int2n(degree(FF_mod(of->field))), 2), 2); + to->order = subii(q, of->order); + obj_insert_shallow(to->curve, 1, to->order); + } } } void twist_rand(curve_t *what) { twist_rand_to(what, what); seed_free(&what->seed); - what->order = NULL; points_free_deep(&what->points, what->npoints); points_free_deep(&what->generators, what->ngens); } \ No newline at end of file diff --git a/src/math/twists.h b/src/math/twists.h index dcbdb31..d68bb27 100644 --- a/src/math/twists.h +++ b/src/math/twists.h @@ -15,8 +15,8 @@ void twist_rand_to(curve_t *to, const curve_t *of); /** - * @brief - * @param what + * @brief Twists the what curve randomly, inplae. + * @param what The curve to be twisted, also the result. */ void twist_rand(curve_t *what); -- cgit v1.3.1