1 #ifndef __G2_H__
2 #define __G2_H__
3
4 #include "G.h"
5 using namespace std;
6
7 class G2: public G {
8 public:
9 G2(){};
10
11 //Create and initialize an element
12 G2(const Pairing &e);
13
14 //Create an identity or a random element
15 G2(const Pairing &e, bool identity);
16
17 //Create an element from import
18 G2(const Pairing &e, const unsigned char *data,
19 unsigned short len, bool compressed = false,
20 unsigned short base = 16);
21
22 //Create an element from hash
23 G2(const Pairing &e, const void *data,
24 unsigned short len);
25
26 //Intialize with another element but with different value
27 G2(const G2 &h, bool identity=false):G(h,identity){}
28
29 //Copy constructor
30 //G2(const G2 &h):G(h){}
31
32 // Assignment operator
33 G2& operator=(const G2 &rhs){return (G2&)G::operator=(rhs);}
34
35 //Arithmetic Assignment Operators
36 G2& operator*=(const G2 &rhs){return (G2&)G::operator*=(rhs);}
37 G2& operator/=(const G2 &rhs){return (G2&)G::operator/=(rhs);}
38 G2& operator^=(const Zr &exp){return (G2&)G::operator^=(exp);}
39
40 // Non-assignment operators
41 const G2 operator*(const G2 &rhs) const {
42 return G2(*this) *= rhs;
43 }
44 const G2 operator/(const G2 &rhs) const {
45 return G2(*this) /= rhs;
46 }
47
48 const G2 operator^(const Zr &exp) const {
49 return G2(*this) ^= exp;
50 }
51
52 bool operator==(const G2 &rhs) const {
53 return G::operator==(rhs);
54 }
55
56 unsigned short getElementSize(bool compressed) const;
57
58 string toString(bool compressed) const;
59
60 const G2 inverse() const{
61 G2 g2;
62 g2.setElement(G::inverse().getElement());
63 return g2;
64 }
65 const G2 square() const{
66 G2 g2;
67 g2.setElement(G::square().getElement());
68 return g2;
69 }
70 };
71
72 #endif