Browse Source

Refactor sort_mtobliv to expose oblivious Waksman-based shuffle in addition to sort

Ian Goldberg 1 year ago
parent
commit
6c221e5ff6
3 changed files with 31 additions and 10 deletions
  1. 21 8
      Enclave/sort.cpp
  2. 7 0
      Enclave/sort.hpp
  3. 3 2
      Makefile

+ 21 - 8
Enclave/sort.cpp

@@ -69,14 +69,12 @@ void sort_precompute_evalplan(uint32_t N, threadid_t nthreads)
     pthread_mutex_unlock(&precomp_eps.mutex);
 }
 
-// Perform the sort using up to nthreads threads.  The items to sort are
-// byte arrays of size msg_size.  The key is the first 4 bytes of each
-// item.
-void sort_mtobliv(threadid_t nthreads, uint8_t* items, uint16_t msg_size,
-    uint32_t Nr, uint32_t Na,
-    // the arguments to the callback are items, the sorted indices, and
-    // the number of non-padding items
-    std::function<void(const uint8_t*, const uint64_t*, uint32_t Nr)> cb)
+// Shuffle Nr items at the beginning of an allocated array of Na items
+// using up to nthreads threads.  The items to shuffle are byte arrays
+// of size msg_size.  Return Nw, the size of the Waksman network we
+// used, which must satisfy Nr <= Nw <= Na.
+uint32_t shuffle_mtobliv(threadid_t nthreads, uint8_t* items, uint16_t msg_size,
+    uint32_t Nr, uint32_t Na)
 {
     // Find the smallest Nw for which we have a precomputed
     // WaksmanNetwork with Nr <= Nw <= Na
@@ -127,6 +125,21 @@ void sort_mtobliv(threadid_t nthreads, uint8_t* items, uint16_t msg_size,
     wn.value().applyInversePermutation<OSWAP_16X>(
         items, msg_size, eval_plan);
 
+    return Nw;
+}
+
+// Perform the sort using up to nthreads threads.  The items to sort are
+// byte arrays of size msg_size.  The key is the 10-bit storage server
+// id concatenated with the 22-bit uid at the storage server.
+void sort_mtobliv(threadid_t nthreads, uint8_t* items, uint16_t msg_size,
+    uint32_t Nr, uint32_t Na,
+    // the arguments to the callback are items, the sorted indices, and
+    // the number of non-padding items
+    std::function<void(const uint8_t*, const uint64_t*, uint32_t Nr)> cb)
+{
+    // Shuffle the items
+    uint32_t Nw = shuffle_mtobliv(nthreads, items, msg_size, Nr, Na);
+
     // Create the indices
     uint64_t *idx = new uint64_t[Nr];
     uint64_t *nextidx = idx;

+ 7 - 0
Enclave/sort.hpp

@@ -34,6 +34,13 @@ size_t sort_precompute(uint32_t N);
 // background thread.
 void sort_precompute_evalplan(uint32_t N, threadid_t nthreads);
 
+// Shuffle Nr items at the beginning of an allocated array of Na items
+// using up to nthreads threads.  The items to shuffle are byte arrays
+// of size msg_size.  Return Nw, the size of the Waksman network we
+// used, which must satisfy Nr <= Nw <= Na.
+uint32_t shuffle_mtobliv(threadid_t nthreads, uint8_t* items, uint16_t msg_size,
+    uint32_t Nr, uint32_t Na);
+
 // Perform the sort using up to nthreads threads.  The items to sort are
 // byte arrays of size msg_size.  The key is the 10-bit storage server
 // id concatenated with the 22-bit uid at the storage server.

+ 3 - 2
Makefile

@@ -294,11 +294,12 @@ Untrusted/Untrusted.o: Untrusted/Untrusted.hpp Enclave/enclave_api.h
 Untrusted/Untrusted.o: Untrusted/Enclave_u.h
 
 Enclave/comms.o: Enclave/Enclave_t.h Enclave/enclave_api.h Enclave/config.hpp
-Enclave/comms.o: Enclave/enclave_api.h Enclave/comms.hpp
+Enclave/comms.o: Enclave/enclave_api.h Enclave/route.hpp Enclave/comms.hpp
 Enclave/config.o: Enclave/Enclave_t.h Enclave/enclave_api.h Enclave/comms.hpp
 Enclave/config.o: Enclave/enclave_api.h Enclave/config.hpp Enclave/route.hpp
 Enclave/route.o: Enclave/Enclave_t.h Enclave/enclave_api.h Enclave/config.hpp
-Enclave/route.o: Enclave/enclave_api.h Enclave/sort.hpp Enclave/route.hpp
+Enclave/route.o: Enclave/enclave_api.h Enclave/sort.hpp Enclave/comms.hpp
+Enclave/route.o: Enclave/route.hpp
 Enclave/sort.o: Enclave/sort.hpp
 Enclave/OblivAlgs/RecursiveShuffle.o: Enclave/OblivAlgs/oasm_lib.h
 Enclave/OblivAlgs/RecursiveShuffle.o: Enclave/OblivAlgs/CONFIG.h