diff --git a/README.md b/README.md index e2bb7f4..fa1756a 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Useful for creating pseudo random bytes as rapidly as possible. Reuse of the sam ### Miscellaneous -Constants (per module): KEYBYTES, NONCEBYTES, MACBYTES, MACBYTES_LONG, RATE, ALIGNMENT +Constants (per module): NAME, KEYBYTES, NONCEBYTES, MACBYTES, MACBYTES_LONG, RATE, ALIGNMENT - random_key() -> bytearray (length KEYBYTES) - random_nonce() -> bytearray (length NONCEBYTES) diff --git a/pyaegis/aegis128l.py b/pyaegis/aegis128l.py index ac2e483..892006c 100644 --- a/pyaegis/aegis128l.py +++ b/pyaegis/aegis128l.py @@ -9,6 +9,7 @@ from ._loader import ffi from ._loader import lib as _lib from .util import Buffer, new_aligned_struct, nonce_increment, wipe +NAME = "AEGIS-128L" #: Algorithm name KEYBYTES = 16 #: Key size in bytes (varies by algorithm) NONCEBYTES = 16 #: Nonce size in bytes (varies by algorithm) MACBYTES = 16 #: Normal MAC size (always 16) @@ -797,6 +798,7 @@ def new_mac_state(): __all__ = [ # constants + "NAME", "KEYBYTES", "NONCEBYTES", "MACBYTES", diff --git a/pyaegis/aegis128x2.py b/pyaegis/aegis128x2.py index 7b1cedb..4d126af 100644 --- a/pyaegis/aegis128x2.py +++ b/pyaegis/aegis128x2.py @@ -9,6 +9,7 @@ from ._loader import ffi from ._loader import lib as _lib from .util import Buffer, new_aligned_struct, nonce_increment, wipe +NAME = "AEGIS-128X2" #: Algorithm name KEYBYTES = 16 #: Key size in bytes (varies by algorithm) NONCEBYTES = 16 #: Nonce size in bytes (varies by algorithm) MACBYTES = 16 #: Normal MAC size (always 16) @@ -797,6 +798,7 @@ def new_mac_state(): __all__ = [ # constants + "NAME", "KEYBYTES", "NONCEBYTES", "MACBYTES", diff --git a/pyaegis/aegis128x4.py b/pyaegis/aegis128x4.py index bde7cb4..93c9561 100644 --- a/pyaegis/aegis128x4.py +++ b/pyaegis/aegis128x4.py @@ -9,6 +9,7 @@ from ._loader import ffi from ._loader import lib as _lib from .util import Buffer, new_aligned_struct, nonce_increment, wipe +NAME = "AEGIS-128X4" #: Algorithm name KEYBYTES = 16 #: Key size in bytes (varies by algorithm) NONCEBYTES = 16 #: Nonce size in bytes (varies by algorithm) MACBYTES = 16 #: Normal MAC size (always 16) @@ -797,6 +798,7 @@ def new_mac_state(): __all__ = [ # constants + "NAME", "KEYBYTES", "NONCEBYTES", "MACBYTES", diff --git a/pyaegis/aegis256.py b/pyaegis/aegis256.py index ce2f2b1..d2ddca9 100644 --- a/pyaegis/aegis256.py +++ b/pyaegis/aegis256.py @@ -9,6 +9,7 @@ from ._loader import ffi from ._loader import lib as _lib from .util import Buffer, new_aligned_struct, nonce_increment, wipe +NAME = "AEGIS-256" #: Algorithm name KEYBYTES = 32 #: Key size in bytes (varies by algorithm) NONCEBYTES = 32 #: Nonce size in bytes (varies by algorithm) MACBYTES = 16 #: Normal MAC size (always 16) @@ -797,6 +798,7 @@ def new_mac_state(): __all__ = [ # constants + "NAME", "KEYBYTES", "NONCEBYTES", "MACBYTES", diff --git a/pyaegis/aegis256x2.py b/pyaegis/aegis256x2.py index 3b56478..ca59070 100644 --- a/pyaegis/aegis256x2.py +++ b/pyaegis/aegis256x2.py @@ -9,6 +9,7 @@ from ._loader import ffi from ._loader import lib as _lib from .util import Buffer, new_aligned_struct, nonce_increment, wipe +NAME = "AEGIS-256X2" #: Algorithm name KEYBYTES = 32 #: Key size in bytes (varies by algorithm) NONCEBYTES = 32 #: Nonce size in bytes (varies by algorithm) MACBYTES = 16 #: Normal MAC size (always 16) @@ -797,6 +798,7 @@ def new_mac_state(): __all__ = [ # constants + "NAME", "KEYBYTES", "NONCEBYTES", "MACBYTES", diff --git a/pyaegis/aegis256x4.py b/pyaegis/aegis256x4.py index 4ba072a..1d9fa93 100644 --- a/pyaegis/aegis256x4.py +++ b/pyaegis/aegis256x4.py @@ -9,6 +9,7 @@ from ._loader import ffi from ._loader import lib as _lib from .util import Buffer, new_aligned_struct, nonce_increment, wipe +NAME = "AEGIS-256X4" #: Algorithm name KEYBYTES = 32 #: Key size in bytes (varies by algorithm) NONCEBYTES = 32 #: Nonce size in bytes (varies by algorithm) MACBYTES = 16 #: Normal MAC size (always 16) @@ -797,6 +798,7 @@ def new_mac_state(): __all__ = [ # constants + "NAME", "KEYBYTES", "NONCEBYTES", "MACBYTES", diff --git a/pyaegis/benchmark.py b/pyaegis/benchmark.py index 24d38cf..394356d 100644 --- a/pyaegis/benchmark.py +++ b/pyaegis/benchmark.py @@ -17,21 +17,12 @@ from pyaegis import aegis128l, aegis128x2, aegis128x4, aegis256, aegis256x2, aeg MSG_LEN = 16384000 # 16 000 KiB ITERATIONS = 100 -ALGORITHMS = [ - ("AEGIS-128L", aegis128l), - ("AEGIS-128X2", aegis128x2), - ("AEGIS-128X4", aegis128x4), - ("AEGIS-256", aegis256), - ("AEGIS-256X2", aegis256x2), - ("AEGIS-256X4", aegis256x4), -] - def _random_bytes(n: int) -> bytes: return os.urandom(n) -def bench_encrypt(alg_name: str, ciph) -> None: +def bench_encrypt(ciph) -> None: key = _random_bytes(ciph.KEYBYTES) nonce = _random_bytes(ciph.NONCEBYTES) @@ -56,10 +47,10 @@ def bench_encrypt(alg_name: str, ciph) -> None: throughput_mbps = ( (bits / (elapsed_s * 1_000_000)) if elapsed_s > 0 else float("inf") ) - print(f"{alg_name}\t{throughput_mbps:10.2f} Mb/s") + print(f"{ciph.NAME}\t{throughput_mbps:10.2f} Mb/s") -def bench_mac(alg_name: str, ciph) -> None: +def bench_mac(ciph) -> None: key = _random_bytes(ciph.KEYBYTES) nonce = _random_bytes(ciph.NONCEBYTES) @@ -83,23 +74,23 @@ def bench_mac(alg_name: str, ciph) -> None: throughput_mbps = ( (bits / (elapsed_s * 1_000_000)) if elapsed_s > 0 else float("inf") ) - print(f"{alg_name} MAC\t{throughput_mbps:10.2f} Mb/s") + print(f"{ciph.NAME} MAC\t{throughput_mbps:10.2f} Mb/s") if __name__ == "__main__": # aegis_init() is called in the loader at import time already # Run encrypt benchmarks in order: 256, 256x2, 256x4, 128l, 128x2, 128x4 - bench_encrypt("AEGIS-256", aegis256) - bench_encrypt("AEGIS-256X2", aegis256x2) - bench_encrypt("AEGIS-256X4", aegis256x4) - bench_encrypt("AEGIS-128L", aegis128l) - bench_encrypt("AEGIS-128X2", aegis128x2) - bench_encrypt("AEGIS-128X4", aegis128x4) + bench_encrypt(aegis256) + bench_encrypt(aegis256x2) + bench_encrypt(aegis256x4) + bench_encrypt(aegis128l) + bench_encrypt(aegis128x2) + bench_encrypt(aegis128x4) # Run MAC benchmarks in order: 128l, 128x2, 128x4, 256, 256x2, 256x4 - bench_mac("AEGIS-128L", aegis128l) - bench_mac("AEGIS-128X2", aegis128x2) - bench_mac("AEGIS-128X4", aegis128x4) - bench_mac("AEGIS-256", aegis256) - bench_mac("AEGIS-256X2", aegis256x2) - bench_mac("AEGIS-256X4", aegis256x4) + bench_mac(aegis128l) + bench_mac(aegis128x2) + bench_mac(aegis128x4) + bench_mac(aegis256) + bench_mac(aegis256x2) + bench_mac(aegis256x4)