Source File
crc32.go
Belonging Package
hash/crc32
package crc32
import (
)
const Size = 4
IEEE = 0xedb88320
Castagnoli = 0x82f63b78
Koopman = 0xeb31d82e
)
var castagnoliTable *Table
var castagnoliTable8 *slicing8Table
var castagnoliArchImpl bool
var updateCastagnoli func(crc uint32, p []byte) uint32
var castagnoliOnce sync.Once
var haveCastagnoli uint32
func () {
castagnoliTable = simpleMakeTable(Castagnoli)
castagnoliArchImpl = archAvailableCastagnoli()
if castagnoliArchImpl {
archInitCastagnoli()
updateCastagnoli = archUpdateCastagnoli
castagnoliTable8 = slicingMakeTable(Castagnoli)
updateCastagnoli = func( uint32, []byte) uint32 {
return slicingUpdate(, castagnoliTable8, )
}
}
atomic.StoreUint32(&haveCastagnoli, 1)
}
var IEEETable = simpleMakeTable(IEEE)
var ieeeTable8 *slicing8Table
var ieeeArchImpl bool
var updateIEEE func(crc uint32, p []byte) uint32
var ieeeOnce sync.Once
func () {
ieeeArchImpl = archAvailableIEEE()
if ieeeArchImpl {
archInitIEEE()
updateIEEE = archUpdateIEEE
ieeeTable8 = slicingMakeTable(IEEE)
updateIEEE = func( uint32, []byte) uint32 {
return slicingUpdate(, ieeeTable8, )
}
}
}
func ( uint32) *Table {
switch {
case IEEE:
ieeeOnce.Do(ieeeInit)
return IEEETable
case Castagnoli:
castagnoliOnce.Do(castagnoliInit)
return castagnoliTable
}
return simpleMakeTable()
}
func () hash.Hash32 { return New(IEEETable) }
func ( *digest) () int { return Size }
func ( *digest) () int { return 1 }
func ( *digest) () { .crc = 0 }
const (
magic = "crc\x01"
marshaledSize = len(magic) + 4 + 4
)
func ( *digest) () ([]byte, error) {
:= make([]byte, 0, marshaledSize)
= append(, magic...)
= appendUint32(, tableSum(.tab))
= appendUint32(, .crc)
return , nil
}
func ( *digest) ( []byte) error {
if len() < len(magic) || string([:len(magic)]) != magic {
return errors.New("hash/crc32: invalid hash state identifier")
}
if len() != marshaledSize {
return errors.New("hash/crc32: invalid hash state size")
}
if tableSum(.tab) != readUint32([4:]) {
return errors.New("hash/crc32: tables do not match")
}
.crc = readUint32([8:])
return nil
}
func ( []byte, uint32) []byte {
:= [4]byte{
byte( >> 24),
byte( >> 16),
byte( >> 8),
byte(),
}
return append(, [:]...)
}
func ( []byte) uint32 {
_ = [3]
return uint32([3]) | uint32([2])<<8 | uint32([1])<<16 | uint32([0])<<24
}
func ( uint32, *Table, []byte) uint32 {
switch {
case atomic.LoadUint32(&haveCastagnoli) != 0 && == castagnoliTable:
return updateCastagnoli(, )
ieeeOnce.Do(ieeeInit)
return updateIEEE(, )
default:
return simpleUpdate(, , )
}
}
func ( *digest) ( []byte) ( int, error) {
switch {
case atomic.LoadUint32(&haveCastagnoli) != 0 && .tab == castagnoliTable:
.crc = updateCastagnoli(.crc, )
func ( *Table) uint32 {
var [1024]byte
:= [:0]
if != nil {
for , := range {
= appendUint32(, )
}
}
return ChecksumIEEE()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |