Source file src/cmd/internal/hash/hash.go
1 // Copyright 2024 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package hash implements hash functions used in the compiler toolchain. 6 package hash 7 8 import ( 9 "crypto/sha256" 10 "hash" 11 ) 12 13 // Size32 is the size of the 32-byte hash functions [New32] and [Sum32]. 14 const Size32 = 32 15 16 // New32 returns a new [hash.Hash] computing the 32-byte hash checksum. 17 // Note that New32 and [Sum32] compute different hashes. 18 func New32() hash.Hash { 19 h := sha256.New() 20 _, _ = h.Write([]byte{1}) // make this hash different from sha256 21 return h 22 } 23 24 // Sum32 returns a 32-byte checksum of the data. 25 // Note that Sum32 and [New32] compute different hashes. 26 func Sum32(data []byte) [32]byte { 27 sum := sha256.Sum256(data) 28 sum[0] ^= 0xff // make this hash different from sha256 29 return sum 30 } 31