Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the bitwise CRC calculation method with a bytewise one #107

Closed
wants to merge 4 commits into from
Closed

Replace the bitwise CRC calculation method with a bytewise one #107

wants to merge 4 commits into from

Conversation

lighterowl
Copy link

Bytewise methods for CRC calculation have much better performance, as I've recently shown in a very simple benchmark, though for a different polynomial.
Here's some proof of concept code which (hopefully) proves that the results are identical.

@smortex
Copy link
Contributor

smortex commented Oct 29, 2019

I would prefer we do not loose how the CRC is computed because it's done in a unusual way (and the documentation is so inaccurate I was lucky to be helped by someone to get it right: feb240e). I know developers relied on the libfreefare code to write support libraries in other languages, I would avoid providing "magic values" to these users.

That being said, we can either have the static values bellow a comment detailing the algorithm used to build that array; or we can build the array the first time the function is called and just use the array after instead of computing each value each time.

@darconeous what do you think?

@darconeous
Copy link
Member

I would add a unit test to confirm that the output is identical for all inputs between the two mechanisms, and add a comment saying that the original bit-by-bit algorithm can be found in the unit test code.

@darconeous darconeous self-requested a review December 11, 2019 19:00
Copy link
Member

@darconeous darconeous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! Your contribution is greatly appreciated, it looks like this will be a significant performance improvement!

libfreefare has a fairly strict unit test policy, so if you could please add a unit test that tests all input values and uses the original algorithm as a benchmark we will get this merged.

@lighterowl
Copy link
Author

@darconeous I moved the original implementation to test_mad.c and provided a simple wrapper function which calls both implementations and asserts that the results are equal.
If you want to actually test all input values (thank goodness it's just a 8-bit CRC!), I can of course add a test like this as well.

@lighterowl lighterowl closed this Dec 10, 2023
@lighterowl lighterowl deleted the use-lut-for-crc branch December 10, 2023 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants