-
Notifications
You must be signed in to change notification settings - Fork 7
/
ellipticcurve.h
150 lines (123 loc) · 2.96 KB
/
ellipticcurve.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
/*
* ellipticcurve.h
*
* Created on: Nov 5, 2009
* Author: bhess
*/
#ifndef ELLIPTICCURVE_H_
#define ELLIPTICCURVE_H_
#include <vector>
#include <gmpxx.h>
#include "coordinates.h"
#include "primes.h"
class Ellipticcurve {
public:
Ellipticcurve();
Ellipticcurve(mpz_class _mod, mpz_class _ECC_a, mpz_class _ECC_b) :
mod(_mod), ECC_a(_ECC_a), ECC_b(_ECC_b) {
}
;
Ellipticcurve(const char* _mod, int _mod_base, const char* _order,
int _order_base, const char* _ecc_a, int _ecc_a_base,
const char* _ecc_b, int _ecc_b_base, const char* _px, int _px_base,
const char* _py, int _py_base);
virtual ~Ellipticcurve();
/*
* --------------------------------
* Definition of the Elliptic Curve
* --------------------------------
*
* The prime modulus for the underlying finite field
*/
mpz_class mod;
/**
* Equation that defines the EC:
* y^2 = x^3 + ax + b
*/
mpz_class ECC_a, ECC_b;
/**
* A point in E(F_p)
*/
Coordinate point;
int get_bits();
void set_point_compressed(string cpoint) {
point = getPointCompressedForm(cpoint);
}
mpz_class getOrder() {
return order;
}
void setOrder(mpz_class _order) {
order = _order;
}
//static Ellipticcurve randomCurve(int number_of_bits,
// RandomNumberGenerator gen);
/*
* -------------
* EC operations
* -------------
*/
/**
* Addition P+Q of a jacobian coordinate
* P and an affine coordinate Q
*/
virtual Coordinate addition(Coordinate P, Coordinate Q) = 0;
/**
* Subtraction P-Q of a jacobian coordinate
* P and an affine coordinate Q
*/
virtual Coordinate subtraction(Coordinate P, Coordinate Q) = 0;
/**
* Doubling of a point P -> 2P
* in jacobian coordinates
*/
virtual Coordinate doubling(Coordinate P) = 0;
/**
* Repeated doubling of a point P in jacobian coordinates
* (m times) -> 2^m P
*/
virtual Coordinate repeatedDoubling(Coordinate P, int m) = 0;
/**
* Point multiplication (k times)
* -> kP
*/
virtual Coordinate pointMultiplication(Coordinate P, mpz_class k) = 0;
/*
* -----------
* Accesseors
* ----------
*
*
*
* Given x, returns the point corresponding to (x,y) (or (x,-y) if asked)
* If there is no corresponding point, returns the infinity
*/
virtual Coordinate getPoint_interface(mpz_class x, bool negative_value = false) = 0;
/*
* Gets the point from compressed format
* see IEEE P1363 / D8 E.2.3.1
*/
virtual Coordinate getPointCompressedForm(string from) = 0;
/*
* Outputs the point in compressed form
* According to IEEE P1363 / D8, E.2.3.1
*
* Implemented here, because it depends on the curve type
*/
virtual string toCompressedForm(Coordinate c) = 0;
protected:
/*
* Order of the EC
*/
mpz_class order;
/**
* Returns the point -P
* According to p.80 (char /= 2,3)
*/
Coordinate getNegative(const Coordinate& P);
/**
* Returns the non-adjacent form (NAF)
* of a positive integer k
*/
std::vector<int> getNAF(mpz_class k);
};
#endif /* ELLIPTICCURVE_H_ */