-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from GiacomoPope/restructure
Restructure code into modules
- Loading branch information
Showing
27 changed files
with
129 additions
and
83 deletions.
There are no files selected for viewing
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from ml_kem import ML_KEM128, ML_KEM192, ML_KEM256 | ||
import cProfile | ||
from time import time | ||
|
||
|
||
def profile_ml_kem(ML_KEM): | ||
(ek, dk) = ML_KEM.keygen() | ||
(K, c) = ML_KEM.encaps(ek) | ||
|
||
gvars = {} | ||
lvars = {"ML_KEM": ML_KEM, "c": c, "ek": ek, "dk": dk} | ||
|
||
cProfile.runctx( | ||
"[ML_KEM.keygen() for _ in range(100)]", | ||
globals=gvars, | ||
locals=lvars, | ||
sort=1, | ||
) | ||
cProfile.runctx( | ||
"[ML_KEM.encaps(ek) for _ in range(100)]", | ||
globals=gvars, | ||
locals=lvars, | ||
sort=1, | ||
) | ||
cProfile.runctx( | ||
"[ML_KEM.decaps(c, dk) for _ in range(100)]", | ||
globals=gvars, | ||
locals=lvars, | ||
sort=1, | ||
) | ||
|
||
|
||
def benchmark_ml_kem(ML_KEM, name, count): | ||
keygen_times = [] | ||
enc_times = [] | ||
dec_times = [] | ||
|
||
for _ in range(count): | ||
t0 = time() | ||
ek, dk = ML_KEM.keygen() | ||
keygen_times.append(time() - t0) | ||
|
||
t1 = time() | ||
_, c = ML_KEM.encaps(ek) | ||
enc_times.append(time() - t1) | ||
|
||
t2 = time() | ||
_ = ML_KEM.decaps(c, dk) | ||
dec_times.append(time() - t2) | ||
|
||
avg_keygen = sum(keygen_times) / count | ||
avg_enc = sum(enc_times) / count | ||
avg_dec = sum(dec_times) / count | ||
print( | ||
f" {name:11} |" | ||
f"{avg_keygen*1000:8.2f}ms {1/avg_keygen:11.2f}" | ||
f"{avg_enc*1000:8.2f}ms {1/avg_enc:10.2f}" | ||
f"{avg_dec*1000:8.2f}ms {1/avg_dec:8.2f}" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
count = 1000 | ||
# common banner | ||
print("-" * 80) | ||
print( | ||
" Params | keygen | keygen/s | encap | encap/s " | ||
"| decap | decap/s" | ||
) | ||
print("-" * 80) | ||
benchmark_ml_kem(ML_KEM128, "ML_KEM128", count) | ||
benchmark_ml_kem(ML_KEM192, "ML_KEM192", count) | ||
benchmark_ml_kem(ML_KEM256, "ML_KEM256", count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
aes256\_ctr\_drbg module | ||
drbg module | ||
======================== | ||
|
||
.. automodule:: aes256_ctr_drbg | ||
.. automodule:: drbg | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
utils module | ||
utilities module | ||
============ | ||
|
||
.. automodule:: utils | ||
.. automodule:: utilities | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
from ml_kem import ML_KEM128, ML_KEM192, ML_KEM256 | ||
|
||
|
||
class TestML_KEM(unittest.TestCase): | ||
""" | ||
Test ML_KEM levels for internal | ||
consistency by generating key pairs | ||
and shared secrets. | ||
""" | ||
|
||
def generic_test_ML_KEM(self, ML_KEM, count): | ||
for _ in range(count): | ||
(ek, dk) = ML_KEM.keygen() | ||
for _ in range(count): | ||
(K, c) = ML_KEM.encaps(ek) | ||
K_prime = ML_KEM.decaps(c, dk) | ||
self.assertEqual(K, K_prime) | ||
|
||
def test_ML_KEM128(self): | ||
self.generic_test_ML_KEM(ML_KEM128, 5) | ||
|
||
def test_ML_KEM192(self): | ||
self.generic_test_ML_KEM(ML_KEM192, 5) | ||
|
||
def test_ML_KEM256(self): | ||
self.generic_test_ML_KEM(ML_KEM256, 5) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Empty file.
File renamed without changes.