summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorJ08nY2018-01-18 17:00:41 +0100
committerJ08nY2018-01-18 17:00:41 +0100
commitf940f80a2cb69ffcd1f0d608cbb1b0f06e0854d6 (patch)
treea088defb41617f21d1cc729c3c71fd378f1b7f10 /src/math
parent8033902b02a82ce2521d4d029b6927e190866c95 (diff)
downloadecgen-f940f80a2cb69ffcd1f0d608cbb1b0f06e0854d6.tar.gz
ecgen-f940f80a2cb69ffcd1f0d608cbb1b0f06e0854d6.tar.zst
ecgen-f940f80a2cb69ffcd1f0d608cbb1b0f06e0854d6.zip
Add utilities to create random curve twists.
Diffstat (limited to 'src/math')
-rw-r--r--src/math/twists.c18
-rw-r--r--src/math/twists.h17
2 files changed, 35 insertions, 0 deletions
diff --git a/src/math/twists.c b/src/math/twists.c
new file mode 100644
index 0000000..78481f4
--- /dev/null
+++ b/src/math/twists.c
@@ -0,0 +1,18 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017-2018 J08nY
+ */
+#include "twists.h"
+
+void curve_twist_rand(curve_t *to, const curve_t *of) {
+ to->field = gcopy(of->field);
+ GEN v = elltwist(of->curve, NULL);
+ to->curve = ellinit(v, to->field, -1);
+ if (typ(of->field) == t_INT) {
+ to->a = ell_get_a4(to->curve);
+ to->b = ell_get_a6(to->curve);
+ } else if (typ(of->field) == t_FFELT) {
+ to->a = ell_get_a2(to->curve);
+ to->b = ell_get_a6(to->curve);
+ }
+} \ No newline at end of file
diff --git a/src/math/twists.h b/src/math/twists.h
new file mode 100644
index 0000000..3249047
--- /dev/null
+++ b/src/math/twists.h
@@ -0,0 +1,17 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017-2018 J08nY
+ */
+#ifndef ECGEN_TWIST_H
+#define ECGEN_TWIST_H
+
+#include "misc/types.h"
+
+/**
+ * @brief Twists the <code>of</code> curve randomly.
+ * @param to The result of the twist.
+ * @param of The curve to be twisted.
+ */
+void curve_twist_rand(curve_t *to, const curve_t *of);
+
+#endif // ECGEN_TWIST_H