Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
fp2.c
Go to the documentation of this file.
1
#include <string.h>
2
#include <assert.h>
3
4
#include "
fp2.h
"
5
6
#ifdef ENABLE_CT_TESTING
7
#include <valgrind/memcheck.h>
8
#endif
9
10
void
fp2_copy
(
fp2
*x,
const
fp2
*y)
11
{
12
fp_copy
(x->re, y->
re
);
13
fp_copy
(x->im, y->
im
);
14
}
15
16
void
fp2_add
(
fp2
*x,
const
fp2
*y,
const
fp2
*z)
17
{
18
fp_add3(&(x->re), &(y->
re
), &(z->
re
));
19
fp_add3(&(x->im), &(y->
im
), &(z->
im
));
20
}
21
22
void
fp2_sub
(
fp2
*x,
const
fp2
*y,
const
fp2
*z)
23
{
24
fp_sub3(&(x->re), &(y->
re
), &(z->
re
));
25
fp_sub3(&(x->im), &(y->
im
), &(z->
im
));
26
}
27
28
void
fp2_neg
(
fp2
*x,
const
fp2
*y)
29
{
30
fp_neg2(&(x->re), &(y->
re
));
31
fp_neg2(&(x->im), &(y->
im
));
32
}
33
34
void
fp2_mul
(
fp2
*x,
const
fp2
*y,
const
fp2
*z)
35
{
36
fp
t0, t1;
37
38
fp_add3(&t0, &(y->
re
), &(y->
im
));
39
fp_add3(&t1, &(z->
re
), &(z->
im
));
40
fp_mul3(&t0, (
const
fp
*)t0, (
const
fp
*)t1);
41
fp_mul3(&t1, &(y->
im
), &(z->
im
));
42
fp_mul3(&(x->re), &(y->
re
), &(z->
re
));
43
fp_sub3(&(x->im), (
const
fp
*)t0, (
const
fp
*)t1);
44
fp_sub3(&(x->im), (
const
fp
*)(x->im), (
const
fp
*)(x->re));
45
fp_sub3(&(x->re), (
const
fp
*)(x->re), (
const
fp
*)t1);
46
}
47
48
void
fp2_sqr
(
fp2
*x,
const
fp2
*y)
49
{
50
fp
sum, diff;
51
52
fp_add3(&sum, &(y->
re
), &(y->
im
));
53
fp_sub3(&diff, &(y->
re
), &(y->
im
));
54
fp_mul3(&(x->im), &(y->
re
), &(y->
im
));
55
fp_add3(&(x->im), (
const
fp
*)(x->im), (
const
fp
*)(x->im));
56
fp_mul3(&(x->re), (
const
fp
*)sum, (
const
fp
*)diff);
57
}
58
59
void
fp2_inv
(
fp2
*x)
60
{
61
fp
t0, t1;
62
63
fp_sqr
(t0, x->re);
64
fp_sqr
(t1, x->im);
65
fp_add3(&t0, (
const
fp
*)t0, (
const
fp
*)t1);
66
fp_inv
(t0);
67
fp_mul3(&(x->re), (
const
fp
*)x->re, (
const
fp
*)t0);
68
fp_mul3(&(x->im), (
const
fp
*)x->im, (
const
fp
*)t0);
69
fp_neg1(&(x->im));
70
}
71
72
void
fp2_test
(
void
)
73
{
74
75
fp2
a
, b, c;
76
77
for
(int64_t
i
= 0;
i
<= 10000;
i
++)
78
{
79
fp_random
(
a
.im);
80
fp_random
(
a
.re);
81
82
fp2_copy
(&b, &
a
);
83
fp2_inv
(&
a
);
84
fp2_mul
(&c, &
a
, &b);
85
assert
(fp_isone(c.re) == 1);
86
assert
(fp_iszero(c.im) == 1);
87
}
88
}
fp2_test
void fp2_test(void)
Definition
fp2.c:72
fp2.h
fp2_neg
#define fp2_neg
Definition
fp2.h:30
fp2_add
#define fp2_add
Definition
fp2.h:24
fp2_mul
#define fp2_mul
Definition
fp2.h:33
fp2_copy
#define fp2_copy
Definition
fp2.h:21
fp2_inv
#define fp2_inv
Definition
fp2.h:39
fp2_sub
#define fp2_sub
Definition
fp2.h:27
fp2_sqr
#define fp2_sqr
Definition
fp2.h:36
fp_sqr
#define fp_sqr
Definition
fp-gmp.h:73
fp
uint64_t fp[NUMBER_OF_WORDS]
Definition
fp-gmp.h:22
fp_inv
#define fp_inv
Definition
fp-gmp.h:88
fp_copy
#define fp_copy
Definition
fp-gmp.h:79
fp_random
#define fp_random
Definition
fp-gmp.h:85
assert
assert(var1 eq var2)
i
for i
Definition
prime_search.m:10
fp2
Definition
fp2.h:17
fp2::re
fp re
Definition
fp2.h:18
fp2::im
fp im
Definition
fp2.h:18
a
f a
Definition
to_model.m:12
dCTIDH
src
common
fp
fp2.c
Generated by
1.9.8