Browse Source

Oblivious compare_keys functions for UidPriorityKey and NidPriorityKey

Ian Goldberg 1 year ago
parent
commit
6017495d5e
1 changed files with 28 additions and 0 deletions
  1. 28 0
      Enclave/sort.tcc

+ 28 - 0
Enclave/sort.tcc

@@ -36,6 +36,34 @@ int compare_keys<UidKey>(const void* a, const void* b)
     return oselect_uint32_t(-1, 1, alarge);
     return oselect_uint32_t(-1, 1, alarge);
 }
 }
 
 
+template<>
+int compare_keys<UidPriorityKey>(const void* a, const void* b)
+{
+    uint64_t aup = ((const UidPriorityKey*)a)->uid_priority;
+    uint64_t bup = ((const UidPriorityKey*)b)->uid_priority;
+    uint32_t aidx = ((const UidPriorityKey*)a)->idx;
+    uint32_t bidx = ((const UidPriorityKey*)b)->idx;
+    bool auplarge = (aup > bup);
+    bool aupeq = (aup == bup);
+    bool aidxlarge = (aidx > bidx);
+    bool alarge = auplarge | (aupeq & aidxlarge);
+    return oselect_uint32_t(-1, 1, alarge);
+}
+
+template<>
+int compare_keys<NidPriorityKey>(const void* a, const void* b)
+{
+    uint64_t anp = ((const NidPriorityKey*)a)->nid_priority;
+    uint64_t bnp = ((const NidPriorityKey*)b)->nid_priority;
+    uint32_t aidx = ((const NidPriorityKey*)a)->idx;
+    uint32_t bidx = ((const NidPriorityKey*)b)->idx;
+    bool anplarge = (anp > bnp);
+    bool anpeq = (anp == bnp);
+    bool aidxlarge = (aidx > bidx);
+    bool alarge = anplarge | (anpeq & aidxlarge);
+    return oselect_uint32_t(-1, 1, alarge);
+}
+
 // Perform the sort using up to nthreads threads.  The items to sort are
 // 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
 // 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.
 // id concatenated with the 22-bit uid at the storage server.