]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.boringcrypto] all: merge master into dev.boringcrypto
authorChressie Himpel <chressie@google.com>
Thu, 3 Feb 2022 18:10:54 +0000 (19:10 +0100)
committerChressie Himpel <chressie@google.com>
Thu, 3 Feb 2022 18:30:02 +0000 (19:30 +0100)
Change-Id: I18dbf4f9fa7e2334fccedd862a523126cf38164e

15 files changed:
1  2 
src/cmd/compile/internal/amd64/versions_test.go
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/go/go_test.go
src/cmd/go/internal/load/pkg.go
src/cmd/link/internal/ld/lib.go
src/crypto/ecdsa/ecdsa.go
src/crypto/tls/cipher_suites.go
src/crypto/tls/common.go
src/crypto/tls/handshake_client.go
src/crypto/tls/handshake_messages_test.go
src/crypto/tls/handshake_server.go
src/crypto/x509/verify.go
src/go/build/build.go
src/go/build/deps_test.go
src/runtime/race/testdata/mop_test.go

index e8bda78291fa6da3e48ff0bed6ddfcc2989bc481,7aa697b811442b3367f83998f1bdfb7b056701b8..a21e5f2e6f774f943fbd56c9decd4909ea585679
@@@ -2,8 -2,6 +2,8 @@@
  // Use of this source code is governed by a BSD-style
  // license that can be found in the LICENSE file.
  
 +//go:build !boringcrypto
 +
  package amd64_test
  
  import (
@@@ -76,8 -74,18 +76,18 @@@ func TestGoAMD64v1(t *testing.T) 
        if err != nil {
                t.Fatalf("couldn't execute test: %s", err)
        }
-       if string(out) != "PASS\n" {
-               t.Fatalf("test reported error: %s", string(out))
+       // Expect to see output of the form "PASS\n", unless the test binary
+       // was compiled for coverage (in which case there will be an extra line).
+       success := false
+       lines := strings.Split(string(out), "\n")
+       if len(lines) == 2 {
+               success = lines[0] == "PASS" && lines[1] == ""
+       } else if len(lines) == 3 {
+               success = lines[0] == "PASS" &&
+                       strings.HasPrefix(lines[1], "coverage") && lines[2] == ""
+       }
+       if !success {
+               t.Fatalf("test reported error: %s lines=%+v", string(out), lines)
        }
  }
  
index 0d3070fd39c6d3e576afa74dcc3d6270d61cdd5c,42ea7bac46cbcb2226228e5c9ab05a526d4c034c..e76f9c5f3c1b19e405e8a6880290e9cfd2771604
@@@ -846,14 -846,19 +846,19 @@@ func TypePtr(t *types.Type) *ir.AddrExp
        return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr)
  }
  
- // ITabLsym returns the LSym representing the itab for concreate type typ
- // implementing interface iface.
+ // ITabLsym returns the LSym representing the itab for concrete type typ implementing
+ // interface iface. A dummy tab will be created in the unusual case where typ doesn't
+ // implement iface. Normally, this wouldn't happen, because the typechecker would
+ // have reported a compile-time error. This situation can only happen when the
+ // destination type of a type assert or a type in a type switch is parameterized, so
+ // it may sometimes, but not always, be a type that can't implement the specified
+ // interface.
  func ITabLsym(typ, iface *types.Type) *obj.LSym {
        s, existed := ir.Pkgs.Itab.LookupOK(typ.LinkString() + "," + iface.LinkString())
        lsym := s.Linksym()
  
        if !existed {
-               writeITab(lsym, typ, iface)
+               writeITab(lsym, typ, iface, true)
        }
        return lsym
  }
@@@ -865,7 -870,7 +870,7 @@@ func ITabAddr(typ, iface *types.Type) *
        lsym := s.Linksym()
  
        if !existed {
-               writeITab(lsym, typ, iface)
+               writeITab(lsym, typ, iface, false)
        }
  
        n := ir.NewLinksymExpr(base.Pos, lsym, types.Types[types.TUINT8])
@@@ -924,11 -929,12 +929,12 @@@ func hashMightPanic(t *types.Type) boo
        }
  }
  
- // formalType replaces byte and rune aliases with real types.
+ // formalType replaces predeclared aliases with real types.
  // They've been separate internally to make error messages
  // better, but we have to merge them in the reflect tables.
  func formalType(t *types.Type) *types.Type {
-       if t == types.ByteType || t == types.RuneType {
+       switch t {
+       case types.AnyType, types.ByteType, types.RuneType:
                return types.Types[t.Kind()]
        }
        return t
@@@ -1149,33 -1155,6 +1155,33 @@@ func writeType(t *types.Type) *obj.LSy
        // for security, only the exported fields.
        case types.TSTRUCT:
                fields := t.Fields().Slice()
 +
 +              // omitFieldForAwfulBoringCryptoKludge reports whether
 +              // the field t should be omitted from the reflect data.
 +              // In the crypto/... packages we omit an unexported field
 +              // named "boring", to keep from breaking client code that
 +              // expects rsa.PublicKey etc to have only public fields.
 +              // As the name suggests, this is an awful kludge, but it is
 +              // limited to the dev.boringcrypto branch and avoids
 +              // much more invasive effects elsewhere.
 +              omitFieldForAwfulBoringCryptoKludge := func(t *types.Field) bool {
 +                      if t.Sym == nil || t.Sym.Name != "boring" || t.Sym.Pkg == nil {
 +                              return false
 +                      }
 +                      path := t.Sym.Pkg.Path
 +                      if t.Sym.Pkg == types.LocalPkg {
 +                              path = base.Ctxt.Pkgpath
 +                      }
 +                      return strings.HasPrefix(path, "crypto/")
 +              }
 +              newFields := fields[:0:0]
 +              for _, t1 := range fields {
 +                      if !omitFieldForAwfulBoringCryptoKludge(t1) {
 +                              newFields = append(newFields, t1)
 +                      }
 +              }
 +              fields = newFields
 +
                for _, t1 := range fields {
                        writeType(t1.Type)
                }
@@@ -1303,9 -1282,10 +1309,10 @@@ func WriteRuntimeTypes() 
        }
  }
  
- // writeITab writes the itab for concrete type typ implementing
- // interface iface.
- func writeITab(lsym *obj.LSym, typ, iface *types.Type) {
+ // writeITab writes the itab for concrete type typ implementing interface iface. If
+ // allowNonImplement is true, allow the case where typ does not implement iface, and just
+ // create a dummy itab with zeroed-out method entries.
+ func writeITab(lsym *obj.LSym, typ, iface *types.Type, allowNonImplement bool) {
        // TODO(mdempsky): Fix methodWrapper, geneq, and genhash (and maybe
        // others) to stop clobbering these.
        oldpos, oldfn := base.Pos, ir.CurFunc
                                break
                        }
                }
-               if sigs[0].Sym.Name == "==" {
-                       sigs = sigs[1:]
-                       if len(sigs) == 0 {
-                               break
-                       }
-               }
        }
-       if len(sigs) != 0 {
+       completeItab := len(sigs) == 0
+       if !allowNonImplement && !completeItab {
                base.Fatalf("incomplete itab")
        }
  
        o = objw.Uint32(lsym, o, types.TypeHash(typ)) // copy of type hash
        o += 4                                        // skip unused field
        for _, fn := range entries {
-               o = objw.SymPtrWeak(lsym, o, fn, 0) // method pointer for each method
+               if !completeItab {
+                       // If typ doesn't implement iface, make method entries be zero.
+                       o = objw.Uintptr(lsym, o, 0)
+               } else {
+                       o = objw.SymPtrWeak(lsym, o, fn, 0) // method pointer for each method
+               }
        }
        // Nothing writes static itabs, so they are read only.
        objw.Global(lsym, int32(o), int16(obj.DUPOK|obj.RODATA))
@@@ -1417,6 -1397,9 +1424,9 @@@ func WriteBasicTypes() 
                }
                writeType(types.NewPtr(types.Types[types.TSTRING]))
                writeType(types.NewPtr(types.Types[types.TUNSAFEPTR]))
