From 2677df3bde41b069764b6bd681c6271513dad268 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Thu, 6 Nov 2025 19:55:51 -0600 Subject: [PATCH] Remove examples folder, keep benchmark as pyaegis.benchmark that becomes part of the install. --- examples/aegis256x4_demo.py | 97 ------------------------------ {examples => pyaegis}/benchmark.py | 2 +- 2 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 examples/aegis256x4_demo.py rename {examples => pyaegis}/benchmark.py (98%) diff --git a/examples/aegis256x4_demo.py b/examples/aegis256x4_demo.py deleted file mode 100644 index e5f19ac..0000000 --- a/examples/aegis256x4_demo.py +++ /dev/null @@ -1,97 +0,0 @@ -"""Demonstration script for aegis.aegis256x4 - -Covers: -- encrypt_detached / decrypt_detached -- encrypt / decrypt (attached tag) -- stream_into -- encrypt_unauthenticated_into / decrypt_unauthenticated_into -- MAC (mac_init/update/final/verify) -""" - -import time - -from pyaegis import aegis256x4 as a - - -def hx(b, limit: int | None = None) -> str: - data = bytes(b) - if limit is not None: - data = data[:limit] - return data.hex() - - -def demo(): - print("KEYBYTES:", a.KEYBYTES, "NPUBBYTES:", a.NPUBBYTES) - - key = b"K" * a.KEYBYTES - nonce = b"N" * a.NPUBBYTES - message = b"hello world" - associated_data = b"header" - - # Detached encrypt/decrypt - ciphertext, mac = a.encrypt_detached( - key, nonce, message, associated_data, maclen=16 - ) - plaintext = a.decrypt_detached(key, nonce, ciphertext, mac, associated_data) - print( - "detached enc: c=", - hx(ciphertext), - " mac=", - hx(mac), - " dec_ok=", - plaintext == message, - ) - - # Attached encrypt/decrypt - ciphertext_with_tag = a.encrypt(key, nonce, message, associated_data, maclen=32) - plaintext2 = a.decrypt(key, nonce, ciphertext_with_tag, associated_data, maclen=32) - print( - "attached enc: ct=", hx(ciphertext_with_tag), " dec_ok=", plaintext2 == message - ) - - # Stream generation (None nonce allowed) -> deterministic for a given key - stream = bytearray(64) - a.stream(key, None, into=stream) - print("stream (first 16 bytes):", hx(stream, 16)) - - # Unauthenticated mode round-trip (INSECURE; compatibility only) - c2 = bytearray(len(message)) - a.encrypt_unauthenticated(key, nonce, message, into=c2) - m2 = bytearray(len(message)) - a.decrypt_unauthenticated(key, nonce, c2, into=m2) - print("unauth round-trip ok:", bytes(m2) == message) - - # MAC: compute then verify - mac_state = a.Mac(key, nonce) - mac_state.update(message) - mac32 = mac_state.final(32) - - mac_verify_state = a.Mac(key, nonce) - mac_verify_state.update(message) - try: - mac_verify_state.verify(mac32) - print("mac verify: ok", " mac=", hx(mac32)) - except ValueError: - print("mac verify: failed") - - # Benchmark: unauthenticated encryption of 1 GiB as a single operation - total_bytes = 1 << 30 # 1 GiB - - def bench_unauth_single(total: int): - src = bytearray(total) - dst = bytearray(total) - t0 = time.perf_counter() - a.encrypt_unauthenticated(key, nonce, src, into=dst) - t1 = time.perf_counter() - secs = t1 - t0 - gib = total / float(1 << 30) - gbps = gib / secs if secs > 0 else float("inf") - print( - f"unauth 1GiB bench (single call): size={gib:.3f} GiB, time={secs:.3f} s, throughput={gbps:.2f} GiB/s" - ) - - bench_unauth_single(total_bytes) - - -if __name__ == "__main__": - demo() diff --git a/examples/benchmark.py b/pyaegis/benchmark.py similarity index 98% rename from examples/benchmark.py rename to pyaegis/benchmark.py index 09e4579..a4797ef 100644 --- a/examples/benchmark.py +++ b/pyaegis/benchmark.py @@ -14,7 +14,7 @@ import time from pyaegis import aegis128l, aegis128x2, aegis128x4, aegis256, aegis256x2, aegis256x4 -MSG_LEN = 16384000 # 16 MiB +MSG_LEN = 16384000 # 16 000 KiB ITERATIONS = 100 ALGORITHMS = [