ソースを参照

Reading and writing with explicit indices

Ian Goldberg 2 年 前
コミット
c3c771899f
3 ファイル変更75 行追加2 行削除
  1. 6 0
      duoram.hpp
  2. 59 0
      duoram.tcc
  3. 10 2
      online.cpp

+ 6 - 0
duoram.hpp

@@ -261,6 +261,12 @@ class Duoram<T>::Shape::MemRefExpl {
 public:
     MemRefExpl(const Shape &shape, address_t idx) :
         shape(shape), idx(idx) {}
+
+    // Explicit read from a given index of Duoram memory
+    operator T();
+
+    // Explicit update to a given index of Duoram memory
+    MemRefExpl &operator+=(const T& M);
 };
 
 #include "duoram.tcc"

+ 59 - 0
duoram.tcc

@@ -199,6 +199,8 @@ Duoram<T>::Shape::MemRefAS::operator T()
         // Send the cancellation terms to the computational players
         shape.tio.iostream_p0() << gamma0;
         shape.tio.iostream_p1() << gamma1;
+
+        shape.yield();
     }
     return res;  // The server will always get 0
 }
@@ -288,3 +290,60 @@ typename Duoram<T>::Shape::MemRefAS
     }
     return *this;
 }
+
+// Explicit read from a given index of Duoram memory
+template <typename T>
+Duoram<T>::Shape::MemRefExpl::operator T()
+{
+    T res;
+    int player = shape.tio.player();
+    if (player < 2) {
+        res = std::get<0>(shape.get_comp(idx));
+    }
+    return res;  // The server will always get 0
+}
+
+// Explicit update to a given index of Duoram memory
+template <typename T>
+typename Duoram<T>::Shape::MemRefExpl
+    &Duoram<T>::Shape::MemRefExpl::operator+=(const T& M)
+{
+    int player = shape.tio.player();
+    if (player < 2) {
+        // Computational players do this
+
+        // Pick a blinding factor
+        T blind;
+        blind.randomize();
+
+        // Send the blind to the server, and the blinded value to the
+        // peer
+        shape.tio.iostream_server() << blind;
+        shape.tio.iostream_peer() << (M + blind);
+
+        shape.yield();
+
+        // Receive the peer's blinded value
+        T peerblinded;
+        shape.tio.iostream_peer() >> peerblinded;
+
+        // Our database, our blind, the peer's blinded database
+        auto [ DB, BL, PBD ] = shape.get_comp(idx);
+        DB += M;
+        BL += blind;
+        PBD += peerblinded;
+    } else if (player == 2) {
+        // The server does this
+
+        // Receive the updates to the blinds
+        T p0blind, p1blind;
+        shape.tio.iostream_p0() >> p0blind;
+        shape.tio.iostream_p1() >> p1blind;
+
+        // The two computational parties' blinds
+        auto [ BL0, BL1 ] = shape.get_server(idx);
+        BL0 += p0blind;
+        BL1 += p1blind;
+    }
+    return *this;
+}

+ 10 - 2
online.cpp

@@ -452,12 +452,18 @@ static void duoram_test(MPCIO &mpcio, yield_t &yield,
             RegXS xidx;
             xidx.xshare = share;
             size_t eidx = share;
+            // Writing and reading with additively shared indices
             printf("Updating\n");
             A[aidx] += M;
             printf("Reading\n");
             T Aa = A[aidx];
+            T Ae;
+            // Writing and reading with explicit indices
+            if (depth > 2) {
+                A[5] += Aa;
+                Ae = A[6];
+            }
             auto Ax = A[xidx];
-            auto Ae = A[eidx];
             if (depth <= 10) {
                 oram.dump();
                 auto check = A.reconstruct();
@@ -468,8 +474,10 @@ static void duoram_test(MPCIO &mpcio, yield_t &yield,
                 }
             }
             auto checkread = A.reconstruct(Aa);
+            auto checkreade = A.reconstruct(Ae);
             if (tio.player() == 0) {
-                printf("Read value = %016lx\n", checkread.share());
+                printf("Read AS value = %016lx\n", checkread.share());
+                printf("Read Ex value = %016lx\n", checkreade.share());
             }
             tio.send();
         });