Skip to content

CRC/Checksum Support #87

@AaronWebster

Description

@AaronWebster

This issue was copied from the upstream repository google/emboss.

Original issue: google#31
Original state: open, created at: 2022-02-15T23:11:57Z, updated at: 2024-12-18T23:14:41Z, by @reventlov


Original description

CRCs and checksums are common enough that there should be built-in support for verifying and setting CRCs/checksums to the correct value. One possible implementation would be $crc(range : UInt:8[]) and $checksum(range : UInt:8[]) functions which can be used in [requires].


Discussion (copied comments)

Comment by @AaronWebster on 2022-03-14T17:52:47Z:

Would be useful if the type could be specified, e.g. $checksum(type : CRC32C, range : UInt:8[]). Maybe more useful if Emboss had a way of supporting a type whose value was computed using a user-defined function.


Comment by @reventlov on 2022-03-14T19:44:32Z:

I was thinking $crc() and $checksum() specifically so that you don't have to specify which algorithm as a parameter. User-defined functions would be nice, but a much bigger feature to design.

$crc() should have an optional parameter for the polynomial, though. Probably default to the IEEE polynomial, at least for CRC-32.

We also need some way to specify how many bits are in the CRC/checksum.


Comment by @AaronWebster on 2022-03-15T17:28:34Z:

pycrc might be a good fit using its c code generator. Supports arbitrary polynomials/bits/endianness/etc.


Comment by @reventlov on 2022-03-15T20:50:24Z:

Something like CRC_t is probably better: a C++ template takes advantage of the C++ compiler to avoid having multiple copies of the same code or extra unneeded code in the final binary, even across translation units.

We would need to import a copy and shove it into a different namespace to avoid potential version skew between the copy in Emboss and a copy that happens to be used in application code.

Also, it would be good to add some options to the C++ backend or site_defines.h to allow applications to pick their own implementation. I assume a lot of embedded projects will already have a CRC library somewhere; we should use theirs when possible instead of adding binary image size.


Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions