mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-01-10 05:57:57 -05:00
Document base OT generation.
This commit is contained in:
@@ -116,6 +116,7 @@ void BaseOT::exec_base(bool new_receiver_inputs)
|
||||
exec_base<ref10_SENDER, ref10_RECEIVER>(new_receiver_inputs);
|
||||
}
|
||||
|
||||
// See https://eprint.iacr.org/2015/267.pdf
|
||||
template<class T, class U>
|
||||
void BaseOT::exec_base(bool new_receiver_inputs)
|
||||
{
|
||||
@@ -135,19 +136,24 @@ void BaseOT::exec_base(bool new_receiver_inputs)
|
||||
|
||||
if (ot_role & SENDER)
|
||||
{
|
||||
// Sample a and compute A=g^a
|
||||
sender_genS(&sender, S_pack);
|
||||
// Send A
|
||||
os[0].store_bytes(S_pack, sizeof(S_pack));
|
||||
}
|
||||
send_if_ot_sender(P, os, ot_role);
|
||||
|
||||
if (ot_role & RECEIVER)
|
||||
{
|
||||
// Receive A
|
||||
os[1].get_bytes((octet*) receiver.S_pack, len);
|
||||
if (len != HASHBYTES)
|
||||
{
|
||||
cerr << "Received invalid length in base OT\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Process A
|
||||
receiver_procS(&receiver);
|
||||
receiver_maketable(&receiver);
|
||||
}
|
||||
@@ -160,12 +166,16 @@ void BaseOT::exec_base(bool new_receiver_inputs)
|
||||
{
|
||||
for (j = 0; j < 4 and (i + j) < nOT; j++)
|
||||
{
|
||||
// Process choice bits
|
||||
if (new_receiver_inputs)
|
||||
receiver_inputs[i + j] = G.get_uchar()&1;
|
||||
cs[j] = receiver_inputs[i + j].get();
|
||||
}
|
||||
// Compute B
|
||||
receiver_rsgen(&receiver, Rs_pack[0], cs);
|
||||
// Send B
|
||||
os[0].store_bytes(Rs_pack[0], sizeof(Rs_pack[0]));
|
||||
// Compute k_R
|
||||
receiver_keygen(&receiver, receiver_keys);
|
||||
|
||||
// Copy keys to receiver_outputs
|
||||
@@ -197,12 +207,14 @@ void BaseOT::exec_base(bool new_receiver_inputs)
|
||||
{
|
||||
if (ot_role & SENDER)
|
||||
{
|
||||
// Receive B
|
||||
os[1].get_bytes((octet*) Rs_pack[1], len);
|
||||
if (len != sizeof(Rs_pack[1]))
|
||||
{
|
||||
cerr << "Received invalid length in base OT\n";
|
||||
exit(1);
|
||||
}
|
||||
// Compute k_0 and k_1
|
||||
sender_keygen(&sender, Rs_pack[1], sender_keys);
|
||||
|
||||
// Copy 128 bits of keys to sender_inputs
|
||||
@@ -232,6 +244,7 @@ void BaseOT::exec_base(bool new_receiver_inputs)
|
||||
#endif
|
||||
}
|
||||
|
||||
// Hash with counter to avoid collisions
|
||||
for (int i = 0; i < nOT; i++)
|
||||
{
|
||||
if (ot_role & RECEIVER)
|
||||
@@ -241,6 +254,7 @@ void BaseOT::exec_base(bool new_receiver_inputs)
|
||||
hash_with_id(sender_inputs.at(i).at(j), i);
|
||||
}
|
||||
|
||||
// Set PRG seeds
|
||||
set_seeds();
|
||||
}
|
||||
|
||||
|
||||
29
OT/BaseOT.h
29
OT/BaseOT.h
@@ -27,16 +27,28 @@ const char* role_to_str(OT_ROLE role);
|
||||
void send_if_ot_sender(TwoPartyPlayer* P, vector<octetStream>& os, OT_ROLE role);
|
||||
void send_if_ot_receiver(TwoPartyPlayer* P, vector<octetStream>& os, OT_ROLE role);
|
||||
|
||||
/** Generating and holding a number of base OTs.
|
||||
* @param nOT number of OTs
|
||||
* @param ot_length obsolete (always 128 bits for seeding PRGs)
|
||||
* @param player two-party networking
|
||||
* @param role which role(s) to play
|
||||
*/
|
||||
class BaseOT
|
||||
{
|
||||
/// Hash with counter
|
||||
static void hash_with_id(BitVector& bits, long id);
|
||||
|
||||
public:
|
||||
/// Receiver choice bits
|
||||
BitVector receiver_inputs;
|
||||
/// Sender inputs
|
||||
vector< array<BitVector, 2> > sender_inputs;
|
||||
/// Receiver outputs (according to choice bits)
|
||||
vector<BitVector> receiver_outputs;
|
||||
TwoPartyPlayer* P;
|
||||
/// Number of OTs
|
||||
int nOT, ot_length;
|
||||
/// Which role(s) on this side
|
||||
OT_ROLE ot_role;
|
||||
|
||||
BaseOT(int nOT, int ot_length, TwoPartyPlayer* player, OT_ROLE role=BOTH)
|
||||
@@ -65,6 +77,7 @@ public:
|
||||
|
||||
int length() { return ot_length; }
|
||||
|
||||
/// Set choice bits
|
||||
void set_receiver_inputs(const BitVector& new_inputs)
|
||||
{
|
||||
if ((int)new_inputs.size() != nOT)
|
||||
@@ -72,6 +85,7 @@ public:
|
||||
receiver_inputs = new_inputs;
|
||||
}
|
||||
|
||||
/// Set choice bits
|
||||
void set_receiver_inputs(int128 inputs)
|
||||
{
|
||||
BitVector new_inputs(128);
|
||||
@@ -80,20 +94,31 @@ public:
|
||||
set_receiver_inputs(new_inputs);
|
||||
}
|
||||
|
||||
// do the OTs -- generate fresh random choice bits by default
|
||||
/**
|
||||
* Generate OTs
|
||||
* @param new_receiver_inputs generate fresh random choice bits
|
||||
*/
|
||||
virtual void exec_base(bool new_receiver_inputs=true);
|
||||
// use PRG to get the next ot_length bits
|
||||
|
||||
/// Set the PRG seeds from the input/output strings
|
||||
void set_seeds();
|
||||
|
||||
/// Set the input/output strings from the PRGs
|
||||
void extend_length();
|
||||
|
||||
/// Check the strings by mutually revealing them
|
||||
void check();
|
||||
|
||||
protected:
|
||||
/// Sender-side PRGs
|
||||
vector< array<PRNG, 2> > G_sender;
|
||||
/// Receiver-side PRGs
|
||||
vector<PRNG> G_receiver;
|
||||
|
||||
bool is_sender() { return (bool) (ot_role & SENDER); }
|
||||
bool is_receiver() { return (bool) (ot_role & RECEIVER); }
|
||||
|
||||
/// CPU-specific instantiation of Simplest OT using Curve25519
|
||||
template<class T, class U>
|
||||
void exec_base(bool new_receiver_inputs=true);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user