github.com/jiajun1992/watercarver@v0.0.0-20191031150618-dfc2b17c0c4a/StadiumForWaterCarver/src/Cipher_elg.cpp (about) 1 /* 2 * Cipher_elg.cpp 3 * 4 * Created on: 03.10.2010 5 * Author: stephaniebayer 6 */ 7 8 #include "Cipher_elg.h" 9 #include "Mod_p.h" 10 #include "G_q.h" 11 12 #include <assert.h> 13 14 #include "FakeZZ.h" 15 #include "CurvePoint.h" 16 NTL_CLIENT 17 18 extern G_q H;// group used for the the encryption 19 20 Cipher_elg::Cipher_elg() {} 21 22 // added: explicit initializer 23 Cipher_elg::Cipher_elg(bool dummy) { 24 #if !USE_NTL 25 mod.is_initialized = true; 26 mod.is_scalar = true; 27 #endif 28 } 29 30 Cipher_elg::Cipher_elg(CurvePoint u_val, ZZ mod_in){ 31 u = u_val; 32 mod = mod_in; 33 } 34 35 Cipher_elg::Cipher_elg(Mod_p u_t){ 36 u = u_t.get_val(); 37 mod = u_t.get_mod(); 38 } 39 40 41 Cipher_elg::~Cipher_elg() {} 42 43 //access to value of u 44 CurvePoint Cipher_elg::get_u() const{ 45 return u; 46 } 47 48 //access to the value of mod 49 ZZ Cipher_elg::get_mod()const{ 50 return mod; 51 } 52 53 //Assignment operator 54 void Cipher_elg::operator =(const Cipher_elg& c){ 55 u = c.get_u(); 56 mod = c.get_mod(); 57 } 58 59 //Multiplicative operator and multiplication functions 60 Cipher_elg Cipher_elg::operator *(const Cipher_elg& el)const{ 61 CurvePoint temp_1; 62 63 MulMod(temp_1,u,el.get_u(),mod); 64 65 return Cipher_elg(temp_1, mod); 66 } 67 68 void Cipher_elg::mult(Cipher_elg & a, const Cipher_elg& b, const Cipher_elg& c){ 69 CurvePoint temp_1; 70 ZZ mod = b.get_mod(); 71 MulMod(temp_1,b.get_u(),c.get_u(),mod); 72 a= Cipher_elg(temp_1,mod); 73 } 74 75 //Equality Check 76 bool Cipher_elg::operator ==(const Cipher_elg& b) const{ 77 bool bo = false; 78 if (u == b.get_u()) { 79 bo=true; 80 } 81 return bo; 82 } 83 84 void Cipher_elg::expo(Cipher_elg& a, const Cipher_elg& el, const ZZ ex){ 85 CurvePoint t_u; 86 ZZ mod =el.get_mod(); 87 PowerMod(t_u, el.get_u(),ex, mod); 88 a= Cipher_elg(t_u, mod); 89 } 90 91 //Output operator, the format of a ciphertext is (u) (modular mod) 92 ostream& operator <<(ostream&os, const Cipher_elg b){ 93 os << "("; 94 os << b.get_u(); 95 os << ")"; 96 return os; 97 } 98 99 //Input operator, 100 istream& operator >>(istream& is, Cipher_elg& el){ 101 CurvePoint val_u; ZZ mod; 102 char ch1, ch2, ch3; 103 //char str1, str2, str3, str4; 104 is >> ch1; 105 is >> val_u; 106 is >> ch2; 107 // is >> val_v; 108 // is >> ch3; 109 if (ch1 != '(' || ch2 != ')'){// || str3 != '(' || str4 != ')' ){ 110 is.clear(ios_base::failbit); 111 return is; 112 } 113 mod = H.get_mod(); 114 el = Cipher_elg(val_u, mod); 115 116 return is; 117 } 118 119 void Cipher_elg::print() const { 120 cout << u << endl; 121 // cout << v << endl; 122 cout << mod << endl; 123 }