Browse Source

Templatize SelectTriple so that it can be used for value_t and bit_t, not just DPFnode

Ian Goldberg 1 year ago
parent
commit
a281346bb1
3 changed files with 13 additions and 11 deletions
  1. 3 3
      mpcio.cpp
  2. 1 1
      mpcio.hpp
  3. 9 7
      types.hpp

+ 3 - 3
mpcio.cpp

@@ -650,9 +650,9 @@ HalfTriple MPCTIO::halftriple(yield_t &yield, bool tally)
     return val;
 }
 
-SelectTriple MPCTIO::nodeselecttriple(yield_t &yield)
+SelectTriple<DPFnode> MPCTIO::nodeselecttriple(yield_t &yield)
 {
-    SelectTriple val;
+    SelectTriple<DPFnode> val;
     if (mpcio.player < 2) {
         MPCPeerIO &mpcpio = static_cast<MPCPeerIO&>(mpcio);
         if (mpcpio.mode != MODE_ONLINE) {
@@ -663,7 +663,7 @@ SelectTriple MPCTIO::nodeselecttriple(yield_t &yield)
             recv_server(&val.Y, sizeof(val.Y));
             recv_server(&val.Z, sizeof(val.Z));
         } else {
-            std::cerr << "Attempted to read SelectTriple in online phase\n";
+            std::cerr << "Attempted to read SelectTriple<DPFnode> in online phase\n";
         }
     } else if (mpcio.mode != MODE_ONLINE) {
         // Create triples (X0,Y0,Z0),(X1,Y1,Z1) such that

+ 1 - 1
mpcio.hpp

@@ -372,7 +372,7 @@ public:
 
     MultTriple multtriple(yield_t &yield);
     HalfTriple halftriple(yield_t &yield, bool tally=true);
-    SelectTriple nodeselecttriple(yield_t &yield);
+    SelectTriple<DPFnode> nodeselecttriple(yield_t &yield);
 
     // These ones only work during the online phase
     // Computational peers call:

+ 9 - 7
types.hpp

@@ -620,17 +620,19 @@ struct HalfTripleName { static constexpr const char *name = "h"; };
 
 using DPFnode = __m128i;
 
-// A Select triple is a triple of (X0,Y0,Z0) where X0 is a bit and Y0
-// and Z0 are DPFnodes held by P0 (and correspondingly (X1,Y1,Z1) held
-// by P1), with all values random, but subject to the relation that
-// (X0*Y1) ^ (Y0*X1) = Z0^Z1.  These are only used while creating RDPFs
-// in the preprocessing phase, so we never need to store them.  This is
-// a struct instead of a tuple for alignment reasons.
+// A Select triple for type V (V is DPFnode, value_t, or bit_t) is a
+// triple of (X0,Y0,Z0) where X0 is a bit and Y0 and Z0 are Vs held by
+// P0 (and correspondingly (X1,Y1,Z1) held by P1), with all values
+// random, but subject to the relation that (X0*Y1) ^ (Y0*X1) = Z0^Z1.
+// This is a struct instead of a tuple for alignment reasons.
 
+template <typename V>
 struct SelectTriple {
     bit_t X;
-    DPFnode Y, Z;
+    V Y, Z;
 };
+// Of the three options for V, we only ever store V = value_t
+struct ValSelectTripleName { static constexpr const char *name = "s"; };
 
 // These are defined in rdpf.hpp, but declared here to avoid cyclic
 // header dependencies.