My goal is just to self-verify the consistency of a file without sending any additional files or signatures. I’d like to append a CRC at the end in a way that creates a predictable output from cksum
on the command line. On the receiving side, I want the check to happen in a simple single line, something like:
$(cksum somefile | awk '{if ($1 == 0) print "pass"}')
Starting from this previous post in stackoverflow: Verification of a CRC checksum against zero_
I don’t understand what I need to add at the end of the file to make it work out to 0, or if it’s even possible to do it with cksum
. According to this cksum man page, the length of the file is artificially appended to the end of the data.
… last octet, padded with zero bits (if necessary) to achieve an integral number of octets, followed by one or more octets representing the length of the file as a binary value, least significant octet first. The smallest number of octets capable of representing this integer shall be used.
Is there a way to manipulate the input data to make the cksum
work out to a 0 value?
Can it be done with one of the sha*sum
or md5sum
apps?
I need it to be done with something that is pre-installed on standard Ubuntu 22. Unfortunately, crc32
isn’t one of those.
2
Answers
So far, the only solution I've come up with is to just append the
cksum
then check the file by ignoring the end bytes, and using them to check it.Yes, it can be done. This C code will append four bytes to the input data, so that the POSIX cksum algorithm will give a zero check value on the output.
The POSIX cksum algorithm is defined here.