summaryrefslogtreecommitdiff
path: root/src/math/field.h
blob: 66c8920507ebb14625eb746426065d2359c98865 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * ecgen, tool for generating Elliptic curve domain parameters
 * Copyright (C) 2017 J08nY
 */
/**
 * @file field.h
 */
#ifndef ECGEN_FIELD_H
#define ECGEN_FIELD_H

#include "io/cli.h"
#include "types.h"

/**
 * GENERATOR(gen_t)
 * Creates a random field.
 * Always succeeds.
 *
 * @param curve
 * @param config
 * @param args unused
 * @return state diff
 */
int field_random(curve_t *curve, config_t *cfg, arg_t *args);

/**
 * GENERATOR(gen_t)
 * Creates a field by reading:
 *  - a prime number in the prime field case
 *  - three short exponents of the reduction polynomial in the binary case
 *
 * @param curve
 * @param config
 * @param args unused
 * @return state diff
 */
int field_input(curve_t *curve, config_t *cfg, arg_t *args);

/**
 *
 * @param curve
 * @param cfg
 * @param args
 * @return
 */
int field_once(curve_t *curve, config_t *cfg, arg_t *args);

/**
 * 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 vector of the field characteristic(p).
 *
 * @param field
 * @return field representation
 */
GEN field_params(GEN field);

/**
 * Transforms a field element to an integer.
 * Uses the polynomial basis of the underlying field in case of a binary field.
 *
 * @param element t_INTMOD, t_INT, t_FFELT to transform
 * @return t_INT
 */
GEN field_elementi(GEN element);

/**
 *
 * @param field
 * @param in
 * @return
 */
GEN field_ielement(GEN field, GEN in);

#endif  // ECGEN_FIELD_H