+               if base.Flag.G > 0 {
+                       writeType(types.AnyType)
+               }
  
                // emit type structs for error and func(error) string.
                // The latter is the type of an auto-generated wrapper.
@@@ -1938,18 -1921,25 +1948,25 @@@ func methodWrapper(rcvr *types.Type, me
  
                        // Target method uses shaped names.
                        targs2 := make([]*types.Type, len(targs))
+                       origRParams := deref(orig).OrigSym().Def.(*ir.Name).Type().RParams()
                        for i, t := range targs {
-                               targs2[i] = typecheck.Shapify(t, i)
+                               targs2[i] = typecheck.Shapify(t, i, origRParams[i])
                        }
                        targs = targs2
  
                        sym := typecheck.MakeFuncInstSym(ir.MethodSym(methodrcvr, method.Sym), targs, false, true)
                        if sym.Def == nil {
-                               // Currently we make sure that we have all the instantiations
-                               // we need by generating them all in ../noder/stencil.go:instantiateMethods
-                               // TODO: maybe there's a better, more incremental way to generate
-                               // only the instantiations we need?
-                               base.Fatalf("instantiation %s not found", sym.Name)
+                               // Currently we make sure that we have all the
+                               // instantiations we need by generating them all in
+                               // ../noder/stencil.go:instantiateMethods
+                               // Extra instantiations because of an inlined function
+                               // should have been exported, and so available via
+                               // Resolve.
+                               in := typecheck.Resolve(ir.NewIdent(src.NoXPos, sym))
+                               if in.Op() == ir.ONONAME {
+                                       base.Fatalf("instantiation %s not found", sym.Name)
+                               }
+                               sym = in.Sym()
                        }
                        target := ir.AsNode(sym.Def)
                        call = ir.NewCallExpr(base.Pos, ir.OCALL, target, args)
@@@ -2075,8 -2065,14 +2092,14 @@@ func getDictionary(gf *types.Sym, targ
        sym := typecheck.MakeDictSym(gf, targs, true)
  
        // Dictionary should already have been generated by instantiateMethods().
+       // Extra dictionaries needed because of an inlined function should have been
+       // exported, and so available via Resolve.
        if lsym := sym.Linksym(); len(lsym.P) == 0 {
-               base.Fatalf("Dictionary should have already been generated: %s.%s", sym.Pkg.Path, sym.Name)
+               in := typecheck.Resolve(ir.NewIdent(src.NoXPos, sym))
+               if in.Op() == ir.ONONAME {
+                       base.Fatalf("Dictionary should have already been generated: %s.%s", sym.Pkg.Path, sym.Name)
+               }
+               sym = in.Sym()
        }
  
        // Make (or reuse) a node referencing the dictionary symbol.
diff --combined src/cmd/go/go_test.go
index 4a81c826a5f542ff4e9378498239ffd97e018896,1ea347ca6e5dbd2d7a8cabf362c3586bd4583bcd..11ba733b38166eed11f9c73c42fb5cddb1acd0fb
@@@ -133,7 -133,7 +133,7 @@@ func TestMain(m *testing.M) 
                }
                gotool, err := testenv.GoTool()
                if err != nil {
-                       fmt.Fprintln(os.Stderr, err)
+                       fmt.Fprintln(os.Stderr, "locating go tool: ", err)
                        os.Exit(2)
                }
  
@@@ -1128,11 -1128,11 +1128,11 @@@ func TestGoListTest(t *testing.T) 
        tg.grepStdoutNot(`^testing \[sort.test\]$`, "unexpected test copy of testing")
        tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing")
  
-       tg.run("list", "-test", "cmd/dist", "cmd/doc")
-       tg.grepStdout(`^cmd/dist$`, "missing cmd/dist")
+       tg.run("list", "-test", "cmd/buildid", "cmd/doc")
+       tg.grepStdout(`^cmd/buildid$`, "missing cmd/buildid")
        tg.grepStdout(`^cmd/doc$`, "missing cmd/doc")
        tg.grepStdout(`^cmd/doc\.test$`, "missing cmd/doc test")
-       tg.grepStdoutNot(`^cmd/dist\.test$`, "unexpected cmd/dist test")
+       tg.grepStdoutNot(`^cmd/buildid\.test$`, "unexpected cmd/buildid test")
        tg.grepStdoutNot(`^testing`, "unexpected testing")
  
        tg.run("list", "-test", "runtime/cgo")
@@@ -1387,7 -1387,7 +1387,7 @@@ func TestLdFlagsLongArgumentsIssue42295
        for buf.Len() < sys.ExecArgLengthLimit+1 {
                buf.WriteString(testStr)
        }
-       tg.run("run", "-buildinfo=false", "-ldflags", fmt.Sprintf(`-X "main.extern=%s"`, buf.String()), tg.path("main.go"))
+       tg.run("run", "-ldflags", fmt.Sprintf(`-X "main.extern=%s"`, buf.String()), tg.path("main.go"))
        if tg.stderr.String() != buf.String() {
                t.Errorf("strings differ")
        }
@@@ -1843,12 -1843,8 +1843,12 @@@ func TestBinaryOnlyPackages(t *testing.
        tg.grepStdout("p2: false", "p2 listed as BinaryOnly")
  }
  
 -// Issue 16050.
 -func TestAlwaysLinkSysoFiles(t *testing.T) {
 +// Issue 16050 and 21884.
 +func TestLinkSysoFiles(t *testing.T) {
 +      if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
 +              t.Skip("not linux/amd64")
 +      }
 +
        tg := testgo(t)
        defer tg.cleanup()
        tg.parallel()
        tg.setenv("CGO_ENABLED", "0")
        tg.run("list", "-f", "{{.SysoFiles}}", "syso")
        tg.grepStdout("a.syso", "missing syso file with CGO_ENABLED=0")
 +
 +      tg.setenv("CGO_ENABLED", "1")
 +      tg.run("list", "-msan", "-f", "{{.SysoFiles}}", "syso")
 +      tg.grepStdoutNot("a.syso", "unexpected syso file with -msan")
  }
  
  // Issue 16120.
index f9051cce3dd0bc902f9178bc42a71c093fc68e96,fca9d5a0a296c83a4e3c236b0b779adead038134..aba1dfd1c163bafe722229a84c8fb4a5ba2ff9b1
@@@ -388,12 -388,6 +388,12 @@@ func (p *Package) copyBuild(opts Packag
        p.SwigFiles = pp.SwigFiles
        p.SwigCXXFiles = pp.SwigCXXFiles
        p.SysoFiles = pp.SysoFiles
 +      if cfg.BuildMSan {
 +              // There's no way for .syso files to be built both with and without
 +              // support for memory sanitizer. Assume they are built without,
 +              // and drop them.
 +              p.SysoFiles = nil
 +      }
        p.CgoCFLAGS = pp.CgoCFLAGS
        p.CgoCPPFLAGS = pp.CgoCPPFLAGS
        p.CgoCXXFLAGS = pp.CgoCXXFLAGS
@@@ -504,7 -498,7 +504,7 @@@ type importError struct 
        err        error // created with fmt.Errorf
  }
  
- func ImportErrorf(path, format string, args ...interface{}) ImportPathError {
+ func ImportErrorf(path, format string, args ...any) ImportPathError {
        err := &importError{importPath: path, err: fmt.Errorf(format, args...)}
        if errStr := err.Error(); !strings.Contains(errStr, path) {
                panic(fmt.Sprintf("path %q not in error %q", path, errStr))
@@@ -595,10 -589,10 +595,10 @@@ func ClearPackageCachePartial(args []st
                        delete(packageCache, arg)
                }
        }
-       resolvedImportCache.DeleteIf(func(key interface{}) bool {
+       resolvedImportCache.DeleteIf(func(key any) bool {
                return shouldDelete[key.(importSpec).path]
        })
-       packageDataCache.DeleteIf(func(key interface{}) bool {
+       packageDataCache.DeleteIf(func(key any) bool {
                return shouldDelete[key.(string)]
        })
  }
@@@ -611,7 -605,7 +611,7 @@@ func ReloadPackageNoFlags(arg string, s
        p := packageCache[arg]
        if p != nil {
                delete(packageCache, arg)
-               resolvedImportCache.DeleteIf(func(key interface{}) bool {
+               resolvedImportCache.DeleteIf(func(key any) bool {
                        return key.(importSpec).path == p.ImportPath
                })
                packageDataCache.Delete(p.ImportPath)
@@@ -823,7 -817,7 +823,7 @@@ func loadPackageData(ctx context.Contex
                parentIsStd: parentIsStd,
                mode:        mode,
        }
-       r := resolvedImportCache.Do(importKey, func() interface{} {
+       r := resolvedImportCache.Do(importKey, func() any {
                var r resolvedImport
                if build.IsLocalImport(path) {
                        r.dir = filepath.Join(parentDir, path)
  
        // Load the package from its directory. If we already found the package's
        // directory when resolving its import path, use that.
-       data := packageDataCache.Do(r.path, func() interface{} {
+       data := packageDataCache.Do(r.path, func() any {
                loaded = true
                var data packageData
                if r.dir != "" {
@@@ -1069,7 -1063,7 +1069,7 @@@ func cleanImport(path string) string 
  var isDirCache par.Cache
  
  func isDir(path string) bool {
-       return isDirCache.Do(path, func() interface{} {
+       return isDirCache.Do(path, func() any {
                fi, err := fsys.Stat(path)
                return err == nil && fi.IsDir()
        }).(bool)
@@@ -1197,7 -1191,7 +1197,7 @@@ var 
  
  // goModPath returns the module path in the go.mod in dir, if any.
  func goModPath(dir string) (path string) {
-       return goModPathCache.Do(dir, func() interface{} {
+       return goModPathCache.Do(dir, func() any {
                data, err := os.ReadFile(filepath.Join(dir, "go.mod"))
                if err != nil {
                        return ""
@@@ -2023,13 -2017,18 +2023,18 @@@ func resolveEmbed(pkgdir string, patter
        for _, pattern = range patterns {
                pid++
  
+               glob := pattern
+               all := strings.HasPrefix(pattern, "all:")
+               if all {
+                       glob = pattern[len("all:"):]
+               }
                // Check pattern is valid for //go:embed.
-               if _, err := path.Match(pattern, ""); err != nil || !validEmbedPattern(pattern) {
+               if _, err := path.Match(glob, ""); err != nil || !validEmbedPattern(glob) {
                        return nil, nil, fmt.Errorf("invalid pattern syntax")
                }
  
                // Glob to find matches.
-               match, err := fsys.Glob(pkgdir + string(filepath.Separator) + filepath.FromSlash(pattern))
+               match, err := fsys.Glob(pkgdir + string(filepath.Separator) + filepath.FromSlash(glob))
                if err != nil {
                        return nil, nil, err
                }
                                        }
                                        rel := filepath.ToSlash(path[len(pkgdir)+1:])
                                        name := info.Name()
-                                       if path != file && (isBadEmbedName(name) || name[0] == '.' || name[0] == '_') {
+                                       if path != file && (isBadEmbedName(name) || ((name[0] == '.' || name[0] == '_') && !all)) {
                                                // Ignore bad names, assuming they won't go into modules.
                                                // Also avoid hidden files that user may not know about.
                                                // See golang.org/issue/42328.
@@@ -2204,6 -2203,10 +2209,10 @@@ func (p *Package) collectDeps() 
        }
  }
  
+ // vcsStatusCache maps repository directories (string)
+ // to their VCS information (vcsStatusError).
+ var vcsStatusCache par.Cache
  // setBuildInfo gathers build information, formats it as a string to be
  // embedded in the binary, then sets p.Internal.BuildInfo to that string.
  // setBuildInfo should only be called on a main package with no errors.
@@@ -2218,7 -2221,7 +2227,7 @@@ func (p *Package) setBuildInfo() 
        // executables always appear stale unless the user sets the same flags.
        // Perhaps it's safe to omit those flags when GO_GCFLAGS and GO_LDFLAGS
        // are not set?
-       setPkgErrorf := func(format string, args ...interface{}) {
+       setPkgErrorf := func(format string, args ...any) {
                if p.Error == nil {
                        p.Error = &PackageError{Err: fmt.Errorf(format, args...)}
                }
                Deps: deps,
        }
        appendSetting := func(key, value string) {
+               value = strings.ReplaceAll(value, "\n", " ") // make value safe
                info.Settings = append(info.Settings, debug.BuildSetting{Key: key, Value: value})
        }
  
        // Add command-line flags relevant to the build.
        // This is informational, not an exhaustive list.
-       if cfg.BuildBuildinfo && !p.Standard {
-               appendSetting("compiler", cfg.BuildContext.Compiler)
-               if BuildAsmflags.present {
-                       appendSetting("asmflags", BuildAsmflags.String())
+       // Please keep the list sorted.
+       if !p.Standard {
+               if cfg.BuildASan {
+                       appendSetting("-asan", "true")
                }
-               if BuildGcflags.present && cfg.BuildContext.Compiler == "gc" {
-                       appendSetting("gcflags", BuildGcflags.String())
+               if BuildAsmflags.present {
+                       appendSetting("-asmflags", BuildAsmflags.String())
                }
+               appendSetting("-compiler", cfg.BuildContext.Compiler)
                if BuildGccgoflags.present && cfg.BuildContext.Compiler == "gccgo" {
-                       appendSetting("gccgoflags", BuildGccgoflags.String())
+                       appendSetting("-gccgoflags", BuildGccgoflags.String())
+               }
+               if BuildGcflags.present && cfg.BuildContext.Compiler == "gc" {
+                       appendSetting("-gcflags", BuildGcflags.String())
                }
                if BuildLdflags.present {
-                       appendSetting("ldflags", BuildLdflags.String())
+                       appendSetting("-ldflags", BuildLdflags.String())
+               }
+               if cfg.BuildMSan {
+                       appendSetting("-msan", "true")
                }
-               tags := append(cfg.BuildContext.BuildTags, cfg.BuildContext.ToolTags...)
-               appendSetting("tags", strings.Join(tags, ","))
-               appendSetting("CGO_ENABLED", strconv.FormatBool(cfg.BuildContext.CgoEnabled))
+               if cfg.BuildRace {
+                       appendSetting("-race", "true")
+               }
+               if tags := cfg.BuildContext.BuildTags; len(tags) > 0 {
+                       appendSetting("-tags", strings.Join(tags, ","))
+               }
+               cgo := "0"
                if cfg.BuildContext.CgoEnabled {
-                       for _, name := range []string{"CGO_CPPFLAGS", "CGO_CFLAGS", "CGO_CXXFLAGS", "CGO_LDFLAGS"} {
+                       cgo = "1"
+               }
+               appendSetting("CGO_ENABLED", cgo)
+               if cfg.BuildContext.CgoEnabled {
+                       for _, name := range []string{"CGO_CFLAGS", "CGO_CPPFLAGS", "CGO_CXXFLAGS", "CGO_LDFLAGS"} {
                                appendSetting(name, cfg.Getenv(name))
                        }
                }
+               appendSetting("GOARCH", cfg.BuildContext.GOARCH)
+               if cfg.GOEXPERIMENT != "" {
+                       appendSetting("GOEXPERIMENT", cfg.GOEXPERIMENT)
+               }
+               appendSetting("GOOS", cfg.BuildContext.GOOS)
+               if key, val := cfg.GetArchEnv(); key != "" && val != "" {
+                       appendSetting(key, val)
+               }
        }
  
        // Add VCS status if all conditions are true:
                        return
                }
  
-               st, err := vcsCmd.Status(vcsCmd, repoDir)
-               if err != nil {
+               type vcsStatusError struct {
+                       Status vcs.Status
+                       Err    error
+               }
+               cached := vcsStatusCache.Do(repoDir, func() any {
+                       st, err := vcsCmd.Status(vcsCmd, repoDir)
+                       return vcsStatusError{st, err}
+               }).(vcsStatusError)
+               if err := cached.Err; err != nil {
                        setVCSError(err)
                        return
                }
+               st := cached.Status
+               appendSetting("vcs", vcsCmd.Cmd)
                if st.Revision != "" {
-                       appendSetting(vcsCmd.Cmd+"revision", st.Revision)
+                       appendSetting("vcs.revision", st.Revision)
                }
                if !st.CommitTime.IsZero() {
                        stamp := st.CommitTime.UTC().Format(time.RFC3339Nano)
-                       appendSetting(vcsCmd.Cmd+"committime", stamp)
+                       appendSetting("vcs.time", stamp)
                }
-               appendSetting(vcsCmd.Cmd+"uncommitted", strconv.FormatBool(st.Uncommitted))
+               appendSetting("vcs.modified", strconv.FormatBool(st.Uncommitted))
        }
  
        text, err := info.MarshalText()
index 4aca36db9866d97ffc8a92195c85f8fd8cdff58d,f1a37e955e93706e2324d1d476041616fd939c29..5b82dc287d20bd9487908e15244d341f46935c57
@@@ -1015,7 -1015,6 +1015,7 @@@ var hostobj []Hostob
  // These packages can use internal linking mode.
  // Others trigger external mode.
  var internalpkg = []string{
 +      "crypto/internal/boring",
        "crypto/x509",
        "net",
        "os/user",
@@@ -1104,7 -1103,6 +1104,6 @@@ func hostlinksetup(ctxt *Link) 
                *flagTmpdir = dir
                ownTmpDir = true
                AtExit(func() {
-                       ctxt.Out.Close()
                        os.RemoveAll(*flagTmpdir)
                })
        }
@@@ -1271,7 -1269,10 +1270,10 @@@ func (ctxt *Link) hostlink() 
                if ctxt.DynlinkingGo() && buildcfg.GOOS != "ios" {
                        // -flat_namespace is deprecated on iOS.
                        // It is useful for supporting plugins. We don't support plugins on iOS.
-                       argv = append(argv, "-Wl,-flat_namespace")
+                       // -flat_namespace may cause the dynamic linker to hang at forkExec when
+                       // resolving a lazy binding. See issue 38824.
+                       // Force eager resolution to work around.
+                       argv = append(argv, "-Wl,-flat_namespace", "-Wl,-bind_at_load")
                }
                if !combineDwarf {
                        argv = append(argv, "-Wl,-S") // suppress STAB (symbolic debugging) symbols
                        }
                        return strings.Trim(string(out), "\n")
                }
-               argv = append(argv, getPathFile("crtcxa.o"))
-               argv = append(argv, getPathFile("crtdbase.o"))
+               // Since GCC version 11, the 64-bit version of GCC starting files
+               // are now suffixed by "_64". Even under "-maix64" multilib directory
+               // "crtcxa.o" is 32-bit.
+               crtcxa := getPathFile("crtcxa_64.o")
+               if !filepath.IsAbs(crtcxa) {
+                       crtcxa = getPathFile("crtcxa.o")
+               }
+               crtdbase := getPathFile("crtdbase_64.o")
+               if !filepath.IsAbs(crtdbase) {
+                       crtdbase = getPathFile("crtdbase.o")
+               }
+               argv = append(argv, crtcxa)
+               argv = append(argv, crtdbase)
        }
  
        if ctxt.linkShared {
index 4be0026b9a5dc4914041c13bf741e9d42084a678,9f9a09a8842f3172b0c11aae171871db6c0f3921..c1dd32a2d803be0ccdbdadff36d1defcfe4336e5
@@@ -3,28 -3,21 +3,21 @@@
  // license that can be found in the LICENSE file.
  
  // Package ecdsa implements the Elliptic Curve Digital Signature Algorithm, as
- // defined in FIPS 186-3.
+ // defined in FIPS 186-4 and SEC 1, Version 2.0.
  //
- // This implementation derives the nonce from an AES-CTR CSPRNG keyed by:
- //
- // SHA2-512(priv.D || entropy || hash)[:32]
- //
- // The CSPRNG key is indifferentiable from a random oracle as shown in
- // [Coron], the AES-CTR stream is indifferentiable from a random oracle
- // under standard cryptographic assumptions (see [Larsson] for examples).
- //
- // References:
- //   [Coron]
- //     https://cs.nyu.edu/~dodis/ps/merkle.pdf
- //   [Larsson]
- //     https://web.archive.org/web/20040719170906/https://www.nada.kth.se/kurser/kth/2D1441/semteo03/lecturenotes/assump.pdf
+ // Signatures generated by this package are not deterministic, but entropy is
+ // mixed with the private key and the message, achieving the same level of
+ // security in case of randomness source failure.
  package ecdsa
  
- // Further references:
- //   [NSA]: Suite B implementer's guide to FIPS 186-3
- //     https://apps.nsa.gov/iaarchive/library/ia-guidance/ia-solutions-for-classified/algorithm-guidance/suite-b-implementers-guide-to-fips-186-3-ecdsa.cfm
- //   [SECG]: SECG, SEC1
- //     http://www.secg.org/sec1-v2.pdf
+ // [FIPS 186-4] references ANSI X9.62-2005 for the bulk of the ECDSA algorithm.
+ // That standard is not freely available, which is a problem in an open source
+ // implementation, because not only the implementer, but also any maintainer,
+ // contributor, reviewer, auditor, and learner needs access to it. Instead, this
+ // package references and follows the equivalent [SEC 1, Version 2.0].
+ //
+ // [FIPS 186-4]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
+ // [SEC 1, Version 2.0]: https://www.secg.org/sec1-v2.pdf
  
  import (
        "crypto"
        "golang.org/x/crypto/cryptobyte/asn1"
  )
  
- // A invertible implements fast inverse mod Curve.Params().N
 +import (
 +      "crypto/internal/boring"
 +      "unsafe"
 +)
 +
+ // A invertible implements fast inverse in GF(N).
  type invertible interface {
-       // Inverse returns the inverse of k in GF(P)
+       // Inverse returns the inverse of k mod Params().N.
        Inverse(k *big.Int) *big.Int
  }
  
- // combinedMult implements fast multiplication S1*g + S2*p (g - generator, p - arbitrary point)
+ // A combinedMult implements fast combined multiplication for verification.
  type combinedMult interface {
-       CombinedMult(bigX, bigY *big.Int, baseScalar, scalar []byte) (x, y *big.Int)
+       // CombinedMult returns [s1]G + [s2]P where G is the generator.
+       CombinedMult(Px, Py *big.Int, s1, s2 []byte) (x, y *big.Int)
  }
  
  const (
@@@ -65,8 -54,6 +59,8 @@@
  type PublicKey struct {
        elliptic.Curve
        X, Y *big.Int
 +
 +      boring unsafe.Pointer
  }
  
  // Any methods implemented on PublicKey might need to also be implemented on
@@@ -94,8 -81,6 +88,8 @@@ func (pub *PublicKey) Equal(x crypto.Pu
  type PrivateKey struct {
        PublicKey
        D *big.Int
 +
 +      boring unsafe.Pointer
  }
  
  // Public returns the public key corresponding to priv.
@@@ -120,17 -105,8 +114,17 @@@ func (priv *PrivateKey) Equal(x crypto.
  //
  // This method implements crypto.Signer, which is an interface to support keys
  // where the private part is kept in, for example, a hardware module. Common
- // uses should use the Sign function in this package directly.
+ // uses can use the SignASN1 function in this package directly.
  func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
 +      if boring.Enabled && rand == boring.RandReader {
 +              b, err := boringPrivateKey(priv)
 +              if err != nil {
 +                      return nil, err
 +              }
 +              return boring.SignMarshalECDSA(b, digest)
 +      }
 +      boring.UnreachableExceptTests()
 +
        r, s, err := Sign(rand, priv, digest)
        if err != nil {
                return nil, err
  
  var one = new(big.Int).SetInt64(1)
  
- // randFieldElement returns a random element of the field underlying the given
- // curve using the procedure given in [NSA] A.2.1.
+ // randFieldElement returns a random element of the order of the given
+ // curve using the procedure given in FIPS 186-4, Appendix B.5.1.
  func randFieldElement(c elliptic.Curve, rand io.Reader) (k *big.Int, err error) {
        params := c.Params()
-       b := make([]byte, params.BitSize/8+8)
+       // Note that for P-521 this will actually be 63 bits more than the order, as
+       // division rounds down, but the extra bit is inconsequential.
+       b := make([]byte, params.BitSize/8+8) // TODO: use params.N.BitLen()
        _, err = io.ReadFull(rand, b)
        if err != nil {
                return
  
  // GenerateKey generates a public and private key pair.
  func GenerateKey(c elliptic.Curve, rand io.Reader) (*PrivateKey, error) {
 +      if boring.Enabled && rand == boring.RandReader {
 +              x, y, d, err := boring.GenerateKeyECDSA(c.Params().Name)
 +              if err != nil {
 +                      return nil, err
 +              }
 +              return &PrivateKey{PublicKey: PublicKey{Curve: c, X: x, Y: y}, D: d}, nil
 +      }
 +      boring.UnreachableExceptTests()
 +
        k, err := randFieldElement(c, rand)
        if err != nil {
                return nil, err
        return priv, nil
  }
  
- // hashToInt converts a hash value to an integer. There is some disagreement
- // about how this is done. [NSA] suggests that this is done in the obvious
- // manner, but [SECG] truncates the hash to the bit-length of the curve order
- // first. We follow [SECG] because that's what OpenSSL does. Additionally,
- // OpenSSL right shifts excess bits from the number if the hash is too large
- // and we mirror that too.
+ // hashToInt converts a hash value to an integer. Per FIPS 186-4, Section 6.4,
+ // we use the left-most bits of the hash to match the bit-length of the order of
+ // the curve. This also performs Step 5 of SEC 1, Version 2.0, Section 4.1.3.
  func hashToInt(hash []byte, c elliptic.Curve) *big.Int {
        orderBits := c.Params().N.BitLen()
        orderBytes := (orderBits + 7) / 8
        return ret
  }
  
- // fermatInverse calculates the inverse of k in GF(P) using Fermat's method.
- // This has better constant-time properties than Euclid's method (implemented
- // in math/big.Int.ModInverse) although math/big itself isn't strictly
- // constant-time so it's not perfect.
+ // fermatInverse calculates the inverse of k in GF(P) using Fermat's method
+ // (exponentiation modulo P - 2, per Euler's theorem). This has better
+ // constant-time properties than Euclid's method (implemented in
+ // math/big.Int.ModInverse and FIPS 186-4, Appendix C.1) although math/big
+ // itself isn't strictly constant-time so it's not perfect.
  func fermatInverse(k, N *big.Int) *big.Int {
        two := big.NewInt(2)
        nMinus2 := new(big.Int).Sub(N, two)
@@@ -222,20 -189,22 +216,31 @@@ var errZeroParam = errors.New("zero par
  // Sign signs a hash (which should be the result of hashing a larger message)
  // using the private key, priv. If the hash is longer than the bit-length of the
  // private key's curve order, the hash will be truncated to that length. It
- // returns the signature as a pair of integers. The security of the private key
- // depends on the entropy of rand.
+ // returns the signature as a pair of integers. Most applications should use
+ // SignASN1 instead of dealing directly with r, s.
  func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error) {
        randutil.MaybeReadByte(rand)
  
 +      if boring.Enabled && rand == boring.RandReader {
 +              b, err := boringPrivateKey(priv)
 +              if err != nil {
 +                      return nil, nil, err
 +              }
 +              return boring.SignECDSA(b, hash)
 +      }
 +      boring.UnreachableExceptTests()
 +
+       // This implementation derives the nonce from an AES-CTR CSPRNG keyed by:
+       //
+       //    SHA2-512(priv.D || entropy || hash)[:32]
+       //
+       // The CSPRNG key is indifferentiable from a random oracle as shown in
+       // [Coron], the AES-CTR stream is indifferentiable from a random oracle
+       // under standard cryptographic assumptions (see [Larsson] for examples).
+       //
+       // [Coron]: https://cs.nyu.edu/~dodis/ps/merkle.pdf
+       // [Larsson]: https://web.archive.org/web/20040719170906/https://www.nada.kth.se/kurser/kth/2D1441/semteo03/lecturenotes/assump.pdf
        // Get 256 bits of entropy from rand.
        entropy := make([]byte, 32)
        _, err = io.ReadFull(rand, entropy)
                return
        }
  
-       // Initialize an SHA-512 hash context; digest ...
+       // Initialize an SHA-512 hash context; digest...
        md := sha512.New()
        md.Write(priv.D.Bytes()) // the private key,
        md.Write(entropy)        // the entropy,
                S: cipher.NewCTR(block, []byte(aesIV)),
        }
  
-       // See [NSA] 3.4.1
        c := priv.PublicKey.Curve
        return sign(priv, &csprng, c, hash)
  }
  
  func signGeneric(priv *PrivateKey, csprng *cipher.StreamReader, c elliptic.Curve, hash []byte) (r, s *big.Int, err error) {
+       // SEC 1, Version 2.0, Section 4.1.3
        N := c.Params().N
        if N.Sign() == 0 {
                return nil, nil, errZeroParam
  // SignASN1 signs a hash (which should be the result of hashing a larger message)
  // using the private key, priv. If the hash is longer than the bit-length of the
  // private key's curve order, the hash will be truncated to that length. It
- // returns the ASN.1 encoded signature. The security of the private key
- // depends on the entropy of rand.
+ // returns the ASN.1 encoded signature.
  func SignASN1(rand io.Reader, priv *PrivateKey, hash []byte) ([]byte, error) {
        return priv.Sign(rand, hash, nil)
  }
  
  // Verify verifies the signature in r, s of hash using the public key, pub. Its
- // return value records whether the signature is valid.
+ // return value records whether the signature is valid. Most applications should
+ // use VerifyASN1 instead of dealing directly with r, s.
  func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool {
-       // See [NSA] 3.4.2
 +      if boring.Enabled {
 +              b, err := boringPublicKey(pub)
 +              if err != nil {
 +                      return false
 +              }
 +              return boring.VerifyECDSA(b, hash, r, s)
 +      }
 +      boring.UnreachableExceptTests()
 +
        c := pub.Curve
        N := c.Params().N
  
  }
  
  func verifyGeneric(pub *PublicKey, c elliptic.Curve, hash []byte, r, s *big.Int) bool {
+       // SEC 1, Version 2.0, Section 4.1.4
        e := hashToInt(hash, c)
        var w *big.Int
        N := c.Params().N
index e07d742bd3b2d018c3215f7e0f3354bf6af2403f,d164991eec94c1c05f53d837e2bdadcded4c0717..76312984ab56afbc9c0ef0daf971c6beaeebbe56
@@@ -4,8 -4,6 +4,8 @@@
  
  package tls
  
 +import "crypto/internal/boring"
 +
  import (
        "crypto"
        "crypto/aes"
@@@ -142,7 -140,7 +142,7 @@@ type cipherSuite struct 
        ka     func(version uint16) keyAgreement
        // flags is a bitmask of the suite* values, above.
        flags  int
-       cipher func(key, iv []byte, isRead bool) interface{}
+       cipher func(key, iv []byte, isRead bool) any
        mac    func(key []byte) hash.Hash
        aead   func(key, fixedNonce []byte) aead
  }
@@@ -401,12 -399,12 +401,12 @@@ func aesgcmPreferred(ciphers []uint16) 
        return false
  }
  
- func cipherRC4(key, iv []byte, isRead bool) interface{} {
+ func cipherRC4(key, iv []byte, isRead bool) any {
        cipher, _ := rc4.NewCipher(key)
        return cipher
  }
  
- func cipher3DES(key, iv []byte, isRead bool) interface{} {
+ func cipher3DES(key, iv []byte, isRead bool) any {
        block, _ := des.NewTripleDESCipher(key)
        if isRead {
                return cipher.NewCBCDecrypter(block, iv)
        return cipher.NewCBCEncrypter(block, iv)
  }
  
- func cipherAES(key, iv []byte, isRead bool) interface{} {
+ func cipherAES(key, iv []byte, isRead bool) any {
        block, _ := aes.NewCipher(key)
        if isRead {
                return cipher.NewCBCDecrypter(block, iv)
  
  // macSHA1 returns a SHA-1 based constant time MAC.
  func macSHA1(key []byte) hash.Hash {
 -      return hmac.New(newConstantTimeHash(sha1.New), key)
 +      h := sha1.New
 +      // The BoringCrypto SHA1 does not have a constant-time
 +      // checksum function, so don't try to use it.
 +      if !boring.Enabled {
 +              h = newConstantTimeHash(h)
 +      }
 +      return hmac.New(h, key)
  }
  
  // macSHA256 returns a SHA-256 based MAC. This is only supported in TLS 1.2 and
@@@ -518,16 -510,7 +518,16 @@@ func aeadAESGCM(key, noncePrefix []byte
        if err != nil {
                panic(err)
        }
 -      aead, err := cipher.NewGCM(aes)
 +      type gcmtls interface {
 +              NewGCMTLS() (cipher.AEAD, error)
 +      }
 +      var aead cipher.AEAD
 +      if aesTLS, ok := aes.(gcmtls); ok {
 +              aead, err = aesTLS.NewGCMTLS()
 +      } else {
 +              boring.Unreachable()
 +              aead, err = cipher.NewGCM(aes)
 +      }
        if err != nil {
                panic(err)
        }
@@@ -587,7 -570,6 +587,7 @@@ func (c *cthWrapper) Write(p []byte) (i
  func (c *cthWrapper) Sum(b []byte) []byte         { return c.h.ConstantTimeSum(b) }
  
  func newConstantTimeHash(h func() hash.Hash) func() hash.Hash {
 +      boring.Unreachable()
        return func() hash.Hash {
                return &cthWrapper{h().(constantTimeHash)}
        }
diff --combined src/crypto/tls/common.go
index d17cac30eb49cd48007410c875c6bc4d81978baa,e6e7598ce97ea13c4fe6934826eac532bd8783fa..fdcebd8a06e17d0475f3632570b2819d57d153af
@@@ -172,11 -172,11 +172,11 @@@ const 
  // hash function associated with the Ed25519 signature scheme.
  var directSigning crypto.Hash = 0
  
 -// supportedSignatureAlgorithms contains the signature and hash algorithms that
 +// defaultSupportedSignatureAlgorithms contains the signature and hash algorithms that
  // the code advertises as supported in a TLS 1.2+ ClientHello and in a TLS 1.2+
  // CertificateRequest. The two fields are merged to match with TLS 1.3.
  // Note that in TLS 1.2, the ECDSA algorithms are not constrained to P-256, etc.
 -var supportedSignatureAlgorithms = []SignatureScheme{
 +var defaultSupportedSignatureAlgorithms = []SignatureScheme{
        PSSWithSHA256,
        ECDSAWithP256AndSHA256,
        Ed25519,
@@@ -961,9 -961,6 +961,9 @@@ func (c *Config) time() time.Time 
  }
  
  func (c *Config) cipherSuites() []uint16 {
 +      if needFIPS() {
 +              return fipsCipherSuites(c)
 +      }
        if c.CipherSuites != nil {
                return c.CipherSuites
        }
@@@ -988,9 -985,6 +988,9 @@@ const roleServer = fals
  func (c *Config) supportedVersions(isClient bool) []uint16 {
        versions := make([]uint16, 0, len(supportedVersions))
        for _, v := range supportedVersions {
 +              if needFIPS() && (v < fipsMinVersion(c) || v > fipsMaxVersion(c)) {
 +                      continue
 +              }
                if (c == nil || c.MinVersion == 0) && !debugEnableTLS10 &&
                        isClient && v < VersionTLS12 {
                        continue
@@@ -1031,9 -1025,6 +1031,9 @@@ func supportedVersionsFromMax(maxVersio
  var defaultCurvePreferences = []CurveID{X25519, CurveP256, CurveP384, CurveP521}
  
  func (c *Config) curvePreferences() []CurveID {
 +      if needFIPS() {
 +              return fipsCurvePreferences(c)
 +      }
        if c == nil || len(c.CurvePreferences) == 0 {
                return defaultCurvePreferences
        }
@@@ -1475,7 -1466,7 +1475,7 @@@ func defaultConfig() *Config 
        return &emptyConfig
  }
  
- func unexpectedMessageError(wanted, got interface{}) error {
+ func unexpectedMessageError(wanted, got any) error {
        return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted)
  }
  
index c368c6cd584b539a38569c925dfe31639a24c940,a3e00777f12559e4739eaf424e227695de1b3126..7bf0f84417c767a430bc02f605b1f51f384b480f
@@@ -117,10 -117,7 +117,10 @@@ func (c *Conn) makeClientHello() (*clie
        }
  
        if hello.vers >= VersionTLS12 {
 -              hello.supportedSignatureAlgorithms = supportedSignatureAlgorithms
 +              hello.supportedSignatureAlgorithms = supportedSignatureAlgorithms()
 +      }
 +      if testingOnlyForceClientHelloSignatureAlgorithms != nil {
 +              hello.supportedSignatureAlgorithms = testingOnlyForceClientHelloSignatureAlgorithms
        }
  
        var params ecdheParameters
@@@ -660,7 -657,7 +660,7 @@@ func (hs *clientHandshakeState) establi
  
        clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
                keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.hello.random, hs.serverHello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen)
-       var clientCipher, serverCipher interface{}
+       var clientCipher, serverCipher any
        var clientHash, serverHash hash.Hash
        if hs.suite.cipher != nil {
                clientCipher = hs.suite.cipher(clientKey, clientIV, false /* not for reading */)
@@@ -859,8 -856,6 +859,8 @@@ func (c *Conn) verifyServerCertificate(
  
        if !c.config.InsecureSkipVerify {
                opts := x509.VerifyOptions{
 +                      IsBoring: isBoringCertificate,
 +
                        Roots:         c.config.RootCAs,
                        CurrentTime:   c.config.time(),
                        DNSName:       c.config.ServerName,
index 8821670e9ae432803fce44b136f502c2aa020d60,cc427bf72a01726b54b1748f696174a83fd504a8..2f5d0e42a85a11aaf2f04b16bf8948655dc3011e
@@@ -14,7 -14,7 +14,7 @@@ import 
        "time"
  )
  
- var tests = []interface{}{
+ var tests = []any{
        &clientHelloMsg{},
        &serverHelloMsg{},
        &finishedMsg{},
@@@ -147,10 -147,10 +147,10 @@@ func (*clientHelloMsg) Generate(rand *r
                }
        }
        if rand.Intn(10) > 5 {
 -              m.supportedSignatureAlgorithms = supportedSignatureAlgorithms
 +              m.supportedSignatureAlgorithms = supportedSignatureAlgorithms()
        }
        if rand.Intn(10) > 5 {
 -              m.supportedSignatureAlgorithmsCert = supportedSignatureAlgorithms
 +              m.supportedSignatureAlgorithmsCert = supportedSignatureAlgorithms()
        }
        for i := 0; i < rand.Intn(5); i++ {
                m.alpnProtocols = append(m.alpnProtocols, randomString(rand.Intn(20)+1, rand))
@@@ -369,10 -369,10 +369,10 @@@ func (*certificateRequestMsgTLS13) Gene
                m.scts = true
        }
        if rand.Intn(10) > 5 {
 -              m.supportedSignatureAlgorithms = supportedSignatureAlgorithms
 +              m.supportedSignatureAlgorithms = supportedSignatureAlgorithms()
        }
        if rand.Intn(10) > 5 {
 -              m.supportedSignatureAlgorithmsCert = supportedSignatureAlgorithms
 +              m.supportedSignatureAlgorithmsCert = supportedSignatureAlgorithms()
        }
        if rand.Intn(10) > 5 {
                m.certificateAuthorities = make([][]byte, 3)
index be6424889105cfbba8ff2e1afbac0f1403f6d6d6,097046340b87b6714ad1ff7d8684c7b3d6a6a496..5db605681e46ac948b8cdfe9324a0641c3558768
@@@ -541,7 -541,7 +541,7 @@@ func (hs *serverHandshakeState) doFullH
                }
                if c.vers >= VersionTLS12 {
                        certReq.hasSignatureAlgorithm = true
 -                      certReq.supportedSignatureAlgorithms = supportedSignatureAlgorithms
 +                      certReq.supportedSignatureAlgorithms = supportedSignatureAlgorithms()
                }
  
                // An empty list of certificateAuthorities signals to
@@@ -681,7 -681,7 +681,7 @@@ func (hs *serverHandshakeState) establi
        clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
                keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.clientHello.random, hs.hello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen)
  
-       var clientCipher, serverCipher interface{}
+       var clientCipher, serverCipher any
        var clientHash, serverHash hash.Hash
  
        if hs.suite.aead == nil {
@@@ -812,8 -812,6 +812,8 @@@ func (c *Conn) processCertsFromClient(c
  
        if c.config.ClientAuth >= VerifyClientCertIfGiven && len(certs) > 0 {
                opts := x509.VerifyOptions{
 +                      IsBoring: isBoringCertificate,
 +
                        Roots:         c.config.ClientCAs,
                        CurrentTime:   c.config.time(),
                        Intermediates: x509.NewCertPool(),
index 25a526181ced3905a36629927ee2c7d1cf52fa84,e8c7707f3fee4a19680fc896260eeda61781678b..98778fe4556c119ea56a5d94bd353e6017848a24
@@@ -172,11 -172,6 +172,11 @@@ var errNotParsed = errors.New("x509: mi
  
  // VerifyOptions contains parameters for Certificate.Verify.
  type VerifyOptions struct {
 +      // IsBoring is a validity check for BoringCrypto.
 +      // If not nil, it will be called to check whether a given certificate
 +      // can be used for constructing verification chains.
 +      IsBoring func(*Certificate) bool
 +
        // DNSName, if set, is checked against the leaf certificate with
        // Certificate.VerifyHostname or the platform verifier.
        DNSName string
@@@ -505,9 -500,9 +505,9 @@@ func (c *Certificate) checkNameConstrai
        maxConstraintComparisons int,
        nameType string,
        name string,
-       parsedName interface{},
-       match func(parsedName, constraint interface{}) (match bool, err error),
-       permitted, excluded interface{}) error {
+       parsedName any,
+       match func(parsedName, constraint any) (match bool, err error),
+       permitted, excluded any) error {
  
        excludedValue := reflect.ValueOf(excluded)
  
@@@ -614,7 -609,7 +614,7 @@@ func (c *Certificate) isValid(certType 
                                }
  
                                if err := c.checkNameConstraints(&comparisonCount, maxConstraintComparisons, "email address", name, mailbox,
-                                       func(parsedName, constraint interface{}) (bool, error) {
+                                       func(parsedName, constraint any) (bool, error) {
                                                return matchEmailConstraint(parsedName.(rfc2821Mailbox), constraint.(string))
                                        }, c.PermittedEmailAddresses, c.ExcludedEmailAddresses); err != nil {
                                        return err
                                }
  
                                if err := c.checkNameConstraints(&comparisonCount, maxConstraintComparisons, "DNS name", name, name,
-                                       func(parsedName, constraint interface{}) (bool, error) {
+                                       func(parsedName, constraint any) (bool, error) {
                                                return matchDomainConstraint(parsedName.(string), constraint.(string))
                                        }, c.PermittedDNSDomains, c.ExcludedDNSDomains); err != nil {
                                        return err
                                }
  
                                if err := c.checkNameConstraints(&comparisonCount, maxConstraintComparisons, "URI", name, uri,
-                                       func(parsedName, constraint interface{}) (bool, error) {
+                                       func(parsedName, constraint any) (bool, error) {
                                                return matchURIConstraint(parsedName.(*url.URL), constraint.(string))
                                        }, c.PermittedURIDomains, c.ExcludedURIDomains); err != nil {
                                        return err
                                }
  
                                if err := c.checkNameConstraints(&comparisonCount, maxConstraintComparisons, "IP address", ip.String(), ip,
-                                       func(parsedName, constraint interface{}) (bool, error) {
+                                       func(parsedName, constraint any) (bool, error) {
                                                return matchIPConstraint(parsedName.(net.IP), constraint.(*net.IPNet))
                                        }, c.PermittedIPRanges, c.ExcludedIPRanges); err != nil {
                                        return err
                }
        }
  
 +      if opts.IsBoring != nil && !opts.IsBoring(c) {
 +              // IncompatibleUsage is not quite right here,
 +              // but it's also the "no chains found" error
 +              // and is close enough.
 +              return CertificateInvalidError{c, IncompatibleUsage, ""}
 +      }
 +
        return nil
  }
  
@@@ -753,9 -741,20 +753,20 @@@ func (c *Certificate) Verify(opts Verif
                }
        }
  
-       // Use Windows's own verification and chain building.
-       if opts.Roots == nil && runtime.GOOS == "windows" {
-               return c.systemVerify(&opts)
+       // Use platform verifiers, where available, if Roots is from SystemCertPool.
+       if runtime.GOOS == "windows" || runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
+               if opts.Roots == nil {
+                       return c.systemVerify(&opts)
+               }
+               if opts.Roots != nil && opts.Roots.systemPool {
+                       platformChains, err := c.systemVerify(&opts)
+                       // If the platform verifier succeeded, or there are no additional
+                       // roots, return the platform verifier result. Otherwise, continue
+                       // with the Go verifier.
+                       if err == nil || opts.Roots.len() == 0 {
+                               return platformChains, err
+                       }
+               }
        }
  
        if opts.Roots == nil {
diff --combined src/go/build/build.go
index b0decbba9f514db3fea79803040f7fba7f5bd4d7,dce0304ba48cc5e9a8c5a3aae3bdea21fa70b27f..4bf46a8970be3a882096aa93e0c5a9a9138730a5
@@@ -789,7 -789,7 +789,7 @@@ Found
                }
  
                // package was not found
-               return p, fmt.Errorf("cannot find package %q in:\n\t%s", path, p.Dir)
+               return p, fmt.Errorf("cannot find package %q in:\n\t%s", p.ImportPath, p.Dir)
        }
  
        if mode&FindOnly != 0 {
  
                isTest := strings.HasSuffix(name, "_test.go")
                isXTest := false
-               if isTest && strings.HasSuffix(pkg, "_test") {
+               if isTest && strings.HasSuffix(pkg, "_test") && p.Name != pkg {
                        isXTest = true
                        pkg = pkg[:len(pkg)-len("_test")]
                }
@@@ -1872,7 -1872,6 +1872,7 @@@ func (ctxt *Context) eval(x constraint.
  //    cgo (if cgo is enabled)
  //    $GOOS
  //    $GOARCH
 +//    boringcrypto
  //    ctxt.Compiler
  //    linux (if GOOS = android)
  //    solaris (if GOOS = illumos)
@@@ -1900,10 -1899,6 +1900,10 @@@ func (ctxt *Context) matchTag(name stri
        if ctxt.GOOS == "ios" && name == "darwin" {
                return true
        }
 +      // Let applications know that the Go+BoringCrypto toolchain is in use.
 +      if name == "boringcrypto" {
 +              return true
 +      }
  
        // other tags
        for _, tag := range ctxt.BuildTags {
index 9b5dabf6f144156d8f0e5be05058470bf876b9ae,7f25038d2d09da29f507b8c750611033e0cc05ab..c148f99123d63985da3d6be7560a908eb6d0c010
@@@ -337,7 -337,7 +337,7 @@@ var depsRules = 
  
        # Bulk of the standard library must not use cgo.
        # The prohibition stops at net and os/user.
 -      C !< fmt, go/types, CRYPTO-MATH;
 +      C !< fmt, go/types;
  
        CGO, OS
        < plugin;
        NET, log
        < net/mail;
  
 -      # CRYPTO is core crypto algorithms - no cgo, fmt, net.
 -      # Unfortunately, stuck with reflect via encoding/binary.
 -      encoding/binary, golang.org/x/sys/cpu, hash
 +      NONE < crypto/internal/boring/sig;
 +      sync/atomic < crypto/internal/boring/fipstls;
 +
 +      encoding/binary, golang.org/x/sys/cpu, hash,
 +      FMT, math/big,
 +      CGO, crypto/internal/boring/sig, crypto/internal/boring/fipstls
        < crypto
        < crypto/subtle
        < crypto/internal/subtle
        < crypto/ed25519/internal/edwards25519/field, golang.org/x/crypto/curve25519/internal/field
        < crypto/ed25519/internal/edwards25519
        < crypto/cipher
 +      < encoding/asn1
 +      < crypto/internal/boring
        < crypto/aes, crypto/des, crypto/hmac, crypto/md5, crypto/rc4,
          crypto/sha1, crypto/sha256, crypto/sha512
 -      < CRYPTO;
 -
 -      CGO, fmt, net !< CRYPTO;
 -
 -      # CRYPTO-MATH is core bignum-based crypto - no cgo, net; fmt now ok.
 -      CRYPTO, FMT, math/big
        < crypto/rand
        < crypto/internal/randutil
        < crypto/ed25519
 -      < encoding/asn1
        < golang.org/x/crypto/cryptobyte/asn1
        < golang.org/x/crypto/cryptobyte
        < golang.org/x/crypto/curve25519
        < crypto/dsa, crypto/elliptic, crypto/rsa
        < crypto/ecdsa
 -      < CRYPTO-MATH;
 +      < CRYPTO-BORING;
  
 -      CGO, net !< CRYPTO-MATH;
 +      net !< CRYPTO-BORING;
  
        # TLS, Prince of Dependencies.
 -      CRYPTO-MATH, NET, container/list, encoding/hex, encoding/pem
 +      CRYPTO-BORING, NET, container/list, encoding/hex, encoding/pem
        < golang.org/x/crypto/internal/subtle
        < golang.org/x/crypto/chacha20
-       < golang.org/x/crypto/poly1305
+       < golang.org/x/crypto/internal/poly1305
        < golang.org/x/crypto/chacha20poly1305
        < golang.org/x/crypto/hkdf
        < crypto/x509/internal/macos
        < crypto/x509
        < crypto/tls;
  
 +      crypto/internal/boring/sig, crypto/internal/boring/fipstls
 +      < crypto/tls/fipsonly;
 +
 +      crypto/internal/boring
 +      < crypto/boring;
 +
        # crypto-aware packages
  
        NET, crypto/rand, mime/quotedprintable
        NET, testing, math/rand
        < golang.org/x/net/nettest;
  
+       syscall
+       < os/exec/internal/fdtest;
        FMT, container/heap, math/rand
        < internal/trace;
  `
index b60cabfe86aacc506efd984b5af6efd3ea0ac220,2d093739dfbd5e792b6c846b3bb4c14b0111a525..94b6e58de093dd1c017b8c15b4dd4ca988a011bc
@@@ -6,9 -6,9 +6,9 @@@ package race_tes
  
  import (
        "bytes"
 -      "crypto/sha1"
        "errors"
        "fmt"
 +      "hash/crc32"
        "io"
        "os"
        "runtime"
@@@ -255,7 -255,7 +255,7 @@@ func TestRaceCaseIssue6418(t *testing.T
  
  func TestRaceCaseType(t *testing.T) {
        var x, y int
-       var i interface{} = x
+       var i any = x
        c := make(chan int, 1)
        go func() {
                switch i.(type) {
  
  func TestRaceCaseTypeBody(t *testing.T) {
        var x, y int
-       var i interface{} = &x
+       var i any = &x
        c := make(chan int, 1)
        go func() {
                switch i := i.(type) {
@@@ -288,8 -288,8 +288,8 @@@ func TestRaceCaseTypeIssue5890(t *testi
        // spurious extra instrumentation of the initial interface
        // value.
        var x, y int
-       m := make(map[int]map[int]interface{})
-       m[0] = make(map[int]interface{})
+       m := make(map[int]map[int]any)
+       m[0] = make(map[int]any)
        c := make(chan int, 1)
        go func() {
                switch i := m[0][1].(type) {
@@@ -758,7 -758,7 +758,7 @@@ func TestRaceStructFieldRW3(t *testing.
  }
  
  func TestRaceEfaceWW(t *testing.T) {
-       var a, b interface{}
+       var a, b any
        ch := make(chan bool, 1)
        go func() {
                a = 1
@@@ -810,7 -810,7 +810,7 @@@ func TestRaceEfaceConv(t *testing.T) 
        c := make(chan bool)
        v := 0
        go func() {
-               go func(x interface{}) {
+               go func(x any) {
                }(v)
                c <- true
        }()
@@@ -1127,7 -1127,7 +1127,7 @@@ func TestRaceRune(t *testing.T) 
  
  func TestRaceEmptyInterface1(t *testing.T) {
        c := make(chan bool)
-       var x interface{}
+       var x any
        go func() {
                x = nil
                c <- true
  
  func TestRaceEmptyInterface2(t *testing.T) {
        c := make(chan bool)
-       var x interface{}
+       var x any
        go func() {
                x = &Point{}
                c <- true
@@@ -1579,7 -1579,7 +1579,7 @@@ func TestRaceAddrExpr(t *testing.T) 
  func TestRaceTypeAssert(t *testing.T) {
        c := make(chan bool, 1)
        x := 0
-       var i interface{} = x
+       var i any = x
        go func() {
                y := 0
                i = y
@@@ -1924,7 -1924,7 +1924,7 @@@ func TestRaceIssue5567(t *testing.T) 
                        err = nil
                }
        }()
 -      h := sha1.New()
 +      h := crc32.New(crc32.MakeTable(0x12345678))
        for b := range in {
                h.Write(b)
        }