summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2018-01-19 23:34:17 +0100
committerJ08nY2018-01-19 23:34:17 +0100
commitcfdddb2a57ad77f485eb4be1a52efe5ffe19a220 (patch)
tree896cb662429b87781b97b49ea88bf3004bd77d61
parentcde38f8c4ed443af6d0074e3e5294029246c2774 (diff)
downloadecgen-cfdddb2a57ad77f485eb4be1a52efe5ffe19a220.tar.gz
ecgen-cfdddb2a57ad77f485eb4be1a52efe5ffe19a220.tar.zst
ecgen-cfdddb2a57ad77f485eb4be1a52efe5ffe19a220.zip
-rw-r--r--src/math/twists.c11
-rw-r--r--src/math/twists.h4
-rw-r--r--test/src/math/test_twists.c9
3 files changed, 18 insertions, 6 deletions
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 <code>what</code> curve randomly, inplae.
+ * @param what The curve to be twisted, also the result.
*/
void twist_rand(curve_t *what);
diff --git a/test/src/math/test_twists.c b/test/src/math/test_twists.c
index 8a869bf..cc39369 100644
--- a/test/src/math/test_twists.c
+++ b/test/src/math/test_twists.c
@@ -4,7 +4,6 @@
*/
#include <criterion/criterion.h>
#include "gen/field.h"
-#include "gen/point.h"
#include "math/poly.h"
#include "math/twists.h"
#include "test/default.h"
@@ -19,7 +18,8 @@ Test(twists, test_twist_rand_to_fp) {
curve_t curve = {.a = a,
.b = b,
.field = stoi(23),
- .curve = ellinit(mkvec2(a, b), stoi(23), -1)};
+ .curve = ellinit(mkvec2(a, b), stoi(23), -1),
+ .order = stoi(24)};
curve_t to = {0};
twist_rand_to(&to, &curve);
@@ -27,6 +27,7 @@ Test(twists, test_twist_rand_to_fp) {
cr_assert_not_null(to.b, );
cr_assert_not_null(to.field, );
cr_assert_not_null(to.curve, );
+ cr_assert(equalii(to.order, stoi(24)), );
}
Test(twists, test_twist_rand_to_f2m) {
@@ -38,7 +39,8 @@ Test(twists, test_twist_rand_to_f2m) {
.a = a,
.b = b,
.field = field,
- .curve = ellinit(mkvecn(5, gen_1, a, gen_0, gen_0, b), NULL, -1)};
+ .curve = ellinit(mkvecn(5, gen_1, a, gen_0, gen_0, b), NULL, -1),
+ .order = stoi(8140)};
curve_t to = {0};
twist_rand_to(&to, &curve);
@@ -46,4 +48,5 @@ Test(twists, test_twist_rand_to_f2m) {
cr_assert_not_null(to.b, );
cr_assert_not_null(to.field, );
cr_assert_not_null(to.curve, );
+ cr_assert(equalii(to.order, stoi(8246)), );
} \ No newline at end of file