const IEEE, Castagnoli, Koopman
Common reversed polynomials.
Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.
Package crc32 implements the CRC-32 checksum as a pure, reusable package.
gno.land/p/moul/x/daily/crc32/v0CRC-32 checksum — Checksum, 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.
Package crc32 implements the CRC-32 checksum as a pure, reusable package.
CRC-32 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 implemented here is the one everything actually uses — zip, gzip, PNG, and Ethernet all speak IEEE.
Three polynomials are provided:
A CRC is an ACCIDENT detector, not a security primitive: it is linear, so anyone can craft a different message with the same checksum. Never use it to authenticate anything.
A live demo of this package is at r/moul/x/daily/crc32demo(/r/moul/x/daily/crc32demo/v0).
Checksum returns the IEEE CRC-32 of s — the one zip, gzip and PNG use.
ChecksumHex is Checksum rendered with Hex.
ChecksumWith returns the CRC-32 of s under the given table.
Finalize turns a running register into the checksum.
Hex renders a checksum as eight lowercase hex digits, zero-padded, which is how CRCs are conventionally shown.
Split returns the checksum of each line of s, in order.
Update adds the bytes of s to a running checksum.
Takes and returns the RAW register, not the final value: the caller-visible checksum is the register XOR 0xFFFFFFFF, so chaining Update calls on final values would be wrong. Start from 0 and finish with Finalize.
Verify reports whether s has the expected checksum.
MakeTable builds the lookup table for a reversed polynomial. Building it once and reusing it is the whole point of the table-driven form: it trades 1 KiB for eight bit-shifts per byte.