summaryrefslogtreecommitdiff
path: root/src/gp/invalid.gp
diff options
context:
space:
mode:
authorJ08nY2017-02-05 03:59:52 +0100
committerJ08nY2017-02-05 03:59:52 +0100
commit763fc80153c5e9287f1b0f0609b11fb4f50c90ab (patch)
tree5cd6e7acc4512cca65bcc16a74f3b63879b2d3bc /src/gp/invalid.gp
parent3d9bf583ccc5eea61c5f78f52d1e2073daee924c (diff)
downloadecgen-0.2.0.tar.gz
ecgen-0.2.0.tar.zst
ecgen-0.2.0.zip
ecgen v0.2: major rewrite0.2.0
Diffstat (limited to 'src/gp/invalid.gp')
-rw-r--r--src/gp/invalid.gp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/gp/invalid.gp b/src/gp/invalid.gp
new file mode 100644
index 0000000..4970014
--- /dev/null
+++ b/src/gp/invalid.gp
@@ -0,0 +1,59 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+
+/**
+ * Computes primes upto some upper bound.
+ *
+ * @param bound an upper bound on primes
+ * @return a vector of primes up to bound^2
+ */
+prime_upto(bound:int) = {
+ local(p:list, product:int, last:int, result:vec);
+ p = List();
+
+ bound = bound^2;
+ listput(p, 2);
+ product = 2;
+ last = 2;
+
+ while(product < bound,
+ last = nextprime(last + 1);
+ listput(p, last);
+ product = product * last;
+ );
+
+ result = list_to_vec(p);
+ listkill(p);
+ return(result);
+}
+
+/**
+ *
+ */
+invalid(coeffs:vec, field:pol, primes:vec, bits:int) = {
+ local(bs:vec, cs:vec, eq:vec, e:ell, b, n, c, o):int;
+ n = length(primes);
+ bs = vector(n);
+ eq = coeffs;
+ c = 0;
+
+ while(c < n,
+ b = random_int(bits):int;
+ eq[4] = b; /* Times field? */
+
+ iferr(e = ellinit(eq,field):ell, E, next());
+
+ o = ellsea(e):int;
+ for(i=1,n,
+ if((o % primes[i]) == 0 && bs[i] == 0,
+ bs[i] = b;
+ cs[i] = e;
+ c = c + 1;
+ );
+ );
+ );
+
+ return(cs);
+} \ No newline at end of file