Bläddra i källkod

Start on the Duoram implementation

Ian Goldberg 2 år sedan
förälder
incheckning
bd0cab0198
4 ändrade filer med 105 tillägg och 1 borttagningar
  1. 1 1
      Makefile
  2. 62 0
      duoram.hpp
  3. 15 0
      duoram.tcc
  4. 27 0
      online.cpp

+ 1 - 1
Makefile

@@ -32,7 +32,7 @@ mpcio.o: mpcio.hpp types.hpp rdpf.hpp coroutine.hpp bitutils.hpp rdpf.tcc
 preproc.o: types.hpp coroutine.hpp mpcio.hpp preproc.hpp options.hpp rdpf.hpp
 preproc.o: bitutils.hpp rdpf.tcc
 online.o: online.hpp mpcio.hpp types.hpp options.hpp mpcops.hpp coroutine.hpp
-online.o: rdpf.hpp bitutils.hpp rdpf.tcc
+online.o: rdpf.hpp bitutils.hpp rdpf.tcc duoram.hpp duoram.tcc
 mpcops.o: mpcops.hpp types.hpp mpcio.hpp coroutine.hpp bitutils.hpp
 rdpf.o: rdpf.hpp mpcio.hpp types.hpp coroutine.hpp bitutils.hpp rdpf.tcc
 rdpf.o: mpcops.hpp aes.hpp prg.hpp

+ 62 - 0
duoram.hpp

@@ -0,0 +1,62 @@
+#ifndef __DUORAM_HPP__
+#define __DUORAM_HPP__
+
+// Implementation of the 3-party protocols described in:
+// Adithya Vadapalli, Ryan Henry, Ian Goldberg, "Duoram: A
+// Bandwidth-Efficient Distributed ORAM for 2- and 3-Party Computation".
+
+// A Duoram object is like physical memory: it's just a flat address
+// space, and you can't access it directly.  Instead, you need to access
+// it through a "Shape", such as Flat, Tree, Path, etc.  Shapes can be
+// nested, so you can have a Path of a Subtree of a Tree sitting on the
+// base Duoram.  Each Shape's parent must remain in scope (references to
+// it must remain valid) for the lifetime of the child Shapre.  Each
+// shape is bound to a context, which is a thread-specific MPCTIO and a
+// coroutine-specific yield_t.  If you launch new threads and/or
+// coroutines, you'll need to make a copy of the current Shape for your
+// new context, and call set_context() on it.  Be sure not to call
+// set_content() on a Shape shared with other threads or coroutines.
+
+// This is templated, because you can have a Duoram of additively shared
+// (RegAS) or XOR shared (RegXS) elements, or std::arrays of those to
+// get "wide" memory cells.
+
+// The initial implementation is focused on additive shares.
+
+template <typename T>
+class Duoram {
+    // The computational parties have three vectors: the share of the
+    // database itself, the party's own blinding factors for its
+    // database share, and the _other_ computational party's blinded
+    // database share (its database share plus its blind).
+
+    // The player number (0 and 1 for the computational parties and 2
+    // for the server) and the size of the Duoram
+    int player;
+    size_t oram_size;
+
+    // The server has two vectors: a copy of each computational party's
+    // blind.  The database vector will remain empty.
+
+    std::vector<T> database;         // computational parties only
+
+    std::vector<T> blind;            // computational parties use this name
+    std::vector<T> &p0_blind;        // server uses this name
+
+    std::vector<T> peer_blinded_db;  // computational parties
+    std::vector<T> &p1_blind;        // server
+
+public:
+    // The type of this Duoram
+    using type = T;
+
+    // Pass the player number and desired size
+    Duoram(int player, size_t size);
+
+    // Get the size
+    inline size_t size() { return oram_size; }
+};
+
+#include "duoram.tcc"
+
+#endif

+ 15 - 0
duoram.tcc

@@ -0,0 +1,15 @@
+// Templated method implementations for duoram.hpp
+
+// Pass the player number and desired size
+template <typename T>
+Duoram<T>::Duoram(int player, size_t size) : player(player),
+        oram_size(size), p0_blind(blind), p1_blind(peer_blinded_db) {
+    if (player < 2) {
+        database.resize(size);
+        blind.resize(size);
+        peer_blinded_db.resize(size);
+    } else {
+        p0_blind.resize(size);
+        p1_blind.resize(size);
+    }
+}

+ 27 - 0
online.cpp

@@ -3,6 +3,7 @@
 #include "online.hpp"
 #include "mpcops.hpp"
 #include "rdpf.hpp"
+#include "duoram.hpp"
 
 
 static void online_test(MPCIO &mpcio, const PRACOptions &opts, char **args)
@@ -407,6 +408,29 @@ static void tupleeval_timing(MPCIO &mpcio, const PRACOptions &opts, char **args)
     pool.join();
 }
 
+static void duoram_test(MPCIO &mpcio, const PRACOptions &opts, char **args)
+{
+    nbits_t depth=6;
+
+    if (*args) {
+        depth = atoi(*args);
+        ++args;
+    }
+
+    int num_threads = opts.num_threads;
+    boost::asio::thread_pool pool(num_threads);
+    for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
+        boost::asio::post(pool, [&mpcio, thread_num, depth] {
+            MPCTIO tio(mpcio, thread_num);
+            // size_t &op_counter = tio.aes_ops();
+            Duoram<RegAS> oram(mpcio.player, size_t(1)<<depth);
+            printf("%ld\n", oram.size());
+            tio.send();
+        });
+    }
+    pool.join();
+}
+
 void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args)
 {
     if (!*args) {
@@ -430,6 +454,9 @@ void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args)
     } else if (!strcmp(*args, "tupletime")) {
         ++args;
         tupleeval_timing(mpcio, opts, args);
+    } else if (!strcmp(*args, "duotest")) {
+        ++args;
+        duoram_test(mpcio, opts, args);
     } else {
         std::cerr << "Unknown mode " << *args << "\n";
     }