[math] Fix crc8_ccitt discarding the MSB of every input byte - #1371
Open
TudorFanaru18 wants to merge 1 commit into
Open
[math] Fix crc8_ccitt discarding the MSB of every input byte#1371TudorFanaru18 wants to merge 1 commit into
TudorFanaru18 wants to merge 1 commit into
Conversation
The non-AVR path transliterates the avr-libc inline assembly literally:
1: lsl %0 ; shift left, MSB -> CARRY
brcc 2f ; branch on CARRY, i.e. the *pre-shift* MSB
eor %0, %2
`lsl` preserves the departing bit in the carry flag, so `brcc` tests bit 7
of the value before the shift. C has no carry flag: `data <<= 1` on a
uint8_t discards that bit, so the following `if (data & 0x80)` tests the
pre-shift bit 6 instead and bit 7 is never examined.
Over all 32768 (crc, data) pairs this made
crc8_ccitt_update(crc, data) == crc8_ccitt_update(crc, data ^ 0x80)
hold universally, left only 128 of 256 output values reachable, and made
single-bit errors in bit 7 of any byte undetectable.
Adds crc_test, which the module picks up by glob. There were no tests for
this header, which is why the fault went unnoticed; the new suite pins the
published check values for all three functions and asserts that flipping
the MSB of an input byte changes the CRC-8.
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.
Draft: CI fails (by design). The 5 failing assertions in communication/amnb/message_test.cpp are the subject of #1370 : AMNB's test fixtures encode the uncorrected CRC values, so fixing the CRC changes AMNB header CRCs on the wire.
Whether to update the fixtures, note it in the changelog, or bump a protocol version is the open question.
Fixes #1370