Fix Victron CTR nonce length regression (#316) - #317
Merged
Conversation
Reverts the 16-byte padding introduced in #308 back to 8 bytes. pycryptodome's AES.MODE_CTR requires the nonce passed via the nonce= parameter to be shorter than the 16-byte block size, because the remaining bytes are reserved for the counter. A 16-byte nonce leaves no room for the counter and pycryptodome rejects it with "Nonce is too long", so every Victron encrypted advertisement has failed to decrypt since 1.7.0. The "consistency with OMG decryption" rationale of #308 does not apply: the OMG decryptors use AES.MODE_CCM, which has different nonce-length rules from CTR.
cnause
approved these changes
Jun 7, 2026
cnause
left a comment
There was a problem hiding this comment.
Works as expected with my Victron charger
Member
Author
|
@DigiH should we merge this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #316.
VictronDecryptor.compute_nonce()back to padding the nonce to 8 bytes (was changed to 16 in Fully consistent 16 byte long nonce #308).Why the 16-byte padding broke decryption
pycryptodome's
AES.new(..., MODE_CTR, nonce=...)requires the nonce length to be strictly less than the 16-byte AES block size, because the remaining bytes are reserved for the internal counter that CTR mode increments per block. Padding to a full 16 bytes leaves no room for the counter and pycryptodome rejects it withValueError: Nonce is too long, which is exactly the traceback the issue reporter captured:The "consistency with OMG decryption" rationale in #308 does not transfer: the OMG decryptors in this same file use
AES.MODE_CCM(lines 70 and 115), which has different nonce-length rules from CTR. CCM and CTR are not API-compatible on this parameter.Net effect of the regression: every Victron encrypted advertisement has silently failed to decrypt since 1.7.0 (MQTT messages contain
"model": "Victron encrypted"with no decoded fields). Confirmed by the reporter on both Pi 5 and Pi 3B against a Victron Blue Smart IP65 12/25 charger; reverting to 8-byte padding restores all expected fields (volt_batt_1,current_batt_1,device_state,error_code).Test plan
The gateway has no Python test suite to add a regression test to, so verification is manual:
volt_batt_1,device_state, etc.) instead of just"model": "Victron encrypted".Decryption failed/Nonce is too longerrors in the log.Standing up Python test infrastructure for the decryption module is worth doing in a follow-up so this can't silently regress again, but is out of scope for this one-line revert.