// hkdfExpandLabel implements TLS 1.3's HKDF-Expand-Label function, as defined
// in section 7.1 of RFC 8446.

hkdfExpandLabel implements TLS 1.3's HKDF-Expand-Label function, as defined
in section 7.1 of RFC 8446.
// hkdfExpandLabel implements TLS 1 . 3 ' s HKDF - Expand - Label function as defined // in section 7 . 1 of RFC 8446 .
func hkdfExpandLabel(hash crypto.Hash, secret, label, hashValue []byte, length int) []byte {
	if len(label) > 255 || len(hashValue) > 255 {
		panic("hkdfExpandLabel: label or hashValue too long")
	}
	versionLabel := []byte("tls13 ")
	hkdfLabel := make([]byte, 3+len(versionLabel)+len(label)+1+len(hashValue))
	x := hkdfLabel
	x[0] = byte(length >> 8)
	x[1] = byte(length)
	x[2] = byte(len(versionLabel) + len(label))
	x = x[3:]
	copy(x, versionLabel)
	x = x[len(versionLabel):]
	copy(x, label)
	x = x[len(label):]
	x[0] = byte(len(hashValue))
	copy(x[1:], hashValue)
	ret := make([]byte, length)
	if n, err := hkdf.Expand(hash.New, secret, hkdfLabel).Read(ret); err != nil || n != length {
		panic("hkdfExpandLabel: hkdf.Expand unexpectedly failed")
	}
	return ret
}
func hkdfExpandLabel ( hash crypto . Hash , secret , label , hashValue [ ] byte , length int ) [ ] byte { if len ( label ) > 255 || len ( hashValue ) > 255 { panic ( " " ) } versionLabel := [ ] byte ( " " ) hkdfLabel := make ( [ ] byte , 3 + len ( versionLabel ) + len ( label ) + 1 + len ( hashValue ) ) x := hkdfLabel x [ 0 ] = byte ( length >> 8 ) x [ 1 ] = byte ( length ) x [ 2 ] = byte ( len ( versionLabel ) + len ( label ) ) x = x [ 3 : ] copy ( x , versionLabel ) x = x [ len ( versionLabel ) : ] copy ( x , label ) x = x [ len ( label ) : ] x [ 0 ] = byte ( len ( hashValue ) ) copy ( x [ 1 : ] , hashValue ) ret := make ( [ ] byte , length ) if n , err := hkdf . Expand ( hash . New , secret , hkdfLabel ) . Read ( ret ) ; err != nil || n != length { panic ( " " ) } return ret }
hkdfExpandLabel implements TLS 1.3's HKDF-Expand-Label function, as defined
in section 7.1 of RFC 8446.
hkdfExpandLabel implements TLS 1 . 3 ' s HKDF - Expand - Label function as defined in section 7 . 1 of RFC 8446 .