From 3248fccbac67d8ff21e24b88a596c723f92da512 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Thu, 6 Nov 2025 16:27:48 -0600 Subject: [PATCH] The update functions of libaegis now return the same number of bytes that went in. Update the binding accordingly. --- pyaegis/aegis128l.py | 20 ++------------------ pyaegis/aegis128x2.py | 20 ++------------------ pyaegis/aegis128x4.py | 20 ++------------------ pyaegis/aegis256.py | 20 ++------------------ pyaegis/aegis256x2.py | 20 ++------------------ pyaegis/aegis256x4.py | 20 ++------------------ 6 files changed, 12 insertions(+), 108 deletions(-) diff --git a/pyaegis/aegis128l.py b/pyaegis/aegis128l.py index 5372a5d..fbf3075 100644 --- a/pyaegis/aegis128l.py +++ b/pyaegis/aegis128l.py @@ -26,19 +26,6 @@ ALIGNMENT = 32 RATE = 32 -def calc_update_output_size(bytes_in: int, bytes_next: int) -> int: - """Calculate the number of bytes output by the next incremental update. - - Args: - bytes_in: Total number of bytes passed to update so far. - bytes_next: Length of the next input chunk. - - Returns: - Number of bytes that the next update will write. - """ - return (((bytes_in % RATE) + bytes_next) // RATE) * RATE - - def _ptr(buf): return ffi.NULL if buf is None else ffi.from_buffer(buf) @@ -631,8 +618,7 @@ class Encryptor: RuntimeError: If the C update call fails. """ message = memoryview(message) - # Compute exact number of bytes this update can emit (multiple of ALIGNMENT) - expected_out = calc_update_output_size(self._bytes_in, message.nbytes) + expected_out = message.nbytes out = memoryview(into if into is not None else bytearray(expected_out)) if out.nbytes < expected_out: raise TypeError( @@ -812,7 +798,7 @@ class Decryptor: RuntimeError: If the C update call fails. """ ct = memoryview(ct) - expected_out = calc_update_output_size(self._bytes_in, ct.nbytes) + expected_out = ct.nbytes out = into if into is not None else bytearray(expected_out) out = memoryview(out) if out.nbytes < expected_out: @@ -893,8 +879,6 @@ __all__ = [ "TAILBYTES_MAX", "ALIGNMENT", "RATE", - # helpers - "calc_update_output_size", # one-shot functions "encrypt_detached", "decrypt_detached", diff --git a/pyaegis/aegis128x2.py b/pyaegis/aegis128x2.py index 3aa83ea..19342be 100644 --- a/pyaegis/aegis128x2.py +++ b/pyaegis/aegis128x2.py @@ -26,19 +26,6 @@ ALIGNMENT = 64 RATE = 64 -def calc_update_output_size(bytes_in: int, bytes_next: int) -> int: - """Calculate the number of bytes output by the next incremental update. - - Args: - bytes_in: Total number of bytes passed to update so far. - bytes_next: Length of the next input chunk. - - Returns: - Number of bytes that the next update will write. - """ - return (((bytes_in % RATE) + bytes_next) // RATE) * RATE - - def _ptr(buf): return ffi.NULL if buf is None else ffi.from_buffer(buf) @@ -631,8 +618,7 @@ class Encryptor: RuntimeError: If the C update call fails. """ message = memoryview(message) - # Compute exact number of bytes this update can emit (multiple of ALIGNMENT) - expected_out = calc_update_output_size(self._bytes_in, message.nbytes) + expected_out = message.nbytes out = memoryview(into if into is not None else bytearray(expected_out)) if out.nbytes < expected_out: raise TypeError( @@ -812,7 +798,7 @@ class Decryptor: RuntimeError: If the C update call fails. """ ct = memoryview(ct) - expected_out = calc_update_output_size(self._bytes_in, ct.nbytes) + expected_out = ct.nbytes out = into if into is not None else bytearray(expected_out) out = memoryview(out) if out.nbytes < expected_out: @@ -893,8 +879,6 @@ __all__ = [ "TAILBYTES_MAX", "ALIGNMENT", "RATE", - # helpers - "calc_update_output_size", # one-shot functions "encrypt_detached", "decrypt_detached", diff --git a/pyaegis/aegis128x4.py b/pyaegis/aegis128x4.py index ef52bf7..0a1cc89 100644 --- a/pyaegis/aegis128x4.py +++ b/pyaegis/aegis128x4.py @@ -26,19 +26,6 @@ ALIGNMENT = 64 RATE = 128 -def calc_update_output_size(bytes_in: int, bytes_next: int) -> int: - """Calculate the number of bytes output by the next incremental update. - - Args: - bytes_in: Total number of bytes passed to update so far. - bytes_next: Length of the next input chunk. - - Returns: - Number of bytes that the next update will write. - """ - return (((bytes_in % RATE) + bytes_next) // RATE) * RATE - - def _ptr(buf): return ffi.NULL if buf is None else ffi.from_buffer(buf) @@ -631,8 +618,7 @@ class Encryptor: RuntimeError: If the C update call fails. """ message = memoryview(message) - # Compute exact number of bytes this update can emit (multiple of ALIGNMENT) - expected_out = calc_update_output_size(self._bytes_in, message.nbytes) + expected_out = message.nbytes out = memoryview(into if into is not None else bytearray(expected_out)) if out.nbytes < expected_out: raise TypeError( @@ -812,7 +798,7 @@ class Decryptor: RuntimeError: If the C update call fails. """ ct = memoryview(ct) - expected_out = calc_update_output_size(self._bytes_in, ct.nbytes) + expected_out = ct.nbytes out = into if into is not None else bytearray(expected_out) out = memoryview(out) if out.nbytes < expected_out: @@ -893,8 +879,6 @@ __all__ = [ "TAILBYTES_MAX", "ALIGNMENT", "RATE", - # helpers - "calc_update_output_size", # one-shot functions "encrypt_detached", "decrypt_detached", diff --git a/pyaegis/aegis256.py b/pyaegis/aegis256.py index ea7e136..b3a385b 100644 --- a/pyaegis/aegis256.py +++ b/pyaegis/aegis256.py @@ -26,19 +26,6 @@ ALIGNMENT = 16 RATE = 16 -def calc_update_output_size(bytes_in: int, bytes_next: int) -> int: - """Calculate the number of bytes output by the next incremental update. - - Args: - bytes_in: Total number of bytes passed to update so far. - bytes_next: Length of the next input chunk. - - Returns: - Number of bytes that the next update will write. - """ - return (((bytes_in % RATE) + bytes_next) // RATE) * RATE - - def _ptr(buf): return ffi.NULL if buf is None else ffi.from_buffer(buf) @@ -631,8 +618,7 @@ class Encryptor: RuntimeError: If the C update call fails. """ message = memoryview(message) - # Compute exact number of bytes this update can emit (multiple of ALIGNMENT) - expected_out = calc_update_output_size(self._bytes_in, message.nbytes) + expected_out = message.nbytes out = memoryview(into if into is not None else bytearray(expected_out)) if out.nbytes < expected_out: raise TypeError( @@ -812,7 +798,7 @@ class Decryptor: RuntimeError: If the C update call fails. """ ct = memoryview(ct) - expected_out = calc_update_output_size(self._bytes_in, ct.nbytes) + expected_out = ct.nbytes out = into if into is not None else bytearray(expected_out) out = memoryview(out) if out.nbytes < expected_out: @@ -893,8 +879,6 @@ __all__ = [ "TAILBYTES_MAX", "ALIGNMENT", "RATE", - # helpers - "calc_update_output_size", # one-shot functions "encrypt_detached", "decrypt_detached", diff --git a/pyaegis/aegis256x2.py b/pyaegis/aegis256x2.py index 8389caf..ee22ac6 100644 --- a/pyaegis/aegis256x2.py +++ b/pyaegis/aegis256x2.py @@ -26,19 +26,6 @@ ALIGNMENT = 32 RATE = 32 -def calc_update_output_size(bytes_in: int, bytes_next: int) -> int: - """Calculate the number of bytes output by the next incremental update. - - Args: - bytes_in: Total number of bytes passed to update so far. - bytes_next: Length of the next input chunk. - - Returns: - Number of bytes that the next update will write. - """ - return (((bytes_in % RATE) + bytes_next) // RATE) * RATE - - def _ptr(buf): return ffi.NULL if buf is None else ffi.from_buffer(buf) @@ -631,8 +618,7 @@ class Encryptor: RuntimeError: If the C update call fails. """ message = memoryview(message) - # Compute exact number of bytes this update can emit (multiple of ALIGNMENT) - expected_out = calc_update_output_size(self._bytes_in, message.nbytes) + expected_out = message.nbytes out = memoryview(into if into is not None else bytearray(expected_out)) if out.nbytes < expected_out: raise TypeError( @@ -812,7 +798,7 @@ class Decryptor: RuntimeError: If the C update call fails. """ ct = memoryview(ct) - expected_out = calc_update_output_size(self._bytes_in, ct.nbytes) + expected_out = ct.nbytes out = into if into is not None else bytearray(expected_out) out = memoryview(out) if out.nbytes < expected_out: @@ -893,8 +879,6 @@ __all__ = [ "TAILBYTES_MAX", "ALIGNMENT", "RATE", - # helpers - "calc_update_output_size", # one-shot functions "encrypt_detached", "decrypt_detached", diff --git a/pyaegis/aegis256x4.py b/pyaegis/aegis256x4.py index 79392e9..bd4f781 100644 --- a/pyaegis/aegis256x4.py +++ b/pyaegis/aegis256x4.py @@ -26,19 +26,6 @@ ALIGNMENT = 64 RATE = 64 -def calc_update_output_size(bytes_in: int, bytes_next: int) -> int: - """Calculate the number of bytes output by the next incremental update. - - Args: - bytes_in: Total number of bytes passed to update so far. - bytes_next: Length of the next input chunk. - - Returns: - Number of bytes that the next update will write. - """ - return (((bytes_in % RATE) + bytes_next) // RATE) * RATE - - def _ptr(buf): return ffi.NULL if buf is None else ffi.from_buffer(buf) @@ -631,8 +618,7 @@ class Encryptor: RuntimeError: If the C update call fails. """ message = memoryview(message) - # Compute exact number of bytes this update can emit (multiple of ALIGNMENT) - expected_out = calc_update_output_size(self._bytes_in, message.nbytes) + expected_out = message.nbytes out = memoryview(into if into is not None else bytearray(expected_out)) if out.nbytes < expected_out: raise TypeError( @@ -812,7 +798,7 @@ class Decryptor: RuntimeError: If the C update call fails. """ ct = memoryview(ct) - expected_out = calc_update_output_size(self._bytes_in, ct.nbytes) + expected_out = ct.nbytes out = into if into is not None else bytearray(expected_out) out = memoryview(out) if out.nbytes < expected_out: @@ -893,8 +879,6 @@ __all__ = [ "TAILBYTES_MAX", "ALIGNMENT", "RATE", - # helpers - "calc_update_output_size", # one-shot functions "encrypt_detached", "decrypt_detached",