-
Notifications
You must be signed in to change notification settings - Fork 0
/
fp2e.h
205 lines (166 loc) · 4.81 KB
/
fp2e.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* File: dclxvi-20130329/fp2e.h
* Author: Ruben Niederhagen, Peter Schwabe
* Public Domain
*/
#ifndef FP2E_H
#define FP2E_H
#include "fpe.h"
#include "mydouble.h"
#include "scalar.h"
#include <stdio.h>
// Elements from F_{p^2}= F_p[X] / (x^2 - alpha)F_p[X] are represented as aX + b
typedef struct fp2e_struct {
// Arrangement in memory: (b0, a0, b1, a1, ... b11,a11)
mydouble v[24];
} __attribute__((aligned(16))) fp2e_struct_t;
typedef fp2e_struct_t fp2e_t[1];
void fp2e_to_2fpe(fpe_t ropa, fpe_t ropb, const fp2e_t op);
void _2fpe_to_fp2e(fp2e_t rop, const fpe_t opa, const fpe_t opb);
#ifdef QHASM
#define fp2e_short_coeffred fp2e_short_coeffred_qhasm
#else
#define fp2e_short_coeffred fp2e_short_coeffred_c
#endif
void fp2e_short_coeffred(fp2e_t rop);
// Set fp2e_t rop to given value:
void fp2e_set(fp2e_t rop, const fp2e_t op);
/* Communicate the fact that the fp2e is reduced (and that we don't know anything more about it) */
void fp2e_isreduced(fp2e_t rop);
// Set fp2e_t rop to given value contained in the subfield F_p:
void fp2e_set_fpe(fp2e_t rop, const fpe_t op);
// Set rop to one
void fp2e_setone(fp2e_t rop);
// Set rop to zero
void fp2e_setzero(fp2e_t rop);
// Compare for equality:
int fp2e_iseq(const fp2e_t op1, const fp2e_t op2);
int fp2e_isone(const fp2e_t op);
int fp2e_iszero(const fp2e_t op);
void fp2e_cmov(fp2e_t rop, const fp2e_t op, int c);
#ifdef QHASM
#define fp2e_double fp2e_double_qhasm
#else
#define fp2e_double fp2e_double_c
#endif
// Double an fp2e:
void fp2e_double(fp2e_t rop, const fp2e_t op);
// Double an fp2e:
#ifdef QHASM
#define fp2e_double2 fp2e_double2_qhasm
#else
#define fp2e_double2 fp2e_double2_c
#endif
void fp2e_double2(fp2e_t rop);
#ifdef QHASM
#define fp2e_triple fp2e_triple_qhasm
#else
#define fp2e_triple fp2e_triple_c
#endif
// Triple an fp2e:
void fp2e_triple(fp2e_t rop, const fp2e_t op);
// Triple an fp2e:
#ifdef QHASM
#define fp2e_triple2 fp2e_triple2_qhasm
#else
#define fp2e_triple2 fp2e_triple2_c
#endif
void fp2e_triple2(fp2e_t rop);
void fp2e_mul_scalar(fp2e_t rop, const fp2e_t op, const int s);
#ifdef QHASM
#define fp2e_add fp2e_add_qhasm
#else
#define fp2e_add fp2e_add_c
#endif
// Add two fp2e, store result in rop:
void fp2e_add(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
// Add rop to up, store result in rop:
#ifdef QHASM
#define fp2e_add2 fp2e_add2_qhasm
#else
#define fp2e_add2 fp2e_add2_c
#endif
void fp2e_add2(fp2e_t rop, const fp2e_t op);
// Load from mem
void fp2e_load(fp2e_struct_t *rop, const fp2e_t op);
//void fp2e_load(fp2e_t rop, const fp2e_t op);
// store to mem
void fp2e_store(fp2e_struct_t *rop, const fp2e_t op);
//void fp2e_store(fp2e_t rop, const fp2e_t op);
#ifdef QHASM
#define fp2e_sub fp2e_sub_qhasm
#else
#define fp2e_sub fp2e_sub_c
#endif
// Subtract op2 from op1, store result in rop:
void fp2e_sub(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
#ifdef QHASM
#define fp2e_sub2 fp2e_sub2_qhasm
#else
#define fp2e_sub2 fp2e_sub2_c
#endif
// Subtract op from rop, store result in rop:
void fp2e_sub2(fp2e_t rop, const fp2e_t op);
#ifdef QHASM
#define fp2e_neg2 fp2e_neg2_qhasm
#else
#define fp2e_neg2 fp2e_neg2_c
#endif
void fp2e_neg2(fp2e_t op);
#ifdef QHASM
#define fp2e_neg fp2e_neg_qhasm
#else
#define fp2e_neg fp2e_neg_c
#endif
void fp2e_neg(fp2e_t rop, const fp2e_t op);
#ifdef QHASM
#define fp2e_conjugate fp2e_conjugate_qhasm
#else
#define fp2e_conjugate fp2e_conjugate_c
#endif
// Conjugates: aX+b to -aX+b
void fp2e_conjugate(fp2e_t rop, const fp2e_t op);
#ifdef QHASM
#define fp2e_mul fp2e_mul_qhasm
#else
#define fp2e_mul fp2e_mul_c
#endif
// Multiply two fp2e, store result in rop:
void fp2e_mul(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
// Square an fp2e, store result in rop:
#ifdef QHASM
#define fp2e_square fp2e_square_qhasm
#else
#define fp2e_square fp2e_square_c
#endif
void fp2e_square(fp2e_t rop, const fp2e_t op);
// Multiply by xi which is used to construct F_p^6
#ifdef QHASM
#define fp2e_mulxi fp2e_mulxi_qhasm
#else
#define fp2e_mulxi fp2e_mulxi_c
#endif
void fp2e_mulxi(fp2e_t rop, const fp2e_t op);
// Multiple of an fp2e, store result in rop:
#ifdef QHASM
#define fp2e_mul_fpe fp2e_mul_fpe_qhasm
#else
#define fp2e_mul_fpe fp2e_mul_fpe_c
#endif
void fp2e_mul_fpe(fp2e_t rop, const fp2e_t op1, const fpe_t op2);
#ifdef QHASM
#define fp2e_parallel_coeffmul fp2e_parallel_coeffmul_qhasm
#else
#define fp2e_parallel_coeffmul fp2e_parallel_coeffmul_c
#endif
/* computes (op1->m_a*op2->m_a, op1->m_b*op2->m_b) */
void fp2e_parallel_coeffmul(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
// Inverse multiple of an fp2e, store result in rop:
void fp2e_invert(fp2e_t rop, const fp2e_t op1);
// Exponentiation:
void fp2e_exp(fp2e_t rop, const fp2e_t op, const scalar_t exp);
// Square root:
int fp2e_sqrt(fp2e_t rop, const fp2e_t op);
// Print the element to stdout:
void fp2e_print(FILE *outfile, const fp2e_t op);
#endif // ifndef FP2E_H