Browse Source

Indexing with OblivIndex

Ian Goldberg 1 year ago
parent
commit
9bfee712cc
3 changed files with 46 additions and 1 deletions
  1. 13 0
      duoram.hpp
  2. 17 1
      online.cpp
  3. 16 0
      shapes.hpp

+ 13 - 0
duoram.hpp

@@ -320,6 +320,14 @@ public:
             res(*this, idx, std::nullopt);
         return res;
     }
+    template <typename U, nbits_t WIDTH>
+    typename Duoram::Shape::template MemRefS<U,T,std::nullopt_t,Flat,WIDTH>
+            operator[](OblivIndex<U,WIDTH> &obidx) {
+        typename Duoram<T>::Shape::
+            template MemRefS<RegXS,T,std::nullopt_t,Flat,1>
+            res(*this, obidx, std::nullopt);
+        return res;
+    }
     typename Duoram::Shape::template MemRefExpl<T,std::nullopt_t>
             operator[](address_t idx) {
         typename Duoram<T>::Shape::
@@ -456,6 +464,11 @@ public:
         oblividx = &(*our_oblividx);
     }
 
+    MemRefS<U,FT,FST,Sh,WIDTH>(Sh &shape, OblivIndex<U,WIDTH> &obidx, FST fieldsel) :
+        shape(shape), fieldsel(fieldsel) {
+        oblividx = &obidx;
+    }
+
     // Create a MemRefExpl for accessing a partcular field of T
     template <typename SFT>
     MemRefS<U,SFT,SFT T::*,Sh,WIDTH> field(SFT T::*subfieldsel) {

+ 17 - 1
online.cpp

@@ -680,6 +680,14 @@ static void duoram_test(MPCIO &mpcio,
         } else {
             N.set(0x0000beef);
         }
+        RegXS oxidx;
+        oxidx.xshare = share+3*tio.player();
+        T O;
+        if (tio.player() == 0) {
+            O.set(0x31410000);
+        } else {
+            O.set(0x00005926);
+        }
         // Writing and reading with additively shared indices
         printf("Additive Updating\n");
         A[aidx] += M;
@@ -690,8 +698,14 @@ static void duoram_test(MPCIO &mpcio,
         A[xidx] += N;
         printf("XOR Reading\n");
         T Ax = A[xidx];
-        T Ae;
+        // Writing and reading with OblivIndex indices
+        typename Duoram<T>::OblivIndex<RegXS,1> oidx(tio, yield, oxidx, depth);
+        printf("OblivIndex Updating\n");
+        A[oidx] += O;
+        printf("OblivIndex Reading\n");
+        T Ox = A[oidx];
         // Writing and reading with explicit indices
+        T Ae;
         if (depth > 2) {
             printf("Explicit Updating\n");
             A[5] += Aa;
@@ -726,10 +740,12 @@ static void duoram_test(MPCIO &mpcio,
         auto checkread = A.reconstruct(Aa);
         auto checkreade = A.reconstruct(Ae);
         auto checkreadx = A.reconstruct(Ax);
+        auto checkreado = A.reconstruct(Ox);
         if (tio.player() == 0) {
             printf("Read AS value = %016lx\n", checkread.share());
             printf("Read AX value = %016lx\n", checkreadx.share());
             printf("Read Ex value = %016lx\n", checkreade.share());
+            printf("Read OI value = %016lx\n", checkreado.share());
         }
         for (auto &v : Av) {
             auto checkv = A.reconstruct(v);

+ 16 - 0
shapes.hpp

@@ -88,6 +88,14 @@ public:
             res(*this, idx, std::nullopt);
         return res;
     }
+    template <typename U, nbits_t WIDTH>
+    typename Duoram::Shape::template MemRefS<U,T,std::nullopt_t,Pad,WIDTH>
+            operator[](OblivIndex<U,WIDTH> &obidx) {
+        typename Duoram<T>::Shape::
+            template MemRefS<RegXS,T,std::nullopt_t,Pad,1>
+            res(*this, obidx, std::nullopt);
+        return res;
+    }
     typename Duoram::Shape::template MemRefExpl<T,std::nullopt_t>
             operator[](address_t idx) {
         typename Duoram<T>::Shape::
@@ -163,6 +171,14 @@ public:
             res(*this, idx, std::nullopt);
         return res;
     }
+    template <typename U, nbits_t WIDTH>
+    typename Duoram::Shape::template MemRefS<U,T,std::nullopt_t,Stride,WIDTH>
+            operator[](OblivIndex<U,WIDTH> &obidx) {
+        typename Duoram<T>::Shape::
+            template MemRefS<RegXS,T,std::nullopt_t,Stride,1>
+            res(*this, obidx, std::nullopt);
+        return res;
+    }
     typename Duoram::Shape::template MemRefExpl<T,std::nullopt_t>
             operator[](address_t idx) {
         typename Duoram<T>::Shape::