github.com/jiajun1992/watercarver@v0.0.0-20191031150618-dfc2b17c0c4a/StadiumForWaterCarver/src/CurvePoint.h (about) 1 #ifndef CURVE_POINT_H 2 #define CURVE_POINT_H 3 4 #include "edgamal.h" 5 #include "FakeZZ.h" 6 NTL_CLIENT 7 8 /* Use elliptic curve points? */ 9 #define USE_REAL_POINTS 1 10 11 /* Size of those curve points points when serialized */ 12 /* Either 128 or 32. 128 does cheap serialization while 32 is expensive */ 13 // TODO changing this also requires changing CurvePoint.h 14 #define CURVE_POINT_BYTESIZE 32 15 16 class CurvePoint { 17 public: 18 CurvePoint(); 19 CurvePoint(const CurvePoint &other); 20 ~CurvePoint(); 21 22 bool operator !=(const CurvePoint& b) const; 23 bool operator ==(const CurvePoint& b) const; 24 void operator =(const CurvePoint& c); 25 26 friend ostream& operator <<(ostream& os, const CurvePoint a); 27 friend istream& operator >>(istream& is, CurvePoint& x); 28 29 void serialize_canonical(char *str); // TODO 32 bytes, inverse is raw_curve_pt 30 void serialize(char *str); // 128 bytes 31 void deserialize(const char *str); // 128 bytes 32 33 static const int bytesize = CURVE_POINT_BYTESIZE; 34 35 #if USE_REAL_POINTS 36 edgamal_curve_point P; 37 #else 38 NTL::ZZ zz; 39 #endif 40 }; 41 42 // note: this takes the packed form as an argument 43 CurvePoint raw_curve_pt(const uint8_t p[32]); 44 CurvePoint curve_zeropoint(); 45 CurvePoint curve_basepoint(); 46 47 void MulMod(CurvePoint& x, const CurvePoint& a, const CurvePoint& b, const ZZ& n); 48 CurvePoint MulMod(const CurvePoint& a, const CurvePoint& b, const ZZ& n); 49 50 void SqrMod(CurvePoint& x, const CurvePoint& a, const ZZ& n); 51 CurvePoint sqr(const CurvePoint& a); 52 53 void PowerMod(CurvePoint& x, const CurvePoint& a, const ZZ& e, const ZZ& n); 54 void PowerMod(CurvePoint& x, const CurvePoint& a, long e, const ZZ& n); 55 CurvePoint PowerMod(const CurvePoint& a, const ZZ& e, const ZZ& n); 56 57 // fast scalar multiplication over basepoint 58 void basepoint_scalarmult(CurvePoint& x, const ZZ& e); 59 60 void InvMod(CurvePoint& x, const CurvePoint& a, const ZZ& n); 61 CurvePoint InvMod(const CurvePoint& a, const ZZ& n); 62 63 // for compatibility 64 CurvePoint zz_to_curve_pt(NTL::ZZ a); 65 66 #endif