Commit 1c52a60bf8 for golang

commit 1c52a60bf822d754fca806153c75b02f17dccf1a
Author: Neal Patel <neal@golang.org>
Date:   Fri Dec 4 15:32:59 2026 -0500

    crypto/tls: add tlskex and tlsauth GODEBUG settings

    We add two GODEBUG settings to provide users
    with additional options for how key exchange
    (KEX) and authentication work in crypto/tls.

    Similarly to the FIPS 140-3 policy, these are
    applied on top of the default or configured
    settings.

    tlskex and tlsauth both allow for the same
    set of values: all, no256ecc, and pq.

    An empty value uses the default for that setting.
    Setting any other value is an error and will
    cause a panic. In Go 1.26, or when using the
    v1.0.0 FIPS 140-3 module, setting tlsauth=pq
    is also an error and will panic.

    Setting tlskex=no256ecc disables P-256 and X25519
    key exchanges, except in post-quantum hybrids.
    Setting tlsauth=no256ecc disables P-256 and Ed25519
    authentication keys. Neither setting excludes RSA.

    In all versions of TLS, sessions are not resumed
    if the peer's leaf key is not allowed by tlsauth,
    even if the certificate chain was not verified.
    When verification is required, a cached chain
    must be both trusted and allowed by tlsauth.
    A resumed connection only reports allowed
    verified chains.

    Up to TLS 1.2, sessions are also not resumed if
    the original KEX is not allowed.

    In TLS 1.3, resumption runs a fresh KEX subject
    to tlskex. The original KEX does not prevent
    resumption or restrict 0-RTT under tlskex.
    Early data and peer authentication still depend
    on the original KEX through the resumption PSK.

    Fixes #83640

    Change-Id: Ie760ffade229077618e35cf08eb4553c9a94b980
    Reviewed-on: https://go-review.googlesource.com/c/go/+/868964
    Reviewed-by: Filippo Valsorda <filippo@golang.org>
    Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
    Reviewed-by: Neal Patel <nealpatel@google.com>
    TryBot-Bypass: Neal Patel <nealpatel@google.com>
    Reviewed-by: Nicholas Husin <nsh@golang.org>
    Reviewed-by: Nicholas Husin <husin@google.com>

