@@ -130,18 +130,25 @@ const (
130
130
scsvRenegotiation uint16 = 0x00ff
131
131
)
132
132
133
- // CurveID is the type of a TLS identifier for an elliptic curve . See
133
+ // CurveID is the type of a TLS identifier for a key exchange mechanism . See
134
134
// https://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8.
135
135
//
136
- // In TLS 1.3, this type is called NamedGroup, but at this time this library
137
- // only supports Elliptic Curve based groups. See RFC 8446, Section 4.2.7.
136
+ // In TLS 1.2, this registry used to support only elliptic curves. In TLS 1.3,
137
+ // it was extended to other groups and renamed NamedGroup. See RFC 8446, Section
138
+ // 4.2.7. It was then also extended to other mechanisms, such as hybrid
139
+ // post-quantum KEMs.
138
140
type CurveID uint16
139
141
140
142
const (
141
143
CurveP256 CurveID = 23
142
144
CurveP384 CurveID = 24
143
145
CurveP521 CurveID = 25
144
146
X25519 CurveID = 29
147
+
148
+ // Experimental codepoint for X25519Kyber768Draft00, specified in
149
+ // draft-tls-westerbaan-xyber768d00-03. Not exported, as support might be
150
+ // removed in the future.
151
+ x25519Kyber768Draft00 CurveID = 0x6399 // X25519Kyber768Draft00
145
152
)
146
153
147
154
// TLS 1.3 Key Share. See RFC 8446, Section 4.2.8.
@@ -302,6 +309,10 @@ type ConnectionState struct {
302
309
303
310
// testingOnlyDidHRR is true if a HelloRetryRequest was sent/received.
304
311
testingOnlyDidHRR bool
312
+
313
+ // testingOnlyCurveID is the selected CurveID, or zero if an RSA exchanges
314
+ // is performed.
315
+ testingOnlyCurveID CurveID
305
316
}
306
317
307
318
// ExportKeyingMaterial returns length bytes of exported key material in a new
@@ -375,7 +386,7 @@ type ClientSessionCache interface {
375
386
Put (sessionKey string , cs * ClientSessionState )
376
387
}
377
388
378
- //go:generate stringer -type=SignatureScheme,CurveID,ClientAuthType -output=common_string.go
389
+ //go:generate stringer -linecomment - type=SignatureScheme,CurveID,ClientAuthType -output=common_string.go
379
390
380
391
// SignatureScheme identifies a signature algorithm supported by TLS. See
381
392
// RFC 8446, Section 4.2.3.
@@ -757,6 +768,10 @@ type Config struct {
757
768
// an ECDHE handshake, in preference order. If empty, the default will
758
769
// be used. The client will use the first preference as the type for
759
770
// its key share in TLS 1.3. This may change in the future.
771
+ //
772
+ // From Go 1.23, the default includes the X25519Kyber768Draft00 hybrid
773
+ // post-quantum key exchange. To disable it, set CurvePreferences explicitly
774
+ // or use the GODEBUG=tlskyber=0 environment variable.
760
775
CurvePreferences []CurveID
761
776
762
777
// DynamicRecordSizingDisabled disables adaptive sizing of TLS records.
@@ -1084,20 +1099,27 @@ func supportedVersionsFromMax(maxVersion uint16) []uint16 {
1084
1099
return versions
1085
1100
}
1086
1101
1087
- var defaultCurvePreferences = [] CurveID { X25519 , CurveP256 , CurveP384 , CurveP521 }
1102
+ var tlskyber = godebug . New ( "tlskyber" )
1088
1103
1089
- func (c * Config ) curvePreferences () []CurveID {
1104
+ var defaultCurvePreferences = []CurveID {x25519Kyber768Draft00 , X25519 , CurveP256 , CurveP384 , CurveP521 }
1105
+
1106
+ var defaultCurvePreferencesWithoutKyber = []CurveID {X25519 , CurveP256 , CurveP384 , CurveP521 }
1107
+
1108
+ func (c * Config ) curvePreferences (version uint16 ) []CurveID {
1090
1109
if needFIPS () {
1091
1110
return fipsCurvePreferences (c )
1092
1111
}
1093
1112
if c == nil || len (c .CurvePreferences ) == 0 {
1113
+ if version < VersionTLS13 || tlskyber .Value () == "0" {
1114
+ return defaultCurvePreferencesWithoutKyber
1115
+ }
1094
1116
return defaultCurvePreferences
1095
1117
}
1096
1118
return c .CurvePreferences
1097
1119
}
1098
1120
1099
- func (c * Config ) supportsCurve (curve CurveID ) bool {
1100
- for _ , cc := range c .curvePreferences () {
1121
+ func (c * Config ) supportsCurve (version uint16 , curve CurveID ) bool {
1122
+ for _ , cc := range c .curvePreferences (version ) {
1101
1123
if cc == curve {
1102
1124
return true
1103
1125
}
@@ -1256,7 +1278,7 @@ func (chi *ClientHelloInfo) SupportsCertificate(c *Certificate) error {
1256
1278
}
1257
1279
1258
1280
// The only signed key exchange we support is ECDHE.
1259
- if ! supportsECDHE (config , chi .SupportedCurves , chi .SupportedPoints ) {
1281
+ if ! supportsECDHE (config , vers , chi .SupportedCurves , chi .SupportedPoints ) {
1260
1282
return supportsRSAFallback (errors .New ("client doesn't support ECDHE, can only use legacy RSA key exchange" ))
1261
1283
}
1262
1284
@@ -1277,7 +1299,7 @@ func (chi *ClientHelloInfo) SupportsCertificate(c *Certificate) error {
1277
1299
}
1278
1300
var curveOk bool
1279
1301
for _ , c := range chi .SupportedCurves {
1280
- if c == curve && config .supportsCurve (c ) {
1302
+ if c == curve && config .supportsCurve (vers , c ) {
1281
1303
curveOk = true
1282
1304
break
1283
1305
}
0 commit comments