-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgroup.h
112 lines (73 loc) · 2.46 KB
/
group.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
#ifndef _SECP256K1_GROUP_
#define _SECP256K1_GROUP_
#include <string>
#include "num.h"
#include "field.h"
namespace secp256k1 {
class GroupElemJac;
/** Defines a point on the secp256k1 curve (y^2 = x^3 + 7) */
class GroupElem {
protected:
bool fInfinity;
FieldElem x;
FieldElem y;
public:
/** Creates the point at infinity */
GroupElem();
/** Creates the point with given affine coordinates */
GroupElem(const FieldElem &xin, const FieldElem &yin);
/** Checks whether this is the point at infinity */
bool IsInfinity() const;
void SetNeg(const GroupElem &p);
void GetX(FieldElem &xout);
void GetY(FieldElem &yout);
std::string ToString() const;
void SetJac(GroupElemJac &jac);
friend class GroupElemJac;
};
/** Represents a point on the secp256k1 curve, with jacobian coordinates */
class GroupElemJac : private GroupElem {
protected:
FieldElem z;
public:
/** Creates the point at infinity */
GroupElemJac();
/** Creates the point with given affine coordinates */
GroupElemJac(const FieldElem &xin, const FieldElem &yin);
GroupElemJac(const GroupElem &in);
void SetJac(const GroupElemJac &jac);
void SetAffine(const GroupElem &aff);
/** Checks whether this is a non-infinite point on the curve */
bool IsValid() const;
/** Returns the affine coordinates of this point */
void GetAffine(GroupElem &aff);
void GetX(FieldElem &xout);
void GetY(FieldElem &yout);
bool IsInfinity() const;
void SetNeg(const GroupElemJac &p);
/** Sets this point to have a given X coordinate & given Y oddness */
void SetCompressed(const FieldElem &xin, bool fOdd);
/** Sets this point to be the EC double of another */
void SetDouble(const GroupElemJac &p);
/** Sets this point to be the EC addition of two others */
void SetAdd(const GroupElemJac &p, const GroupElemJac &q);
/** Sets this point to be the EC addition of two others (one of which is in affine coordinates) */
void SetAdd(const GroupElemJac &p, const GroupElem &q);
std::string ToString() const;
void SetMulLambda(const GroupElemJac &p);
};
class GroupConstants {
private:
const FieldElem g_x;
const FieldElem g_y;
public:
const Number order;
const GroupElem g;
const FieldElem beta;
const Number lambda, a1b2, b1, a2;
GroupConstants();
};
const GroupConstants &GetGroupConst();
void SplitExp(const Number &exp, Number &exp1, Number &exp2);
}
#endif