aboutsummaryrefslogtreecommitdiff
path: root/src/math/order.c
blob: 7e7eeda6e08ebf8d10130d0cf754cb9e5cfcac75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * ecgen, tool for generating Elliptic curve domain parameters
 * Copyright (C) 2017 J08nY
 */
#include "order.h"

int order_init(curve_t *curve, config_t *cfg, arg_t *args) {
	curve->order = ellff_get_card(curve->curve);
	return 1;
}

int order_smallfact(curve_t *curve, config_t *cfg, arg_t *args) {
	if (!args) {
		fprintf(stderr, "No args to an arged function. points_random");
		return INT_MIN;
	}
	pari_ulong smallfact = *(pari_ulong *)args->args;
	pari_sp ltop = avma;
	curve->order = ellsea(curve->curve, smallfact);
	if (gequal0(curve->order)) {
		avma = ltop;
		return -4;
	} else {
		return 1;
	}
}

int order_prime(curve_t *curve, config_t *cfg, arg_t *args) {
	pari_sp ltop = avma;
	curve->order = ellsea(curve->curve, 1);
	if (gequal0(curve->order) || !(isprime(curve->order))) {
		avma = ltop;
		return -4;
	} else {
		return 1;
	}
}