2 # This example measures the performance of Path ORAM when
3 # storage is accessed through an SSH client using the Secure
4 # File Transfer Protocol (SFTP).
6 # In order to run this example, you must provide a host
7 # (server) address along with valid login credentials
15 from pyoram.util.misc import MemorySize
16 from pyoram.oblivious_storage.tree.path_oram import \
22 pyoram.config.SHOW_PROGRESS_BAR = True
24 # Set SSH login credentials here
25 # (by default, we pull these from the environment
26 # for testing purposes)
27 ssh_host = os.environ.get('PYORAM_SSH_TEST_HOST')
28 ssh_username = os.environ.get('PYORAM_SSH_TEST_USERNAME')
29 ssh_password = os.environ.get('PYORAM_SSH_TEST_PASSWORD')
31 # Set the storage location and size
32 storage_name = "heap.bin"
35 # one block per bucket in the
36 # storage heap of height 8
37 block_count = 2**(8+1)-1
41 print("Storage Name: %s" % (storage_name))
42 print("Block Count: %s" % (block_count))
43 print("Block Size: %s" % (MemorySize(block_size)))
44 print("Total Memory: %s"
45 % (MemorySize(block_size*block_count)))
46 print("Actual Storage Required: %s"
48 PathORAM.compute_storage_size(
51 storage_type='sftp'))))
54 # Start an SSH client using paramiko
55 print("Starting SSH Client")
56 with paramiko.SSHClient() as ssh:
57 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
58 ssh.load_system_host_keys()
60 username=ssh_username,
61 password=ssh_password)
63 print("Setting Up Path ORAM Storage")
64 setup_start = time.time()
65 with PathORAM.setup(storage_name,
70 ignore_existing=True) as f:
71 print("Total Setup Time: %.2f s"
72 % (time.time()-setup_start))
73 print("Current Stash Size: %s"
75 print("Total Data Transmission: %s"
76 % (MemorySize(f.bytes_sent + f.bytes_received)))
79 # We close the device and reopen it after
80 # setup to reset the bytes sent and bytes
82 with PathORAM(storage_name,
90 start_time = time.time()
91 for t in tqdm.tqdm(list(range(test_count)),
92 desc="Running I/O Performance Test"):
93 f.read_block(random.randint(0,f.block_count-1))
94 stop_time = time.time()
95 print("Current Stash Size: %s"
97 print("Access Block Avg. Data Transmitted: %s (%.3fx)"
98 % (MemorySize((f.bytes_sent + f.bytes_received)/float(test_count)),
99 (f.bytes_sent + f.bytes_received)/float(test_count)/float(block_size)))
100 print("Fetch Block Avg. Latency: %.2f ms"
101 % ((stop_time-start_time)/float(test_count)*1000))
104 if __name__ == "__main__":
105 main() # pragma: no cover