"sync"
"cmd/internal/edit"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/objabi"
"cmd/internal/telemetry/counter"
)
// we use to coordinate between gcc and ourselves.
// We already put _cgo_ at the beginning, so the main
// concern is other cgo wrappers for the same functions.
- // Use the beginning of the notsha256 of the input to disambiguate.
- h := notsha256.New()
+ // Use the beginning of the 32 bytes hash of the input to disambiguate.
+ h := hash.New32()
io.WriteString(h, *importPath)
var once sync.Once
var wg sync.WaitGroup
"cmd/compile/internal/ssa"
"cmd/compile/internal/typebits"
"cmd/compile/internal/types"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/obj"
"cmd/internal/src"
// Clobber only functions where the hash of the function name matches a pattern.
// Useful for binary searching for a miscompiled function.
hstr := ""
- for _, b := range notsha256.Sum256([]byte(lv.f.Name)) {
+ for _, b := range hash.Sum32([]byte(lv.f.Name)) {
hstr += fmt.Sprintf("%08b", b)
}
if !strings.HasSuffix(hstr, h) {
"cmd/compile/internal/staticinit"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/src"
uls := under.LinkString()
if base.Debug.MaxShapeLen != 0 &&
len(uls) > base.Debug.MaxShapeLen {
- h := notsha256.Sum256([]byte(uls))
+ h := hash.Sum32([]byte(uls))
uls = hex.EncodeToString(h[:])
}
"io"
"strings"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/src"
)
}
func hashFunc(f *Func) []byte {
- h := notsha256.New()
+ h := hash.New32()
p := stringFuncPrinter{w: h, printDead: true}
fprintFunc(p, f)
return h.Sum(nil)
// rewriteHash returns a hash of f suitable for detecting rewrite cycles.
func (f *Func) rewriteHash() string {
- h := notsha256.New()
+ h := hash.New32()
p := stringFuncPrinter{w: h, printDead: false}
fprintFunc(p, f)
return fmt.Sprintf("%x", h.Sum(nil))
"cmd/compile/internal/ir"
"cmd/compile/internal/objw"
"cmd/compile/internal/types"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/src"
// Indulge in some paranoia by writing the length of s, too,
// as protection against length extension attacks.
// Same pattern is known to fileStringSym below.
- h := notsha256.New()
+ h := hash.New32()
io.WriteString(h, s)
symname = fmt.Sprintf(stringSymPattern, len(s), shortHashString(h.Sum(nil)))
} else {
// or other file with the same content and is placed in a read-only section.
// If readonly is false, the symbol is a read-write copy separate from any other,
// for use as the backing store of a []byte.
-// The content hash of file is copied into hash. (If hash is nil, nothing is copied.)
+// The content hash of file is copied into hashBytes. (If hash is nil, nothing is copied.)
// The returned symbol contains the data itself, not a string header.
-func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.LSym, int64, error) {
+func fileStringSym(pos src.XPos, file string, readonly bool, hashBytes []byte) (*obj.LSym, int64, error) {
f, err := os.Open(file)
if err != nil {
return nil, 0, err
} else {
sym = slicedata(pos, string(data))
}
- if len(hash) > 0 {
- sum := notsha256.Sum256(data)
- copy(hash, sum[:])
+ if len(hashBytes) > 0 {
+ sum := hash.Sum32(data)
+ copy(hashBytes, sum[:])
}
return sym, size, nil
}
}
// File is too big to read and keep in memory.
- // Compute hash if needed for read-only content hashing or if the caller wants it.
+ // Compute hashBytes if needed for read-only content hashing or if the caller wants it.
var sum []byte
- if readonly || len(hash) > 0 {
- h := notsha256.New()
+ if readonly || len(hashBytes) > 0 {
+ h := hash.New32()
n, err := io.Copy(h, f)
if err != nil {
return nil, 0, err
return nil, 0, fmt.Errorf("file changed between reads")
}
sum = h.Sum(nil)
- copy(hash, sum)
+ copy(hashBytes, sum)
}
var symdata *obj.LSym
"sync"
"cmd/compile/internal/base"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
)
// BuiltinPkg is a fake package that declares the universe block.
func TypeHash(t *Type) uint32 {
p := t.LinkString()
- // Using SHA256 is overkill, but reduces accidental collisions.
- h := notsha256.Sum256([]byte(p))
+ // Using 32 bytes hash is overkill, but reduces accidental collisions.
+ h := hash.Sum32([]byte(p))
return binary.LittleEndian.Uint32(h[:4])
}
"cmd/internal/edit",
"cmd/internal/gcprog",
"cmd/internal/goobj",
+ "cmd/internal/hash",
"cmd/internal/notsha256",
"cmd/internal/obj/...",
"cmd/internal/objabi",
package codesign
import (
+ "crypto/sha256"
"debug/macho"
"encoding/binary"
"io"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
)
// Code signature layout.
nhashes := (codeSize + pageSize - 1) / pageSize
idOff := int64(codeDirectorySize)
hashOff := idOff + int64(len(id)+1)
- cdirSz := hashOff + nhashes*notsha256.Size
+ cdirSz := hashOff + nhashes*hash.Size32
return int64(superBlobSize+blobSize) + cdirSz
}
identOffset: uint32(idOff),
nCodeSlots: uint32(nhashes),
codeLimit: uint32(codeSize),
- hashSize: notsha256.Size,
+ hashSize: hash.Size32,
hashType: CS_HASHTYPE_SHA256,
pageSize: uint8(pageSizeBits),
execSegBase: uint64(textOff),
outp = puts(outp, []byte(id+"\000"))
// emit hashes
- // NOTE(rsc): These must be SHA256, but for cgo bootstrap reasons
- // we cannot import crypto/sha256 when GOEXPERIMENT=boringcrypto
- // and the host is linux/amd64. So we use NOT-SHA256
- // and then apply a NOT ourselves to get SHA256. Sigh.
var buf [pageSize]byte
- h := notsha256.New()
p := 0
for p < int(codeSize) {
n, err := io.ReadFull(data, buf[:])
n = int(codeSize) - p
}
p += n
- h.Reset()
- h.Write(buf[:n])
- b := h.Sum(nil)
- for i := range b {
- b[i] ^= 0xFF // convert notsha256 to sha256
- }
+ b := sha256.Sum256(buf[:n])
outp = puts(outp, b[:])
}
}
"bytes"
"cmd/internal/bio"
"cmd/internal/goobj"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/objabi"
"cmd/internal/sys"
"cmp"
// For now, we assume there is no circular dependencies among
// hashed symbols.
func (w *writer) contentHash(s *LSym) goobj.HashType {
- h := notsha256.New()
+ h := hash.New32()
var tmp [14]byte
// Include the size of the symbol in the hash.
import (
"cmd/internal/goobj"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/objabi"
"encoding/base64"
"encoding/binary"
// GCLocalsSym generates a content-addressable sym containing data.
func (ctxt *Link) GCLocalsSym(data []byte) *LSym {
- sum := notsha256.Sum256(data)
+ sum := hash.Sum32(data)
str := base64.StdEncoding.EncodeToString(sum[:16])
return ctxt.LookupInit(fmt.Sprintf("gclocals·%s", str), func(lsym *LSym) {
lsym.P = data
import (
"bytes"
"cmd/internal/buildid"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/link/internal/ld"
"debug/elf"
"fmt"
t.Fatal(err)
}
- expectedGoBuildID := notsha256.Sum256([]byte("0x1234"))
+ expectedGoBuildID := hash.Sum32([]byte("0x1234"))
gnuBuildID, err := buildid.ReadELFNote(outFile, string(ld.ELF_NOTE_BUILDINFO_NAME), ld.ELF_NOTE_BUILDINFO_TAG)
if err != nil || gnuBuildID == nil {
package ld
import (
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/objabi"
"cmd/internal/sys"
"cmd/link/internal/loader"
Exitf("-B gobuildid requires a Go build ID supplied via -buildid")
}
- hashedBuildID := notsha256.Sum256([]byte(buildID))
+ hashedBuildID := hash.Sum32([]byte(buildID))
buildinfo = hashedBuildID[:20]
return
sb.SetType(sym.SRODATA)
ldr.SetAttrSpecial(s, true)
sb.SetReachable(true)
- sb.SetSize(notsha256.Size)
+ sb.SetSize(hash.Size32)
slices.SortFunc(ctxt.Library, func(a, b *sym.Library) int {
return strings.Compare(a.Pkg, b.Pkg)
})
- h := notsha256.New()
+ h := hash.New32()
for _, l := range ctxt.Library {
h.Write(l.Fingerprint[:])
}
"cmd/internal/bio"
"cmd/internal/goobj"
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"cmd/internal/objabi"
"cmd/internal/sys"
"cmd/link/internal/loadelf"
return name
}
if isType {
- hash := notsha256.Sum256([]byte(name[5:]))
+ hb := hash.Sum32([]byte(name[5:]))
prefix := "type:"
if name[5] == '.' {
prefix = "type:."
}
- return prefix + base64.StdEncoding.EncodeToString(hash[:6])
+ return prefix + base64.StdEncoding.EncodeToString(hb[:6])
}
// instantiated symbol, replace type name in []
i := strings.IndexByte(name, '[')
if j == -1 || j <= i {
j = len(name)
}
- hash := notsha256.Sum256([]byte(name[i+1 : j]))
- return name[:i+1] + base64.StdEncoding.EncodeToString(hash[:6]) + name[j:]
+ hb := hash.Sum32([]byte(name[i+1 : j]))
+ return name[:i+1] + base64.StdEncoding.EncodeToString(hb[:6]) + name[j:]
}
/*
// final executable generated by the external linker.
import (
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"debug/macho"
"io"
"os"
if buildID == "" {
return make([]byte, 16)
}
- hashedBuildID := notsha256.Sum256([]byte(buildID))
+ hashedBuildID := hash.Sum32([]byte(buildID))
rv := hashedBuildID[:16]
// RFC 4122 conformance (see RFC 4122 Sections 4.2.2, 4.1.3). We
package main
import (
- "cmd/internal/notsha256"
+ "cmd/internal/hash"
"flag"
"fmt"
"internal/platform"
goarch = f[1]
}
- hash := notsha256.Sum256([]byte(fmt.Sprintf("%v-%v-%v-%v", srcfname, flags, printCode, printGnuAsm)))
+ hash := hash.Sum32([]byte(fmt.Sprintf("%v-%v-%v-%v", srcfname, flags, printCode, printGnuAsm)))
tmp := t.TempDir()
hello := filepath.Join(tmp, fmt.Sprintf("hello-%x.exe", hash))
args := []string{"build", "-o", hello}