Repository navigation
Conversation
decode_structured() cut the expected checksum down to however many characters the input supplied and compared only that prefix, so a checksum group reduced to its identifier compared empty against empty and validated. Require every checksum character to be present and to match, keeping the tolerance for the trailing padding the encoder adds to fill the group.
ronaldtse
left a comment
There was a problem hiding this comment.
Thank you for this fix, @danish293 — the truncated-checksum bypass is real and the analysis is precise: the identifier-only checksum group compared empty against empty and let tampered entropy through validation.
The fix is correct as written: requiring every checksum character to be present closes the bypass, while the trailing group padding the encoder emits remains tolerated by the prefix comparison. The regression test is exactly what this needed — it walks every truncation length from the identifier alone up to the full checksum with a flipped payload character and asserts both validation and decoding fail in each case, then confirms the pristine form still validates.
Verified locally: the new test fails on main at the first truncated-checksum assertion and passes on this branch (338/338 full suite, OpenSSL backend).
Truncated checksum group passes validation
decode_structured()cuts the expected checksum down to however many characters the input supplied and then compares only that prefix, so a checksum group reduced to its identifier character compares empty against empty and the check passes:rnp_entropy_encoding_validate()returnsRNP_SUCCESSandrnp_entropy_decode_human_readable()hands back the corrupted entropy, where the documented result isRNP_ERROR_SIGNATURE_INVALIDwhen the checksum does not match. Keeping one character reduces the check to a single character out ofchecksum_chars(). With the defaults (hex alphabet, 256 entropy bits,group_size4,checksum_bits16),!5973 0333B 11785 ...with one data-group payload character flipped and the checksum group cut to!validates and decodes to the wrong 64 hex characters. The encoder pads the group togroup_size, so trailing padding is still tolerated, but the checksum characters themselves now all have to be present and match.Tested with the OpenSSL backend on macOS arm64,
ENABLE_CRYPTO_REFRESH=ON: the new case intest_ffi_entropy_encoding_roundtripfails on main at the first truncated-checksum assertion and passes with the fix.test_ffi_encrypt_pkand thecli_tests-*legs fail identically before and after on this machine (CAST5 off in this build, no GnuPG installed), so the Botan leg is left to CI.