package handshake

import (
	
	

	

	
)

var (
	quicSaltV1 = []byte{0x38, 0x76, 0x2c, 0xf7, 0xf5, 0x59, 0x34, 0xb3, 0x4d, 0x17, 0x9a, 0xe6, 0xa4, 0xc8, 0x0c, 0xad, 0xcc, 0xbb, 0x7f, 0x0a}
	quicSaltV2 = []byte{0x0d, 0xed, 0xe3, 0xde, 0xf7, 0x00, 0xa6, 0xdb, 0x81, 0x93, 0x81, 0xbe, 0x6e, 0x26, 0x9d, 0xcb, 0xf9, 0xbd, 0x2e, 0xd9}
)

const (
	hkdfLabelKeyV1 = "quic key"
	hkdfLabelKeyV2 = "quicv2 key"
	hkdfLabelIVV1  = "quic iv"
	hkdfLabelIVV2  = "quicv2 iv"
)

func getSalt( protocol.Version) []byte {
	if  == protocol.Version2 {
		return quicSaltV2
	}
	return quicSaltV1
}

var initialSuite = getCipherSuite(tls.TLS_AES_128_GCM_SHA256)

// NewInitialAEAD creates a new AEAD for Initial encryption / decryption.
func ( protocol.ConnectionID,  protocol.Perspective,  protocol.Version) (LongHeaderSealer, LongHeaderOpener) {
	,  := computeSecrets(, )
	var ,  []byte
	if  == protocol.PerspectiveClient {
		 = 
		 = 
	} else {
		 = 
		 = 
	}
	,  := computeInitialKeyAndIV(, )
	,  := computeInitialKeyAndIV(, )

	 := initialSuite.AEAD(, )
	 := initialSuite.AEAD(, )

	return newLongHeaderSealer(, newHeaderProtector(initialSuite, , true, )),
		newLongHeaderOpener(, newAESHeaderProtector(initialSuite, , true, hkdfHeaderProtectionLabel()))
}

func computeSecrets( protocol.ConnectionID,  protocol.Version) (,  []byte) {
	 := hkdf.Extract(crypto.SHA256.New, .Bytes(), getSalt())
	 = hkdfExpandLabel(crypto.SHA256, , []byte{}, "client in", crypto.SHA256.Size())
	 = hkdfExpandLabel(crypto.SHA256, , []byte{}, "server in", crypto.SHA256.Size())
	return
}

func computeInitialKeyAndIV( []byte,  protocol.Version) (,  []byte) {
	 := hkdfLabelKeyV1
	 := hkdfLabelIVV1
	if  == protocol.Version2 {
		 = hkdfLabelKeyV2
		 = hkdfLabelIVV2
	}
	 = hkdfExpandLabel(crypto.SHA256, , []byte{}, , 16)
	 = hkdfExpandLabel(crypto.SHA256, , []byte{}, , 12)
	return
}