瀏覽代碼

Move defined types into types.hpp and make the basic value type flexible as to whether it is 32 or 64 bits

Ian Goldberg 2 年之前
父節點
當前提交
146cdf32dc
共有 4 個文件被更改,包括 42 次插入11 次删除
  1. 3 3
      Makefile
  2. 3 6
      mpcio.hpp
  3. 3 2
      preproc.cpp
  4. 33 0
      types.hpp

+ 3 - 3
Makefile

@@ -10,9 +10,9 @@ OBJS=oblivds.o mpcio.o preproc.o
 $(BIN): $(OBJS)
 	g++ $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-oblivds.o: preproc.hpp mpcio.hpp
-mpcio.o: mpcio.hpp
-preproc.o: preproc.hpp mpcio.hpp
+oblivds.o: preproc.hpp mpcio.hpp types.hpp
+mpcio.o: mpcio.hpp types.hpp
+preproc.o: preproc.hpp mpcio.hpp types.hpp
 
 clean:
 	-rm -f $(BIN) $(OBJS) *.p[01].t*

+ 3 - 6
mpcio.hpp

@@ -3,23 +3,20 @@
 
 #include <iostream>
 #include <fstream>
-#include <tuple>
 #include <vector>
 #include <deque>
 #include <queue>
 #include <string>
-#include <cstdint>
 
 #include <boost/asio.hpp>
 #include <boost/coroutine2/all.hpp>
 #include <boost/thread.hpp>
 
-using boost::asio::ip::tcp;
+#include "types.hpp"
 
-// Classes to represent stored precomputed data (e.g., multiplicative triples)
+using boost::asio::ip::tcp;
 
-typedef std::tuple<uint64_t, uint64_t, uint64_t> MultTriple;
-typedef std::tuple<uint64_t, uint64_t> HalfTriple;
+// Classes to represent stored precomputed data (e.g., multiplication triples)
 
 template<typename T>
 class PreCompStorage {

+ 3 - 2
preproc.cpp

@@ -1,6 +1,7 @@
 #include <vector>
 #include <bsd/stdlib.h> // arc4random_buf
 
+#include "types.hpp"
 #include "preproc.hpp"
 
 // Open a file for writing with name the given prefix, and ".pX.tY"
@@ -93,7 +94,7 @@ void preprocessing_comp(MPCIO &mpcio, int num_threads, char **args)
 static void create_triples(MPCServerIO &mpcsrvio, unsigned num)
 {
     for (unsigned int i=0; i<num; ++i) {
-        uint64_t X0, Y0, Z0, X1, Y1, Z1;
+        value_t X0, Y0, Z0, X1, Y1, Z1;
         arc4random_buf(&X0, sizeof(X0));
         arc4random_buf(&Y0, sizeof(Y0));
         arc4random_buf(&Z0, sizeof(Z0));
@@ -113,7 +114,7 @@ static void create_triples(MPCServerIO &mpcsrvio, unsigned num)
 static void create_halftriples(MPCServerIO &mpcsrvio, unsigned num)
 {
     for (unsigned int i=0; i<num; ++i) {
-        uint64_t X0, Z0, Y1, Z1;
+        value_t X0, Z0, Y1, Z1;
         arc4random_buf(&X0, sizeof(X0));
         arc4random_buf(&Z0, sizeof(Z0));
         arc4random_buf(&Y1, sizeof(Y1));

+ 33 - 0
types.hpp

@@ -0,0 +1,33 @@
+#ifndef __OBLIVDS_TYPES_HPP__
+#define __OBLIVDS_TYPES_HPP__
+
+#include <tuple>
+#include <cstdint>
+
+#ifndef VALUE_BITS
+#define VALUE_BITS 64
+#endif
+
+// Values in memory are of this type
+
+#if VALUE_BITS == 64
+typedef uint64_t value_t;
+#elif VALUE_BITS == 32
+typedef uint32_t value_t;
+#else
+#error "Unsupported value of VALUE_BITS"
+#endif
+
+// A multiplication triple is a triple (X0,Y0,Z0) held by P0 (and
+// correspondingly (X1,Y1,Z1) held by P1), with all values random,
+// but subject to the relation that X0*Y1 + Y0*X1 = Z0+Z1
+
+typedef std::tuple<value_t, value_t, value_t> MultTriple;
+
+// A half-triple is (X0,Z0) held by P0 (and correspondingly (Y1,Z1) held
+// by P1), with all values random, but subject to the relation that
+// X0*Y1 = Z0+Z1
+
+typedef std::tuple<value_t, value_t> HalfTriple;
+
+#endif