diff --git a/doc/godebug.md b/doc/godebug.md
index 1908f42ad7..dce24c29b8 100644
--- a/doc/godebug.md
+++ b/doc/godebug.md
@@ -214,6 +214,22 @@ these checks. Programs targeting Go 1.27 or earlier default to `tlsupki=0`,
 disabling them. A [`crypto/tls.Config`](/pkg/crypto/tls#Config) that
 names a cache directory explicitly uses it with either setting.

+Go 1.28 added new `tlskex` and `tlsauth` settings that control which key
+exchanges and which authentication algorithms [`crypto/tls`](/pkg/crypto/tls)
+allows, regardless of the [`crypto/tls.Config`](/pkg/crypto/tls#Config).
+Both settings default to `all`. An empty value uses
+the default for that setting. Setting `tlskex=all` or `tlsauth=all`
+applies no additional restriction to key exchange or authentication, respectively.
+Setting `tlskex=no256ecc` disables P-256 and X25519 key exchanges, except
+in post-quantum hybrids. Setting `tlsauth=no256ecc` disables P-256 and
+Ed25519 authentication keys.
+Setting `tlskex=pq` or `tlsauth=pq` only allows post-quantum algorithms,
+including hybrids, and disables TLS 1.2 and earlier.
+The `tlskex` setting also applies to Encrypted Client Hello.
+Any other value causes a panic at startup, as does `tlsauth=pq` when ML-DSA
+is not available: in Go 1.26, and with the v1.0.0 FIPS 140-3 module.
+These settings were backported to Go 1.26.12 and Go 1.27.5.
+
 ### Go 1.27

 Go 1.27 removed the `gotypesalias` setting, as noted in the [Go 1.22](#go-122) section.
diff --git a/src/crypto/tls/auth.go b/src/crypto/tls/auth.go
index 7a3bd1baea..ffa2f701fd 100644
--- a/src/crypto/tls/auth.go
+++ b/src/crypto/tls/auth.go
@@ -263,6 +263,9 @@ func selectSignatureScheme(vers uint16, c *Certificate, peerAlgs []SignatureSche
 	if !ok {
 		return 0, unsupportedCertificateError(c)
 	}
+	if !authPolicyAllowsPublicKey(priv.Public()) {
+		return 0, &policyError{setting: "tlsauth", value: authPolicy, msg: "tls: certificate"}
+	}
 	supportedAlgs := signatureSchemesForPublicKey(vers, priv.Public())
 	if c.SupportedSignatureAlgorithms != nil {
 		supportedAlgs = slices.DeleteFunc(supportedAlgs, func(sigAlg SignatureScheme) bool {
diff --git a/src/crypto/tls/common.go b/src/crypto/tls/common.go
index 17ffc1eef9..752600a98e 100644
--- a/src/crypto/tls/common.go
+++ b/src/crypto/tls/common.go
@@ -1280,6 +1280,10 @@ func (c *Config) supportedVersions(isClient, isQUIC bool) []uint16 {
 		if fips140Restrictions(c != nil && c.noFIPS140Restrictions) && !slices.Contains(allowedSupportedVersionsFIPS, v) {
 			continue
 		}
+		if (kexPolicy == "pq" || authPolicy == "pq") && v < VersionTLS13 {
+			// Post-quantum algorithms are only available in TLS 1.3.
+			continue
+		}
 		if (c == nil || c.MinVersion == 0) && v < VersionTLS12 {
 			continue
 		}
@@ -1329,6 +1333,11 @@ func (c *Config) curvePreferences(version uint16) []CurveID {
 }

 func (c *Config) supportsCurve(version uint16, x CurveID) bool {
+	return kexPolicyAllowsCurve(x) && c.curveEnabled(version, x)
+}
+
+// curveEnabled checks the configured curves without applying tlskex.
+func (c *Config) curveEnabled(version uint16, x CurveID) bool {
 	if c != nil && len(c.CurvePreferences) != 0 {
 		if !slices.Contains(c.CurvePreferences, x) {
 			return false
@@ -1519,6 +1528,12 @@ func (chi *ClientHelloInfo) SupportsCertificate(c *Certificate) error {

 	var ecdsaCipherSuite bool
 	if priv, ok := c.PrivateKey.(crypto.Signer); ok {
+		// Clients that don't send signature_algorithms, like before TLS 1.2,
+		// skip selectSignatureScheme above, so apply the tlsauth GODEBUG
+		// setting here.
+		if !authPolicyAllowsPublicKey(priv.Public()) {
+			return &policyError{setting: "tlsauth", value: authPolicy, msg: "tls: certificate"}
+		}
 		switch pub := priv.Public().(type) {
 		case *ecdsa.PublicKey:
 			var curve CurveID
@@ -1534,7 +1549,7 @@ func (chi *ClientHelloInfo) SupportsCertificate(c *Certificate) error {
 			}
 			var curveOk bool
 			for _, c := range chi.SupportedCurves {
-				if c == curve && config.supportsCurve(vers, c) {
+				if c == curve && config.curveEnabled(vers, c) {
 					curveOk = true
 					break
 				}
@@ -1820,19 +1835,25 @@ var testingOnlySupportedSignatureAlgorithms []SignatureScheme

 // supportedSignatureAlgorithms returns the signature algorithms supported in
 // handshake messages for the given range of TLS versions. An algorithm is
-// included if it is enabled at any version in the range.
+// included if it is enabled at any version in the range and allowed by tlsauth
+// at the highest version offered.
 func supportedSignatureAlgorithms(minVers, maxVers uint16, fips140Restrictions bool) []SignatureScheme {
 	return enabledSignatureAlgorithms(minVers, maxVers, sigAlgHandshake, fips140Restrictions)
 }

 // enabledSignatureAlgorithms returns the signature algorithms enabled for the
-// given use at any TLS version in the range.
+// given use at any TLS version in the range, subject to tlsauth at maxVers.
 func enabledSignatureAlgorithms(minVers, maxVers uint16, use sigAlgUse, fips140Restrictions bool) []SignatureScheme {
 	sigAlgs := defaultSupportedSignatureAlgorithms()
 	if testingOnlySupportedSignatureAlgorithms != nil {
 		sigAlgs = slices.Clone(testingOnlySupportedSignatureAlgorithms)
 	}
 	return slices.DeleteFunc(sigAlgs, func(s SignatureScheme) bool {
+		// In TLS 1.2, ECDSA/SHA-256 can use P-384. In TLS 1.3, the
+		// same codepoint specifically offers P-256.
+		if !authPolicyAllowsSignatureAlgorithm(maxVers, s) {
+			return true
+		}
 		for v := minVers; v <= maxVers; v++ {
 			if !isDisabledSignatureAlgorithm(v, s, use, fips140Restrictions) {
 				return false
@@ -1862,6 +1883,9 @@ func isDisabledSignatureAlgorithm(version uint16, s SignatureScheme, use sigAlgU
 	if fips140Restrictions && !slices.Contains(allowedSignatureAlgorithmsFIPS, s) {
 		return true
 	}
+	if !authPolicyAllowsSignatureAlgorithm(version, s) {
+		return true
+	}

 	switch s {
 	case MLDSA44, MLDSA65, MLDSA87:
@@ -1960,6 +1984,17 @@ func (e *CertificateVerificationError) Unwrap() error {
 	return e.Err
 }

+// allowedChains returns chains that are allowed to be used in a TLS connection
+// based on fips140Restrictions and on the tlsauth GODEBUG setting. If this
+// results in no chains it returns an error.
+func allowedChains(chains [][]*x509.Certificate, fips140Restrictions bool) ([][]*x509.Certificate, error) {
+	chains, err := fipsAllowedChains(chains, fips140Restrictions)
+	if err != nil {
+		return nil, err
+	}
+	return authPolicyAllowedChains(chains)
+}
+
 // fipsAllowedChains returns chains that are allowed to be used in a TLS connection
 // based on fips140Restrictions.
 //
@@ -2020,18 +2055,25 @@ func anyValidVerifiedChain(verifiedChains [][]*x509.Certificate, opts x509.Verif
 		// root. On other platforms, we have to do full verification again,
 		// because EKU handling might differ. We will want to replace this with
 		// CertPool.Contains if/once that is available. See go.dev/issue/77376.
+		suffix := chain[len(chain)-1:]
 		if runtime.GOOS == "windows" || runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
 			opts.Intermediates = x509.NewCertPool()
 			for _, cert := range chain[1:max(1, len(chain)-1)] {
 				opts.Intermediates.AddCert(cert)
 			}
-			leaf := chain[0]
-			if _, err := leaf.Verify(opts); err == nil {
-				return true
-			}
-		} else {
-			root := chain[len(chain)-1]
-			if _, err := root.Verify(opts); err == nil {
+			suffix = chain
+		}
+		paths, err := suffix[0].Verify(opts)
+		if err != nil {
+			continue
+		}
+		if authPolicy == "all" {
+			return true
+		}
+		// Verify may have found a different path, with certificates not
+		// checked against tlsauth. Only accept the path we checked.
+		for _, path := range paths {
+			if slices.EqualFunc(path, suffix, (*x509.Certificate).Equal) {
 				return true
 			}
 		}
diff --git a/src/crypto/tls/ech.go b/src/crypto/tls/ech.go
index 4d0e4d1468..cb2b35c3df 100644
--- a/src/crypto/tls/ech.go
+++ b/src/crypto/tls/ech.go
@@ -177,6 +177,9 @@ func pickECHConfig(list []echConfig) (*echConfig, hpke.PublicKey, hpke.KDF, hpke
 		if unsupportedExt {
 			continue
 		}
+		if !kexPolicyAllowsKEM(ec.KemID) {
+			continue
+		}
 		kem, err := hpke.NewKEM(ec.KemID)
 		if err != nil {
 			continue
@@ -617,6 +620,11 @@ func (c *Conn) processECHClientHello(outer *clientHelloMsg, echKeys []EncryptedC
 		if skip {
 			continue
 		}
+		// Don't decrypt with keys disallowed by the tlskex GODEBUG setting,
+		// rejecting ECH if the client used one of them.
+		if !kexPolicyAllowsKEM(config.KemID) {
+			continue
+		}
 		// RFC 9849, Section 7.1 requires trying the next config if the
 		// offered cipher suite is not supported by this config.
 		if !slices.Contains(config.SymmetricCipherSuite, echCiphersuite) {
@@ -740,6 +748,14 @@ func buildRetryConfigList(keys []EncryptedClientHelloKey) ([]byte, error) {
 			if !c.SendAsRetry {
 				continue
 			}
+			if kexPolicy != "all" {
+				// Don't advertise configs with a KEM disallowed by the tlskex
+				// GODEBUG setting, or that can't be parsed to tell.
+				skip, config, err := parseECHConfig(c.Config)
+				if err != nil || !skip && !kexPolicyAllowsKEM(config.KemID) {
+					continue
+				}
+			}
 			atLeastOneRetryConfig = true
 			b.AddBytes(c.Config)
 		}
diff --git a/src/crypto/tls/ech_test.go b/src/crypto/tls/ech_test.go
index 87fc9e0f84..8084bc06f5 100644
--- a/src/crypto/tls/ech_test.go
+++ b/src/crypto/tls/ech_test.go
@@ -269,6 +269,8 @@ func TestDecodeECHConfigListOverflow(t *testing.T) {
 }

 func TestPickECHConfigWithIPPublicName(t *testing.T) {
+	// The ECH configuration uses X25519.
+	setPolicy(t, "all", "all")
 	b, err := hex.DecodeString("0045fe0d0041590020002092a01233db2218518ccbbbbc24df20686af417b37388de6460e94011974777090004000100010012636c6f7564666c6172652d6563682e636f6d0000")
 	if err != nil {
 		t.Fatal(err)
@@ -297,6 +299,8 @@ func TestPickECHConfigWithIPPublicName(t *testing.T) {
 }

 func TestECHServerCipherSuite(t *testing.T) {
+	// The ECH configuration uses X25519.
+	setPolicy(t, "all", "all")
 	key, err := ecdh.X25519().GenerateKey(rand.Reader)
 	if err != nil {
 		t.Fatal(err)
@@ -385,6 +389,8 @@ func TestECHServerCipherSuite(t *testing.T) {
 // TestECHOuterHelloOmitsPSK verifies computeAndUpdateOuterECHExtension strips
 // the inner hello's PSK offer from the outer hello.
 func TestECHOuterHelloOmitsPSK(t *testing.T) {
+	// The ECH configuration uses X25519.
+	setPolicy(t, "all", "all")
 	// Generate the ECH config in-test so the private key is known and the
 	// sealed payload can be decrypted below.
 	echKey, err := ecdh.X25519().GenerateKey(rand.Reader)
diff --git a/src/crypto/tls/fips140_test.go b/src/crypto/tls/fips140_test.go
index 8ee5811429..986f1a4bdf 100644
--- a/src/crypto/tls/fips140_test.go
+++ b/src/crypto/tls/fips140_test.go
@@ -207,8 +207,8 @@ func TestFIPSServerCipherSuites(t *testing.T) {
 				random:                       make([]byte, 32),
 				cipherSuites:                 []uint16{id},
 				compressionMethods:           []uint8{compressionNone},
-				supportedCurves:              []CurveID{CurveP256},
-				keyShares:                    []keyShare{generateKeyShare(CurveP256)},
+				supportedCurves:              []CurveID{CurveP384},
+				keyShares:                    []keyShare{generateKeyShare(CurveP384)},
 				supportedPoints:              []uint8{pointFormatUncompressed},
 				supportedVersions:            []uint16{VersionTLS12},
 				supportedSignatureAlgorithms: allowedSignatureAlgorithmsFIPS,
@@ -239,6 +239,8 @@ func TestFIPSServerCipherSuites(t *testing.T) {
 }

 func TestFIPSServerCurves(t *testing.T) {
+	// Test the FIPS restrictions independently of tlskex.
+	setPolicy(t, "all", "all")
 	for _, curveid := range curvePreferenceOrder() {
 		t.Run(fmt.Sprintf("curve=%v", curveid), func(t *testing.T) {
 			testConfig := testConfigFIPS140()
@@ -740,6 +742,8 @@ func fipsCert(t *testing.T, name string, key any, parent *fipsCertificate, mode
 }

 func TestFIPS140NoRestrictions(t *testing.T) {
+	// Test the FIPS restrictions independently of tlskex.
+	setPolicy(t, "all", "all")
 	if fips140.Enforced() {
 		t.Skip("noFIPS140Restrictions is not supported in fips140=only mode")
 	}
diff --git a/src/crypto/tls/handshake_client.go b/src/crypto/tls/handshake_client.go
index 38a6374fbd..0b6a708c57 100644
--- a/src/crypto/tls/handshake_client.go
+++ b/src/crypto/tls/handshake_client.go
@@ -60,7 +60,14 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, map[CurveID]*keySharePrivateK

 	supportedVersions := config.supportedVersions(roleClient, c.quic != nil)
 	if len(supportedVersions) == 0 {
-		return nil, nil, nil, errors.New("tls: no supported versions satisfy MinVersion and MaxVersion")
+		const msg = "tls: no supported versions satisfy MinVersion and MaxVersion"
+		switch {
+		case kexPolicy == "pq":
+			return nil, nil, nil, &policyError{setting: "tlskex", value: kexPolicy, msg: msg, tls13: true}
+		case authPolicy == "pq":
+			return nil, nil, nil, &policyError{setting: "tlsauth", value: authPolicy, msg: msg, tls13: true}
+		}
+		return nil, nil, nil, errors.New(msg)
 	}
 	// Since supportedVersions is sorted in descending order, the first element
 	// is the maximum version and the last element is the minimum version.
@@ -429,7 +436,10 @@ func (c *Conn) loadSession(hello *clientHelloMsg) (
 	if !ok || cs == nil {
 		return nil, nil, nil, nil
 	}
-	session = cs.session
+	session = authPolicySession(cs.session)
+	if session == nil {
+		return nil, nil, nil, nil
+	}

 	// Check that version used for the previous session is still valid.
 	versOk := false
@@ -481,6 +491,10 @@ func (c *Conn) loadSession(hello *clientHelloMsg) (
 		}
 	}

+	if !kexPolicyAllowsSession(session.version, session.curveID) {
+		return nil, nil, nil, nil
+	}
+
 	if session.version != VersionTLS13 {
 		// In TLS 1.2 the cipher suite must match the resumed session. Ensure we
 		// are still offering it.
@@ -880,6 +894,10 @@ func (hs *clientHandshakeState) doFullHandshake() error {
 				return err
 			}
 		} else {
+			if !authPolicyAllowsPublicKey(key.Public()) {
+				c.sendAlert(alertHandshakeFailure)
+				return &policyError{setting: "tlsauth", value: authPolicy, msg: "tls: certificate"}
+			}
 			sigType, sigHash, err := legacyTypeAndHashFromPublicKey(key.Public())
 			if err != nil {
 				c.sendAlert(alertIllegalParameter)
@@ -1198,7 +1216,7 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
 				return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
 			}

-			c.verifiedChains, err = fipsAllowedChains(chains, fips140Restrictions(c.config.noFIPS140Restrictions))
+			c.verifiedChains, err = allowedChains(chains, fips140Restrictions(c.config.noFIPS140Restrictions))
 			if err != nil {
 				c.sendAlert(alertBadCertificate)
 				return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
@@ -1221,7 +1239,7 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
 			return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
 		}

-		c.verifiedChains, err = fipsAllowedChains(chains, fips140Restrictions(c.config.noFIPS140Restrictions))
+		c.verifiedChains, err = allowedChains(chains, fips140Restrictions(c.config.noFIPS140Restrictions))
 		if err != nil {
 			c.sendAlert(alertBadCertificate)
 			return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
@@ -1233,6 +1251,11 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
 		err := errors.New("server's certificate is not allowed in FIPS 140-3 mode")
 		return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
 	}
+	if !authPolicyAllowsPublicKey(certs[0].PublicKey) {
+		c.sendAlert(alertBadCertificate)
+		err := &policyError{setting: "tlsauth", value: authPolicy, msg: "server's certificate"}
+		return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
+	}

 	switch certs[0].PublicKey.(type) {
 	case *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey:
diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go
index 1af8c13df2..ff0e814e1c 100644
--- a/src/crypto/tls/handshake_client_test.go
+++ b/src/crypto/tls/handshake_client_test.go
@@ -2833,6 +2833,8 @@ u58=
 }

 func TestTLS13ECHRejectionCallbacks(t *testing.T) {
+	// The ECH configuration uses X25519.
+	setPolicy(t, "all", "all")
 	k, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
 	if err != nil {
 		t.Fatal(err)
@@ -2954,6 +2956,8 @@ func TestTLS13ECHRejectionCallbacks(t *testing.T) {
 }

 func TestECHTLS12Server(t *testing.T) {
+	// The ECH configuration uses X25519.
+	setPolicy(t, "all", "all")
 	clientConfig, serverConfig := testConfigClient(), testConfigServer()

 	serverConfig.MaxVersion = VersionTLS12
diff --git a/src/crypto/tls/handshake_server.go b/src/crypto/tls/handshake_server.go
index 92f472752d..7b6aeeb77f 100644
--- a/src/crypto/tls/handshake_server.go
+++ b/src/crypto/tls/handshake_server.go
@@ -515,6 +515,10 @@ func (hs *serverHandshakeState) checkForResumption() error {
 	if sessionHasClientCerts && c.config.time().After(sessionState.peerCertificates[0].NotAfter) {
 		return nil
 	}
+	sessionState = authPolicySession(sessionState)
+	if sessionState == nil {
+		return nil
+	}
 	opts := x509.VerifyOptions{
 		CurrentTime: c.config.time(),
 		Roots:       c.config.ClientCAs,
@@ -525,6 +529,10 @@ func (hs *serverHandshakeState) checkForResumption() error {
 		return nil
 	}

+	if !kexPolicyAllowsSession(sessionState.version, sessionState.curveID) {
+		return nil
+	}
+
 	// RFC 7627, Section 5.3
 	if !sessionState.extMasterSecret && hs.clientHello.extendedMasterSecret {
 		return nil
@@ -990,7 +998,7 @@ func (c *Conn) processCertsFromClient(certificate Certificate) error {
 			return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
 		}

-		c.verifiedChains, err = fipsAllowedChains(chains, fips140Restrictions(c.config.noFIPS140Restrictions))
+		c.verifiedChains, err = allowedChains(chains, fips140Restrictions(c.config.noFIPS140Restrictions))
 		if err != nil {
 			c.sendAlert(alertBadCertificate)
 			return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
@@ -1007,6 +1015,11 @@ func (c *Conn) processCertsFromClient(certificate Certificate) error {
 			err := errors.New("client's certificate is not allowed in FIPS 140-3 mode")
 			return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
 		}
+		if !authPolicyAllowsPublicKey(certs[0].PublicKey) {
+			c.sendAlert(alertBadCertificate)
+			err := &policyError{setting: "tlsauth", value: authPolicy, msg: "client's certificate"}
+			return &CertificateVerificationError{UnverifiedCertificates: certs, Err: err}
+		}

 		switch certs[0].PublicKey.(type) {
 		case *ecdsa.PublicKey, *rsa.PublicKey, ed25519.PublicKey:
diff --git a/src/crypto/tls/handshake_server_test.go b/src/crypto/tls/handshake_server_test.go
index be35924bee..630f934dfd 100644
--- a/src/crypto/tls/handshake_server_test.go
+++ b/src/crypto/tls/handshake_server_test.go
@@ -171,7 +171,7 @@ func TestDontSelectECDSAWithRSAKey(t *testing.T) {
 		random:             make([]byte, 32),
 		cipherSuites:       []uint16{TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
 		compressionMethods: []uint8{compressionNone},
-		supportedCurves:    []CurveID{CurveP256},
+		supportedCurves:    []CurveID{CurveP384, CurveP256},
 		supportedPoints:    []uint8{pointFormatUncompressed},
 	}
 	serverConfig := testConfigServer()
@@ -196,7 +196,7 @@ func TestDontSelectRSAWithECDSAKey(t *testing.T) {
 		random:             make([]byte, 32),
 		cipherSuites:       []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
 		compressionMethods: []uint8{compressionNone},
-		supportedCurves:    []CurveID{CurveP256},
+		supportedCurves:    []CurveID{CurveP384, CurveP256},
 		supportedPoints:    []uint8{pointFormatUncompressed},
 	}
 	serverConfig := testConfigServer()
@@ -219,7 +219,7 @@ func TestRenegotiationExtension(t *testing.T) {
 		random:                       make([]byte, 32),
 		secureRenegotiationSupported: true,
 		cipherSuites:                 []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
-		supportedCurves:              []CurveID{CurveP256},
+		supportedCurves:              []CurveID{CurveP384},
 		supportedPoints:              []uint8{pointFormatUncompressed},
 	}

@@ -330,9 +330,9 @@ func TestTLSPointFormats(t *testing.T) {
 		supportedPoints     []uint8
 		wantSupportedPoints bool
 	}{
-		{"ECC", []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, []CurveID{CurveP256}, []uint8{pointFormatUncompressed}, true},
-		{"ECC without ec_point_format", []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, []CurveID{CurveP256}, nil, false},
-		{"ECC with extra values", []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, []CurveID{CurveP256}, []uint8{13, 37, pointFormatUncompressed, 42}, true},
+		{"ECC", []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, []CurveID{CurveP384}, []uint8{pointFormatUncompressed}, true},
+		{"ECC without ec_point_format", []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, []CurveID{CurveP384}, nil, false},
+		{"ECC with extra values", []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, []CurveID{CurveP384}, []uint8{13, 37, pointFormatUncompressed, 42}, true},
 		{"RSA", []uint16{TLS_RSA_WITH_AES_256_GCM_SHA384}, nil, nil, false},
 		{"RSA with ec_point_format", []uint16{TLS_RSA_WITH_AES_256_GCM_SHA384}, nil, []uint8{pointFormatUncompressed}, false},
 	}
@@ -1156,15 +1156,15 @@ func TestHandshakeServerGetCertificateExtensions(t *testing.T) {
 	testVersions := []uint16{VersionTLS12, VersionTLS13}
 	for _, vers := range testVersions {
 		t.Run(fmt.Sprintf("TLS version %04x", vers), func(t *testing.T) {
-			pk, _ := ecdh.P256().GenerateKey(rand.Reader)
+			pk, _ := ecdh.P384().GenerateKey(rand.Reader)
 			clientHello := &clientHelloMsg{
 				vers:                         vers,
 				random:                       make([]byte, 32),
 				cipherSuites:                 []uint16{TLS_AES_128_GCM_SHA256},
 				compressionMethods:           []uint8{compressionNone},
 				serverName:                   "test",
-				keyShares:                    []keyShare{{group: CurveP256, data: pk.PublicKey().Bytes()}},
-				supportedCurves:              []CurveID{CurveP256},
+				keyShares:                    []keyShare{{group: CurveP384, data: pk.PublicKey().Bytes()}},
+				supportedCurves:              []CurveID{CurveP384},
 				supportedSignatureAlgorithms: []SignatureScheme{ECDSAWithP256AndSHA256},
 			}

@@ -2041,7 +2041,7 @@ func TestAESCipherReorderingTLS13(t *testing.T) {
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
 			hasAESGCMHardwareSupport = tc.serverHasAESGCM
-			pk, _ := ecdh.X25519().GenerateKey(rand.Reader)
+			pk, _ := ecdh.P384().GenerateKey(rand.Reader)
 			hs := &serverHandshakeStateTLS13{
 				c: &Conn{
 					config: &Config{},
@@ -2051,8 +2051,8 @@ func TestAESCipherReorderingTLS13(t *testing.T) {
 					cipherSuites:       tc.clientCiphers,
 					supportedVersions:  []uint16{VersionTLS13},
 					compressionMethods: []uint8{compressionNone},
-					keyShares:          []keyShare{{group: X25519, data: pk.PublicKey().Bytes()}},
-					supportedCurves:    []CurveID{X25519},
+					keyShares:          []keyShare{{group: CurveP384, data: pk.PublicKey().Bytes()}},
+					supportedCurves:    []CurveID{CurveP384},
 				},
 			}

diff --git a/src/crypto/tls/handshake_server_tls13.go b/src/crypto/tls/handshake_server_tls13.go
index 39815d32a5..00e7f2416c 100644
--- a/src/crypto/tls/handshake_server_tls13.go
+++ b/src/crypto/tls/handshake_server_tls13.go
@@ -370,6 +370,10 @@ func (hs *serverHandshakeStateTLS13) checkForResumption() error {
 		if sessionHasClientCerts && c.config.time().After(sessionState.peerCertificates[0].NotAfter) {
 			continue
 		}
+		sessionState = authPolicySession(sessionState)
+		if sessionState == nil {
+			continue
+		}
 		opts := x509.VerifyOptions{
 			CurrentTime: c.config.time(),
 			Roots:       c.config.ClientCAs,
diff --git a/src/crypto/tls/handshake_test.go b/src/crypto/tls/handshake_test.go
index bb98b11126..049bf20141 100644
--- a/src/crypto/tls/handshake_test.go
+++ b/src/crypto/tls/handshake_test.go
@@ -54,6 +54,8 @@ var (
 )

 func runTestAndUpdateIfNeeded(t *testing.T, name string, run func(t *testing.T, update bool)) {
+	// The recorded transcripts use the unrestricted group list.
+	setPolicy(t, "all", "all")
 	skipFIPS(t) // FIPS 140-3 mode changes the advertised parameters.

 	// Go+BoringCrypto's boring.RandReader ignores the testing override set by
diff --git a/src/crypto/tls/key_agreement.go b/src/crypto/tls/key_agreement.go
index 969bfd12b8..b410ca5c10 100644
--- a/src/crypto/tls/key_agreement.go
+++ b/src/crypto/tls/key_agreement.go
@@ -217,6 +217,9 @@ func (ka *ecdheKeyAgreement) generateServerKeyExchange(config *Config, cert *Cer
 			return nil, errors.New("tls: failed to sign ECDHE parameters: " + err.Error())
 		}
 	} else {
+		if !authPolicyAllowsPublicKey(priv.Public()) {
+			return nil, &policyError{setting: "tlsauth", value: authPolicy, msg: "tls: certificate"}
+		}
 		sigType, sigHash, err := legacyTypeAndHashFromPublicKey(priv.Public())
 		if err != nil {
 			return nil, err
diff --git a/src/crypto/tls/policy.go b/src/crypto/tls/policy.go
new file mode 100644
index 0000000000..dd05e5f1f1
--- /dev/null
+++ b/src/crypto/tls/policy.go
@@ -0,0 +1,252 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package tls
+
+import (
+	"crypto"
+	"crypto/ecdsa"
+	"crypto/elliptic"
+	"crypto/fips140"
+	"crypto/mldsa"
+	"crypto/rsa"
+	"crypto/x509"
+	"fmt"
+	"internal/godebug"
+)
+
+// tlskex and tlsauth restrict the key exchanges and the authentication
+// algorithms that can be negotiated, regardless of the Config.
+var (
+	kexPolicy  = policySetting("tlskex", "all")
+	authPolicy = policySetting("tlsauth", "all")
+)
+
+func policySetting(name, defaultValue string) string {
+	switch v := godebug.New(name).Value(); v {
+	case "":
+		return defaultValue
+	case "all", "no256ecc":
+		return v
+	case "pq":
+		// ML-DSA is not available in FIPS 140-3 module v1.0.0, so nothing
+		// could satisfy tlsauth=pq.
+		if name == "tlsauth" && fips140.Version() == "v1.0.0" {
+			panic("crypto/tls: GODEBUG setting tlsauth=pq requires ML-DSA, which is not available in FIPS 140-3 module v1.0.0")
+		}
+		return v
+	default:
+		panic("crypto/tls: unknown GODEBUG setting " + name + "=" + v)
+	}
+}
+
+// kexPolicyAllowsCurve reports whether the tlskex GODEBUG setting allows the
+// key exchange c.
+func kexPolicyAllowsCurve(c CurveID) bool {
+	switch kexPolicy {
+	case "all":
+		return true
+	case "no256ecc":
+		switch c {
+		case CurveP384, CurveP521,
+			X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024, MLKEM1024:
+			return true
+		}
+		return false
+	case "pq":
+		switch c {
+		case X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024, MLKEM1024:
+			return true
+		}
+		return false
+	default:
+		panic("tls: internal error: unknown tlskex policy")
+	}
+}
+
+// kexPolicyAllowsKEM reports whether the tlskex GODEBUG setting allows the HPKE
+// KEM with the given ID to be used for Encrypted Client Hello.
+func kexPolicyAllowsKEM(id uint16) bool {
+	switch kexPolicy {
+	case "all":
+		return true
+	case "no256ecc":
+		switch id {
+		case 0x0011, // DHKEM(P-384, HKDF-SHA384)
+			0x0012, // DHKEM(P-521, HKDF-SHA512)
+			0x0041, // ML-KEM-768
+			0x0042, // ML-KEM-1024
+			0x0050, // MLKEM768-P256
+			0x0051, // MLKEM1024-P384
+			0x647a: // MLKEM768-X25519
+			return true
+		}
+		return false
+	case "pq":
+		switch id {
+		case 0x0041, // ML-KEM-768
+			0x0042, // ML-KEM-1024
+			0x0050, // MLKEM768-P256
+			0x0051, // MLKEM1024-P384
+			0x647a: // MLKEM768-X25519
+			return true
+		}
+		return false
+	default:
+		panic("tls: internal error: unknown tlskex policy")
+	}
+}
+
+// authPolicyAllowsSignatureAlgorithm reports whether the tlsauth GODEBUG
+// setting allows the signature algorithm s at the given protocol version.
+func authPolicyAllowsSignatureAlgorithm(version uint16, s SignatureScheme) bool {
+	switch authPolicy {
+	case "all":
+		return true
+	case "no256ecc":
+		switch s {
+		case MLDSA44, MLDSA65, MLDSA87,
+			PSSWithSHA256, PSSWithSHA384, PSSWithSHA512,
+			PKCS1WithSHA256, PKCS1WithSHA384, PKCS1WithSHA512,
+			ECDSAWithP384AndSHA384, ECDSAWithP521AndSHA512:
+			return true
+		case ECDSAWithP256AndSHA256:
+			// Before TLS 1.3, ECDSA algorithms are not constrained to a
+			// curve, so this might be P-384 with SHA-256. The curve is
+			// checked by authPolicyAllowsPublicKey.
+			return version < VersionTLS13
+		case PKCS1WithSHA1, ECDSAWithSHA1:
+			// SHA-1 is not the concern of this setting: it is left to the
+			// tlssha1 GODEBUG setting, and the ECDSA curve is checked by
+			// authPolicyAllowsPublicKey.
+			return true
+		}
+		return false
+	case "pq":
+		switch s {
+		case MLDSA44, MLDSA65, MLDSA87:
+			return true
+		}
+		return false
+	default:
+		panic("tls: internal error: unknown tlsauth policy")
+	}
+}
+
+// authPolicyAllowsPublicKey reports whether the tlsauth GODEBUG setting allows
+// certificates with the public key pub.
+func authPolicyAllowsPublicKey(pub crypto.PublicKey) bool {
+	switch authPolicy {
+	case "all":
+		return true
+	case "no256ecc":
+		switch pub := pub.(type) {
+		case *rsa.PublicKey, *mldsa.PublicKey:
+			return true
+		case *ecdsa.PublicKey:
+			return pub.Curve == elliptic.P384() || pub.Curve == elliptic.P521()
+		}
+		return false
+	case "pq":
+		_, ok := pub.(*mldsa.PublicKey)
+		return ok
+	default:
+		panic("tls: internal error: unknown tlsauth policy")
+	}
+}
+
+// policyError is the error for something rejected by the tlskex or tlsauth
+// GODEBUG setting.
+type policyError struct {
+	setting string // "tlskex" or "tlsauth"
+	value   string
+	msg     string // what was rejected, such as "tls: certificate"
+	tls13   bool   // whether it was rejected because value requires TLS 1.3
+}
+
+func (e *policyError) Error() string {
+	if e.tls13 {
+		return fmt.Sprintf("%s (GODEBUG setting %s=%s requires TLS 1.3)", e.msg, e.setting, e.value)
+	}
+	return fmt.Sprintf("%s is not allowed by GODEBUG setting %s=%s", e.msg, e.setting, e.value)
+}
+
+// authPolicyAllowedChains returns the chains in which every certificate has a
+// public key allowed by the tlsauth GODEBUG setting. If this results in no
+// chains it returns an error.
+func authPolicyAllowedChains(chains [][]*x509.Certificate) ([][]*x509.Certificate, error) {
+	if authPolicy == "all" {
+		return chains, nil
+	}
+
+	permittedChains := make([][]*x509.Certificate, 0, len(chains))
+chains:
+	for _, chain := range chains {
+		for _, cert := range chain {
+			if !authPolicyAllowsPublicKey(cert.PublicKey) {
+				continue chains
+			}
+		}
+		permittedChains = append(permittedChains, chain)
+	}
+
+	if len(permittedChains) == 0 {
+		return nil, &policyError{setting: "tlsauth", value: authPolicy, msg: "tls: certificate chain"}
+	}
+
+	return permittedChains, nil
+}
+
+// kexPolicyAllowsSession reports whether the tlskex GODEBUG setting allows
+// resuming a session of the given version that was established with the
+// key exchange curveID.
+//
+// Up to TLS 1.2, resumption reuses the master secret of the original
+// connection, so the original key exchange must be allowed. A zero curveID
+// is the RSA key exchange, which is allowed.
+//
+// In TLS 1.3, resumption runs a new key exchange, subject to tlskex, so
+// sessions are always resumed. Two things still rest on the original key
+// exchange, through the PSK:
+//
+//   - Early data. It is protected only by the original key exchange, not
+//     the fresh key exchange subject to tlskex. We accept this.
+//
+//   - Authentication. The PSK replaces the certificate, and tickets from
+//     resumed connections extend the session indefinitely, so breaking the
+//     original key exchange allows impersonating the peer. We accept this.
+//
+// TODO(filippo, nealpatel): Determine what the acceptable tradeoff is here.
+func kexPolicyAllowsSession(version uint16, curveID CurveID) bool {
+	if version >= VersionTLS13 || curveID == 0 {
+		return true
+	}
+	return kexPolicyAllowsCurve(curveID)
+}
+
+// authPolicySession returns a session with only the verified chains allowed by
+// tlsauth, or nil if the session cannot be resumed. Filter before rechecking
+// trust so that the chain that is still trusted must also satisfy tlsauth.
+func authPolicySession(s *SessionState) *SessionState {
+	if authPolicy == "all" || len(s.peerCertificates) == 0 {
+		return s
+	}
+	if !authPolicyAllowsPublicKey(s.peerCertificates[0].PublicKey) {
+		return nil
+	}
+	if len(s.verifiedChains) == 0 {
+		return s // The certificate was not verified.
+	}
+	chains, err := authPolicyAllowedChains(s.verifiedChains)
+	if err != nil {
+		return nil
+	}
+	if len(chains) == len(s.verifiedChains) {
+		return s
+	}
+	// The cache or UnwrapSession may share this state across connections.
+	filtered := *s
+	filtered.verifiedChains = chains
+	return &filtered
+}
diff --git a/src/crypto/tls/policy_test.go b/src/crypto/tls/policy_test.go
new file mode 100644
index 0000000000..de1640bafa
--- /dev/null
+++ b/src/crypto/tls/policy_test.go
@@ -0,0 +1,849 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package tls
+
+import (
+	"bytes"
+	"context"
+	"crypto/ecdh"
+	"crypto/elliptic"
+	"crypto/fips140"
+	"crypto/hpke"
+	"crypto/internal/cryptotest"
+	"crypto/tls/internal/fips140tls"
+	"crypto/x509"
+	"fmt"
+	"internal/testenv"
+	"io"
+	"os"
+	"slices"
+	"strings"
+	"testing"
+	"time"
+
+	"golang.org/x/crypto/cryptobyte"
+)
+
+func setPolicy(t *testing.T, kex, auth string) {
+	t.Helper()
+	for _, v := range []string{kex, auth} {
+		if v != "all" && v != "no256ecc" && v != "pq" {
+			t.Fatalf("unknown policy %q", v)
+		}
+	}
+	if auth == "pq" {
+		// tlsauth=pq is refused at startup without ML-DSA.
+		cryptotest.MustMinimumFIPS140ModuleVersion(t, "v1.26.0")
+	}
+	oldKex, oldAuth := kexPolicy, authPolicy
+	kexPolicy, authPolicy = kex, auth
+	t.Cleanup(func() { kexPolicy, authPolicy = oldKex, oldAuth })
+}
+
+func TestPolicyCurves(t *testing.T) {
+	all := []CurveID{X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024, MLKEM1024,
+		CurveP384, CurveP521, X25519, CurveP256}
+	tests := []struct {
+		kex, auth string
+		version   uint16
+		want      []CurveID
+	}{
+		{"all", "all", VersionTLS13, all},
+		{"no256ecc", "all", VersionTLS13, []CurveID{X25519MLKEM768, SecP256r1MLKEM768,
+			SecP384r1MLKEM1024, MLKEM1024, CurveP384, CurveP521}},
+		{"no256ecc", "all", VersionTLS12, []CurveID{CurveP384, CurveP521}},
+		{"pq", "all", VersionTLS13, []CurveID{X25519MLKEM768, SecP256r1MLKEM768,
+			SecP384r1MLKEM1024, MLKEM1024}},
+		{"pq", "all", VersionTLS12, []CurveID{}},
+		// tlsauth does not affect key exchanges.
+		{"all", "pq", VersionTLS13, all},
+	}
+	for _, test := range tests {
+		t.Run(fmt.Sprintf("tlskex=%s/tlsauth=%s/%s", test.kex, test.auth, VersionName(test.version)), func(t *testing.T) {
+			setPolicy(t, test.kex, test.auth)
+			want := slices.DeleteFunc(slices.Clone(test.want), func(c CurveID) bool {
+				return fips140tls.Required() && c == X25519
+			})
+			// The policy is a filter, so it applies to CurvePreferences, too.
+			config := &Config{CurvePreferences: all}
+			if got := config.curvePreferences(test.version); !slices.Equal(got, want) {
+				t.Errorf("got curves %v, want %v", got, want)
+			}
+		})
+	}
+}
+
+func TestPolicySignatureAlgorithms(t *testing.T) {
+	if fips140tls.Required() {
+		t.Skip("the lists are different in TLS FIPS mode")
+	}
+	cryptotest.MustMinimumFIPS140ModuleVersion(t, "v1.26.0") // for ML-DSA
+	mldsa := []SignatureScheme{MLDSA44, MLDSA65, MLDSA87}
+	tls13 := []SignatureScheme{MLDSA44, MLDSA65, MLDSA87, PSSWithSHA256, ECDSAWithP256AndSHA256,
+		Ed25519, PSSWithSHA384, PSSWithSHA512, ECDSAWithP384AndSHA384, ECDSAWithP521AndSHA512}
+	tls12 := []SignatureScheme{PSSWithSHA256, ECDSAWithP256AndSHA256, Ed25519, PSSWithSHA384,
+		PSSWithSHA512, PKCS1WithSHA256, PKCS1WithSHA384, PKCS1WithSHA512,
+		ECDSAWithP384AndSHA384, ECDSAWithP521AndSHA512}
+	tests := []struct {
+		kex, auth string
+		version   uint16
+		want      []SignatureScheme
+	}{
+		{"all", "all", VersionTLS13, tls13},
+		{"all", "all", VersionTLS12, tls12},
+		{"all", "no256ecc", VersionTLS13, []SignatureScheme{MLDSA44, MLDSA65, MLDSA87, PSSWithSHA256,
+			PSSWithSHA384, PSSWithSHA512, ECDSAWithP384AndSHA384, ECDSAWithP521AndSHA512}},
+		// Before TLS 1.3, ECDSAWithP256AndSHA256 is not tied to P-256.
+		{"all", "no256ecc", VersionTLS12, []SignatureScheme{PSSWithSHA256, ECDSAWithP256AndSHA256,
+			PSSWithSHA384, PSSWithSHA512, PKCS1WithSHA256, PKCS1WithSHA384, PKCS1WithSHA512,
+			ECDSAWithP384AndSHA384, ECDSAWithP521AndSHA512}},
+		{"all", "pq", VersionTLS13, mldsa},
+		{"all", "pq", VersionTLS12, []SignatureScheme{}},
+		// tlskex does not affect authentication.
+		{"pq", "all", VersionTLS13, tls13},
+	}
+	for _, test := range tests {
+		t.Run(fmt.Sprintf("tlskex=%s/tlsauth=%s/%s", test.kex, test.auth, VersionName(test.version)), func(t *testing.T) {
+			setPolicy(t, test.kex, test.auth)
+			if got := supportedSignatureAlgorithms(test.version, test.version, false); !slices.Equal(got, test.want) {
+				t.Errorf("got signature algorithms %v, want %v", got, test.want)
+			}
+		})
+	}
+
+	// A P-384 key can sign with ECDSAWithP256AndSHA256 in TLS 1.2.
+	setPolicy(t, "all", "no256ecc")
+	sigAlgs := []SignatureScheme{ECDSAWithP256AndSHA256}
+	if got, err := selectSignatureScheme(VersionTLS12, &testECDSAP384Cert, sigAlgs, false); err != nil || got != ECDSAWithP256AndSHA256 {
+		t.Errorf("selected %v, %v for a P-384 key in TLS 1.2, want ECDSAWithP256AndSHA256", got, err)
+	}
+
+	// SHA-1 is left to the tlssha1 GODEBUG setting.
+	t.Setenv("GODEBUG", "tlssha1=1")
+	sha1 := []SignatureScheme{PKCS1WithSHA1, ECDSAWithSHA1}
+	if got := supportedSignatureAlgorithms(VersionTLS12, VersionTLS12, false); !slices.Equal(got[max(len(got)-2, 0):], sha1) {
+		t.Errorf("got signature algorithms %v with tlssha1=1, want them to end with %v", got, sha1)
+	}
+}
+
+func TestPolicyHandshake(t *testing.T) {
+	tests := []struct {
+		name       string
+		kex, auth  string
+		cert       Certificate
+		maxVersion uint16
+		wantErr    string
+	}{
+		{"no256ecc/RSA/TLSv12", "no256ecc", "no256ecc", testRSA2048Cert, VersionTLS12, ""},
+		{"no256ecc/P384/TLSv12", "no256ecc", "no256ecc", testECDSAP384Cert, VersionTLS12, ""},
+		{"no256ecc/P384/TLSv13", "no256ecc", "no256ecc", testECDSAP384Cert, VersionTLS13, ""},
+		// Before TLS 1.2 the server's key is checked in generateServerKeyExchange.
+		{"no256ecc/P256/TLSv11", "all", "no256ecc", testECDSAP256Cert, VersionTLS11, "server: tls: certificate is not allowed"},
+		{"no256ecc/P256/TLSv12", "all", "no256ecc", testECDSAP256Cert, VersionTLS12, "tlsauth=no256ecc"},
+		{"no256ecc/P256/TLSv13", "all", "no256ecc", testECDSAP256Cert, VersionTLS13, "tlsauth=no256ecc"},
+		{"no256ecc/Ed25519/TLSv13", "all", "no256ecc", testEd25519Cert, VersionTLS13, "tlsauth=no256ecc"},
+		{"kexpq/TLSv13", "pq", "all", testECDSAP256Cert, VersionTLS13, ""},
+		{"kexpq/TLSv12", "pq", "all", testECDSAP256Cert, VersionTLS12, "GODEBUG setting tlskex=pq requires TLS 1.3"},
+		{"pq/MLDSA/TLSv13", "pq", "pq", testMLDSA65Cert, VersionTLS13, ""},
+		{"pq/RSA/TLSv13", "all", "pq", testRSA2048Cert, VersionTLS13, "tlsauth=pq"},
+		{"authpq/MLDSA/TLSv12", "all", "pq", testMLDSA65Cert, VersionTLS12, "GODEBUG setting tlsauth=pq requires TLS 1.3"},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			if fips140tls.Required() && (test.cert.Leaf == testEd25519Cert.Leaf || test.maxVersion < VersionTLS12) {
+				t.Skip("skipping test not compatible with TLS FIPS mode")
+			}
+			setPolicy(t, test.kex, test.auth)
+			serverConfig := &Config{Certificates: []Certificate{test.cert}, Time: testTime,
+				MinVersion: VersionTLS10}
+			clientConfig := &Config{InsecureSkipVerify: true, ServerName: "servername",
+				MinVersion: VersionTLS10, MaxVersion: test.maxVersion, Time: testTime}
+			ss, cs, err := testHandshake(t, clientConfig, serverConfig)
+			if test.wantErr != "" {
+				if err == nil || !strings.Contains(err.Error(), test.wantErr) {
+					t.Errorf("got error %v, want it to contain %q", err, test.wantErr)
+				}
+				return
+			}
+			if err != nil {
+				t.Fatal(err)
+			}
+			if ss.Version != test.maxVersion || cs.Version != test.maxVersion {
+				t.Errorf("got versions %#x and %#x, want %#x", ss.Version, cs.Version, test.maxVersion)
+			}
+			if !kexPolicyAllowsCurve(ss.CurveID) || ss.CurveID != cs.CurveID {
+				t.Errorf("got curves %v and %v", ss.CurveID, cs.CurveID)
+			}
+		})
+	}
+}
+
+func TestPolicyKEXCertificateCurve(t *testing.T) {
+	setPolicy(t, "no256ecc", "all")
+	// The peer offers P-256 for the certificate and P-384 for ECDHE.
+	chi := &ClientHelloInfo{
+		SupportedVersions: []uint16{VersionTLS12},
+		SupportedCurves:   []CurveID{CurveP256, CurveP384},
+		SupportedPoints:   []uint8{pointFormatUncompressed},
+		CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
+		SignatureSchemes:  []SignatureScheme{ECDSAWithP256AndSHA256},
+	}
+	if err := chi.SupportsCertificate(&testECDSAP256Cert); err != nil {
+		t.Fatalf("P-256 signing key with P-384 key exchange: %v", err)
+	}
+	chi.SupportedCurves = []CurveID{CurveP384}
+	if err := chi.SupportsCertificate(&testECDSAP256Cert); err == nil {
+		t.Error("accepted certificate on a curve the client did not offer")
+	}
+}
+
+func TestPolicyClientHelloSignatureAlgorithms(t *testing.T) {
+	setPolicy(t, "all", "no256ecc")
+	t.Setenv("GODEBUG", "tlssigalgscert=1")
+	for _, maxVersion := range []uint16{VersionTLS12, VersionTLS13} {
+		c := Client(nil, &Config{ServerName: "example.com", MinVersion: VersionTLS12, MaxVersion: maxVersion})
+		hello, _, _, err := c.makeClientHello()
+		if err != nil {
+			t.Fatal(err)
+		}
+		for _, algorithms := range [][]SignatureScheme{hello.supportedSignatureAlgorithms, hello.supportedSignatureAlgorithmsCert} {
+			if got, want := slices.Contains(algorithms, ECDSAWithP256AndSHA256), maxVersion == VersionTLS12; got != want {
+				t.Errorf("max %s: got %v, want ECDSA/SHA-256 present = %t", VersionName(maxVersion), algorithms, want)
+			}
+		}
+	}
+}
+
+func TestPolicyCertificateSelection(t *testing.T) {
+	// The server skips the certificates it is not allowed to use, even if the
+	// client doesn't send signature_algorithms, like before TLS 1.2.
+	for _, version := range []uint16{VersionTLS10, VersionTLS11, VersionTLS12, VersionTLS13} {
+		t.Run(VersionName(version), func(t *testing.T) {
+			if fips140tls.Required() && version < VersionTLS12 {
+				t.Skip("skipping test not compatible with TLS FIPS mode")
+			}
+			setPolicy(t, "all", "no256ecc")
+			serverConfig := &Config{Certificates: []Certificate{testECDSAP256Cert, testECDSAP384Cert},
+				Time: testTime, MinVersion: VersionTLS10}
+			clientConfig := &Config{InsecureSkipVerify: true, MinVersion: VersionTLS10,
+				MaxVersion: version, Time: testTime}
+			_, cs, err := testHandshake(t, clientConfig, serverConfig)
+			if err != nil {
+				t.Fatal(err)
+			}
+			if got := cs.PeerCertificates[0]; !got.Equal(testECDSAP384Cert.Leaf) {
+				t.Errorf("server selected the certificate of %v, want the P-384 one", got.Subject)
+			}
+		})
+	}
+}
+
+type policyCerts struct {
+	rootP384, rootP256 *fipsCertificate
+	p384, p256         *fipsCertificate // leaves issued by rootP384
+	p384UnderP256      *fipsCertificate // leaf issued by rootP256
+}
+
+func newPolicyCerts(t *testing.T) policyCerts {
+	const ca, leaf = fipsCertCA | fipsCertFIPSOK, fipsCertLeaf | fipsCertFIPSOK
+	var c policyCerts
+	c.rootP384 = fipsCert(t, "RP384", fipsECDSAKey(t, elliptic.P384()), nil, ca)
+	c.rootP256 = fipsCert(t, "RP256", fipsECDSAKey(t, elliptic.P256()), nil, ca)
+	c.p384 = fipsCert(t, "L1_RP384", fipsECDSAKey(t, elliptic.P384()), c.rootP384, leaf)
+	c.p256 = fipsCert(t, "L2_RP384", fipsECDSAKey(t, elliptic.P256()), c.rootP384, leaf)
+	c.p384UnderP256 = fipsCert(t, "L3_RP256", fipsECDSAKey(t, elliptic.P384()), c.rootP256, leaf)
+	return c
+}
+
+type policyPeers struct {
+	serverCert *fipsCertificate
+	serverRoot *fipsCertificate // nil to not verify the server certificate
+	clientCert *fipsCertificate // nil for no client certificate
+	clientRoot *fipsCertificate // nil to not verify the client certificate
+}
+
+func (p policyPeers) configs(version uint16) (clientConfig, serverConfig *Config) {
+	now := func() time.Time { return time.Unix(0, 0) }
+	certificate := func(c *fipsCertificate) []Certificate {
+		return []Certificate{{Certificate: [][]byte{c.der}, PrivateKey: c.key, Leaf: c.cert}}
+	}
+	pool := func(c *fipsCertificate) *x509.CertPool {
+		pool := x509.NewCertPool()
+		pool.AddCert(c.cert)
+		return pool
+	}
+	clientConfig = &Config{ServerName: "example.com", Time: now, MaxVersion: version}
+	serverConfig = &Config{Time: now, Certificates: certificate(p.serverCert)}
+	if p.serverRoot != nil {
+		clientConfig.RootCAs = pool(p.serverRoot)
+	} else {
+		clientConfig.InsecureSkipVerify = true
+	}
+	if p.clientCert != nil {
+		clientConfig.Certificates = certificate(p.clientCert)
+		serverConfig.ClientAuth = RequireAnyClientCert
+	}
+	if p.clientRoot != nil {
+		serverConfig.ClientAuth = RequireAndVerifyClientCert
+		serverConfig.ClientCAs = pool(p.clientRoot)
+	}
+	return clientConfig, serverConfig
+}
+
+func TestPolicyCertificates(t *testing.T) {
+	c := newPolicyCerts(t)
+	const chainErr = "certificate chain is not allowed by GODEBUG setting tlsauth=no256ecc"
+	tests := []struct {
+		name    string
+		peers   policyPeers
+		wantErr string
+	}{
+		{"Server/P384", policyPeers{serverCert: c.p384, serverRoot: c.rootP384}, ""},
+		{"Server/P384UnderP256", policyPeers{serverCert: c.p384UnderP256, serverRoot: c.rootP256}, chainErr},
+		{"Client/P384", policyPeers{serverCert: c.p384, clientCert: c.p384, clientRoot: c.rootP384}, ""},
+		{"Client/P384UnderP256", policyPeers{serverCert: c.p384, clientCert: c.p384UnderP256, clientRoot: c.rootP256}, chainErr},
+		// The client doesn't send a certificate it is not allowed to use.
+		{"Client/P256", policyPeers{serverCert: c.p384, clientCert: c.p256}, "client didn't provide a certificate"},
+	}
+	for _, test := range tests {
+		for _, version := range []uint16{VersionTLS12, VersionTLS13} {
+			t.Run(test.name+"/"+VersionName(version), func(t *testing.T) {
+				setPolicy(t, "all", "no256ecc")
+				clientConfig, serverConfig := test.peers.configs(version)
+				ss, cs, err := testHandshake(t, clientConfig, serverConfig)
+				if test.wantErr != "" {
+					if err == nil || !strings.Contains(err.Error(), test.wantErr) {
+						t.Errorf("got error %v, want it to contain %q", err, test.wantErr)
+					}
+					return
+				}
+				if err != nil {
+					t.Fatal(err)
+				}
+				if chains := cs.VerifiedChains; test.peers.serverRoot != nil && len(chains) != 1 {
+					t.Errorf("client got %d verified chains, want 1", len(chains))
+				}
+				if chains := ss.VerifiedChains; test.peers.clientRoot != nil && len(chains) != 1 {
+					t.Errorf("server got %d verified chains, want 1", len(chains))
+				}
+			})
+		}
+	}
+}
+
+func TestPolicyLegacyClientCertificate(t *testing.T) {
+	if fips140tls.Required() {
+		t.Skip("skipping test not compatible with TLS FIPS mode")
+	}
+	setPolicy(t, "all", "no256ecc")
+	c, s := localPipe(t)
+	defer c.Close()
+	defer s.Close()
+	serverConfig := &Config{Certificates: []Certificate{testRSA2048Cert}, Time: testTime,
+		MinVersion: VersionTLS10, ClientAuth: RequireAnyClientCert}
+	clientConfig := &Config{InsecureSkipVerify: true, Time: testTime,
+		MinVersion: VersionTLS10, MaxVersion: VersionTLS11,
+		GetClientCertificate: func(*CertificateRequestInfo) (*Certificate, error) {
+			return &testECDSAP256Cert, nil
+		}}
+	done := make(chan struct{})
+	go func() {
+		defer close(done)
+		Server(s, serverConfig).Handshake()
+	}()
+	err := Client(c, clientConfig).Handshake()
+	c.Close()
+	<-done // the server reads the policy
+	if want := "tls: certificate is not allowed by GODEBUG setting tlsauth=no256ecc"; err == nil || err.Error() != want {
+		t.Errorf("got error %v, want %q", err, want)
+	}
+}
+
+func TestPolicyPeerLeaf(t *testing.T) {
+	setPolicy(t, "all", "no256ecc")
+	newConn := func(t *testing.T, client bool, config *Config) *Conn {
+		c, s := localPipe(t)
+		t.Cleanup(func() { c.Close(); s.Close() })
+		go io.Copy(io.Discard, s) // alerts
+		conn := Server(c, config)
+		if client {
+			conn = Client(c, config)
+		}
+		conn.vers = VersionTLS13
+		return conn
+	}
+	check := func(side string, p256Err, p384Err error) {
+		want := side + "'s certificate is not allowed by GODEBUG setting tlsauth=no256ecc"
+		if p256Err == nil || !strings.Contains(p256Err.Error(), want) {
+			t.Errorf("got error %v, want %q", p256Err, want)
+		}
+		if p384Err != nil {
+			t.Errorf("%s's P-384 certificate rejected: %v", side, p384Err)
+		}
+	}
+	config := &Config{InsecureSkipVerify: true, ClientAuth: RequireAnyClientCert}
+	check("server", newConn(t, true, config).verifyServerCertificate(testECDSAP256Cert.Certificate),
+		newConn(t, true, config).verifyServerCertificate(testECDSAP384Cert.Certificate))
+	check("client", newConn(t, false, config).processCertsFromClient(testECDSAP256Cert),
+		newConn(t, false, config).processCertsFromClient(testECDSAP384Cert))
+}
+
+func TestPolicyResumption(t *testing.T) {
+	setPolicy(t, "all", "all")
+	type outcome int
+	const (
+		resumes outcome = iota
+		fullHandshake
+		// fails means the session is declined and then the full handshake
+		// fails, since a resumption would have succeeded.
+		fails
+	)
+	c := newPolicyCerts(t)
+	unverified := policyPeers{serverCert: c.p384}
+	clientChain := policyPeers{serverCert: c.p384, clientCert: c.p384UnderP256, clientRoot: c.rootP256}
+	const p256, p384 = CurveP256, CurveP384
+	tests := []struct {
+		name      string
+		kex, auth string
+		version   uint16
+		peers     policyPeers
+		// The session is established with P-256, and then each side is made
+		// to believe it was established with these key exchanges.
+		client, server CurveID
+		want           outcome
+	}{
+		// Both sides check the original key exchange: each row hides it from
+		// the other side, which would then resume.
+		{"tlskex=no256ecc/Client", "no256ecc", "all", VersionTLS12, unverified, p256, p384, fullHandshake},
+		{"tlskex=no256ecc/Server", "no256ecc", "all", VersionTLS12, unverified, p384, p256, fullHandshake},
+		{"tlskex=no256ecc/Allowed", "no256ecc", "all", VersionTLS12, unverified, p384, p384, resumes},
+		// A zero key exchange is the RSA key exchange.
+		{"tlskex=no256ecc/RSA", "no256ecc", "all", VersionTLS12, unverified, 0, 0, resumes},
+		// TLS 1.3 resumption runs a new key exchange.
+		{"tlskex=no256ecc", "no256ecc", "all", VersionTLS13, unverified, p256, p256, resumes},
+		{"tlskex=pq", "pq", "all", VersionTLS13, unverified, p256, p256, resumes},
+		// The client checks the server's certificates in loadSession.
+		{"ServerLeaf", "all", "no256ecc", VersionTLS12, policyPeers{serverCert: c.p256}, p256, p256, fails},
+		{"ServerChain", "all", "no256ecc", VersionTLS13, policyPeers{serverCert: c.p384UnderP256, serverRoot: c.rootP256}, p256, p256, fails},
+		{"ServerAllowed", "all", "no256ecc", VersionTLS12, policyPeers{serverCert: c.p384, serverRoot: c.rootP384}, p256, p256, resumes},
+		// The server checks the client's certificates in checkForResumption.
+		{"ClientChain", "all", "no256ecc", VersionTLS12, clientChain, p256, p256, fails},
+		{"ClientChain", "all", "no256ecc", VersionTLS13, clientChain, p256, p256, fails},
+		{"ClientAllowed", "all", "no256ecc", VersionTLS13, policyPeers{serverCert: c.p384, clientCert: c.p384, clientRoot: c.rootP384}, p256, p256, resumes},
+	}
+	for _, test := range tests {
+		t.Run(test.name+"/"+VersionName(test.version), func(t *testing.T) {
+			clientConfig, serverConfig := test.peers.configs(test.version)
+			clientConfig.ClientSessionCache = NewLRUClientSessionCache(1)
+			clientConfig.CurvePreferences = []CurveID{p256}
+			if _, _, err := testHandshake(t, clientConfig, serverConfig); err != nil {
+				t.Fatalf("handshake failed: %v", err)
+			}
+			state, _, err := testHandshake(t, clientConfig, serverConfig)
+			if err != nil || !state.DidResume || state.CurveID != p256 {
+				t.Fatalf("got DidResume = %v with %v, %v, want resumption with P-256", state.DidResume, state.CurveID, err)
+			}
+
+			session, ok := clientConfig.ClientSessionCache.Get("example.com")
+			if !ok {
+				t.Fatal("session not found in the client cache")
+			}
+			session.session.curveID = test.client
+			serverConfig.UnwrapSession = func(identity []byte, cs ConnectionState) (*SessionState, error) {
+				session, err := serverConfig.DecryptTicket(identity, cs)
+				if session != nil {
+					session.curveID = test.server
+				}
+				return session, err
+			}
+
+			clientConfig.CurvePreferences = nil
+			setPolicy(t, test.kex, test.auth)
+			state, _, err = testHandshake(t, clientConfig, serverConfig)
+			if test.want == fails {
+				if err == nil {
+					t.Errorf("handshake succeeded (resumed: %v), want error", state.DidResume)
+				}
+				return
+			}
+			if err != nil {
+				t.Fatalf("handshake failed: %v", err)
+			}
+			if state.DidResume != (test.want == resumes) {
+				t.Errorf("DidResume = %v", state.DidResume)
+			}
+			if state.CurveID != 0 && !kexPolicyAllowsCurve(state.CurveID) {
+				t.Errorf("connection used disallowed key exchange %v", state.CurveID)
+			}
+		})
+	}
+}
+
+func TestPolicyResumptionChains(t *testing.T) {
+	const ca, leaf = fipsCertCA | fipsCertFIPSOK, fipsCertLeaf | fipsCertFIPSOK
+	// The leaf chains to both a P-384 and a P-256 root, through two
+	// certificates of the same intermediate.
+	rootP384 := fipsCert(t, "RA", fipsECDSAKey(t, elliptic.P384()), nil, ca)
+	rootP256 := fipsCert(t, "RB", fipsECDSAKey(t, elliptic.P256()), nil, ca)
+	intermediateKey := fipsECDSAKey(t, elliptic.P384())
+	intermediateA := fipsCert(t, "I_RA", intermediateKey, rootP384, ca)
+	intermediateB := fipsCert(t, "I_RB", intermediateKey, rootP256, ca)
+	l := fipsCert(t, "L_I", fipsECDSAKey(t, elliptic.P384()), intermediateA, leaf)
+	cert := Certificate{Certificate: [][]byte{l.der, intermediateA.der, intermediateB.der}, PrivateKey: l.key}
+	roots := x509.NewCertPool()
+	roots.AddCert(rootP384.cert)
+	roots.AddCert(rootP256.cert)
+	now := func() time.Time { return time.Unix(0, 0) }
+
+	t.Run("RebuiltChain", func(t *testing.T) {
+		setPolicy(t, "all", "no256ecc")
+		// The intermediate used to be a trust anchor. Verify can still
+		// build a chain from it, but only through the disallowed P-256 root.
+		trusted := x509.NewCertPool()
+		trusted.AddCert(rootP256.cert)
+		cached := [][]*x509.Certificate{{l.cert, intermediateB.cert}}
+		if anyValidVerifiedChain(cached, x509.VerifyOptions{Roots: trusted, CurrentTime: now()}) {
+			t.Error("accepted a cached chain whose trust anchor was replaced")
+		}
+	})
+
+	for _, version := range []uint16{VersionTLS12, VersionTLS13} {
+		t.Run(VersionName(version), func(t *testing.T) {
+			// Both peers authenticate with cert.
+			clientConfig := &Config{ServerName: "example.com", Time: now, MaxVersion: version,
+				RootCAs: roots, Certificates: []Certificate{cert},
+				ClientSessionCache: NewLRUClientSessionCache(1)}
+			serverConfig := &Config{Time: now, Certificates: []Certificate{cert},
+				ClientAuth: RequireAndVerifyClientCert, ClientCAs: roots}
+
+			handshake := func(wantResume bool, wantChains int) {
+				t.Helper()
+				ss, cs, err := testHandshake(t, clientConfig, serverConfig)
+				if err != nil {
+					t.Fatalf("handshake failed: %v", err)
+				}
+				if ss.DidResume != wantResume {
+					t.Errorf("DidResume = %v, want %v", ss.DidResume, wantResume)
+				}
+				for side, chains := range map[string][][]*x509.Certificate{"client": cs.VerifiedChains, "server": ss.VerifiedChains} {
+					if len(chains) != wantChains {
+						t.Errorf("%s got %d verified chains, want %d", side, len(chains), wantChains)
+					}
+					for _, chain := range chains {
+						for _, c := range chain {
+							if !authPolicyAllowsPublicKey(c.PublicKey) {
+								t.Errorf("%s got a verified chain with disallowed certificate %v", side, c.Subject)
+							}
+						}
+					}
+				}
+			}
+			handshake(false, 2)
+			handshake(true, 2)
+			session, ok := clientConfig.ClientSessionCache.Get("example.com")
+			if !ok {
+				t.Fatal("session not found in client cache")
+			}
+			setPolicy(t, "all", "no256ecc")
+			handshake(true, 1)
+
+			// Retry the original ticket with only the P-256 root trusted on one
+			// side. Neither cached chain is both trusted and allowed by tlsauth.
+			p256Only := x509.NewCertPool()
+			p256Only.AddCert(rootP256.cert)
+			for _, side := range []string{"Client", "Server"} {
+				t.Run(side, func(t *testing.T) {
+					cli, srv := clientConfig.Clone(), serverConfig.Clone()
+					cli.ClientSessionCache = NewLRUClientSessionCache(1)
+					cli.ClientSessionCache.Put("example.com", session)
+					if side == "Client" {
+						cli.RootCAs = p256Only
+					} else {
+						srv.ClientCAs = p256Only
+					}
+					_, _, err := testHandshake(t, cli, srv)
+					if err == nil || !strings.Contains(err.Error(), "certificate chain is not allowed by GODEBUG setting tlsauth=no256ecc") {
+						t.Errorf("got %v, want full handshake rejecting the P-256 chain", err)
+					}
+				})
+			}
+		})
+	}
+}
+
+func TestPolicyEarlyData(t *testing.T) {
+	setPolicy(t, "all", "all")
+	// run establishes a session with the given key exchange and early data
+	// enabled, like TestQUICEarlyData, then resumes it with tlskex=no256ecc.
+	// If unrecorded is set, the client's session loses its key exchange,
+	// like one that went through SessionState.Bytes.
+	run := func(t *testing.T, curve CurveID, unrecorded bool) {
+		clientConfig := &QUICConfig{TLSConfig: testConfigClient()}
+		clientConfig.TLSConfig.MinVersion = VersionTLS13
+		clientConfig.TLSConfig.ClientSessionCache = NewLRUClientSessionCache(1)
+		clientConfig.TLSConfig.NextProtos = []string{"h3"}
+		clientConfig.TLSConfig.CurvePreferences = []CurveID{curve}
+		serverConfig := &QUICConfig{TLSConfig: testConfigServer()}
+		serverConfig.TLSConfig.MinVersion = VersionTLS13
+		serverConfig.TLSConfig.NextProtos = []string{"h3"}
+
+		cli := newTestQUICClient(t, clientConfig)
+		cli.conn.SetTransportParameters(nil)
+		srv := newTestQUICServer(t, serverConfig)
+		srv.conn.SetTransportParameters(nil)
+		srv.ticketOpts.EarlyData = true
+		if err := runTestQUICConnection(context.Background(), cli, srv, nil); err != nil {
+			t.Fatalf("error during first connection handshake: %v", err)
+		}
+		if got := cli.conn.ConnectionState().CurveID; got != curve {
+			t.Fatalf("first connection used %v, want %v", got, curve)
+		}
+		if unrecorded {
+			session, ok := clientConfig.TLSConfig.ClientSessionCache.Get(clientConfig.TLSConfig.ServerName)
+			if !ok {
+				t.Fatal("session not found in the client cache")
+			}
+			session.session.curveID = 0
+		}
+
+		clientConfig.TLSConfig.CurvePreferences = []CurveID{CurveP384}
+		setPolicy(t, "no256ecc", "all")
+		cli = newTestQUICClient(t, clientConfig)
+		cli.conn.SetTransportParameters(nil)
+		srv = newTestQUICServer(t, serverConfig)
+		srv.conn.SetTransportParameters(nil)
+		if err := runTestQUICConnection(context.Background(), cli, srv, nil); err != nil {
+			t.Fatalf("error during second connection handshake: %v", err)
+		}
+		if !cli.conn.ConnectionState().DidResume {
+			t.Errorf("second connection did not use session resumption")
+		}
+		if got := cli.conn.ConnectionState().CurveID; got != CurveP384 {
+			t.Fatalf("second connection used %v, want %v", got, CurveP384)
+		}
+		cliSecret := cli.writeSecret[QUICEncryptionLevelEarly]
+		if cliSecret.secret == nil {
+			t.Errorf("client did not receive early data write secret")
+		}
+		srvSecret := srv.readSecret[QUICEncryptionLevelEarly]
+		if srvSecret.secret == nil {
+			t.Errorf("server did not receive early data read secret")
+		}
+		if cliSecret.suite != srvSecret.suite || !bytes.Equal(cliSecret.secret, srvSecret.secret) {
+			t.Errorf("client early data secret does not match server")
+		}
+		if cli.earlyDataRejected {
+			t.Errorf("client received QUICEarlyDataRejected")
+		}
+	}
+
+	// Early data is accepted regardless of whether the original key exchange
+	// is allowed or known, while the fresh key exchange must satisfy tlskex.
+	t.Run("server", func(t *testing.T) { run(t, X25519MLKEM768, false) })
+	t.Run("client", func(t *testing.T) { run(t, CurveP256, false) })
+	t.Run("client/unrecorded", func(t *testing.T) { run(t, X25519MLKEM768, true) })
+}
+
+func testECHKey(t *testing.T, id uint8, kem hpke.KEM) EncryptedClientHelloKey {
+	t.Helper()
+	priv, err := kem.GenerateKey()
+	if err != nil {
+		t.Fatal(err)
+	}
+	privBytes, err := priv.Bytes()
+	if err != nil {
+		t.Fatal(err)
+	}
+	var b cryptobyte.Builder
+	b.AddUint16(extensionEncryptedClientHello)
+	b.AddUint16LengthPrefixed(func(b *cryptobyte.Builder) {
+		b.AddUint8(id)
+		b.AddUint16(kem.ID())
+		b.AddUint16LengthPrefixed(func(b *cryptobyte.Builder) { b.AddBytes(priv.PublicKey().Bytes()) })
+		b.AddUint16LengthPrefixed(func(b *cryptobyte.Builder) {
+			b.AddUint16(0x0001) // HKDF-SHA256
+			b.AddUint16(0x0001) // AES-128-GCM
+		})
+		b.AddUint8(32)
+		b.AddUint8LengthPrefixed(func(b *cryptobyte.Builder) { b.AddBytes([]byte("public.example")) })
+		b.AddUint16(0) // extensions
+	})
+	return EncryptedClientHelloKey{Config: b.BytesOrPanic(), PrivateKey: privBytes, SendAsRetry: true}
+}
+
+func testECHConfigList(keys ...EncryptedClientHelloKey) []byte {
+	var b cryptobyte.Builder
+	b.AddUint16LengthPrefixed(func(b *cryptobyte.Builder) {
+		for _, k := range keys {
+			b.AddBytes(k.Config)
+		}
+	})
+	return b.BytesOrPanic()
+}
+
+func testECHConfigs(keys ...EncryptedClientHelloKey) (clientConfig, serverConfig *Config) {
+	clientConfig, serverConfig = testConfigClient(), testConfigServer()
+	clientConfig.MinVersion = VersionTLS13
+	clientConfig.ServerName = "test.golang.example"
+	clientConfig.EncryptedClientHelloConfigList = testECHConfigList(keys...)
+	serverConfig.EncryptedClientHelloKeys = keys
+	return clientConfig, serverConfig
+}
+
+func TestPolicyECH(t *testing.T) {
+	if fips140tls.Required() {
+		t.Skip("skipping test not compatible with TLS FIPS mode")
+	}
+	x25519 := testECHKey(t, 1, hpke.DHKEM(ecdh.X25519()))
+	p256 := testECHKey(t, 2, hpke.DHKEM(ecdh.P256()))
+	p384 := testECHKey(t, 3, hpke.DHKEM(ecdh.P384()))
+	p521 := testECHKey(t, 4, hpke.DHKEM(ecdh.P521()))
+	mlkem768 := testECHKey(t, 5, hpke.MLKEM768())
+	mlkem1024 := testECHKey(t, 6, hpke.MLKEM1024())
+	mlkem768X25519 := testECHKey(t, 7, hpke.MLKEM768X25519())
+	mlkem768P256 := testECHKey(t, 8, hpke.MLKEM768P256())
+	mlkem1024P384 := testECHKey(t, 9, hpke.MLKEM1024P384())
+	all := []EncryptedClientHelloKey{x25519, p256, p384, p521, mlkem768, mlkem1024,
+		mlkem768X25519, mlkem768P256, mlkem1024P384}
+	classical := []EncryptedClientHelloKey{x25519, p256, p384, p521}
+	type keys = []EncryptedClientHelloKey
+
+	tests := []struct {
+		name string
+		kex  string
+		keys keys
+		// allowed are the keys allowed by the policy, which are sent as retry
+		// configs. If there are none, the client can't use ECH.
+		allowed keys
+	}{
+		{"all", "all", all, all},
+		{"no256ecc", "no256ecc", all, keys{p384, p521, mlkem768, mlkem1024, mlkem768X25519, mlkem768P256, mlkem1024P384}},
+		{"pq", "pq", all, keys{mlkem768, mlkem1024, mlkem768X25519, mlkem768P256, mlkem1024P384}},
+		{"pq/Classical", "pq", classical, nil},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			setPolicy(t, test.kex, "all")
+
+			var wantRetry []byte
+			if test.allowed != nil {
+				wantRetry = testECHConfigList(test.allowed...)
+			}
+			if retry, err := buildRetryConfigList(test.keys); err != nil || !bytes.Equal(retry, wantRetry) {
+				t.Errorf("got retry configs %x, %v, want %x", retry, err, wantRetry)
+			}
+
+			// The server skips disallowed keys, so if ECH is accepted the
+			// client picked an allowed config.
+			clientConfig, serverConfig := testECHConfigs(test.keys...)
+			ss, cs, err := testHandshake(t, clientConfig, serverConfig)
+			if test.allowed == nil {
+				if err == nil || !strings.Contains(err.Error(), "no valid configs") {
+					t.Errorf("got error %v, want no valid configs", err)
+				}
+				return
+			}
+			if err != nil {
+				t.Fatal(err)
+			}
+			if !ss.ECHAccepted || !cs.ECHAccepted {
+				t.Errorf("ECH not accepted: server %v, client %v", ss.ECHAccepted, cs.ECHAccepted)
+			}
+		})
+	}
+
+	// A config that can't be parsed is sent as a retry config without the
+	// policy, as before, but not with it, as its KEM is unknown.
+	t.Run("retry/invalid", func(t *testing.T) {
+		invalid := EncryptedClientHelloKey{Config: []byte{1, 2, 3}, SendAsRetry: true}
+		for kex, want := range map[string][]byte{
+			"all": testECHConfigList(invalid, mlkem768),
+			"pq":  testECHConfigList(mlkem768),
+		} {
+			setPolicy(t, kex, "all")
+			if got, err := buildRetryConfigList(keys{invalid, mlkem768}); err != nil || !bytes.Equal(got, want) {
+				t.Errorf("tlskex=%s: got retry configs %x, %v, want %x", kex, got, err, want)
+			}
+		}
+	})
+
+	// A server must not decrypt a ClientHello encrypted to a disallowed key.
+	// A client with the same policy never sends one, so capture one without
+	// the policy and process it with it.
+	t.Run("server", func(t *testing.T) {
+		setPolicy(t, "all", "all")
+		clientConfig, serverConfig := testECHConfigs(x25519)
+		c, s := localPipe(t)
+		defer c.Close()
+		defer s.Close()
+		done := make(chan struct{})
+		go func() {
+			defer close(done)
+			Client(c, clientConfig).Handshake()
+		}()
+		header := make([]byte, recordHeaderLen)
+		if _, err := io.ReadFull(s, header); err != nil {
+			t.Fatal(err)
+		}
+		record := make([]byte, int(header[3])<<8|int(header[4]))
+		if _, err := io.ReadFull(s, record); err != nil {
+			t.Fatal(err)
+		}
+		c.Close()
+		<-done // the client reads the policy
+		outer := new(clientHelloMsg)
+		if !outer.unmarshal(record) {
+			t.Fatal("failed to parse ClientHello")
+		}
+
+		server := Server(nil, serverConfig)
+		hello, ech, err := server.processECHClientHello(outer, keys{x25519})
+		if err != nil || hello == outer || ech == nil || !server.echAccepted {
+			t.Fatalf("ECH not accepted without policy: %v", err)
+		}
+
+		setPolicy(t, "no256ecc", "all")
+		server = Server(nil, serverConfig)
+		hello, ech, err = server.processECHClientHello(outer, keys{x25519})
+		if err != nil {
+			t.Fatal(err)
+		}
+		if hello != outer || ech != nil || server.echAccepted {
+			t.Error("server accepted ECH with a disallowed KEM")
+		}
+	})
+}
+
+func TestPolicyGODEBUG(t *testing.T) {
+	if os.Getenv("GO_TLS_POLICY_TEST") == "1" {
+		fmt.Printf("tlskex=%s,tlsauth=%s\n", kexPolicy, authPolicy)
+		return
+	}
+	authPQ := "tlskex=all,tlsauth=pq"
+	if fips140.Version() == "v1.0.0" {
+		authPQ = "panic: crypto/tls: GODEBUG setting tlsauth=pq requires ML-DSA"
+	}
+	for _, test := range []struct{ godebug, want string }{
+		{"", "tlskex=all,tlsauth=all"},
+		{"tlskex=,tlsauth=", "tlskex=all,tlsauth=all"},
+		{"tlskex=all", "tlskex=all,tlsauth=all"},
+		{"tlskex=pq,tlsauth=no256ecc", "tlskex=pq,tlsauth=no256ecc"},
+		{"tlsauth=pq", authPQ},
+		{"tlskex=bogus", "panic: crypto/tls: unknown GODEBUG setting tlskex=bogus"},
+		{"tlsauth=1", "panic: crypto/tls: unknown GODEBUG setting tlsauth=1"},
+	} {
+		t.Run(test.godebug, func(t *testing.T) {
+			cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestPolicyGODEBUG$")
+			cmd.Env = append(cmd.Environ(), "GODEBUG="+test.godebug, "GO_TLS_POLICY_TEST=1")
+			out, err := cmd.CombinedOutput()
+			if !strings.Contains(string(out), test.want) {
+				t.Errorf("got output %q, want it to contain %q", out, test.want)
+			}
+			if panics := strings.HasPrefix(test.want, "panic: "); panics != (err != nil) {
+				t.Errorf("got error %v", err)
+			}
+		})
+	}
+}
diff --git a/src/crypto/tls/tls_test.go b/src/crypto/tls/tls_test.go
index 79a948cc22..7cce52987d 100644
--- a/src/crypto/tls/tls_test.go
+++ b/src/crypto/tls/tls_test.go
@@ -1526,35 +1526,35 @@ func TestClientHelloInfo_SupportsCertificate(t *testing.T) {

 		{testECDSAP256Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  []SignatureScheme{ECDSAWithP256AndSHA256},
 			SupportedVersions: []uint16{VersionTLS12},
 		}, ""},
 		{testECDSAP256Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  []SignatureScheme{ECDSAWithP384AndSHA384},
 			SupportedVersions: []uint16{VersionTLS12},
 		}, ""}, // TLS 1.2 does not restrict curves based on the SignatureScheme.
 		{testECDSAP256Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  nil,
 			SupportedVersions: []uint16{VersionTLS12},
 		}, ""}, // TLS 1.2 comes with default signature schemes.
 		{testECDSAP256Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  []SignatureScheme{ECDSAWithP256AndSHA256},
 			SupportedVersions: []uint16{VersionTLS12},
 		}, "cipher suite"},
 		{testECDSAP256Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  []SignatureScheme{ECDSAWithP256AndSHA256},
 			SupportedVersions: []uint16{VersionTLS12},
@@ -1571,14 +1571,14 @@ func TestClientHelloInfo_SupportsCertificate(t *testing.T) {
 		}, "certificate curve"},
 		{testECDSAP256Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{1},
 			SignatureSchemes:  []SignatureScheme{ECDSAWithP256AndSHA256},
 			SupportedVersions: []uint16{VersionTLS12},
 		}, "only incompatible point formats"},
 		{testECDSAP256Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  []SignatureScheme{PSSWithSHA256},
 			SupportedVersions: []uint16{VersionTLS12},
@@ -1586,14 +1586,14 @@ func TestClientHelloInfo_SupportsCertificate(t *testing.T) {

 		{testEd25519Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256}, // only relevant for ECDHE support
+			SupportedCurves:   []CurveID{CurveP384, CurveP256}, // only relevant for ECDHE support
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  []SignatureScheme{Ed25519},
 			SupportedVersions: []uint16{VersionTLS12},
 		}, ""},
 		{testEd25519Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256}, // only relevant for ECDHE support
+			SupportedCurves:   []CurveID{CurveP384, CurveP256}, // only relevant for ECDHE support
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SignatureSchemes:  []SignatureScheme{Ed25519},
 			SupportedVersions: []uint16{VersionTLS10},
@@ -1609,7 +1609,7 @@ func TestClientHelloInfo_SupportsCertificate(t *testing.T) {

 		{testRSA2048Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
-			SupportedCurves:   []CurveID{CurveP256}, // only relevant for ECDHE support
+			SupportedCurves:   []CurveID{CurveP384, CurveP256}, // only relevant for ECDHE support
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SupportedVersions: []uint16{VersionTLS10},
 			config:            &Config{MinVersion: VersionTLS10},
@@ -1636,7 +1636,7 @@ func TestClientHelloInfo_SupportsCertificate(t *testing.T) {
 		}, ""},
 		{testMLDSA44Cert, &ClientHelloInfo{
 			CipherSuites:      []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
-			SupportedCurves:   []CurveID{CurveP256},
+			SupportedCurves:   []CurveID{CurveP384, CurveP256},
 			SupportedPoints:   []uint8{pointFormatUncompressed},
 			SupportedVersions: []uint16{VersionTLS12},
 		}, "doesn't support ML-DSA"},
@@ -2062,6 +2062,8 @@ func testVerifyCertificates(t *testing.T, version uint16) {
 }

 func TestHandshakeMLKEM(t *testing.T) {
+	// Exercise the full group list, independently of tlskex.
+	setPolicy(t, "all", "all")
 	if boring.Enabled && fips140tls.Required() {
 		t.Skip("ML-KEM not supported in BoringCrypto FIPS mode")
 	}
@@ -2856,6 +2858,8 @@ func TestLargeCertMsg(t *testing.T) {
 }

 func TestECH(t *testing.T) {
+	// The ECH configurations use X25519.
+	setPolicy(t, "all", "all")
 	k, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
 	if err != nil {
 		t.Fatal(err)
@@ -3211,6 +3215,7 @@ func testLocalCertificate(t *testing.T, version uint16, callback bool) {

 	serverCert, clientCert := testConfigServer().Certificates[0], testConfigClient().Certificates[0]

+	serverConfig.Certificates = []Certificate{serverCert}
 	if callback {
 		clientConfig.GetClientCertificate = func(_ *CertificateRequestInfo) (*Certificate, error) {
 			return &Certificate{
diff --git a/src/internal/godebugs/table.go b/src/internal/godebugs/table.go
index bc5c30215f..e4d1ee922f 100644
--- a/src/internal/godebugs/table.go
+++ b/src/internal/godebugs/table.go
@@ -63,8 +63,10 @@ var All = []Info{
 	{Name: "randseednop", Package: "math/rand", Changed: 24, Old: "0"},
 	{Name: "rsa1024min", Package: "crypto/rsa", Changed: 24, Old: "0"},
 	{Name: "tarinsecurepath", Package: "archive/tar"},
+	{Name: "tlsauth", Package: "crypto/tls", Opaque: true, Immutable: true},
 	{Name: "tlsdemote256ecc", Package: "crypto/tls", Opaque: true},
 	{Name: "tlsechgrease", Package: "crypto/tls", Changed: 28, Old: "0"},
+	{Name: "tlskex", Package: "crypto/tls", Opaque: true, Immutable: true},
 	{Name: "tlsmaxrsasize", Package: "crypto/tls"},
 	{Name: "tlsmlkem", Package: "crypto/tls", Changed: 24, Old: "0", Opaque: true},
 	{Name: "tlssecpmlkem", Package: "crypto/tls", Changed: 26, Old: "0", Opaque: true},