Fake preprocessing for Shamir secret sharing.

This commit is contained in:
Marcel Keller
2019-11-11 22:51:25 +11:00
parent 2b214fe1a1
commit 1e2d73b4ba
6 changed files with 66 additions and 21 deletions

View File

@@ -38,12 +38,16 @@ class ShamirInput : public IndividualInput<T>
{
friend class Shamir<typename T::clear>;
vector<vector<typename T::clear>> vandermonde;
static vector<vector<typename T::clear>> vandermonde;
SeededPRNG secure_prng;
vector<typename T::Scalar> randomness;
public:
static const vector<vector<typename T::clear>>& get_vandermonde(size_t t,
size_t n);
ShamirInput(SubProcessor<T>& proc, ShamirMC<T>& MC) :
IndividualInput<T>(proc)
{

View File

@@ -9,6 +9,9 @@
#include "ShamirInput.h"
#include "Machines/ShamirMachine.h"
template<class T>
vector<vector<typename T::clear>> ShamirInput<T>::vandermonde;
template<class U>
void IndividualInput<U>::reset(int player)
{
@@ -21,6 +24,28 @@ void IndividualInput<U>::reset(int player)
}
}
template<class T>
const vector<vector<typename T::clear>>& ShamirInput<T>::get_vandermonde(
size_t t, size_t n)
{
if (vandermonde.size() < n)
vandermonde.resize(n, vector<typename T::clear>(t));
for (int i = 0; i < int(n); i++)
if (vandermonde[n].size() < t)
{
vandermonde[n].resize(t);
typename T::clear x = 1;
for (size_t j = 0; j < t; j++)
{
x *= (i + 1);
vandermonde[i][j] = x;
}
}
return vandermonde;
}
template<class T>
void ShamirInput<T>::add_mine(const typename T::clear& input, int n_bits)
{
@@ -28,19 +53,7 @@ void ShamirInput<T>::add_mine(const typename T::clear& input, int n_bits)
auto& P = this->P;
int n = P.num_players();
int t = ShamirMachine::s().threshold;
if (vandermonde.empty())
{
vandermonde.resize(n, vector<typename T::clear>(t));
for (int i = 0; i < n; i++)
{
typename T::clear x = 1;
for (int j = 0; j < t; j++)
{
x *= (i + 1);
vandermonde[i][j] = x;
}
}
}
const auto& vandermonde = get_vandermonde(t, n);
randomness.resize(t);
for (auto& x : randomness)

View File

@@ -8,6 +8,7 @@
#include "Protocols/Shamir.h"
#include "Protocols/ShamirInput.h"
#include "Machines/ShamirMachine.h"
template<class T> class ReplicatedPrep;

View File

@@ -37,9 +37,9 @@ class Files
public:
ofstream* outf;
int N;
typename T::mac_type key;
typename T::mac_key_type key;
PRNG G;
Files(int N, const typename T::mac_type& key, const string& prefix) : N(N), key(key)
Files(int N, const typename T::mac_key_type& key, const string& prefix) : N(N), key(key)
{
outf = new ofstream[N];
for (int i=0; i<N; i++)

View File

@@ -5,10 +5,13 @@
#include "Math/gfp.h"
#include "Math/gf2n.h"
#include "Protocols/ShamirInput.hpp"
#include <fstream>
template<class T> class Share;
template<class T> class SemiShare;
template<class T> class ShamirShare;
template<class T, int L> class FixedVec;
namespace GC
@@ -96,6 +99,23 @@ void make_share(FixedVec<T, 2>* Sa, const T& a, int N, const T& key, PRNG& G)
}
}
template<class T>
void make_share(ShamirShare<T>* Sa, const T& a, int N, const T&, PRNG& G)
{
insecure("share generation", false);
const auto& vandermonde = ShamirInput<ShamirShare<T>>::get_vandermonde(N / 2, N);
vector<T> randomness(N / 2);
for (auto& x : randomness)
x.randomize(G);
for (int i = 0; i < N; i++)
{
auto& share = Sa[i];
share = a;
for (int j = 0; j < N / 2; j++)
share += vandermonde[i][j] * randomness[j];
}
}
template<class T, class V>
void check_share(vector<Share<T> >& Sa,
V& value,
@@ -325,7 +345,7 @@ void make_mult_triples(const typename T::mac_key_type& key, int N, int ntrip,
* str = "2" or "p"
*/
template<class T>
void make_inverse(const typename T::mac_type& key, int N, int ntrip, bool zero,
void make_inverse(const typename T::mac_key_type& key, int N, int ntrip, bool zero,
string prep_data_prefix)
{
PRNG G;

View File

@@ -7,6 +7,7 @@
#include "Protocols/BrainShare.h"
#include "Protocols/MaliciousRep3Share.h"
#include "Protocols/SemiShare.h"
#include "Protocols/MaliciousShamirShare.h"
#include "Protocols/fake-stuff.h"
#include "Exceptions/Exceptions.h"
#include "GC/MaliciousRepSecret.h"
@@ -78,7 +79,7 @@ void make_bit_triples(const gf2n& key,int N,int ntrip,Dtype dtype,bool zero)
* str = "2" or "p"
*/
template<class T>
void make_square_tuples(const typename T::mac_type& key,int N,int ntrip,const string& str,bool zero)
void make_square_tuples(const typename T::mac_key_type& key,int N,int ntrip,const string& str,bool zero)
{
(void) str;
@@ -154,7 +155,7 @@ void make_bits(const typename T::mac_key_type& key, int N, int ntrip, bool zero,
*
*/
template<class T>
void make_inputs(const typename T::mac_type& key,int N,int ntrip,const string& str,bool zero)
void make_inputs(const typename T::mac_key_type& key,int N,int ntrip,const string& str,bool zero)
{
(void) str;
@@ -192,7 +193,7 @@ void make_inputs(const typename T::mac_type& key,int N,int ntrip,const string& s
template<class T>
void make_PreMulC(const typename T::mac_type& key, int N, int ntrip, bool zero)
void make_PreMulC(const typename T::mac_key_type& key, int N, int ntrip, bool zero)
{
stringstream ss;
ss << prep_data_prefix << "PreMulC-" << T::type_short();
@@ -220,7 +221,7 @@ void make_PreMulC(const typename T::mac_type& key, int N, int ntrip, bool zero)
}
template<class T>
void make_basic(const typename T::mac_type& key, int nplayers, int nitems, bool zero)
void make_basic(const typename T::mac_key_type& key, int nplayers, int nitems, bool zero)
{
make_mult_triples<T>(key, nplayers, nitems, zero, prep_data_prefix);
make_bits<T>(key, nplayers, nitems, zero);
@@ -542,5 +543,11 @@ int generate(ez::ezOptionParser& opt)
make_mult_triples<GC::TinySecret<40>>(keyt, nplayers, default_num, zero, prep_data_prefix);
make_bits<GC::TinySecret<40>>(keyt, nplayers, default_num, zero);
make_basic<ShamirShare<gfp>>({}, nplayers, default_num, zero);
make_basic<ShamirShare<gf2n>>({}, nplayers, default_num, zero);
make_basic<MaliciousShamirShare<gfp>>({}, nplayers, default_num, zero);
make_basic<MaliciousShamirShare<gf2n>>({}, nplayers, default_num, zero);
return 0;
}