mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-01-10 05:57:57 -05:00
Security bug: proper accounting for random elements.
This commit is contained in:
@@ -165,6 +165,8 @@ public:
|
||||
virtual T get_bit();
|
||||
/// Get fresh random value in domain
|
||||
virtual T get_random();
|
||||
virtual T get_random_for_open();
|
||||
virtual T get_random_no_count();
|
||||
/// Store fresh daBit in ``a`` (arithmetic part) and ``b`` (binary part)
|
||||
virtual void get_dabit(T& a, typename T::bit_type& b);
|
||||
virtual void get_dabit_no_count(T&, typename T::bit_type&) { throw runtime_error("no daBit"); }
|
||||
@@ -226,6 +228,8 @@ public:
|
||||
static string get_edabit_filename(const Names& N, int n_bits,
|
||||
int thread_num = -1);
|
||||
|
||||
static long additional_inputs(const DataPositions& usage);
|
||||
|
||||
Sub_Data_Files(int my_num, int num_players, const string& prep_data_dir,
|
||||
DataPositions& usage, int thread_num = -1);
|
||||
Sub_Data_Files(const Names& N, DataPositions& usage, int thread_num = -1);
|
||||
@@ -421,6 +425,21 @@ T Preprocessing<T>::get_bit()
|
||||
|
||||
template<class T>
|
||||
T Preprocessing<T>::get_random()
|
||||
{
|
||||
count(DATA_RANDOM);
|
||||
return get_random_no_count();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T Preprocessing<T>::get_random_for_open()
|
||||
{
|
||||
assert(T::randoms_for_opens);
|
||||
count(DATA_OPEN);
|
||||
return get_random_no_count();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T Preprocessing<T>::get_random_no_count()
|
||||
{
|
||||
assert(not usage.inputs.empty());
|
||||
return get_random_from_inputs(usage.inputs.size());
|
||||
|
||||
@@ -187,6 +187,16 @@ Sub_Data_Files<T>::~Sub_Data_Files()
|
||||
delete part;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
long Sub_Data_Files<T>::additional_inputs(const DataPositions& usage)
|
||||
{
|
||||
auto& domain_usage = usage.files[T::clear::field_type()];
|
||||
long add_to_inputs = domain_usage[DATA_RANDOM];
|
||||
if (T::randoms_for_opens)
|
||||
add_to_inputs += domain_usage[DATA_OPEN];
|
||||
return add_to_inputs;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Sub_Data_Files<T>::seekg(DataPositions& pos)
|
||||
{
|
||||
@@ -203,11 +213,15 @@ void Sub_Data_Files<T>::seekg(DataPositions& pos)
|
||||
for (int dtype = 0; dtype < N_DTYPE; dtype++)
|
||||
if (T::clear::allows(Dtype(dtype)))
|
||||
buffers[dtype].seekg(pos.files[field_type][dtype]);
|
||||
|
||||
long add_to_inputs = additional_inputs(pos);
|
||||
|
||||
for (int j = 0; j < num_players; j++)
|
||||
if (j == my_num)
|
||||
my_input_buffers.seekg(pos.inputs[j][field_type]);
|
||||
my_input_buffers.seekg(pos.inputs[j][field_type] + add_to_inputs);
|
||||
else
|
||||
input_buffers[j].seekg(pos.inputs[j][field_type]);
|
||||
input_buffers[j].seekg(pos.inputs[j][field_type] + add_to_inputs);
|
||||
|
||||
for (map<DataTag, long long>::const_iterator it = pos.extended[field_type].begin();
|
||||
it != pos.extended[field_type].end(); it++)
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ void OfflineMachine<W>::generate()
|
||||
dabit<T>(a, b).output(out, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (not (i == DATA_RANDOM or i == DATA_OPEN))
|
||||
{
|
||||
vector<T> tuple(DataPositions::tuple_size[i]);
|
||||
for (long long j = 0;
|
||||
@@ -127,9 +127,12 @@ void OfflineMachine<W>::generate()
|
||||
remove(filename.c_str());
|
||||
}
|
||||
|
||||
long additional_inputs = Sub_Data_Files<T>::additional_inputs(usage);
|
||||
|
||||
for (int i = 0; i < P.num_players(); i++)
|
||||
{
|
||||
auto n_inputs = usage.inputs[i][T::clear::field_type()];
|
||||
auto n_inputs = usage.inputs[i][T::clear::field_type()]
|
||||
+ additional_inputs;
|
||||
string filename = Sub_Data_Files<T>::get_input_filename(playerNames, i, 0);
|
||||
if (n_inputs > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user