static void test_value_move_ctor () { rw_info (0, __FILE__, __LINE__, "value move constructor"); #define INTEGER_CONSTANT 256 std::tuple<int> it1 (INTEGER_CONSTANT); test (__LINE__, it1, INTEGER_CONSTANT); const int c = std::rand (); int i = c; // move semantics can alter source value std::tuple<int> it2 (i); // temporary source value test (__LINE__, it2, c); const std::tuple<int> it3 (INTEGER_CONSTANT); test (__LINE__, it3, INTEGER_CONSTANT); i = c; const std::tuple<int> it4 (i); test (__LINE__, it4, c); std::tuple<const int> ct1 (INTEGER_CONSTANT); test (__LINE__, ct1, INTEGER_CONSTANT); i = c; std::tuple<const int> ct2 (i); test (__LINE__, ct2, c); // ill-formed for tuples with element types containing references std::tuple<std::tuple<int> > nt (it1); test (__LINE__, nt, it1); std::tuple<long, const char*> pt (123456789L, "string"); test (__LINE__, pt, 123456789L, (const char*) "string"); const UserDefined src (c); UserDefined tmp (src); UserDefined::reset (); std::tuple<UserDefined> ut (tmp); UserDefined::expect.move_ctor = 1; test (__LINE__, ut, src); tmp = src; ++UserDefined::expect.copy_asgn; std::tuple<bool, char, int, double, void*, UserDefined> bt (true, 'a', INTEGER_CONSTANT, 3.14159, (void*) 0, tmp); ++UserDefined::expect.move_ctor; test (__LINE__, bt, true, 'a', INTEGER_CONSTANT, 3.14159, (void*) 0, src); }
static void test_homo_copy_ctor () { rw_info (0, __FILE__, __LINE__, "copy constructor (homogenous tuples)"); std::tuple<> et1, et2 (et1); _RWSTD_UNUSED (et2); const int ci = std::rand (); const std::tuple<int> it1 (ci); std::tuple<int> it2 (it1); test (__LINE__, it2, ci); const std::tuple<const int>& ct1 = it1; // same as copy ctor std::tuple<const int> ct2 (ct1); test (__LINE__, ct2, ci); int i = ci; const std::tuple<int&> rt1 (i); std::tuple<int&> rt2 (rt1); test (__LINE__, rt2, ci); const std::tuple<std::tuple<int> > nt1 (it1); std::tuple<std::tuple<int> > nt2 (nt1); test (__LINE__, nt2, it1); const std::tuple<long, const char*> pt1 (1234567890L, "string"); std::tuple<long, const char*> pt2 (pt1); test (__LINE__, pt2, 1234567890L, (const char*) "string"); UserDefined ud (ci); const std::tuple<UserDefined> ut1 (ud); UserDefined::reset (); std::tuple<UserDefined> ut2 (ut1); ++UserDefined::expect.copy_ctor; test (__LINE__, ut2, ud); const std::tuple<bool, char, int, double, void*, UserDefined> bt1 (true, 'a', ci, 3.14159, (void* const) &i, ud); ++UserDefined::expect.move_ctor; // moved ud to bt1 std::tuple<bool, char, int, double, void*, UserDefined> bt2 (bt1); ++UserDefined::expect.copy_ctor; // copied to bt2 test (__LINE__, bt2, true, 'a', ci, 3.14159, (void* const) &i, ud); }
static int test_argv_type_converter (void) { char *argv[20]; argv[0] = ACE_OS_String::strdup ("one"); argv[1] = ACE_OS_String::strdup ("two"); argv[2] = ACE_OS_String::strdup ("three"); argv[3] = ACE_OS_String::strdup ("four"); argv[4] = 0; char *save_argv[20]; ACE_OS_String::memcpy (save_argv, argv, sizeof (argv)); int argc = 4; { ACE_Argv_Type_Converter ct2 (argc, argv); } { ACE_Argv_Type_Converter ct (argc, argv); ct.get_argc (); ct.get_TCHAR_argv (); consume_arg ( ct.get_argc (), ct.get_TCHAR_argv ()); } { ACE_Argv_Type_Converter ct3 (argc, argv); ct3.get_argc (); ct3.get_ASCII_argv (); consume_arg ( ct3.get_argc (), ct3.get_TCHAR_argv ()); } { for (size_t i = 0; i < 4; i++) ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%d) %C\n"), i, argv[i])); } for (size_t i = 0; save_argv[i]; ++i) ACE_OS_Memory::free (save_argv[i]); return 0; }
int main(int argc, char **argv) { /* On our trusted system we generate a new key * (or read one in) and encrypt the secret data set. */ long m=0, p=2, r=1; // Native plaintext space // Computations will be 'modulo p' long L=16; // Levels long c=3; // Columns in key switching matrix long w=64; // Hamming weight of secret key long d=0; long security = 128; ZZX G; m = FindM(security,L,c,p, d, 0, 0); FHEcontext context(m, p, r); // initialize context buildModChain(context, L, c); // modify the context, adding primes to the modulus chain FHESecKey secretKey(context); // construct a secret key structure const FHEPubKey& publicKey = secretKey; // an "upcast": FHESecKey is a subclass of FHEPubKey //if(0 == d) G = context.alMod.getFactorsOverZZ()[0]; secretKey.GenSecKey(w); // actually generate a secret key with Hamming weight w addSome1DMatrices(secretKey); cout << "Generated key..." << endl; EncryptedArray ea(context, G); // constuct an Encrypted array object ea that is // associated with the given context and the polynomial G long nslots = ea.size(); cout << "Vector Size " << nslots << endl;; vector<long> v1; for(int i = 0 ; i < nslots; i++) { v1.push_back(1); //v1.push_back(i*2); } Ctxt ct1(publicKey); startFHEtimer("ea.encrypt1"); ea.encrypt(ct1, publicKey, v1); stopFHEtimer("ea.encrypt1"); vector<long> v2; Ctxt ct2(publicKey); for(int i = 0 ; i < nslots; i++) { v2.push_back(1); //v2.push_back(i*3); } startFHEtimer("ea.encrypt2"); ea.encrypt(ct2, publicKey, v2); stopFHEtimer("ea.encrypt2"); // v1.mul(v2); // c3.multiplyBy(c2) // ct2.multiplyBy(ct1); // CheckCtxt(ct2, "c3*=c2"); // debugCompare(ea,secretKey,v1,ct2); // On the public (untrusted) system we // can now perform our computation Ctxt ctSum = ct1; Ctxt ctProd = ct1; startFHEtimer("sum"); ctSum += ct2; stopFHEtimer("sum"); //ctProd *= ct2; startFHEtimer("product"); ctProd *= ct2; //ctProd.multiplyBy(ct2); stopFHEtimer("product"); //ea.mat_mul(ctProd,ct2); vector<long> res; startFHEtimer("decryptsum"); ea.decrypt(ctSum, secretKey, res); stopFHEtimer("decryptsum"); //cout << "All computations are modulo " << p << "." << endl; for (unsigned int i = 0; i<res.size(); i++){ cout<< res[i]; } for(unsigned int i = 0; i < res.size(); i++) { cout << v1[i] << " + " << v2[i] << " = " << res[i] << endl; } startFHEtimer("decryptproduct"); ea.decrypt(ctProd, secretKey, res); stopFHEtimer("decryptproduct"); for (unsigned int i = 0; i<res.size(); i++){ cout<< res[i]; } for(unsigned int i = 0; i < res.size(); i++) { cout << v1[i] << " * " << v2[i] << " = " << res[i] << endl; } printAllTimers(); cout << endl; cout << "All computations are modulo " << p << "." << endl; return 0; }