From a4564f696fa38d2b3f3af62f966bc54b7a0c149d Mon Sep 17 00:00:00 2001 From: DigiH <17110652+DigiH@users.noreply.github.com> Date: Wed, 6 Aug 2025 17:48:40 +0200 Subject: [PATCH] Fully consistent 16 byte long nonce MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For consistency with OMG decryption and general bindkey AES CTR matching. > In Counter (CTR) mode, the nonce (or IV) is combined with a counter that increments with each block of ciphertext being decrypted. The length of the nonce is typically 8 to 16 bytes, depending on the implementation, and pycryptodome allows for nonces of various lengths. > 8-byte IV: Some libraries will accept an 8-byte IV (used as the nonce), then increment the counter automatically. This might work if the library’s implementation is flexible, but this is not universal behaviour. Some libraries will throw an error or expect you to provide a full 16-byte IV. --- TheengsGateway/decryption.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TheengsGateway/decryption.py b/TheengsGateway/decryption.py index 89469cfb..7e5ece36 100644 --- a/TheengsGateway/decryption.py +++ b/TheengsGateway/decryption.py @@ -140,9 +140,9 @@ class VictronDecryptor(AdvertisementDecryptor): def compute_nonce(self, address: str, decoded_json: dict) -> bytes: """Get the nonce from a specific address and JSON input.""" - # The nonce is provided in the message and needs to be padded to 8 bytes + # The nonce is provided in the message and needs to be padded to 16 bytes nonce = bytes.fromhex(decoded_json["ctr"]) - nonce = nonce.ljust(8, b"\x00") # Pad to 8 bytes with zeros + nonce = nonce.ljust(16, b"\x00") # Pad to 16 bytes with zeros return nonce def decrypt(