Run `go fix`

Go 1.26 includes a new `go fix` that updates Go code to take advantage
of more recent abilities. This CL runs it over the code base.

Change-Id: I3772015d1f6f09e49d52e2446dc6706d6548b28c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/89587
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Auto-Submit: Adam Langley <agl@google.com>
diff --git a/crypto/cipher/test/make_legacy_aead_tests.go b/crypto/cipher/test/make_legacy_aead_tests.go
index b5c6894..8bf4623 100644
--- a/crypto/cipher/test/make_legacy_aead_tests.go
+++ b/crypto/cipher/test/make_legacy_aead_tests.go
@@ -296,7 +296,7 @@
 	// block cipher rotations. This is to ensure full coverage of the
 	// kVarianceBlocks value in the constant-time logic.
 	hashBlockSize := hash.New().BlockSize()
-	for i := 0; i < hashBlockSize; i++ {
+	for i := range hashBlockSize {
 		fmt.Printf("# Test with maximal padding (%d mod %d).\n", i, hashBlockSize)
 		addTestCase(hashBlockSize+i, options{maximalPadding: true})
 	}
@@ -305,7 +305,7 @@
 	addTestCase(0, options{omitMAC: true, maximalPadding: true})
 
 	fmt.Printf("# Test that each byte of incorrect padding is noticed.\n")
-	for i := 0; i < 256; i++ {
+	for i := range 256 {
 		addTestCase(64-hash.Size(), options{
 			maximalPadding:     true,
 			wrongPadding:       true,
diff --git a/crypto/cipher/test/nist_cavp/make_cavp.go b/crypto/cipher/test/nist_cavp/make_cavp.go
index 0de782c..0a6701e 100644
--- a/crypto/cipher/test/nist_cavp/make_cavp.go
+++ b/crypto/cipher/test/nist_cavp/make_cavp.go
@@ -99,8 +99,8 @@
 	// Auxiliary labels passed as a flag.
 	cmdLineLabels := make(map[string]string)
 	if cmdLineLabelStr != "" {
-		pairs := strings.Split(cmdLineLabelStr, ",")
-		for _, p := range pairs {
+		pairs := strings.SplitSeq(cmdLineLabelStr, ",")
+		for p := range pairs {
 			key, value := t.parseKeyValue(p)
 			cmdLineLabels[key] = value
 		}
diff --git a/crypto/fipsmodule/bn/bn_test_to_fuzzer.go b/crypto/fipsmodule/bn/bn_test_to_fuzzer.go
index 6e100cc..3038d760 100644
--- a/crypto/fipsmodule/bn/bn_test_to_fuzzer.go
+++ b/crypto/fipsmodule/bn/bn_test_to_fuzzer.go
@@ -26,6 +26,7 @@
 	"math/big"
 	"os"
 	"path/filepath"
+	"slices"
 	"strings"
 )
 
@@ -141,14 +142,7 @@
 	}
 
 	for k := range t.Values {
-		var found bool
-		for _, k2 := range keys {
-			if k == k2 {
-				found = true
-				break
-			}
-		}
-		if !found {
+		if !slices.Contains(keys, k) {
 			fmt.Fprintf(os.Stderr, "Line %d: unexpected key %q.\n", t.LineNumber, k)
 			foundErrors = true
 		}
diff --git a/crypto/fipsmodule/bn/check_bn_tests.go b/crypto/fipsmodule/bn/check_bn_tests.go
index 3541e60..c271d75 100644
--- a/crypto/fipsmodule/bn/check_bn_tests.go
+++ b/crypto/fipsmodule/bn/check_bn_tests.go
@@ -23,6 +23,7 @@
 	"io"
 	"math/big"
 	"os"
+	"slices"
 	"strings"
 )
 
@@ -138,14 +139,7 @@
 	}
 
 	for k := range t.Values {
-		var found bool
-		for _, k2 := range keys {
-			if k == k2 {
-				found = true
-				break
-			}
-		}
-		if !found {
+		if !slices.Contains(keys, k) {
 			fmt.Fprintf(os.Stderr, "Line %d: unexpected key %q.\n", t.LineNumber, k)
 			foundErrors = true
 		}
diff --git a/crypto/fipsmodule/ec/make_p256-nistz-tests.go b/crypto/fipsmodule/ec/make_p256-nistz-tests.go
index 75b149f..2317233 100644
--- a/crypto/fipsmodule/ec/make_p256-nistz-tests.go
+++ b/crypto/fipsmodule/ec/make_p256-nistz-tests.go
@@ -186,27 +186,27 @@
 	printTestCase(gx, gy, affine, gx, minusGy, affine)
 
 	fmt.Printf("# Test some random Jacobian sums.\n")
-	for i := 0; i < 4; i++ {
+	for range 4 {
 		ax, ay := randPoint()
 		bx, by := randPoint()
 		printTestCase(ax, ay, jacobian, bx, by, jacobian)
 	}
 
 	fmt.Printf("# Test some random Jacobian doublings.\n")
-	for i := 0; i < 4; i++ {
+	for range 4 {
 		ax, ay := randPoint()
 		printTestCase(ax, ay, jacobian, ax, ay, jacobian)
 	}
 
 	fmt.Printf("# Test some random affine sums.\n")
-	for i := 0; i < 4; i++ {
+	for range 4 {
 		ax, ay := randPoint()
 		bx, by := randPoint()
 		printTestCase(ax, ay, affine, bx, by, affine)
 	}
 
 	fmt.Printf("# Test some random affine doublings.\n")
-	for i := 0; i < 4; i++ {
+	for range 4 {
 		ax, ay := randPoint()
 		printTestCase(ax, ay, affine, ax, ay, affine)
 	}
diff --git a/crypto/fipsmodule/ec/make_tables.go b/crypto/fipsmodule/ec/make_tables.go
index 323bf4d..8c58514 100644
--- a/crypto/fipsmodule/ec/make_tables.go
+++ b/crypto/fipsmodule/ec/make_tables.go
@@ -307,7 +307,7 @@
 func makeMultiples(curve elliptic.Curve, n, shift int) [][2]*big.Int {
 	ret := make([][2]*big.Int, n)
 	x, y := curve.Params().Gx, curve.Params().Gy
-	for j := 0; j < shift; j++ {
+	for range shift {
 		x, y = curve.Double(x, y)
 	}
 	ret[1-1] = [2]*big.Int{x, y}
@@ -330,14 +330,14 @@
 func makeComb(curve elliptic.Curve, stride, size, shift int) [][2]*big.Int {
 	ret := make([][2]*big.Int, 1<<size-1)
 	x, y := curve.Params().Gx, curve.Params().Gy
-	for j := 0; j < shift; j++ {
+	for range shift {
 		x, y = curve.Double(x, y)
 	}
 	ret[1<<0-1] = [2]*big.Int{x, y}
 	for i := 1; i < size; i++ {
 		// Entry 2^i is entry 2^(i-1) doubled stride times.
 		x, y = ret[1<<(i-1)-1][0], ret[1<<(i-1)-1][1]
-		for j := 0; j < stride; j++ {
+		for range stride {
 			x, y = curve.Double(x, y)
 		}
 		ret[1<<i-1] = [2]*big.Int{x, y}
@@ -427,7 +427,7 @@
 }
 
 func writeIndent(w io.Writer, indent int) error {
-	for i := 0; i < indent; i++ {
+	for range indent {
 		if _, err := io.WriteString(w, " "); err != nil {
 			return err
 		}
diff --git a/crypto/x509/test/make_many_constraints.go b/crypto/x509/test/make_many_constraints.go
index 8a06b37..f32626f 100644
--- a/crypto/x509/test/make_many_constraints.go
+++ b/crypto/x509/test/make_many_constraints.go
@@ -114,10 +114,10 @@
 		KeyUsage:              x509.KeyUsageCertSign,
 		SignatureAlgorithm:    x509.SHA256WithRSA,
 	}
-	for i := 0; i < 513; i++ {
+	for i := range 513 {
 		caTemplate.ExcludedDNSDomains = append(caTemplate.ExcludedDNSDomains, fmt.Sprintf("x%d.test", i))
 	}
-	for i := 0; i < 513; i++ {
+	for i := range 513 {
 		caTemplate.PermittedDNSDomains = append(caTemplate.PermittedDNSDomains, fmt.Sprintf("t%d.test", i))
 	}
 	caTemplate.PermittedDNSDomains = append(caTemplate.PermittedDNSDomains, ".test")
@@ -166,7 +166,7 @@
 					Class:      asn1.ClassUniversal,
 					Tag:        asn1.TagIA5String,
 					IsCompound: false,
-					Bytes:      []byte(fmt.Sprintf("t%d@test", i)),
+					Bytes:      fmt.Appendf(nil, "t%d@test", i),
 				},
 			})
 		}
diff --git a/ssl/test/runner/basic_tests.go b/ssl/test/runner/basic_tests.go
index faeb352..dfd17d5 100644
--- a/ssl/test/runner/basic_tests.go
+++ b/ssl/test/runner/basic_tests.go
@@ -1788,7 +1788,7 @@
 
 	// Test that very large messages can be received.
 	cert := rsaCertificate
-	for i := 0; i < 50; i++ {
+	for range 50 {
 		cert.Certificate = append(cert.Certificate, cert.Certificate[0])
 	}
 	testCases = append(testCases, testCase{
diff --git a/ssl/test/runner/dtls_tests.go b/ssl/test/runner/dtls_tests.go
index d2e1614..45bbf67 100644
--- a/ssl/test/runner/dtls_tests.go
+++ b/ssl/test/runner/dtls_tests.go
@@ -191,7 +191,7 @@
 				// In DTLS 1.2, the final flight is retransmitted on receipt of
 				// the previous flight. Test the peer is willing to retransmit
 				// it several times.
-				for i := 0; i < 5; i++ {
+				for range 5 {
 					c.WriteFlight(prev)
 					c.ReadRetransmit()
 				}
diff --git a/ssl/test/runner/handshake_server.go b/ssl/test/runner/handshake_server.go
index 238f25c..66e73f6 100644
--- a/ssl/test/runner/handshake_server.go
+++ b/ssl/test/runner/handshake_server.go
@@ -1462,7 +1462,7 @@
 	// testing.
 	if !c.config.SessionTicketsDisabled && foundKEMode {
 		ticketCount := 2
-		for i := 0; i < ticketCount; i++ {
+		for i := range ticketCount {
 			c.SendNewSessionTicket([]byte{byte(i)})
 		}
 		if err := c.flushHandshake(); err != nil {
@@ -1810,15 +1810,8 @@
 			return false
 		}
 
-		cipherSuiteOk := false
 		// Check that the client is still offering the ciphersuite in the session.
-		for _, id := range hs.clientHello.cipherSuites {
-			if id == hs.sessionState.cipherSuite {
-				cipherSuiteOk = true
-				break
-			}
-		}
-		if !cipherSuiteOk {
+		if !slices.Contains(hs.clientHello.cipherSuites, hs.sessionState.cipherSuite) {
 			return false
 		}
 	}
@@ -2316,14 +2309,7 @@
 			return nil, errors.New("tls: failed to verify client's certificate: " + err.Error())
 		}
 
-		ok := false
-		for _, ku := range certs[0].ExtKeyUsage {
-			if ku == x509.ExtKeyUsageClientAuth {
-				ok = true
-				break
-			}
-		}
-		if !ok {
+		if !slices.Contains(certs[0].ExtKeyUsage, x509.ExtKeyUsageClientAuth) {
 			c.sendAlert(alertHandshakeFailure)
 			return nil, errors.New("tls: client's certificate's extended key usage doesn't permit it to be used for client authentication")
 		}
diff --git a/ssl/test/runner/key_update_tests.go b/ssl/test/runner/key_update_tests.go
index 0a90530..f985282 100644
--- a/ssl/test/runner/key_update_tests.go
+++ b/ssl/test/runner/key_update_tests.go
@@ -232,7 +232,7 @@
 					// an ACK. (If it sent KeyUpdate, ReadAppData would report
 					// an unexpected record.)
 					msg := []byte("test")
-					for i := 0; i < 10; i++ {
+					for range 10 {
 						c.WriteAppData(c.OutEpoch(), msg)
 						c.ReadAppData(c.InEpoch(), expectedReply(msg))
 					}
@@ -241,7 +241,7 @@
 					c.WriteACK(c.OutEpoch(), records[:1])
 
 					// The shim continues to defer KeyUpdate.
-					for i := 0; i < 10; i++ {
+					for range 10 {
 						c.WriteAppData(c.OutEpoch(), msg)
 						c.ReadAppData(c.InEpoch(), expectedReply(msg))
 					}
@@ -279,7 +279,7 @@
 					// try to KeyUpdate again. These calls will be suppressed
 					// because there is still an outstanding KeyUpdate.
 					msg := []byte("test")
-					for i := 0; i < 10; i++ {
+					for range 10 {
 						c.WriteAppData(c.OutEpoch(), msg)
 						c.ReadAppData(c.InEpoch()-1, expectedReply(msg))
 					}
diff --git a/ssl/test/runner/prf.go b/ssl/test/runner/prf.go
index 4062a23..7fda3a7 100644
--- a/ssl/test/runner/prf.go
+++ b/ssl/test/runner/prf.go
@@ -440,7 +440,7 @@
 func (h *finishedHash) certificateVerifyInput(context []byte) []byte {
 	const paddingLen = 64
 	b := make([]byte, paddingLen, paddingLen+len(context)+1+2*h.hash.Size())
-	for i := 0; i < paddingLen; i++ {
+	for i := range paddingLen {
 		b[i] = 32
 	}
 	b = append(b, context...)
diff --git a/ssl/test/runner/recordingconn.go b/ssl/test/runner/recordingconn.go
index 465d745..df90623 100644
--- a/ssl/test/runner/recordingconn.go
+++ b/ssl/test/runner/recordingconn.go
@@ -153,8 +153,8 @@
 			return nil, errors.New("invalid test data")
 		}
 
-		hexBytes := strings.Fields(line)
-		for _, hexByte := range hexBytes {
+		hexBytes := strings.FieldsSeq(line)
+		for hexByte := range hexBytes {
 			val, err := strconv.ParseUint(hexByte, 16, 8)
 			if err != nil {
 				return nil, errors.New("invalid hex byte in test data: " + err.Error())
diff --git a/ssl/test/runner/runner.go b/ssl/test/runner/runner.go
index 80a72dc..786aba7 100644
--- a/ssl/test/runner/runner.go
+++ b/ssl/test/runner/runner.go
@@ -345,15 +345,15 @@
 
 // encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
 func encodeDERValues(values [][]byte) string {
-	var ret string
+	var ret strings.Builder
 	for i, v := range values {
 		if i > 0 {
-			ret += ","
+			ret.WriteString(",")
 		}
-		ret += hex.EncodeToString(v)
+		ret.WriteString(hex.EncodeToString(v))
 	}
 
-	return ret
+	return ret.String()
 }
 
 func decodeHexOrPanic(in string) []byte {
@@ -1210,12 +1210,12 @@
 }
 
 func removeFirstLineIfSuffix(s, suffix string) string {
-	idx := strings.IndexByte(s, '\n')
-	if idx < 0 {
+	before, after, ok := strings.Cut(s, "\n")
+	if !ok {
 		return s
 	}
-	if strings.HasSuffix(s[:idx], suffix) {
-		return s[idx+1:]
+	if strings.HasSuffix(before, suffix) {
+		return after
 	}
 	return s
 }
@@ -1335,7 +1335,7 @@
 	}
 
 	nextTicketKey := config.SessionTicketKey
-	for i := 0; i < resumeCount; i++ {
+	for i := range resumeCount {
 		var resumeConfig Config
 		if test.resumeConfig != nil {
 			resumeConfig = *test.resumeConfig
@@ -2051,11 +2051,11 @@
 	for msg := range statusChan {
 		if !*pipe {
 			// Erase the previous status line.
-			var erase string
-			for i := 0; i < lineLen; i++ {
-				erase += "\b \b"
+			var erase strings.Builder
+			for range lineLen {
+				erase.WriteString("\b \b")
 			}
-			fmt.Print(erase)
+			fmt.Print(erase.String())
 		}
 
 		if msg.statusType == statusStarted {
@@ -2154,12 +2154,7 @@
 					found = found || test.resumeExpectations.version == ver.version
 				}
 				shimFlag := ver.shimFlag(test.protocol)
-				for _, flag := range test.flags {
-					if flag == shimFlag {
-						found = true
-						break
-					}
-				}
+				found = found || slices.Contains(test.flags, shimFlag)
 				if !found {
 					panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but the test does not reference %s", test.name, ver.name))
 				}
diff --git a/ssl/test/runner/shim_ticket.go b/ssl/test/runner/shim_ticket.go
index b9fabac..767ffe4 100644
--- a/ssl/test/runner/shim_ticket.go
+++ b/ssl/test/runner/shim_ticket.go
@@ -75,7 +75,7 @@
 		return nil, errors.New("tls: bad shim ticket CBC pad")
 	}
 
-	for i := 0; i < pad; i++ {
+	for i := range pad {
 		if out[len(out)-1-i] != byte(pad) {
 			return nil, errors.New("tls: bad shim ticket CBC pad")
 		}
@@ -105,7 +105,7 @@
 	out = append(out, name...)
 	out = append(out, iv...)
 	out = append(out, in...)
-	for i := 0; i < pad; i++ {
+	for range pad {
 		out = append(out, byte(pad))
 	}
 
diff --git a/ssl/test/runner/version_tests.go b/ssl/test/runner/version_tests.go
index 51be8b3..5a9e727 100644
--- a/ssl/test/runner/version_tests.go
+++ b/ssl/test/runner/version_tests.go
@@ -29,19 +29,13 @@
 
 			// Test configuring the runner's maximum version.
 			for _, runnerVers := range allVersions(protocol) {
-				expectedVersion := shimVers.version
-				if runnerVers.version < shimVers.version {
-					expectedVersion = runnerVers.version
-				}
+				expectedVersion := min(runnerVers.version, shimVers.version)
 
 				suffix := shimVers.name + "-" + runnerVers.name
 				suffix += "-" + protocol.String()
 
 				// Determine the expected initial record-layer versions.
-				clientVers := shimVers.version
-				if clientVers > VersionTLS10 {
-					clientVers = VersionTLS10
-				}
+				clientVers := min(shimVers.version, VersionTLS10)
 				clientVers = recordVersionToWire(clientVers, protocol)
 				serverVers := expectedVersion
 				if expectedVersion >= VersionTLS13 {