Browse Source

New Shape::init() functions that initialize the contents of a Shape

You can pass either a constant (all elements of the shape are
initialized to that constant) or a function f : size_t -> size_t
(element i is initialized to f(i) for each i).  The function f must be
deterministic and public.

The initialization is entirely a local operation; no communication is
done.
Ian Goldberg 2 years ago
parent
commit
593b7845ec
2 changed files with 37 additions and 14 deletions
  1. 34 0
      duoram.hpp
  2. 3 14
      online.cpp

+ 34 - 0
duoram.hpp

@@ -2,6 +2,7 @@
 #define __DUORAM_HPP__
 
 #include <optional>
+#include <functional>
 
 #include "types.hpp"
 #include "mpcio.hpp"
@@ -244,6 +245,39 @@ public:
     // Get the size
     inline size_t size() const { return shape_size; }
 
+    // Initialize the contents of the Shape to a constant.  This method
+    // does no communication; all the operations are local.
+    void init(size_t value) {
+        init([value] (size_t i) { return value; });
+    }
+
+    // Pass a function f: size_t -> size_t, and initialize element i of
+    // the Shape to f(i) for each i.  This method does no communication;
+    // all the operations are local.  This function _must_ be
+    // deterministic.
+    void init(std::function<size_t(size_t)> f) {
+        int player = tio.player();
+        if (player < 2) {
+            for (size_t i=0; i<shape_size; ++i) {
+                auto [DB, BL, PBD] = get_comp(i);
+                BL.set(0);
+                if (player) {
+                    DB.set(f(i));
+                    PBD.set(0);
+                } else {
+                    DB.set(0);
+                    PBD.set(f(i));
+                }
+            }
+        } else {
+            for (size_t i=0; i<shape_size; ++i) {
+                auto [BL0, BL1] = get_server(i);
+                BL0.set(0);
+                BL1.set(0);
+            }
+        }
+    }
+
     // Enable or disable explicit-only mode.  Only using [] with
     // explicit (address_t) indices are allowed in this mode.  Using []
     // with RegAS or RegXS indices will automatically turn off this

+ 3 - 14
online.cpp

@@ -1367,20 +1367,9 @@ static void related(MPCIO &mpcio,
         Duoram<T> oram(tio.player(), size);
         auto A = oram.flat(tio, yield);
 
-        // Initialize A with words with random top halves, and
-        // sequential bottom halves (just so we can more easily eyeball
-        // the right answers)
-        A.explicitonly(true);
-        for (address_t i=0;i<size;++i) {
-            T v;
-            v.randomize();
-            value_t vv = v.share();
-            vv &= 0x3fffffff00000000;
-            vv += (i * tio.player());
-            v.set(vv);
-            A[i] = v;
-        }
-        A.explicitonly(false);
+        // Initialize A with words with sequential top and bottom halves
+        // (just so we can more easily eyeball the right answers)
+        A.init([] (size_t i) { return i * 0x100000001; } );
 
         // We use this layout for the tree:
         // A[0] is unused