MCPcopy Create free account
hub / github.com/XTLS/Go / expandLabel

Method expandLabel

key_schedule.go:35–51  ·  view source on GitHub ↗

expandLabel implements HKDF-Expand-Label from RFC 8446, Section 7.1.

(secret []byte, label string, context []byte, length int)

Source from the content-addressed store, hash-verified

33
34// expandLabel implements HKDF-Expand-Label from RFC 8446, Section 7.1.
35func (c *cipherSuiteTLS13) expandLabel(secret []byte, label string, context []byte, length int) []byte {
36 var hkdfLabel cryptobyte.Builder
37 hkdfLabel.AddUint16(uint16(length))
38 hkdfLabel.AddUint8LengthPrefixed(func(b *cryptobyte.Builder) {
39 b.AddBytes([]byte("tls13 "))
40 b.AddBytes([]byte(label))
41 })
42 hkdfLabel.AddUint8LengthPrefixed(func(b *cryptobyte.Builder) {
43 b.AddBytes(context)
44 })
45 out := make([]byte, length)
46 n, err := hkdf.Expand(c.hash.New, secret, hkdfLabel.BytesOrPanic()).Read(out)
47 if err != nil || n != length {
48 panic("tls: HKDF-Expand-Label invocation failed unexpectedly")
49 }
50 return out
51}
52
53// deriveSecret implements Derive-Secret from RFC 8446, Section 7.1.
54func (c *cipherSuiteTLS13) deriveSecret(secret []byte, label string, transcript hash.Hash) []byte {

Callers 7

deriveSecretMethod · 0.95
nextTrafficSecretMethod · 0.95
trafficKeyMethod · 0.95
finishedHashMethod · 0.95
exportKeyingMaterialMethod · 0.95
loadSessionMethod · 0.80
checkForResumptionMethod · 0.80

Calls 1

ReadMethod · 0.45

Tested by

no test coverage detected