void use_class() { Class c; c.thiscall_method_small(); c.thiscall_method_small_with_ctor(); c.cdecl_method_small(); c.cdecl_method_big(); c.thiscall_method_arg(Empty()); c.thiscall_method_arg(EmptyWithCtor()); c.thiscall_method_arg(Small()); c.thiscall_method_arg(SmallWithCtor()); c.thiscall_method_arg(Big()); }
CharmListZR stringToInt(PairingGroup & group, string strID, int z, int l) { /* 1. hash string. */ CharmListZR zrlist; // = new CharmListZR; ZR intval; Big mask( pow(Big(2), l) - 1 ); ZR id = group.hashListToZR(strID); /* 2. cut up result into zz pieces of ll size */ for(int i = 0; i < z; i++) { intval = land(id, mask); zrlist.append(intval); id = id >> l; // shift to the right by ll bits } return zrlist; }
int Element_FromBytes(Element &e, int type, unsigned char *data) { if(type == ZR_t) { if(is_base64((unsigned char) data[0])) { string b64_encoded((char *) data); string s = _base64_decode(b64_encoded); int cnt = 0; Big b = Big(bytesToBig(s, &cnt)); e = Element(b); // cout << "Element_FromBytes: " << e << endl; return TRUE; } } else if(type == G1_t) { if(is_base64((unsigned char) data[0])) { string b64_encoded((char *) data); string s = _base64_decode(b64_encoded); int cnt = 0; Big x, y; x = bytesToBig(s, &cnt); s = s.substr(cnt); y = bytesToBig(s, &cnt); // cout << "point => (" << x << ", " << y << ")" << endl; G1 p; p.g.set(x, y); e = Element(p); //cout << "Element_FromBytes: " << e << endl; return TRUE; } } #if ASYMMETRIC == 1 else if(type == G2_t) { if(is_base64((unsigned char) data[0])) { string b64_encoded((char *) data); string s = _base64_decode(b64_encoded); // cout << "original => " << s << endl; int cnt = 0; G2 p; #if BUILD_MNT_CURVE == 1 ZZn a[MNT_G2_SIZE]; for(int i = 0; i < MNT_G2_SIZE; i++) { Big b = bytesToBig(s, &cnt); a[i] = ZZn( b ); // retrieve all six coordinates s = s.substr(cnt); } ZZn3 x (a[0], a[1], a[2]); ZZn3 y (a[3], a[4], a[5]); p.g.set(x, y); #elif BUILD_BN_CURVE == 1 Big a[BN_G2_SIZE]; for(int i = 0; i < BN_G2_SIZE; i++) { a[i] = bytesToBig(s, &cnt); s = s.substr(cnt); // advance s ptr } ZZn2 x1(a[0], a[1]); // each zzn2 has a (x, y) coordinate of type Big ZZn2 y1(a[2], a[3]); p.g.set(x1, y1); #endif e = Element(p); //cout << "Element_FromBytes: " << e << endl; return TRUE; } } #endif else if(type == GT_t) { if(is_base64((unsigned char) data[0])) { string b64_encoded((char *) data); string s = _base64_decode(b64_encoded); // cout << "original => " << s << endl; int cnt = 0; GT p; #if BUILD_MNT_CURVE == 1 Big a[MNT_GT_SIZE]; for(int i = 0; i < MNT_GT_SIZE; i++) { a[i] = bytesToBig(s, &cnt); s = s.substr(cnt); // advance s ptr } ZZn2 x, y, z; x.set(a[0], a[1]); y.set(a[2], a[3]); z.set(a[4], a[5]); p.g.set(x, y, z); #elif BUILD_BN_CURVE == 1 Big a[BN_GT_SIZE]; for(int i = 0; i < BN_GT_SIZE; i++) { a[i] = bytesToBig(s, &cnt); s = s.substr(cnt); // advance s ptr } ZZn2 x0, x1, y0, y1, z0, z1; x0.set(a[0], a[1]); x1.set(a[2], a[3]); y0.set(a[4], a[5]); y1.set(a[6], a[7]); z0.set(a[8], a[9]); z1.set(a[10], a[11]); ZZn4 x(x0, x1); ZZn4 y(y0, y1); ZZn4 z(z0, z1); p.g.set(x, y, z); #elif BUILD_SS_CURVE == 1 // must be symmetric Big a[SS_GT_SIZE]; for(int i = 0; i < SS_GT_SIZE; i++) { a[i] = bytesToBig(s, &cnt); s = s.substr(cnt); // advance s ptr } p.g.set(a[0], a[1]); #endif e = Element(p); //cout << "Element_FromBytes: " << e << endl; return TRUE; } } return 0; }
string Element_ToBytes(Element &e) { int type = e.type; char c[MAX_LEN+1]; memset(c, 0, MAX_LEN); string t; if(type == ZR_t) { Big s = e.zr; t.append(bigToBytes(s)); string encoded = _base64_encode(reinterpret_cast<const unsigned char*>(t.c_str()), t.size()); return encoded; } else if(type == G1_t) { G1 p = e.g1; Big x, y; p.g.get(x, y); t.append(bigToBytes(x)); t.append(bigToBytes(y)); string encoded = _base64_encode(reinterpret_cast<const unsigned char*>(t.c_str()), t.size()); return encoded; } #if ASYMMETRIC == 1 else if(type == G2_t) { G2 P = e.g2; // embeds an ECn3 element (for MNT curves) #if BUILD_MNT_CURVE == 1 ZZn3 x, y; ZZn *a = new ZZn[6]; P.g.get(x, y); // get ZZn3's x.get(a[0], a[1], a[2]); // get coordinates for each ZZn y.get(a[3], a[4], a[5]); for(int i = 0; i < 6; i++) { t.append( bigToBytes(Big(a[i])) ); } delete [] a; #elif BUILD_BN_CURVE == 1 ZZn2 x1, y1; // each zzn2 has a (x, y) coordinate of type Big P.g.get(x1, y1); Big *a = new Big[4]; x1.get(a[0], a[1]); y1.get(a[2], a[3]); for(int i = 0; i < 4; i++) { string tmp = bigToBytes(a[i]); t.append( tmp ); } delete [] a; #endif // base64 encode t and return string encoded = _base64_encode(reinterpret_cast<const unsigned char*>(t.c_str()), t.size()); return encoded; } #endif else if(type == GT_t) { #if BUILD_MNT_CURVE == 1 GT P = e.gt; // embeds an ZZn6 element (for MNT curves) is equivalent to // control this w/ a flag ZZn2 x, y, z; // each zzn2 has a (x,y) coordinates of type Big Big *a = new Big[6]; P.g.get(x, y, z); // get ZZn2's x.get(a[0], a[1]); // get coordinates for each ZZn2 y.get(a[2], a[3]); z.get(a[4], a[5]); // cout << "Point => (" << x << ", " << y << ", " << z << ")" << endl; for(int i = 0; i < 6; i++) { t.append( bigToBytes(a[i]) ); } delete [] a; #elif BUILD_BN_CURVE == 1 GT P = e.gt; ZZn4 x, y, z; ZZn2 x0, x1, y0, y1, z0, z1; P.g.get(x, y, z); Big *a = new Big[12]; x.get(x0, x1); y.get(y0, y1); z.get(z0, z1); x0.get(a[0], a[1]); x1.get(a[2], a[3]); y0.get(a[4], a[5]); y1.get(a[6], a[7]); z0.get(a[8], a[9]); z1.get(a[10], a[11]); for(int i = 0; i < 12; i++) { t.append( bigToBytes(a[i]) ); } delete [] a; #elif BUILD_SS_CURVE == 1 GT P = e.gt; Big *a = new Big[2]; P.g.get(a[0], a[1]); for(int i = 0; i < 2; i++) { t.append( bigToBytes(a[i]) ); } delete [] a; #endif string encoded = _base64_encode(reinterpret_cast<const unsigned char*>(t.c_str()), t.size()); return encoded; } return 0; }
// Returning a large struct that doesn't fit into a register. Big big_return() { return Big(); }
Big __cdecl cdecl_method_big() { return Big(); }
void test() { Big big_val = 1; big_val += std::numeric_limits<Big>::epsilon(); Small small_val = 1; BOOST_CHECK_EQUAL(big_val == small_val, false); BOOST_CHECK_EQUAL(big_val <= small_val, false); BOOST_CHECK_EQUAL(big_val >= small_val, true); BOOST_CHECK_EQUAL(big_val < small_val, false); BOOST_CHECK_EQUAL(big_val > small_val, true); BOOST_CHECK_EQUAL(big_val != small_val, true); BOOST_CHECK_EQUAL(small_val == big_val, false); BOOST_CHECK_EQUAL(small_val <= big_val, true); BOOST_CHECK_EQUAL(small_val >= big_val, false); BOOST_CHECK_EQUAL(small_val < big_val, true); BOOST_CHECK_EQUAL(small_val > big_val, false); BOOST_CHECK_EQUAL(small_val != big_val, true); // Again with expression templates, on one the other, or both args: BOOST_CHECK_EQUAL(big_val == small_val * 1, false); BOOST_CHECK_EQUAL(big_val <= small_val * 1, false); BOOST_CHECK_EQUAL(big_val >= small_val * 1, true); BOOST_CHECK_EQUAL(big_val < small_val * 1, false); BOOST_CHECK_EQUAL(big_val > small_val * 1, true); BOOST_CHECK_EQUAL(big_val != small_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 == big_val, false); BOOST_CHECK_EQUAL(small_val * 1 <= big_val, true); BOOST_CHECK_EQUAL(small_val * 1 >= big_val, false); BOOST_CHECK_EQUAL(small_val * 1 < big_val, true); BOOST_CHECK_EQUAL(small_val * 1 > big_val, false); BOOST_CHECK_EQUAL(small_val * 1 != big_val, true); BOOST_CHECK_EQUAL(big_val * 1 == small_val, false); BOOST_CHECK_EQUAL(big_val * 1 <= small_val, false); BOOST_CHECK_EQUAL(big_val * 1 >= small_val, true); BOOST_CHECK_EQUAL(big_val * 1 < small_val, false); BOOST_CHECK_EQUAL(big_val * 1 > small_val, true); BOOST_CHECK_EQUAL(big_val * 1 != small_val, true); BOOST_CHECK_EQUAL(small_val == big_val * 1, false); BOOST_CHECK_EQUAL(small_val <= big_val * 1, true); BOOST_CHECK_EQUAL(small_val >= big_val * 1, false); BOOST_CHECK_EQUAL(small_val < big_val * 1, true); BOOST_CHECK_EQUAL(small_val > big_val * 1, false); BOOST_CHECK_EQUAL(small_val != big_val * 1, true); BOOST_CHECK_EQUAL(big_val * 1 == small_val * 1, false); BOOST_CHECK_EQUAL(big_val * 1 <= small_val * 1, false); BOOST_CHECK_EQUAL(big_val * 1 >= small_val * 1, true); BOOST_CHECK_EQUAL(big_val * 1 < small_val * 1, false); BOOST_CHECK_EQUAL(big_val * 1 > small_val * 1, true); BOOST_CHECK_EQUAL(big_val * 1 != small_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 == big_val * 1, false); BOOST_CHECK_EQUAL(small_val * 1 <= big_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 >= big_val * 1, false); BOOST_CHECK_EQUAL(small_val * 1 < big_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 > big_val * 1, false); BOOST_CHECK_EQUAL(small_val * 1 != big_val * 1, true); BOOST_CHECK_EQUAL(small_val + big_val, Big(small_val) + big_val); BOOST_CHECK_EQUAL(small_val - big_val, Big(small_val) - big_val); BOOST_CHECK_EQUAL(small_val * big_val, Big(small_val) * big_val); BOOST_CHECK_EQUAL(small_val / big_val, Big(small_val) / big_val); BOOST_CHECK_EQUAL(big_val + small_val, big_val + Big(small_val)); BOOST_CHECK_EQUAL(big_val - small_val, big_val - Big(small_val)); BOOST_CHECK_EQUAL(big_val * small_val, big_val * Big(small_val)); BOOST_CHECK_EQUAL(big_val / small_val, big_val / Big(small_val)); // Again with expression templates, on one the other, or both args: BOOST_CHECK_EQUAL(small_val + (big_val * 1), Big(small_val) + (big_val * 1)); BOOST_CHECK_EQUAL(small_val - (big_val * 1), Big(small_val) - (big_val * 1)); BOOST_CHECK_EQUAL(small_val * (big_val * 1), Big(small_val) * (big_val * 1)); BOOST_CHECK_EQUAL(small_val / (big_val * 1), Big(small_val) / (big_val * 1)); BOOST_CHECK_EQUAL((big_val * 1) + small_val, (big_val * 1) + Big(small_val)); BOOST_CHECK_EQUAL((big_val * 1) - small_val, (big_val * 1) - Big(small_val)); BOOST_CHECK_EQUAL((big_val * 1) * small_val, (big_val * 1) * Big(small_val)); BOOST_CHECK_EQUAL((big_val * 1) / small_val, (big_val * 1) / Big(small_val)); BOOST_CHECK_EQUAL((small_val * 1) + big_val, Big((small_val * 1)) + big_val); BOOST_CHECK_EQUAL((small_val * 1) - big_val, Big((small_val * 1)) - big_val); BOOST_CHECK_EQUAL((small_val * 1) * big_val, Big((small_val * 1)) * big_val); BOOST_CHECK_EQUAL((small_val * 1) / big_val, Big((small_val * 1)) / big_val); BOOST_CHECK_EQUAL(big_val + (small_val * 1), big_val + Big((small_val * 1))); BOOST_CHECK_EQUAL(big_val - (small_val * 1), big_val - Big((small_val * 1))); BOOST_CHECK_EQUAL(big_val * (small_val * 1), big_val * Big((small_val * 1))); BOOST_CHECK_EQUAL(big_val / (small_val * 1), big_val / Big((small_val * 1))); BOOST_CHECK_EQUAL((small_val * 1) + (big_val * 1), Big((small_val * 1)) + (big_val * 1)); BOOST_CHECK_EQUAL((small_val * 1) - (big_val * 1), Big((small_val * 1)) - (big_val * 1)); BOOST_CHECK_EQUAL((small_val * 1) * (big_val * 1), Big((small_val * 1)) * (big_val * 1)); BOOST_CHECK_EQUAL((small_val * 1) / (big_val * 1), Big((small_val * 1)) / (big_val * 1)); BOOST_CHECK_EQUAL((big_val * 1) + (small_val * 1), (big_val * 1) + Big((small_val * 1))); BOOST_CHECK_EQUAL((big_val * 1) - (small_val * 1), (big_val * 1) - Big((small_val * 1))); BOOST_CHECK_EQUAL((big_val * 1) * (small_val * 1), (big_val * 1) * Big((small_val * 1))); BOOST_CHECK_EQUAL((big_val * 1) / (small_val * 1), (big_val * 1) / Big((small_val * 1))); big_val = 1; big_val -= std::numeric_limits<Big>::epsilon(); BOOST_CHECK_EQUAL(big_val == small_val, false); BOOST_CHECK_EQUAL(big_val <= small_val, true); BOOST_CHECK_EQUAL(big_val >= small_val, false); BOOST_CHECK_EQUAL(big_val < small_val, true); BOOST_CHECK_EQUAL(big_val > small_val, false); BOOST_CHECK_EQUAL(big_val != small_val, true); BOOST_CHECK_EQUAL(small_val == big_val, false); BOOST_CHECK_EQUAL(small_val <= big_val, false); BOOST_CHECK_EQUAL(small_val >= big_val, true); BOOST_CHECK_EQUAL(small_val < big_val, false); BOOST_CHECK_EQUAL(small_val > big_val, true); BOOST_CHECK_EQUAL(small_val != big_val, true); // Again with expression templates, on one the other, or both args: BOOST_CHECK_EQUAL(big_val == small_val * 1, false); BOOST_CHECK_EQUAL(big_val <= small_val * 1, true); BOOST_CHECK_EQUAL(big_val >= small_val * 1, false); BOOST_CHECK_EQUAL(big_val < small_val * 1, true); BOOST_CHECK_EQUAL(big_val > small_val * 1, false); BOOST_CHECK_EQUAL(big_val != small_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 == big_val, false); BOOST_CHECK_EQUAL(small_val * 1 <= big_val, false); BOOST_CHECK_EQUAL(small_val * 1 >= big_val, true); BOOST_CHECK_EQUAL(small_val * 1 < big_val, false); BOOST_CHECK_EQUAL(small_val * 1 > big_val, true); BOOST_CHECK_EQUAL(small_val * 1 != big_val, true); BOOST_CHECK_EQUAL(big_val * 1 == small_val, false); BOOST_CHECK_EQUAL(big_val * 1 <= small_val, true); BOOST_CHECK_EQUAL(big_val * 1 >= small_val, false); BOOST_CHECK_EQUAL(big_val * 1 < small_val, true); BOOST_CHECK_EQUAL(big_val * 1 > small_val, false); BOOST_CHECK_EQUAL(big_val * 1 != small_val, true); BOOST_CHECK_EQUAL(small_val == big_val * 1, false); BOOST_CHECK_EQUAL(small_val <= big_val * 1, false); BOOST_CHECK_EQUAL(small_val >= big_val * 1, true); BOOST_CHECK_EQUAL(small_val < big_val * 1, false); BOOST_CHECK_EQUAL(small_val > big_val * 1, true); BOOST_CHECK_EQUAL(small_val != big_val * 1, true); BOOST_CHECK_EQUAL(big_val * 1 == small_val * 1, false); BOOST_CHECK_EQUAL(big_val * 1 <= small_val * 1, true); BOOST_CHECK_EQUAL(big_val * 1 >= small_val * 1, false); BOOST_CHECK_EQUAL(big_val * 1 < small_val * 1, true); BOOST_CHECK_EQUAL(big_val * 1 > small_val * 1, false); BOOST_CHECK_EQUAL(big_val * 1 != small_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 == big_val * 1, false); BOOST_CHECK_EQUAL(small_val * 1 <= big_val * 1, false); BOOST_CHECK_EQUAL(small_val * 1 >= big_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 < big_val * 1, false); BOOST_CHECK_EQUAL(small_val * 1 > big_val * 1, true); BOOST_CHECK_EQUAL(small_val * 1 != big_val * 1, true); BOOST_CHECK_EQUAL(small_val + big_val, Big(small_val) + big_val); BOOST_CHECK_EQUAL(small_val - big_val, Big(small_val) - big_val); BOOST_CHECK_EQUAL(small_val * big_val, Big(small_val) * big_val); BOOST_CHECK_EQUAL(small_val / big_val, Big(small_val) / big_val); BOOST_CHECK_EQUAL(big_val + small_val, big_val + Big(small_val)); BOOST_CHECK_EQUAL(big_val - small_val, big_val - Big(small_val)); BOOST_CHECK_EQUAL(big_val * small_val, big_val * Big(small_val)); BOOST_CHECK_EQUAL(big_val / small_val, big_val / Big(small_val)); // Again with expression templates, on one the other, or both args: BOOST_CHECK_EQUAL(small_val + (big_val * 1), Big(small_val) + (big_val * 1)); BOOST_CHECK_EQUAL(small_val - (big_val * 1), Big(small_val) - (big_val * 1)); BOOST_CHECK_EQUAL(small_val * (big_val * 1), Big(small_val) * (big_val * 1)); BOOST_CHECK_EQUAL(small_val / (big_val * 1), Big(small_val) / (big_val * 1)); BOOST_CHECK_EQUAL((big_val * 1) + small_val, (big_val * 1) + Big(small_val)); BOOST_CHECK_EQUAL((big_val * 1) - small_val, (big_val * 1) - Big(small_val)); BOOST_CHECK_EQUAL((big_val * 1) * small_val, (big_val * 1) * Big(small_val)); BOOST_CHECK_EQUAL((big_val * 1) / small_val, (big_val * 1) / Big(small_val)); BOOST_CHECK_EQUAL((small_val * 1) + big_val, Big((small_val * 1)) + big_val); BOOST_CHECK_EQUAL((small_val * 1) - big_val, Big((small_val * 1)) - big_val); BOOST_CHECK_EQUAL((small_val * 1) * big_val, Big((small_val * 1)) * big_val); BOOST_CHECK_EQUAL((small_val * 1) / big_val, Big((small_val * 1)) / big_val); BOOST_CHECK_EQUAL(big_val + (small_val * 1), big_val + Big((small_val * 1))); BOOST_CHECK_EQUAL(big_val - (small_val * 1), big_val - Big((small_val * 1))); BOOST_CHECK_EQUAL(big_val * (small_val * 1), big_val * Big((small_val * 1))); BOOST_CHECK_EQUAL(big_val / (small_val * 1), big_val / Big((small_val * 1))); BOOST_CHECK_EQUAL((small_val * 1) + (big_val * 1), Big((small_val * 1)) + (big_val * 1)); BOOST_CHECK_EQUAL((small_val * 1) - (big_val * 1), Big((small_val * 1)) - (big_val * 1)); BOOST_CHECK_EQUAL((small_val * 1) * (big_val * 1), Big((small_val * 1)) * (big_val * 1)); BOOST_CHECK_EQUAL((small_val * 1) / (big_val * 1), Big((small_val * 1)) / (big_val * 1)); BOOST_CHECK_EQUAL((big_val * 1) + (small_val * 1), (big_val * 1) + Big((small_val * 1))); BOOST_CHECK_EQUAL((big_val * 1) - (small_val * 1), (big_val * 1) - Big((small_val * 1))); BOOST_CHECK_EQUAL((big_val * 1) * (small_val * 1), (big_val * 1) * Big((small_val * 1))); BOOST_CHECK_EQUAL((big_val * 1) / (small_val * 1), (big_val * 1) / Big((small_val * 1))); }
void f() try { throw Big(); } catch(E e) {} catch(int i) {} catch(...) {}