소스 검색

RDPF pairs (for the server) and triples (for the computational peers)

Ian Goldberg 1 년 전
부모
커밋
8f0ea5629f
3개의 변경된 파일106개의 추가작업 그리고 6개의 파일을 삭제
  1. 17 5
      preproc.cpp
  2. 26 0
      rdpf.cpp
  3. 63 1
      rdpf.hpp

+ 17 - 5
preproc.cpp

@@ -80,9 +80,15 @@ void preprocessing_comp(MPCIO &mpcio, int num_threads, char **args)
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
                             [&](yield_t &yield) {
-                                RegXS ri;
-                                ri.randomize(type);
-                                RDPF rdpf(tio, yield, ri, type);
+                                RDPFTriple rdpftrip(tio, yield, type);
+                                printf("usi0 = %016lx\n", rdpftrip.dpf[0].unit_sum_inverse);
+                                printf("sxr0 = %016lx\n", rdpftrip.dpf[0].scaled_xor.xshare);
+                                printf("usi1 = %016lx\n", rdpftrip.dpf[1].unit_sum_inverse);
+                                printf("sxr1 = %016lx\n", rdpftrip.dpf[1].scaled_xor.xshare);
+                                printf("usi2 = %016lx\n", rdpftrip.dpf[2].unit_sum_inverse);
+                                printf("sxr2 = %016lx\n", rdpftrip.dpf[2].scaled_xor.xshare);
+                                tio.iostream_server() <<
+                                    rdpftrip.dpf[(mpcio.player == 0) ? 1 : 2];
                             });
                     }
                 }
@@ -164,8 +170,14 @@ void preprocessing_server(MPCServerIO &mpcsrvio, int num_threads, char **args)
                         for (unsigned int i=0; i<num; ++i) {
                             coroutines.emplace_back(
                                 [&](yield_t &yield) {
-                                    RegXS ri;
-                                    RDPF rdpf(stio, yield, ri, depth);
+                                    RDPFTriple rdpftrip(stio, yield, depth);
+                                    RDPFPair rdpfpair;
+                                    stio.iostream_p0() >> rdpfpair.dpf[0];
+                                    stio.iostream_p1() >> rdpfpair.dpf[1];
+                                printf("usi0 = %016lx\n", rdpfpair.dpf[0].unit_sum_inverse);
+                                printf("sxr0 = %016lx\n", rdpfpair.dpf[0].scaled_xor.xshare);
+                                printf("usi1 = %016lx\n", rdpfpair.dpf[1].unit_sum_inverse);
+                                printf("sxr1 = %016lx\n", rdpfpair.dpf[1].scaled_xor.xshare);
                                 });
                         }
                     }

+ 26 - 0
rdpf.cpp

@@ -269,3 +269,29 @@ size_t RDPF::size() const
     uint8_t depth = cw.size();
     return size(depth);
 }
+
+// Construct three RDPFs of the given depth all with the same randomly
+// generated target index.
+RDPFTriple::RDPFTriple(MPCTIO &tio, yield_t &yield,
+    nbits_t depth)
+{
+    // Pick a random XOR share of the target
+    xs_target.randomize(depth);
+
+    // Now create three RDPFs with that target, and also convert the XOR
+    // shares of the target to additive shares
+    std::vector<coro_t> coroutines;
+    for (int i=0;i<3;++i) {
+        coroutines.emplace_back(
+            [&, i](yield_t &yield) {
+                printf("Starting DPF %d\n", i);
+                dpf[i] = RDPF(tio, yield, xs_target, depth);
+                printf("Ending DPF %d\n", i);
+            });
+    }
+    coroutines.emplace_back(
+        [&](yield_t &yield) {
+            mpc_xs_to_as(tio, yield, as_target, xs_target, depth);
+        });
+    run_coroutines(yield, coroutines);
+}

+ 63 - 1
rdpf.hpp

@@ -61,8 +61,8 @@ T& operator>>(T &is, RDPF &rdpf)
 {
     is.read((char *)&rdpf.seed, sizeof(rdpf.seed));
     uint8_t depth;
-    assert(depth <= VALUE_BITS);
     is.read((char *)&depth, sizeof(depth));
+    assert(depth <= VALUE_BITS);
     rdpf.cw.clear();
     for (uint8_t i=0; i<depth; ++i) {
         DPFnode cw;
@@ -97,4 +97,66 @@ T& operator<<(T &os, const RDPF &rdpf)
     return os;
 }
 
+// Computational peers will generate triples of RDPFs with the _same_
+// random target for use in Duoram.  They will each hold a share of the
+// target (neither knowing the complete target index).  They will each
+// give one of the DPFs (not a matching pair) to the server, but not the
+// shares of the target index.  So computational peers will hold a
+// RDPFTriple (which includes both an additive and an XOR share of the
+// target index), while the server will hold a RDPFPair (which does
+// not).
+
+struct RDPFTriple {
+    RegAS as_target;
+    RegXS xs_target;
+    RDPF dpf[3];
+
+    RDPFTriple() {}
+
+    // Construct three RDPFs of the given depth all with the same
+    // randomly generated target index.
+    RDPFTriple(MPCTIO &tio, yield_t &yield,
+        nbits_t depth);
+};
+
+// I/O for RDPF Triples
+
+template <typename T>
+T& operator<<(T &os, const RDPFTriple &rdpftrip)
+{
+    os << rdpftrip.dpf[0] << rdpftrip.dpf[1] << rdpftrip.dpf[2];
+    nbits_t depth = rdpftrip.dpf[0].depth();
+    os.write(&rdpftrip.as_target.ashare, BITBYTES(depth));
+    os.write(&rdpftrip.xs_target.xshare, BITBYTES(depth));
+}
+
+template <typename T>
+T& operator>>(T &is, RDPFTriple &rdpftrip)
+{
+    is >> rdpftrip.dpf[0] >> rdpftrip.dpf[1] >> rdpftrip.dpf[2];
+    nbits_t depth = rdpftrip.dpf[0].depth();
+    rdpftrip.as_target.ashare = 0;
+    is.read(&rdpftrip.as_target.ashare, BITBYTES(depth));
+    rdpftrip.xs_target.xshare = 0;
+    is.read(&rdpftrip.xs_target.xshare, BITBYTES(depth));
+}
+
+struct RDPFPair {
+    RDPF dpf[2];
+};
+
+// I/O for RDPF Pairs
+
+template <typename T>
+T& operator<<(T &os, const RDPFPair &rdpfpair)
+{
+    os << rdpfpair.dpf[0] << rdpfpair.dpf[1];
+}
+
+template <typename T>
+T& operator>>(T &is, RDPFPair &rdpfpair)
+{
+    is >> rdpfpair.dpf[0] >> rdpfpair.dpf[1];
+}
+
 #endif