Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241782 views
1
/*********************************************************************
2
3
(c) Copyright 2006-2010 Salman Baig and Chris Hall
4
5
This file is part of ELLFF
6
7
ELLFF is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
11
12
ELLFF is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
*********************************************************************/
21
22
#ifndef ELL_H
23
#define ELL_H
24
25
// meant for elliptic curves in char != 2,3
26
27
class ell_pEInfoT {
28
private:
29
ell_pEInfoT(); // do not use
30
ell_pEInfoT(const ell_pEInfoT&); // do not use
31
void operator=(const ell_pEInfoT&); // do not use
32
33
public:
34
long ref_count; // for garbage collection
35
36
ell_pEInfoT(const zz_pE& new_a4, const zz_pE& new_a6);
37
38
~ell_pEInfoT();
39
40
zz_pE a4, a6;
41
long q;
42
};
43
44
typedef ell_pEInfoT *ell_pEInfoPtr;
45
46
class ell_pEContext {
47
private:
48
ell_pEInfoT *ptr;
49
50
public:
51
void save();
52
void restore() const;
53
54
ell_pEContext() { ptr = NULL; }
55
ell_pEContext(const zz_pE& a4, const zz_pE& a6);
56
57
ell_pEContext(const ell_pEContext&);
58
59
ell_pEContext& operator=(const ell_pEContext&);
60
61
~ell_pEContext();
62
};
63
64
extern ell_pEInfoPtr ell_pEInfo;
65
66
class ell_pE {
67
public:
68
//ell_pE();
69
70
// set curve to E/F_q : y^2 = x^3 + a4*x + a6
71
static void init(zz_pE& a4, zz_pE& a6);
72
73
static long order();
74
};
75
76
class ellpoint_pE {
77
private:
78
79
public:
80
zz_pE x, y;
81
int identity_f;
82
83
ellpoint_pE();
84
ellpoint_pE(const zz_pE& x, const zz_pE& y);
85
86
inline int on_curve()
87
{ return sqr(y) == ((sqr(x)+ell_pEInfo->a4)*x + ell_pEInfo->a6); }
88
89
inline void set() { identity_f = 1; }
90
inline void set(const zz_pE& _x, const zz_pE& _y)
91
{ identity_f = 0; x = _x; y = _y; }
92
93
long order();
94
};
95
96
void neg(ellpoint_pE& Q, const ellpoint_pE& P);
97
98
void add(ellpoint_pE& R, const ellpoint_pE& P, const ellpoint_pE& Q);
99
void sub(ellpoint_pE& R, const ellpoint_pE& P, const ellpoint_pE& Q);
100
101
ellpoint_pE operator-(const ellpoint_pE& P);
102
103
ellpoint_pE operator+(const ellpoint_pE& P, const ellpoint_pE& Q);
104
ellpoint_pE operator-(const ellpoint_pE& P, const ellpoint_pE& Q);
105
106
ellpoint_pE& operator+=(ellpoint_pE& P, const ellpoint_pE& Q);
107
ellpoint_pE& operator-=(ellpoint_pE& P, const ellpoint_pE& Q);
108
109
ellpoint_pE operator*(int m, const ellpoint_pE& P);
110
111
int is_zero(const ellpoint_pE& P);
112
113
long operator==(const ellpoint_pE& P, const ellpoint_pE& Q);
114
long operator<( ellpoint_pE& P, ellpoint_pE& Q);
115
long operator>( ellpoint_pE& P, ellpoint_pE& Q);
116
long operator<=(ellpoint_pE& P, ellpoint_pE& Q);
117
long operator>=(ellpoint_pE& P, ellpoint_pE& Q);
118
ostream& operator<<(ostream& s, const ellpoint_pE& P);
119
120
unsigned long* to_ulong(ellpoint_pE& P);
121
122
// routine for freeing any large chunks of memory allocated
123
void ell_cleanup();
124
125
#endif // ELL_H
126
127
128