// Package pow implements the hashcash-style proof-of-work used to make // mass-publishing of listings and revocations expensive. package pow import ( "crypto/sha256" "math/bits" ) // LeadingZeroBits returns the number of leading zero bits of sha256(data). func LeadingZeroBits(data []byte) int { sum := sha256.Sum256(data) return zeroBits(sum[:]) } func zeroBits(sum []byte) int { n := 0 for _, b := range sum { if b == 0 { n += 8 continue } return n + bits.LeadingZeros8(b) } return n }