avoid unnecessary initializations of heaper protectors on key updates

This commit is contained in:
Marten Seemann
2019-06-13 14:32:22 +08:00
parent ca8b7ddeef
commit 4e1f18e833
3 changed files with 23 additions and 11 deletions

View File

@@ -94,13 +94,17 @@ func (o *longHeaderOpener) DecryptHeader(sample []byte, firstByte *byte, pnBytes
}
}
func createAEAD(suite cipherSuite, trafficSecret []byte) (cipher.AEAD, cipher.Block) {
func createAEAD(suite cipherSuite, trafficSecret []byte) cipher.AEAD {
key := qtls.HkdfExpandLabel(suite.Hash(), trafficSecret, []byte{}, "quic key", suite.KeyLen())
iv := qtls.HkdfExpandLabel(suite.Hash(), trafficSecret, []byte{}, "quic iv", suite.IVLen())
return suite.AEAD(key, iv)
}
func createHeaderProtector(suite cipherSuite, trafficSecret []byte) cipher.Block {
hpKey := qtls.HkdfExpandLabel(suite.Hash(), trafficSecret, []byte{}, "quic hp", suite.KeyLen())
hpDecrypter, err := aes.NewCipher(hpKey)
hp, err := aes.NewCipher(hpKey)
if err != nil {
panic(fmt.Sprintf("error creating new AES cipher: %s", err))
}
return suite.AEAD(key, iv), hpDecrypter
return hp
}