#include "Math/gf2n.h" #include "Math/gfp.h" #include "Protocols/Share.h" #include "Math/Setup.h" #include "Protocols/Spdz2kShare.h" #include "Protocols/BrainShare.h" #include "Protocols/MaliciousRep3Share.h" #include "Protocols/PostSacriRepRingShare.h" #include "Protocols/PostSacriRepFieldShare.h" #include "Protocols/SemiShare.h" #include "Protocols/MaliciousShamirShare.h" #include "Protocols/SpdzWiseRingShare.h" #include "Protocols/SpdzWiseShare.h" #include "Protocols/Rep4Share2k.h" #include "Protocols/MamaShare.h" #include "Protocols/fake-stuff.h" #include "Tools/Exceptions.h" #include "GC/MaliciousRepSecret.h" #include "GC/SemiSecret.h" #include "GC/TinySecret.h" #include "GC/TinierSecret.h" #include "GC/MaliciousCcdSecret.h" #include "GC/Rep4Secret.h" #include "Math/Setup.h" #include "Processor/Data_Files.h" #include "Tools/mkpath.h" #include "Tools/ezOptionParser.h" #include "Tools/benchmarking.h" #include "Protocols/fake-stuff.hpp" #include "Protocols/Shamir.hpp" #include "Protocols/Share.hpp" #include "Processor/Data_Files.hpp" #include "Math/Z2k.hpp" #include "Math/gfp.hpp" #include "GC/Secret.hpp" #include "Machines/Shamir.hpp" #include #include using namespace std; string prep_data_prefix; class FakeParams { int nplayers, default_num; int n_edabits; bool zero; public: ez::ezOptionParser opt; DataPositions usage; template int generate(); template void generate_field(true_type, PRNG& G); template void generate_field(false_type, PRNG&) { } template void generate_ring(PRNG& G); template void make_with_mac_key(int nplayers, int default_num, bool zero,PRNG& G, const KeySetup& bit_keys = {}); template void make_basic(const KeySetup& key, int nplayers, int nitems, bool zero, PRNG& G, const KeySetup& bit_keys = {}); template void make_minimal(const KeySetup& key, int nplayers, int nitems, bool zero, PRNG& G); template void make_mult_triples(const KeySetup& key, int N, int ntrip, bool zero, const string& prep_data_prefix, PRNG& G, int thread_num = -1); template void make_square_tuples(const KeySetup& key, int N, int ntrip, const string& str, bool zero, PRNG& G); template void make_bits(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G, int thread_num = -1); template void make_inverse(const KeySetup& key, int N, int ntrip, bool zero, const string& prep_data_prefix, PRNG& G); template void make_inputs(const KeySetup& key, int N, int ntrip, const string& str, bool zero, PRNG& G); template void make_dabits(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G, const KeySetup& bit_key = { }); template void make_edabits(const KeySetup& key, int N, PRNG& G, false_type, const KeySetup& bit_key = {}); template void make_edabits(const KeySetup&, int, PRNG&, true_type, const KeySetup& = {}) { } template void make_matrix_triples(const KeySetup& key, PRNG& G); template int get_usage(Dtype type, int def) { auto field_type = T::clear::field_type(); if (not usage.empty()) { auto res = usage.files[field_type][type] + BUFFER_SIZE; if (type == DATA_TRIPLE and field_type == DATA_INT) res -= usage.triples_for_matmul(); return limit(res); } else return def; } long long limit(long long demand) { if (opt.isSet("--default") and default_num < demand) return default_num; else return demand; } }; template void FakeParams::make_mult_triples(const KeySetup& key, int N, int ntrip, bool zero, const string& prep_data_prefix, PRNG& G, int thread_num) { ::make_mult_triples(key, N, get_usage(DATA_TRIPLE, ntrip), zero, prep_data_prefix, G, thread_num); } template void FakeParams::make_inverse(const KeySetup& key, int N, int ntrip, bool zero, const string& prep_data_prefix, PRNG& G) { ::make_inverse(key, N, get_usage(DATA_INVERSE, ntrip), zero, prep_data_prefix, G); } /* N = Number players * ntrip = Number tuples needed */ template void FakeParams::make_square_tuples(const KeySetup& key, int N, int ntrip, const string& str, bool zero, PRNG& G) { (void) str; ntrip = get_usage(DATA_SQUARE, ntrip); Files files(N, key, prep_data_prefix, DATA_SQUARE, G); typename T::clear a,c; /* Generate Squares */ for (int i=0; i void FakeParams::make_bits(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G, int thread_num) { ntrip = get_usage(DATA_BIT, ntrip); Files files(N, key, prep_data_prefix, DATA_BIT, G, thread_num); typename T::clear a; /* Generate Bits */ for (int i=0; i void FakeParams::make_dabits(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G, const KeySetup& bit_key) { ntrip = get_usage(DATA_DABIT, ntrip); Files files(N, key, prep_data_prefix, DATA_DABIT, G); for (int i = 0; i < ntrip; i++) { bool bit = not zero && G.get_bit(); files.template output_shares(bit); files.template output_shares::bit_type>(bit, bit_key.key); } } template void FakeParams::make_edabits(const KeySetup& key, int N, PRNG& G, false_type, const KeySetup& bit_key) { vector lengths; opt.get("-e")->getInts(lengths); if (not usage.empty()) { lengths.clear(); for (auto& x : usage.edabits) lengths.push_back(x.first.second); } for (auto length : lengths) { vector filenames; for (int i = 0; i < N; i++) filenames.push_back( PrepBase::get_edabit_filename( get_prep_sub_dir(prep_data_prefix, N), length, i)); Files files(key, filenames, G); bigint value; int max_size = edabitvec::MAX_SIZE; int n; if (usage.empty()) n = DIV_CEIL(n_edabits, max_size); else n = limit(usage.edabits[{false, length}] + usage.edabits[{true, length}]); for (int i = 0; i < n + 1; i++) { vector as; vector bs; plain_edabits(as, bs, length, G, max_size, zero); for (auto& a : as) files.template output_shares(a); for (auto& b : bs) files.template output_shares(b, bit_key.key); } } } /* N = Number players * ntrip = Number inputs needed */ template void FakeParams::make_inputs(const KeySetup& key, int N, int ntrip, const string& str, bool zero, PRNG& G) { (void) str; typename T::open_type a; vector Sa(N); /* Generate Inputs */ for (int player=0; player(DATA_OPEN, 0); ntrip = limit(ntrip) + BUFFER_SIZE; } vector filenames; for (int i=0; i(prep_data_prefix, N), T::type_short(), player, i); filenames.push_back(filename); } Files files(key, filenames, G); for (int i=0; i void make_PreMulC(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G) { stringstream ss; ss << get_prep_sub_dir(prep_data_prefix, N) << "PreMulC-" << T::type_short(); Files files(N, key, ss.str(), G); typename T::clear a, b, c; c = 1; for (int i=0; i void make_AES(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G) { stringstream ss; ss << get_prep_sub_dir(prep_data_prefix, N) << "Sbox-" << T::type_short(); Files files(N, key, ss.str(), G); files.make_AES(ntrip, zero, G); } void FilesBase::make_AES(int ntrip, bool zero, PRNG& G) { auto& files = *this; gf2n_short x; for (int i = 0; i < ntrip; i++) { int mask = 0; if (!zero) mask = G.get_uchar(); expand_byte(x, mask); files.output_shares(x.get()); for (int j = 0; j < 256; j++) { expand_byte(x, sbox[mask ^ j]); files.output_shares(x.get()); } } } // Code for TTP DES vector> des_sbox = { {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}, {15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}, {10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}, {7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}, {2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}, {12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}, {4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}, {13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11} }; template void make_DES(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G) { stringstream ss; ss << get_prep_sub_dir(prep_data_prefix, N) << "SboxDes-" << T::type_short(); Files files(N, key, ss.str(), G); files.make_DES(ntrip, zero, G); } void FilesBase::make_DES(int ntrip, bool zero, PRNG& G) { auto& files = *this; gf2n_short x; for (int i = 0; i < ntrip; i++) { for (int r = 0; r < 8; ++r) { int mask = 0; if (!zero) mask = G.get_uchar(); mask &= 63; //take only first 6 bits expand_byte(x, mask); files.output_shares(x.get()); for (int j = 0; j < 64; j++) { files.output_shares(des_sbox[r][mask ^ j]); } } } } template void make_Sbox(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G, T, true_type) { make_AES(key, N, ntrip, zero, G); make_DES(key, N, ntrip, zero, G); } template void make_Sbox(const KeySetup& key, int N, int ntrip, bool zero, PRNG&, T, false_type) { (void)key, (void)N, (void)ntrip, (void)zero; } template void make_Sbox(const KeySetup& key, int N, int ntrip, bool zero, PRNG& G) { make_Sbox(key, N, ntrip, zero, G, T(), T::clear::characteristic_two); } template void FakeParams::make_matrix_triples(const KeySetup& key, PRNG& G) { for (auto& x : usage.matmuls) if (x.second > 0) { auto& dim = x.first; Files files(nplayers, key, PrepBase::get_matrix_prefix( get_prep_sub_dir(prep_data_prefix, nplayers, true), dim), G); for (int i = 0; i < limit(x.second); i++) { ValueMatrix matrices[3] = {{dim[0], dim[1]}, {dim[1], dim[2]}, {dim[0], dim[2]}}; for (auto& matrix : matrices) matrix.entries.init(); if (zero) { for (int i = 0; i < 2; i++) { for (int j = 0; j < min(matrices[i].n_rows, matrices[i].n_cols); j++) { matrices[i][{j, j}] = 1; } } } else { matrices[0].randomize(G); matrices[1].randomize(G); } matrices[2] = matrices[0] * matrices[1]; for (auto& matrix : matrices) for (auto& value : matrix.entries) files.output_shares(value); } } } template void FakeParams::make_minimal(const KeySetup& key, int nplayers, int nitems, bool zero, PRNG& G) { make_mult_triples(key, nplayers, nitems, zero, prep_data_prefix, G); make_bits(key, nplayers, nitems, zero, G); make_inputs(key, nplayers, nitems, T::type_short(), zero, G); } template void FakeParams::make_basic(const KeySetup& key, int nplayers, int nitems, bool zero, PRNG& G, const KeySetup& bit_key) { make_minimal(key, nplayers, nitems, zero, G); make_square_tuples(key, nplayers, nitems, T::type_short(), zero, G); make_dabits(key, nplayers, nitems, zero, G, bit_key); make_edabits(key, nplayers, G, T::clear::characteristic_two, bit_key); if (not T::clear::characteristic_two) make_matrix_triples(key, G); if (T::clear::invertible) { make_inverse(key, nplayers, nitems, zero, prep_data_prefix, G); if (opt.isSet("-s")) { make_PreMulC(key, nplayers, nitems, zero, G); make_Sbox(key, nplayers, nitems, zero, G); } } } template void FakeParams::make_with_mac_key(int nplayers, int default_num, bool zero, PRNG& G, const KeySetup& bit_keys) { KeySetup keys; generate_mac_keys(keys, nplayers, prep_data_prefix, G); make_basic(keys, nplayers, default_num, zero, G, bit_keys); } template int generate(ez::ezOptionParser& opt); int main(int argc, const char** argv) { insecure_fake(); bigint::init_thread(); FakeParams params; auto& opt = params.opt; opt.syntax = "./Fake-Offline.x [OPTIONS]\n\nOptions with 2 arguments take the form '-X <#gf2n tuples>,<#modp tuples>'"; opt.example = "./Fake-Offline.x 2 -lgp 128 -lg2 128 --default 10000\n./Fake-Offline.x 3 -trip 50000,10000 -btrip 100000\n"; opt.add( "128", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Bit length of GF(p) field (default: 128) and Z_2^k rings (default: 64)", // Help description. "-lgp", // Flag token. "--lgp" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Prime for GF(p) field (default: generated from -lgp argument)", // Help description. "-P", // Flag token. "--prime" // Flag token. ); opt.add( to_string(gf2n::default_degree()).c_str(), // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. ("Bit length of GF(2^n) field (default: " + to_string(gf2n::default_degree()) + ")").c_str(), // Help description. "-lg2", // Flag token. "--lg2" // Flag token. ); opt.add( "1000", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Default number of tuples to generate for ALL data types (default: 1000)", // Help description. "-d", // Flag token. "--default" // Flag token. ); opt.add( "", // Default. 0, // Required? 2, // Number of args expected. ',', // Delimiter if expecting multiple args. "Number of triples, for gf2n / modp types", // Help description. "-trip", // Flag token. "--ntriples" // Flag token. ); opt.add( "", // Default. 0, // Required? 2, // Number of args expected. ',', // Delimiter if expecting multiple args. "Number of random bits, for gf2n / modp types", // Help description. "-bit", // Flag token. "--nbits" // Flag token. ); opt.add( "", // Default. 0, // Required? 2, // Number of args expected. ',', // Delimiter if expecting multiple args. "Number of input tuples, for gf2n / modp types", // Help description. "-inp", // Flag token. "--ninputs" // Flag token. ); opt.add( "", // Default. 0, // Required? 2, // Number of args expected. ',', // Delimiter if expecting multiple args. "Number of square tuples, for gf2n / modp types", // Help description. "-sq", // Flag token. "--nsquares" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Number of inverse tuples (modp only)", // Help description. "-inv", // Flag token. "--ninverses" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Number of GF(2) triples", // Help description. "-btrip", // Flag token. "--nbittriples" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Number of GF(2) x GF(2^n) triples", // Help description. "-mixed", // Flag token. "--nbitgf2ntriples" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Number of edaBits", // Help description. "-eda", // Flag token. "--nedabits" // Flag token. ); opt.add( "", // Default. 0, // Required? 0, // Number of args expected. 0, // Delimiter if expecting multiple args. "Set all values to zero, but not the shares", // Help description. "-z", // Flag token. "--zero" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Generate for SPDZ2k with parameter k (bit length)", // Help description. "-Z", // Flag token. "--spdz2k" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. ("SPDZ2k security parameter (default: " + to_string(SPDZ2K_DEFAULT_SECURITY) + ")").c_str(), // Help description. "-S", // Flag token. "--security" // Flag token. ); opt.add( "", // Default. 0, // Required? -1, // Number of args expected. ',', // Delimiter if expecting multiple args. "edaBit lengths (separate by comma)", // Help description. "-e", // Flag token. "--edabits" // Flag token. ); opt.add( "", // Default. 0, // Required? 0, // Number of args expected. ',', // Delimiter if expecting multiple args. "Special preprocessing", // Help description. "-s", // Flag token. "--special" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Number of corrupted parties for Shamir secret sharing " "(default: just below half)", // Help description. "-T", // Flag token. "--threshold" // Flag token. ); opt.add( "", // Default. 0, // Required? 0, // Number of args expected. 0, // Delimiter if expecting multiple args. "Deactivate Montgomery representation" "(default: activated)", // Help description. "-n", // Flag token. "--nontgomery" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Seed to use for initializing pseudorandom number generator" "(default: seed from /dev/random)", // Help description. "-seed", // Flag token. "--prngseed" // Flag token. ); opt.add( "", // Default. 0, // Required? 1, // Number of args expected. 0, // Delimiter if expecting multiple args. "Compiled program to use for preprocessing requirements", // Help description. "-p", // Flag token. "--program" // Flag token. ); opt.parse(argc, argv); int lgp; opt.get("--lgp")->getInt(lgp); if (opt.isSet("-Z")) { int k, s; opt.get("-Z")->getInt(k); s = SPDZ2K_DEFAULT_SECURITY; if (opt.isSet("-S")) opt.get("-S")->getInt(s); #define X(K, S) if (k == K and s == S) \ return params.generate>(); #ifdef RING_SIZE X(RING_SIZE, SPDZ2K_DEFAULT_SECURITY) #endif X(32, 32) X(64, 64) X(64, 48) #undef X cerr << "Not compiled for " << k << "-bit rings with " << s << "-bit security." << endl << "Add 'X(" << k << "," << s << ")' to line " << (__LINE__ - 4) << " in " << __FILE__ << endl; exit(1); } else params.generate>(); } template int FakeParams::generate() { vector badOptions; string usage; unsigned int i; if(!opt.gotRequired(badOptions)) { for (i=0; i < badOptions.size(); ++i) cerr << "ERROR: Missing required option " << badOptions[i] << "."; opt.getUsage(usage); cout << usage; return 1; } if(!opt.gotExpected(badOptions)) { for(i=0; i < badOptions.size(); ++i) cerr << "ERROR: Got unexpected number of arguments for option " << badOptions[i] << "."; opt.getUsage(usage); cout << usage; return 1; } if (opt.firstArgs.size() == 2) { nplayers = atoi(opt.firstArgs[1]->c_str()); } else if (opt.lastArgs.size() == 1) { nplayers = atoi(opt.lastArgs[0]->c_str()); } else { cerr << "ERROR: invalid number of arguments\n"; opt.getUsage(usage); cout << usage; return 1; } if (nplayers > 2) { ShamirOptions::singleton.nparties = nplayers; ShamirOptions::singleton.set_threshold(opt); } if (opt.isSet("--program")) { Program program(nplayers); string name; opt.get("--program") -> getString(name); BaseMachine machine; program.parse_with_error("Programs/Bytecode/" + name + "-0.bc"); this->usage = program.get_offline_data_used(); } int ntrip2=0, ntripp=0, nbits2=0,nbitsp=0,nsqr2=0,nsqrp=0,ninp2=0,ninpp=0,ninv=0; vector list_options; int lg2, lgp; opt.get("--lgp")->getInt(lgp); opt.get("--lg2")->getInt(lg2); opt.get("--default")->getInt(default_num); ntrip2 = ntripp = nbits2 = nbitsp = nsqr2 = nsqrp = ninp2 = ninpp = ninv = n_edabits = default_num; if (opt.isSet("--ntriples")) { opt.get("--ntriples")->getInts(list_options); ntrip2 = list_options[0]; ntripp = list_options[1]; } if (opt.isSet("--nbits")) { opt.get("--nbits")->getInts(list_options); nbits2 = list_options[0]; nbitsp = list_options[1]; } if (opt.isSet("--ninputs")) { opt.get("--ninputs")->getInts(list_options); ninp2 = list_options[0]; ninpp = list_options[1]; } if (opt.isSet("--nsquares")) { opt.get("--nsquares")->getInts(list_options); nsqr2 = list_options[0]; nsqrp = list_options[1]; } if (opt.isSet("--ninverses")) opt.get("--ninverses")->getInt(ninv); if (opt.isSet("--nedabits")) opt.get("--nedabits")->getInt(n_edabits); zero = opt.isSet("--zero"); if (zero) cout << "Set all values to zero" << endl; // check compatibility gf2n::init_field(lg2); // Initialize PRNG PRNG G; if (opt.isSet("--prngseed")) { std::string seed; opt.get("--prngseed")->getString(seed); if (seed.length() != SEED_SIZE) { cerr << "ERROR: invalid seed length. Must be " << SEED_SIZE << " bytes"; opt.getUsage(usage); cout << usage; return 1; } unsigned char *val = new unsigned char[seed.length()+1]; strcpy((char *)val, seed.c_str()); G.SetSeed(val); delete [] val; } else { G.ReSeed(); } prep_data_prefix = PREP_DIR; // Set up the fields if (opt.isSet("--prime")) { string p; opt.get("--prime")->getString(p); T::clear::init_field(p, not opt.isSet("--nontgomery")); } else { T::clear::init_default(lgp, not opt.isSet("--nontgomery")); } T::clear::template write_setup(nplayers); /* Find number players and MAC keys etc*/ typedef Share sgf2n; KeySetup keyp; KeySetup key2; // create PREP_DIR if not there if (mkdir_p(PREP_DIR) == -1) { cerr << "mkdir_p(" PREP_DIR ") failed\n"; throw file_error(PREP_DIR); } generate_mac_keys(keyp, nplayers, prep_data_prefix, G); generate_mac_keys(key2, nplayers, prep_data_prefix, G); make_mult_triples(key2,nplayers,ntrip2,zero,prep_data_prefix,G); make_mult_triples(keyp,nplayers,ntripp,zero,prep_data_prefix,G); make_bits>(key2,nplayers,nbits2,zero,G); make_bits(keyp,nplayers,nbitsp,zero,G); make_square_tuples(key2,nplayers,nsqr2,"2",zero,G); make_square_tuples(keyp,nplayers,nsqrp,"p",zero,G); make_inputs(key2,nplayers,ninp2,"2",zero,G); make_inputs(keyp,nplayers,ninpp,"p",zero,G); make_inverse(key2,nplayers,ninv,zero,prep_data_prefix,G); if (T::clear::invertible) make_inverse(keyp,nplayers,ninv,zero,prep_data_prefix,G); make_matrix_triples(keyp, G); if (opt.isSet("-s")) { make_PreMulC(key2,nplayers,ninv,zero,G); if (T::clear::invertible) make_PreMulC(keyp,nplayers,ninv,zero,G); make_Sbox(key2,nplayers,ninv,zero,G); } // replicated secret sharing only for three parties if (nplayers == 3) { make_mult_triples({}, nplayers, ntrip2, zero, prep_data_prefix, G); make_bits({}, nplayers, nbits2, zero, G); } else if (nplayers == 4) make_basic>({}, nplayers, default_num, zero, G); make_minimal({}, nplayers, default_num, zero, G); make_mult_triples({}, nplayers, default_num, zero, prep_data_prefix, G); make_bits({}, nplayers, default_num, zero, G); gf2n_short::reset(); gf2n_short::init_field(); KeySetup> keyt; generate_mac_keys>(keyt, nplayers, prep_data_prefix, G); make_minimal>(keyt, nplayers, default_num / 64, zero, G); KeySetup keytt; generate_mac_keys(keytt, nplayers, prep_data_prefix, G); make_minimal(keytt, nplayers, default_num, zero, G); make_dabits(keyp, nplayers, default_num, zero, G, keytt); make_edabits(keyp, nplayers, G, false_type(), keytt); if (T::clear::prime_field) { int n_macs = DIV_CEIL(DEFAULT_SECURITY, T::clear::length() - 1); n_macs = 1 << int(ceil(log2(n_macs))); if (n_macs > 4) n_macs = 10; #define X(N) if (N == n_macs) \ make_with_mac_key>(nplayers, \ default_num, zero, G, keytt); X(1) X(2) X(4) X(10) #undef X } if (nplayers > 2) { make_mult_triples>({}, nplayers, default_num, zero, prep_data_prefix, G); make_bits>({}, nplayers, default_num, zero, G); } generate_field(T::clear::prime_field, G); generate_field(true_type(), G); if (gf2n::degree() != gf2n_short::degree()) generate_field(true_type(), G); // default generate_ring<64>(G); #if defined(RING_SIZE) and RING_SIZE != 64 generate_ring(G); #endif // reuse lgp for simplified interface switch (lgp) { case 64: break; #define X(L) case L: generate_ring(G); break; X(128) X(192) X(256) default: cerr << "Not compiled for " << lgp << "-bit rings." << endl << "Add 'X(" << lgp << "') to line " << (__LINE__ - 2) << " in " << __FILE__ << endl; exit(1); } return 0; } template void FakeParams::generate_field(true_type, PRNG& G) { if (nplayers == 3) { make_basic>({}, nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); make_with_mac_key>>(nplayers, default_num, zero, G); } else if (nplayers == 4) make_basic>({}, nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); if (nplayers > 2) { ShamirShare::bit_type::clear::init_field(); make_basic>({}, nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); make_with_mac_key>>(nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); } } template inline void FakeParams::generate_ring(PRNG& G) { if (nplayers == 3) { make_bits>({}, nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); make_basic>({}, nplayers, default_num, zero, G); make_with_mac_key>(nplayers, default_num, zero, G); } else if (nplayers == 4) make_basic>({}, nplayers, default_num, zero, G); make_basic>>({}, nplayers, default_num, zero, G); if (nplayers > 2) make_basic>>({}, nplayers, default_num, zero, G); }