diff --git a/Machines/ShamirMachine.h b/Machines/ShamirMachine.h index cc716105..6a460927 100644 --- a/Machines/ShamirMachine.h +++ b/Machines/ShamirMachine.h @@ -17,8 +17,10 @@ public: int nparties; int threshold; - ShamirOptions(); + ShamirOptions(int nparties = 3, int threshold = 1); ShamirOptions(ez::ezOptionParser& opt, int argc, const char** argv); + + void set_threshold(ez::ezOptionParser& opt); }; class ShamirMachine : public ShamirOptions diff --git a/Machines/ShamirMachine.hpp b/Machines/ShamirMachine.hpp index 19c32db4..f6b79019 100644 --- a/Machines/ShamirMachine.hpp +++ b/Machines/ShamirMachine.hpp @@ -39,8 +39,8 @@ ShamirOptions& ShamirOptions::s() return singleton; } -ShamirOptions::ShamirOptions() : - nparties(3), threshold(1) +ShamirOptions::ShamirOptions(int nparties, int threshold) : + nparties(nparties), threshold(threshold) { } @@ -66,6 +66,12 @@ ShamirOptions::ShamirOptions(ez::ezOptionParser& opt, int argc, const char** arg ); opt.parse(argc, argv); opt.get("-N")->getInt(nparties); + set_threshold(opt); + opt.resetArgs(); +} + +void ShamirOptions::set_threshold(ez::ezOptionParser& opt) +{ if (opt.isSet("-T")) opt.get("-T")->getInt(threshold); else @@ -80,7 +86,6 @@ ShamirOptions::ShamirOptions(ez::ezOptionParser& opt, int argc, const char** arg cerr << "Threshold has to be positive" << endl; exit(1); } - opt.resetArgs(); } template class T> diff --git a/Protocols/ShamirShare.h b/Protocols/ShamirShare.h index 4728cbc0..c84d4175 100644 --- a/Protocols/ShamirShare.h +++ b/Protocols/ShamirShare.h @@ -50,7 +50,11 @@ public: static string type_short() { - return "S" + string(1, clear::type_char()); + auto res = "S" + string(1, clear::type_char()); + auto opts = ShamirOptions::singleton; + if (opts.threshold != (opts.nparties - 1) / 2) + res += "T" + to_string(opts.threshold); + return res; } static string type_string() { diff --git a/Protocols/fake-stuff.hpp b/Protocols/fake-stuff.hpp index e4bae38a..76f28f36 100644 --- a/Protocols/fake-stuff.hpp +++ b/Protocols/fake-stuff.hpp @@ -187,7 +187,7 @@ void make_share(ShamirShare* Sa, const V& a, int N, { auto& share = Sa[i]; share = a; - for (int j = 0; j < (N - 1) / 2; j++) + for (int j = 0; j < ShamirOptions::singleton.threshold; j++) share += vandermonde[i][j] * randomness[j]; } } diff --git a/Utils/Fake-Offline.cpp b/Utils/Fake-Offline.cpp index d406e6f2..1f43ecf8 100644 --- a/Utils/Fake-Offline.cpp +++ b/Utils/Fake-Offline.cpp @@ -34,6 +34,7 @@ #include "Math/Z2k.hpp" #include "Math/gfp.hpp" #include "GC/Secret.hpp" +#include "Machines/ShamirMachine.hpp" #include #include @@ -615,6 +616,16 @@ int main(int argc, const char** argv) "-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.parse(argc, argv); int lgp; @@ -680,6 +691,12 @@ int FakeParams::generate() return 1; } + if (nplayers > 2) + { + ShamirOptions::singleton.nparties = nplayers; + ShamirOptions::singleton.set_threshold(opt); + } + int ntrip2=0, ntripp=0, nbits2=0,nbitsp=0,nsqr2=0,nsqrp=0,ninp2=0,ninpp=0,ninv=0, nbittrip=0, nbitgf2ntrip=0; vector list_options; int lg2, lgp;