crc32.go (931B)
1 package scte35 2 3 var crctab = makeCRC32Table(crc32PolyNormal) 4 5 // The reverse of crc32.IEEE, from 6 // https://en.wikipedia.org/wiki/Cyclic_redundancy_check#Polynomial_representations 7 const crc32PolyNormal = 0x04C11DB7 8 9 // From Go's package compress/bzip2. 10 // Copyright 2011 The Go Authors. All rights reserved. 11 // Use of this source code is governed by a BSD-style 12 // license that can be found in 13 // https://cs.opensource.google/go/go/+/master:LICENSE;bpv=0 14 15 // makeCRC32Table generates CRC32/BZIP2 table using poly. 16 func makeCRC32Table(poly uint32) [256]uint32 { 17 var tab [256]uint32 18 for i := range tab { 19 crc := uint32(i) << 24 20 for j := 0; j < 8; j++ { 21 if crc&0x80000000 != 0 { 22 crc = (crc << 1) ^ poly 23 } else { 24 crc = crc << 1 25 } 26 } 27 tab[i] = crc 28 } 29 return tab 30 } 31 32 func updateCRC(val uint32, b []byte) uint32 { 33 crc := ^val 34 for _, v := range b { 35 crc = crctab[byte(crc>>24)^v] ^ (crc << 8) 36 } 37 return ^crc 38 }