Skip to content

A pure Go implementation of CRC32A (ITU I.363.5) checksum missing from Golang standard library.

License

Notifications You must be signed in to change notification settings

boguslaw-wojcik/crc32a

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRC32A

A pure Go implementation of CRC32A (ITU I.363.5) checksum missing from Golang standard library. Largely based on C implementation found in PHP source files.

Usage

package main

import (
	"fmt"
	
	"github.com/boguslaw-wojcik/crc32a"
)

func main() {
	b := []byte("123456789")
	sum := crc32a.Checksum(b)
	sumHex := crc32a.ChecksumHex(b)

	fmt.Println(sum)    // 404326908
	fmt.Println(sumHex) // 181989fc
}

Background

There are four popular implementations of CRC32 of which three are included in Golang standard library. This package provides missing implementation of CRC32A (ITU I.363.5) popularized by bzip2 and PHP. If you're unsure what CRC32 algorithm you're using, calculate checksum for string 123456789 and compare results with the table below.

Variant Performance Standard Library Data Hex Sum
CRC32A (ITU I.363.5) 31.4 ns/op no 123456789 181989fc 404326908
CRC32B (ITU V.42 / IEEE 802.3) 24.0 ns/op yes 123456789 cbf43926 3421780262
CRC32C (Castagnoli) 15.2 ns/op yes 123456789 e3069283 3808858755
CRC32K (Koopman) 4534 ns/op yes 123456789 2d3dd0ae 759025838

Note: Unless you're required to use CRC32A for legacy reasons, in general you should choose CRC32B as the most popular and widely implemented CRC32 variation.

References

About

A pure Go implementation of CRC32A (ITU I.363.5) checksum missing from Golang standard library.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages