aboutsummaryrefslogtreecommitdiff
path: root/src/math/order.c
diff options
context:
space:
mode:
authorJ08nY2017-05-23 19:47:10 +0200
committerJ08nY2017-05-23 19:47:10 +0200
commitca21d236ea409fa40f4bda693777054add7ef73f (patch)
tree2f48596d5a28c631be159bed5637e3350f187f4b /src/math/order.c
parent3f9e42b055c305f05da3f57b2501600488d377a7 (diff)
downloadecgen-ca21d236ea409fa40f4bda693777054add7ef73f.tar.gz
ecgen-ca21d236ea409fa40f4bda693777054add7ef73f.tar.zst
ecgen-ca21d236ea409fa40f4bda693777054add7ef73f.zip
Diffstat (limited to 'src/math/order.c')
-rw-r--r--src/math/order.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/math/order.c b/src/math/order.c
index 4c8c728..347015c 100644
--- a/src/math/order.c
+++ b/src/math/order.c
@@ -4,6 +4,39 @@
*/
#include "order.h"
+GEN order_factors(curve_t *curve, const config_t *cfg) {
+ if (cfg->prime) {
+ return gtovec(curve->order);
+ } else {
+ GEN factors = Z_factor(curve->order);
+ return gel(factors, 1);
+ }
+}
+
+GEN order_groups(curve_t *curve, const config_t *cfg, GEN factors) {
+ long nprimes = glength(factors);
+ if (cfg->prime) {
+ return gtovec(curve->order);
+ } else {
+ GEN amount = int2n(nprimes);
+ GEN groups = gtovec0(gen_0, itos(amount) - 1);
+
+ for (size_t count = 1; count < (size_t)(1 << nprimes); ++count) {
+ GEN result = gen_1;
+ for (long bit = 0; bit < nprimes; ++bit) {
+ size_t mask = (size_t)(1 << bit);
+ if (count & mask) {
+ result = mulii(result, gel(factors, bit + 1));
+ }
+ }
+ gel(groups, count) = result;
+ }
+ // TODO: sort this, as it is not necessarily sorted, in fact most likely
+ // not
+ return groups;
+ }
+}
+
GENERATOR(order_gen_any) {
GEN ord = ellff_get_card(curve->curve);
if (isclone(ord)) {