summaryrefslogtreecommitdiff
path: root/src/gp/field.gp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gp/field.gp')
-rw-r--r--src/gp/field.gp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/gp/field.gp b/src/gp/field.gp
new file mode 100644
index 0000000..c428abd
--- /dev/null
+++ b/src/gp/field.gp
@@ -0,0 +1,33 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+
+/**
+ * Extract a field representation from a field.
+ * - char(field) == 2:
+ * returns the vector of powers of middle coefficients of the reduction polynomial.
+ * - char(field) != 2:
+ * returns the field characteristic(p).
+ *
+ * @return field representation
+ */
+field_params(field:gen) = {
+ if(type(field) == "t_INT",
+ return([field]);
+ );
+
+ local(out:vec, j:int, c:int);
+ out = vector(3);
+
+ j = 1;
+ for(i=2, length(field.mod) - 2,
+ c = polcoeff(field.mod, i):int;
+ if(c != 0,
+ out[j] = i;
+ j++;
+ );
+ );
+
+ return(out);
+} \ No newline at end of file