diff options
| author | Russ Cox <rsc@golang.org> | 2022-04-27 09:03:35 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2022-04-29 14:23:19 +0000 |
| commit | e5407501cb5c43f9ba874fe5dad215435acbf5a2 (patch) | |
| tree | 656e8f9892a61d65a75c05b933570de49c2b5a4a /src/cmd/compile | |
| parent | fe006d641079e8943833573bd1275ef51eb7fb60 (diff) | |
| download | go-e5407501cb5c43f9ba874fe5dad215435acbf5a2.tar.xz | |
[dev.boringcrypto] cmd: use notsha256 instead of md5, sha1, sha256
When we add GOEXPERIMENT=boringcrypto, the bootstrap process
will not converge if the compiler itself depends on the boringcrypto
cgo-based implementations of sha1 and sha256.
Using notsha256 avoids boringcrypto and makes bootstrap converge.
Removing md5 is not strictly necessary but it seemed worthwhile to
be consistent.
For #51940.
Change-Id: Iba649507e0964d1a49a1d16e463dd23c4e348f14
Reviewed-on: https://go-review.googlesource.com/c/go/+/402595
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile')
| -rw-r--r-- | src/cmd/compile/internal/liveness/plive.go | 4 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssa/func.go | 4 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssa/print.go | 9 | ||||
| -rw-r--r-- | src/cmd/compile/internal/staticdata/data.go | 8 | ||||
| -rw-r--r-- | src/cmd/compile/internal/typecheck/iexport.go | 4 | ||||
| -rw-r--r-- | src/cmd/compile/internal/types/fmt.go | 6 |
6 files changed, 18 insertions, 17 deletions
diff --git a/src/cmd/compile/internal/liveness/plive.go b/src/cmd/compile/internal/liveness/plive.go index bd0a6fa1a3..93f49fad45 100644 --- a/src/cmd/compile/internal/liveness/plive.go +++ b/src/cmd/compile/internal/liveness/plive.go @@ -15,7 +15,6 @@ package liveness import ( - "crypto/sha1" "fmt" "os" "sort" @@ -30,6 +29,7 @@ import ( "cmd/compile/internal/ssa" "cmd/compile/internal/typebits" "cmd/compile/internal/types" + "cmd/internal/notsha256" "cmd/internal/obj" "cmd/internal/objabi" "cmd/internal/src" @@ -959,7 +959,7 @@ func (lv *liveness) enableClobber() { // 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 sha1.Sum([]byte(lv.f.Name)) { + for _, b := range notsha256.Sum256([]byte(lv.f.Name)) { hstr += fmt.Sprintf("%08b", b) } if !strings.HasSuffix(hstr, h) { diff --git a/src/cmd/compile/internal/ssa/func.go b/src/cmd/compile/internal/ssa/func.go index 35a9382663..75f17634ec 100644 --- a/src/cmd/compile/internal/ssa/func.go +++ b/src/cmd/compile/internal/ssa/func.go @@ -8,8 +8,8 @@ import ( "cmd/compile/internal/abi" "cmd/compile/internal/base" "cmd/compile/internal/types" + "cmd/internal/notsha256" "cmd/internal/src" - "crypto/sha1" "fmt" "io" "math" @@ -854,7 +854,7 @@ func (f *Func) DebugHashMatch(evname string) bool { // We use this feature to do a binary search to // find a function that is incorrectly compiled. hstr := "" - for _, b := range sha1.Sum([]byte(name)) { + for _, b := range notsha256.Sum256([]byte(name)) { hstr += fmt.Sprintf("%08b", b) } diff --git a/src/cmd/compile/internal/ssa/print.go b/src/cmd/compile/internal/ssa/print.go index 96cd2c7c90..aea9ce9e33 100644 --- a/src/cmd/compile/internal/ssa/print.go +++ b/src/cmd/compile/internal/ssa/print.go @@ -6,10 +6,11 @@ package ssa import ( "bytes" - "cmd/internal/src" - "crypto/sha256" "fmt" "io" + + "cmd/internal/notsha256" + "cmd/internal/src" ) func printFunc(f *Func) { @@ -17,7 +18,7 @@ func printFunc(f *Func) { } func hashFunc(f *Func) []byte { - h := sha256.New() + h := notsha256.New() p := stringFuncPrinter{w: h, printDead: true} fprintFunc(p, f) return h.Sum(nil) @@ -32,7 +33,7 @@ func (f *Func) String() string { // rewriteHash returns a hash of f suitable for detecting rewrite cycles. func (f *Func) rewriteHash() string { - h := sha256.New() + h := notsha256.New() p := stringFuncPrinter{w: h, printDead: false} fprintFunc(p, f) return fmt.Sprintf("%x", h.Sum(nil)) diff --git a/src/cmd/compile/internal/staticdata/data.go b/src/cmd/compile/internal/staticdata/data.go index b114bb2df6..b8b645f246 100644 --- a/src/cmd/compile/internal/staticdata/data.go +++ b/src/cmd/compile/internal/staticdata/data.go @@ -5,7 +5,6 @@ package staticdata import ( - "crypto/sha256" "fmt" "go/constant" "io" @@ -20,6 +19,7 @@ import ( "cmd/compile/internal/objw" "cmd/compile/internal/typecheck" "cmd/compile/internal/types" + "cmd/internal/notsha256" "cmd/internal/obj" "cmd/internal/objabi" "cmd/internal/src" @@ -73,7 +73,7 @@ func StringSym(pos src.XPos, s string) (data *obj.LSym) { // 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 := sha256.New() + h := notsha256.New() io.WriteString(h, s) symname = fmt.Sprintf(stringSymPattern, len(s), h.Sum(nil)) } else { @@ -131,7 +131,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj. sym = slicedata(pos, string(data)).Linksym() } if len(hash) > 0 { - sum := sha256.Sum256(data) + sum := notsha256.Sum256(data) copy(hash, sum[:]) } return sym, size, nil @@ -148,7 +148,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj. // Compute hash if needed for read-only content hashing or if the caller wants it. var sum []byte if readonly || len(hash) > 0 { - h := sha256.New() + h := notsha256.New() n, err := io.Copy(h, f) if err != nil { return nil, 0, err diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go index 12159b71e1..9436aa5504 100644 --- a/src/cmd/compile/internal/typecheck/iexport.go +++ b/src/cmd/compile/internal/typecheck/iexport.go @@ -236,7 +236,6 @@ package typecheck import ( "bytes" - "crypto/md5" "encoding/binary" "fmt" "go/constant" @@ -250,6 +249,7 @@ import ( "cmd/compile/internal/ir" "cmd/compile/internal/types" "cmd/internal/goobj" + "cmd/internal/notsha256" "cmd/internal/src" ) @@ -353,7 +353,7 @@ func WriteExports(out io.Writer, extensions bool) { hdr.uint64(dataLen) // Flush output. - h := md5.New() + h := notsha256.New() wr := io.MultiWriter(out, h) io.Copy(wr, &hdr) io.Copy(wr, &p.strings) diff --git a/src/cmd/compile/internal/types/fmt.go b/src/cmd/compile/internal/types/fmt.go index bdd3ca1d28..3c02cb8681 100644 --- a/src/cmd/compile/internal/types/fmt.go +++ b/src/cmd/compile/internal/types/fmt.go @@ -6,7 +6,6 @@ package types import ( "bytes" - "crypto/md5" "encoding/binary" "fmt" "go/constant" @@ -15,6 +14,7 @@ import ( "sync" "cmd/compile/internal/base" + "cmd/internal/notsha256" ) // BuiltinPkg is a fake package that declares the universe block. @@ -771,7 +771,7 @@ func FmtConst(v constant.Value, sharp bool) string { func TypeHash(t *Type) uint32 { p := tconv(t, 0, fmtTypeIDHash) - // Using MD5 is overkill, but reduces accidental collisions. - h := md5.Sum([]byte(p)) + // Using SHA256 is overkill, but reduces accidental collisions. + h := notsha256.Sum256([]byte(p)) return binary.LittleEndian.Uint32(h[:4]) } |
