Skip to content

Commit

Permalink
fixed broken performance and analysis test
Browse files Browse the repository at this point in the history
  • Loading branch information
PyryL committed Dec 22, 2023
1 parent b8c6d54 commit 0149e59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions analysis/aes_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
times_with_aes = []
times_without_aes = []

for payload_length in test_sample_sizes:
for i, payload_length in enumerate(test_sample_sizes):
payload = randbytes(payload_length)

durations = run_with_aes(payload)
Expand All @@ -18,7 +18,7 @@
durations = run_without_aes(payload)
times_without_aes.append(sum(durations))

print(f"Test {payload_length} completed")
print(f"{(i+1) / len(test_sample_sizes) * 100:.0f}% completed")

# save CSV
with open(path.join(path.dirname(__file__), "aes_comparison.csv"), "w") as file:
Expand All @@ -31,4 +31,5 @@
plt.plot(test_sample_sizes, times_without_aes, marker="x", label="without AES")
plt.xlabel("Payload size, bytes")
plt.ylabel("Encryption + decryption time, seconds")
plt.legend(loc='upper left')
plt.show()
4 changes: 2 additions & 2 deletions perf_tests/test_encryption.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from random import randbytes
from time import time
from kyber.encryption import Encrypt, Decrypt, generate_keys
from kyber.encryption import Encrypt, decrypt, generate_keys
from kyber.constants import k, n, du, dv

def run(payload: bytes) -> tuple[float, float, float]:
Expand All @@ -19,7 +19,7 @@ def run(payload: bytes) -> tuple[float, float, float]:
ciphertext_chunk_size = du*k*n//8 + dv*n//8
restored_payload = bytearray()
for i in range(0, len(ciphertext), ciphertext_chunk_size):
restored_payload += Decrypt(private_key, ciphertext[i:i+ciphertext_chunk_size]).decrypt()
restored_payload += decrypt(private_key, ciphertext[i:i+ciphertext_chunk_size])

t3 = time()

Expand Down

0 comments on commit 0149e59

Please sign in to comment.