mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-22 14:38:35 +00:00
crypto/tls: use crypto/hkdf
For consistency, prefer crypto/hkdf over crypto/internal/fips140/hkdf. Both should have the same behavior given the constrained use of HKDF in TLS. Change-Id: Ia982b9f7a6ea66537d748eb5ecae1ac1eade68a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/658217 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
This commit is contained in:
parent
989cf77b4e
commit
5052e9a93c
4
go.mod
4
go.mod
@ -4,6 +4,6 @@ go 1.24
|
||||
|
||||
require (
|
||||
github.com/pires/go-proxyproto v0.8.1
|
||||
golang.org/x/crypto v0.37.0
|
||||
golang.org/x/sys v0.32.0
|
||||
golang.org/x/crypto v0.38.0
|
||||
golang.org/x/sys v0.33.0
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -6,7 +6,11 @@ golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
|
||||
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
|
||||
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
||||
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/hkdf"
|
||||
"crypto/hmac"
|
||||
"crypto/mlkem"
|
||||
"crypto/rsa"
|
||||
@ -18,7 +19,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/xtls/reality/tls13"
|
||||
"golang.org/x/crypto/hkdf"
|
||||
)
|
||||
|
||||
type clientHandshakeStateTLS13 struct {
|
||||
@ -90,12 +90,13 @@ func (hs *clientHandshakeStateTLS13) handshake() error {
|
||||
confTranscript.Write(hs.serverHello.original[:30])
|
||||
confTranscript.Write(make([]byte, 8))
|
||||
confTranscript.Write(hs.serverHello.original[38:])
|
||||
acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New,
|
||||
hkdf.Extract(hs.suite.hash.New, hs.echContext.innerHello.random, nil),
|
||||
"ech accept confirmation",
|
||||
confTranscript.Sum(nil),
|
||||
8,
|
||||
)
|
||||
h := hs.suite.hash.New
|
||||
prk, err := hkdf.Extract(h, hs.echContext.innerHello.random, nil)
|
||||
if err != nil {
|
||||
c.sendAlert(alertInternalError)
|
||||
return err
|
||||
}
|
||||
acceptConfirmation := tls13.ExpandLabel(h, prk, "ech accept confirmation", confTranscript.Sum(nil), 8)
|
||||
if subtle.ConstantTimeCompare(acceptConfirmation, hs.serverHello.random[len(hs.serverHello.random)-8:]) == 1 {
|
||||
hs.hello = hs.echContext.innerHello
|
||||
c.serverName = c.config.ServerName
|
||||
@ -264,12 +265,13 @@ func (hs *clientHandshakeStateTLS13) processHelloRetryRequest() error {
|
||||
copy(hrrHello, hs.serverHello.original)
|
||||
hrrHello = bytes.Replace(hrrHello, hs.serverHello.encryptedClientHello, make([]byte, 8), 1)
|
||||
confTranscript.Write(hrrHello)
|
||||
acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New,
|
||||
hkdf.Extract(hs.suite.hash.New, hs.echContext.innerHello.random, nil),
|
||||
"hrr ech accept confirmation",
|
||||
confTranscript.Sum(nil),
|
||||
8,
|
||||
)
|
||||
h := hs.suite.hash.New
|
||||
prk, err := hkdf.Extract(h, hs.echContext.innerHello.random, nil)
|
||||
if err != nil {
|
||||
c.sendAlert(alertInternalError)
|
||||
return err
|
||||
}
|
||||
acceptConfirmation := tls13.ExpandLabel(h, prk, "hrr ech accept confirmation", confTranscript.Sum(nil), 8)
|
||||
if subtle.ConstantTimeCompare(acceptConfirmation, hs.serverHello.encryptedClientHello) == 1 {
|
||||
hello = hs.echContext.innerHello
|
||||
c.serverName = c.config.ServerName
|
||||
|
@ -625,13 +625,13 @@ func (hs *serverHandshakeStateTLS13) doHelloRetryRequest(selectedGroup CurveID)
|
||||
if err := transcriptMsg(helloRetryRequest, confTranscript); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, _ := hkdf.Extract(hs.suite.hash.New, hs.clientHello.random, nil)
|
||||
acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New,
|
||||
b,
|
||||
"hrr ech accept confirmation",
|
||||
confTranscript.Sum(nil),
|
||||
8,
|
||||
)
|
||||
h := hs.suite.hash.New
|
||||
prf, err := hkdf.Extract(h, hs.clientHello.random, nil)
|
||||
if err != nil {
|
||||
c.sendAlert(alertInternalError)
|
||||
return nil, err
|
||||
}
|
||||
acceptConfirmation := tls13.ExpandLabel(h, prf, "hrr ech accept confirmation", confTranscript.Sum(nil), 8)
|
||||
helloRetryRequest.encryptedClientHello = acceptConfirmation
|
||||
}
|
||||
|
||||
@ -789,13 +789,13 @@ func (hs *serverHandshakeStateTLS13) sendServerParameters() error {
|
||||
return err
|
||||
}
|
||||
// compute the acceptance message
|
||||
b, _ := hkdf.Extract(hs.suite.hash.New, hs.clientHello.random, nil)
|
||||
acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New,
|
||||
b,
|
||||
"ech accept confirmation",
|
||||
echTranscript.Sum(nil),
|
||||
8,
|
||||
)
|
||||
h := hs.suite.hash.New
|
||||
prk, err := hkdf.Extract(h, hs.clientHello.random, nil)
|
||||
if err != nil {
|
||||
c.sendAlert(alertInternalError)
|
||||
return err
|
||||
}
|
||||
acceptConfirmation := tls13.ExpandLabel(h, prk, "ech accept confirmation", echTranscript.Sum(nil), 8)
|
||||
copy(hs.hello.random[32-8:], acceptConfirmation)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user