aboutsummaryrefslogtreecommitdiff
path: root/src/gen/field.h
blob: e02c0b409baa86471c6723de67207f561fb3fbf1 (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
79
80
/*
 * ecgen, tool for generating Elliptic curve domain parameters
 * Copyright (C) 2017 J08nY
 */
/**
 * @file field.h
 */
#ifndef ECGEN_FIELD_H
#define ECGEN_FIELD_H

#include "misc/types.h"

/**
 * GENERATOR(gen_f)
 * Creates a random field.
 * Always succeeds.
 *
 * @param curve A curve_t being generated
 * @param cfg An application config
 * @param args unused
 * @return state diff
 */
GENERATOR(field_gen_random);

/**
 * GENERATOR(gen_f)
 * 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 A curve_t being generated
 * @param cfg An application config
 * @param args unused
 * @return state diff
 */
GENERATOR(field_gen_input);

/**
 * GENERATOR(gen_f)
 * Creates the field by reading it once.
 *
 * @param curve A curve_t being generated
 * @param cfg An application config
 * @param args unused
 * @return state diff
 */
GENERATOR(field_gen_once);

/**
 * 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);

/**
 * Transforms an integer into a field element.
 *
 * @param field the field to work in
 * @param in the integer to transform
 * @return a field element, t_INTMOD or t_FFELT
 */
GEN field_ielement(GEN field, GEN in);

#endif  // ECGEN_FIELD_H