-
Notifications
You must be signed in to change notification settings - Fork 7
/
coordinates.h
92 lines (71 loc) · 1.87 KB
/
coordinates.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
/*
* coordinates.h
*
* Created on: Nov 5, 2009
* Author: bhess
*/
#ifndef COORDINATES_H_
#define COORDINATES_H_
#include <iostream>
#include <gmpxx.h>
using namespace std;
//#include "ellipticcurve.h"
//#define isInfJac(mpz_class m) = m.z
class Coordinate;
class Jacobian;
class LD;
class Coordinate {
public:
Coordinate() {}
Coordinate(const char* _x, int basex,
const char* _y, int basey);
Coordinate(mpz_class _x, mpz_class _y):
X(_x), Y(_y) {}
Coordinate(const Jacobian& jac, const mpz_class mod);
//Coordinate(const LD& ld, const mpz_class mod);
//returns the point at infinity, as is represented by this class in the context of elliptic curves
static Coordinate infinity(){return Coordinate(0,0);}
bool operator==(const Coordinate& eqTo) {
return X == eqTo.X && Y == eqTo.Y;
}
bool isInfinite() {
return X == 0 && Y == 0;
}
mpz_class X, Y;
};
ostream& operator<<(ostream& out, Coordinate& rhs);
class Jacobian {
public:
Jacobian() {}
Jacobian(mpz_class _x, mpz_class _y, mpz_class _z):
X(_x), Y(_y), Z(_z) {}
Jacobian(const Coordinate& rhs): //TODO: is this really the correct conversion?
X(rhs.X), Y(rhs.Y), Z(1) {}
static Jacobian infinity(){return Jacobian(1, 1, 0);}
bool isInfinite() {
return X == 1 && Y == 1 && Z == 0;
}
mpz_class X, Y, Z;
};
/**
* Lopez-Dahab projective coordinate
* (X;Y;Z) corresponds to (X/Z;X/Z^2) in standard
* coordinates
*
* See p.93, Menezes et. al.
*/
class LD {
public:
LD() {}
// Deprecated..
LD(mpz_class _x, mpz_class _y, mpz_class _z):
X(_x), Y(_y), Z(_z) {}
LD(const Coordinate& rhs): //TODO: is this really the correct conversion?
X(rhs.X), Y(rhs.Y), Z(1) {}
static LD infinity(){return LD(1, 0, 0);}
bool isInfinite() {
return X == 1 && Y == 0 && Z == 0;
}
mpz_class X, Y, Z;
};
#endif /* COORDINATES_H_ */