Browse Source

Move expansion into LeafInfo

so that we can have one expansion per layer in an expanded incremental DPF
Ian Goldberg 1 year ago
parent
commit
46907324e7
2 changed files with 22 additions and 23 deletions
  1. 6 7
      rdpf.hpp
  2. 16 16
      rdpf.tcc

+ 6 - 7
rdpf.hpp

@@ -57,6 +57,8 @@ struct RDPF : public DPF {
         // XOR share of the scaling values M_xs such that the high words
         // of the WIDTH leaf values for P0 and P1 XOR to M_xs * e_{target}
         std::array<RegXS,WIDTH> scaled_xor;
+        // If we're saving the expansion, put it here
+        std::vector<LeafNode> expansion;
 
         LeafInfo() : unit_sum_inverse(0) {}
     };
@@ -82,9 +84,6 @@ struct RDPF : public DPF {
     // but therefore only the low bit gets used.
     value_t leaf_cfbits;
 
-    // If we're saving the expansion, put it here
-    std::vector<LeafNode> expansion;
-
     RDPF() {}
 
     // Construct a DPF with the given (XOR-shared) target location, and
@@ -104,11 +103,11 @@ struct RDPF : public DPF {
         bool save_expansion = false);
 
     // Do we have a precomputed expansion?
-    inline bool has_expansion() const { return expansion.size() > 0; }
+    inline bool has_expansion() const { return li[0].expansion.size() > 0; }
 
     // Get an element of the expansion
     inline LeafNode get_expansion(address_t index) const {
-        return expansion[index];
+        return li[0].expansion[index];
     }
 
     // The depth
@@ -238,7 +237,7 @@ struct RDPFTriple {
 
     // Do we have a precomputed expansion?
     inline bool has_expansion() const {
-        return dpf[0].expansion.size() > 0;
+        return dpf[0].li[0].expansion.size() > 0;
     }
 
     // Get an element of the expansion
@@ -362,7 +361,7 @@ struct RDPFPair {
 
     // Do we have a precomputed expansion?
     inline bool has_expansion() const {
-        return dpf[0].expansion.size() > 0;
+        return dpf[0].li[0].expansion.size() > 0;
     }
 
     // Get an element of the expansion

+ 16 - 16
rdpf.tcc

@@ -228,9 +228,9 @@ T& operator>>(T &is, RDPF<WIDTH> &rdpf)
         rdpf.cw.push_back(cw);
     }
     if (read_expanded) {
-        rdpf.expansion.resize(1<<depth);
-        is.read((char *)rdpf.expansion.data(),
-            sizeof(rdpf.expansion[0])<<depth);
+        rdpf.li[0].expansion.resize(1<<depth);
+        is.read((char *)rdpf.li[0].expansion.data(),
+            sizeof(rdpf.li[0].expansion[0])<<depth);
     }
     value_t cfbits = 0;
     is.read((char *)&cfbits, BITBYTES(depth-1));
@@ -267,7 +267,7 @@ T& write_maybe_expanded(T &os, const RDPF<WIDTH> &rdpf,
     // If we're writing an expansion, add 64 to depth
     uint8_t expanded_depth = depth;
     bool write_expansion = false;
-    if (expanded && rdpf.expansion.size() == (size_t(1)<<depth)) {
+    if (expanded && rdpf.li[0].expansion.size() == (size_t(1)<<depth)) {
         write_expansion = true;
         expanded_depth += 64;
     }
@@ -276,8 +276,8 @@ T& write_maybe_expanded(T &os, const RDPF<WIDTH> &rdpf,
         os.write((const char *)&rdpf.cw[i], sizeof(rdpf.cw[i]));
     }
     if (write_expansion) {
-        os.write((const char *)rdpf.expansion.data(),
-            sizeof(rdpf.expansion[0])<<depth);
+        os.write((const char *)rdpf.li[0].expansion.data(),
+            sizeof(rdpf.li[0].expansion[0])<<depth);
     }
     os.write((const char *)&rdpf.cfbits, BITBYTES(depth-1));
     nbits_t num_leaflevels = 1;
@@ -849,8 +849,8 @@ RDPF<WIDTH>::RDPF(MPCTIO &tio, yield_t &yield,
             curlevel = nextlevel;
             nextlevel = NULL;
             if (save_expansion && level == depth-1) {
-                expansion.resize(1<<depth);
-                leaflevel = expansion.data();
+                li[0].expansion.resize(1<<depth);
+                leaflevel = li[0].expansion.data();
             } else if (level == depth-1) {
                 leaflevel = new LeafNode[1<<depth];
             } else {
@@ -902,8 +902,8 @@ typename RDPF<WIDTH>::LeafNode
     RDPF<WIDTH>::leaf(address_t input, size_t &aes_ops) const
 {
     // If we have a precomputed expansion, just use it
-    if (expansion.size()) {
-        return expansion[input];
+    if (li[0].expansion.size()) {
+        return li[0].expansion[input];
     }
 
     DPFnode node = seed;
@@ -924,8 +924,8 @@ void RDPF<WIDTH>::expand(size_t &aes_ops)
 {
     nbits_t depth = this->depth();
     size_t num_leaves = size_t(1)<<depth;
-    if (expansion.size() == num_leaves) return;
-    expansion.resize(num_leaves);
+    if (li[0].expansion.size() == num_leaves) return;
+    li[0].expansion.resize(num_leaves);
     address_t index = 0;
     address_t lastindex = 0;
     DPFnode *path = new DPFnode[depth];
@@ -933,8 +933,8 @@ void RDPF<WIDTH>::expand(size_t &aes_ops)
     for (nbits_t i=1;i<depth;++i) {
         path[i] = descend(path[i-1], i-1, 0, aes_ops);
     }
-    expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 0, aes_ops);
-    expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 1, aes_ops);
+    li[0].expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 0, aes_ops);
+    li[0].expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 1, aes_ops);
     while(index < num_leaves) {
         // Invariant: lastindex and index will both be even, and
         // index=lastindex+2
@@ -954,8 +954,8 @@ void RDPF<WIDTH>::expand(size_t &aes_ops)
             path[i+1] = descend(path[i], i, 0, aes_ops);
         }
         lastindex = index;
-        expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 0, aes_ops);
-        expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 1, aes_ops);
+        li[0].expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 0, aes_ops);
+        li[0].expansion[index++] = descend_to_leaf(path[depth-1], depth-1, 1, aes_ops);
     }
 
     delete[] path;