github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/proxy/shadowsocksr/utils/adler32.go (about) 1 package ssr 2 3 func calcShortAdler32(input []byte, a, b uint32) (uint32, uint32) { 4 for _, i := range input { 5 a += uint32(i) 6 b += a 7 } 8 a %= 65521 9 b %= 65521 10 return a, b 11 } 12 13 func CalcAdler32(input []byte) uint32 { 14 var a uint32 = 1 15 var b uint32 = 0 16 const nMax = 5552 17 for length := len(input); length > nMax; length -= nMax { 18 a, b = calcShortAdler32(input[:nMax], a, b) 19 input = input[nMax:] 20 } 21 a, b = calcShortAdler32(input, a, b) 22 return (b << 16) + a 23 }