package tls
import (
"crypto/ecdh"
"crypto/hmac"
"crypto/internal/fips140/mlkem"
"crypto/internal/fips140/tls13"
"errors"
"hash"
"io"
)
func (c *cipherSuiteTLS13 ) nextTrafficSecret (trafficSecret []byte ) []byte {
return tls13 .ExpandLabel (c .hash .New , trafficSecret , "traffic upd" , nil , c .hash .Size ())
}
func (c *cipherSuiteTLS13 ) trafficKey (trafficSecret []byte ) (key , iv []byte ) {
key = tls13 .ExpandLabel (c .hash .New , trafficSecret , "key" , nil , c .keyLen )
iv = tls13 .ExpandLabel (c .hash .New , trafficSecret , "iv" , nil , aeadNonceLength )
return
}
func (c *cipherSuiteTLS13 ) finishedHash (baseKey []byte , transcript hash .Hash ) []byte {
finishedKey := tls13 .ExpandLabel (c .hash .New , baseKey , "finished" , nil , c .hash .Size ())
verifyData := hmac .New (c .hash .New , finishedKey )
verifyData .Write (transcript .Sum (nil ))
return verifyData .Sum (nil )
}
func (c *cipherSuiteTLS13 ) exportKeyingMaterial (s *tls13 .MasterSecret , transcript hash .Hash ) func (string , []byte , int ) ([]byte , error ) {
expMasterSecret := s .ExporterMasterSecret (transcript )
return func (label string , context []byte , length int ) ([]byte , error ) {
return expMasterSecret .Exporter (label , context , length ), nil
}
}
type keySharePrivateKeys struct {
curveID CurveID
ecdhe *ecdh .PrivateKey
mlkem *mlkem .DecapsulationKey768
}
const x25519PublicKeySize = 32
func generateECDHEKey(rand io .Reader , curveID CurveID ) (*ecdh .PrivateKey , error ) {
curve , ok := curveForCurveID (curveID )
if !ok {
return nil , errors .New ("tls: internal error: unsupported curve" )
}
return curve .GenerateKey (rand )
}
func curveForCurveID(id CurveID ) (ecdh .Curve , bool ) {
switch id {
case X25519 :
return ecdh .X25519 (), true
case CurveP256 :
return ecdh .P256 (), true
case CurveP384 :
return ecdh .P384 (), true
case CurveP521 :
return ecdh .P521 (), true
default :
return nil , false
}
}
func curveIDForCurve(curve ecdh .Curve ) (CurveID , bool ) {
switch curve {
case ecdh .X25519 ():
return X25519 , true
case ecdh .P256 ():
return CurveP256 , true
case ecdh .P384 ():
return CurveP384 , true
case ecdh .P521 ():
return CurveP521 , true
default :
return 0 , false
}
}
The pages are generated with Golds v0.7.3 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .