Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

README.md

1.97 Kb · 43 lines

gno.land/p/moul/x/daily/crc32/v0

CRC-32 checksumChecksum, ChecksumHex, ChecksumWith, Verify, MakeTable, Update, Finalize, Hex, Split.

Treats a message as one enormous binary number and takes the remainder of dividing it by a fixed polynomial. The bit-reflected, table-driven form — the one zip, gzip, PNG and Ethernet actually use.

1import "gno.land/p/moul/x/daily/crc32/v0"
2
3crc32.ChecksumHex("123456789")   // "cbf43926" — the standard check value
4crc32.Checksum("abc")            // 0x352441C2
5crc32.Verify("abc", 0x352441C2)  // true

Three polynomials: IEEE (zip/gzip/PNG, the default), Castagnoli (iSCSI/btrfs, better error detection) and Koopman. MakeTable builds the 256-entry table once — that is the whole point of the table-driven form, trading 1 KiB for eight bit-shifts per byte.

Update/Finalize take and return the raw register, not the finished checksum, so a long message can be fed in chunks. Chaining on final values would be wrong; there is a test asserting chunked equals one-shot.

⚠️ A CRC detects accidents, not tampering. It is linear, so anyone can craft a different message with the same checksum. Never use it to authenticate anything.

Live demo: r/moul/x/daily/crc32demo · render it at /r/moul/x/daily/crc32demo/v0.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.