From 06aab4a377a77237260d09cf3a28cdc5b2c6e548 Mon Sep 17 00:00:00 2001 From: Emil Lenngren Date: Wed, 21 Sep 2022 14:24:26 +0200 Subject: [PATCH] espsecure: Run AES-XTS encryption in O(n) instead of O(n^2) time complexity --- espsecure/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/espsecure/__init__.py b/espsecure/__init__.py index 35a3cbafd..33d08da63 100755 --- a/espsecure/__init__.py +++ b/espsecure/__init__.py @@ -1050,7 +1050,7 @@ def _flash_encryption_operation_aes_xts( inblocks = _split_blocks(indata, 0x80) # split into 1024 bit blocks - output = b"" + output = [] for inblock in inblocks: # for each block tweak = struct.pack(" 0: - yield text[0:block_len] - text = text[block_len:] + pos = 0 + while pos < len(text): + yield text[pos : pos + block_len] + pos = pos + block_len def decrypt_flash_data(args):