change the label and the context of HKDF-Expand-Label

This now uses the draft-14 test vectors from the QUIC WG wiki.
This commit is contained in:
Marten Seemann
2018-09-27 18:44:18 -06:00
parent 99c5d0df25
commit 3516780264
3 changed files with 21 additions and 21 deletions

View File

@@ -49,8 +49,8 @@ func hkdfExpand(hash crypto.Hash, prk, info []byte, l int) []byte {
// hkdfExpandLabel HKDF expands a label // hkdfExpandLabel HKDF expands a label
func hkdfExpandLabel(hash crypto.Hash, secret []byte, label string, length int) []byte { func hkdfExpandLabel(hash crypto.Hash, secret []byte, label string, length int) []byte {
const prefix = "QUIC " const prefix = "quic "
qlabel := make([]byte, 2+1+len(prefix)+len(label)) qlabel := make([]byte, 2 /* length */ +1 /* length of label */ +len(prefix)+len(label)+1 /* length of context (empty) */)
binary.BigEndian.PutUint16(qlabel[0:2], uint16(length)) binary.BigEndian.PutUint16(qlabel[0:2], uint16(length))
qlabel[2] = uint8(len(prefix) + len(label)) qlabel[2] = uint8(len(prefix) + len(label))
copy(qlabel[3:], []byte(prefix+label)) copy(qlabel[3:], []byte(prefix+label))

View File

@@ -27,9 +27,9 @@ func newNullAEADAESGCM(connectionID protocol.ConnectionID, pers protocol.Perspec
} }
func computeSecrets(connID protocol.ConnectionID) (clientSecret, serverSecret []byte) { func computeSecrets(connID protocol.ConnectionID) (clientSecret, serverSecret []byte) {
handshakeSecret := hkdfExtract(crypto.SHA256, connID, quicVersion1Salt) initialSecret := hkdfExtract(crypto.SHA256, connID, quicVersion1Salt)
clientSecret = hkdfExpandLabel(crypto.SHA256, handshakeSecret, "client hs", crypto.SHA256.Size()) clientSecret = hkdfExpandLabel(crypto.SHA256, initialSecret, "client in", crypto.SHA256.Size())
serverSecret = hkdfExpandLabel(crypto.SHA256, handshakeSecret, "server hs", crypto.SHA256.Size()) serverSecret = hkdfExpandLabel(crypto.SHA256, initialSecret, "server in", crypto.SHA256.Size())
return return
} }

View File

@@ -14,16 +14,16 @@ var _ = Describe("NullAEAD using AES-GCM", func() {
It("computes the secrets", func() { It("computes the secrets", func() {
clientSecret, serverSecret := computeSecrets(connID) clientSecret, serverSecret := computeSecrets(connID)
Expect(clientSecret).To(Equal([]byte{ Expect(clientSecret).To(Equal([]byte{
0x83, 0x55, 0xf2, 0x1a, 0x3d, 0x8f, 0x83, 0xec, 0x9f, 0x53, 0x64, 0x57, 0xf3, 0x2a, 0x1e, 0x0a,
0xb3, 0xd0, 0xf9, 0x71, 0x08, 0xd3, 0xf9, 0x5e, 0xe8, 0x64, 0xbc, 0xb3, 0xca, 0xf1, 0x23, 0x51,
0x0f, 0x65, 0xb4, 0xd8, 0xae, 0x88, 0xa0, 0x61, 0x10, 0x63, 0x0e, 0x1d, 0x1f, 0xb3, 0x38, 0x35,
0x1e, 0xe4, 0x9d, 0xb0, 0xb5, 0x23, 0x59, 0x1d, 0xbd, 0x05, 0x41, 0x70, 0xf9, 0x9b, 0xf7, 0xdc,
})) }))
Expect(serverSecret).To(Equal([]byte{ Expect(serverSecret).To(Equal([]byte{
0xf8, 0x0e, 0x57, 0x71, 0x48, 0x4b, 0x21, 0xcd, 0xb0, 0x87, 0xdc, 0xd7, 0x47, 0x8d, 0xda, 0x8a,
0xeb, 0xb5, 0xaf, 0xe0, 0xa2, 0x56, 0xa3, 0x17, 0x85, 0x8f, 0xbf, 0x3d, 0x60, 0x5c, 0x88, 0x85,
0x41, 0xef, 0xe2, 0xb5, 0xc6, 0xb6, 0x17, 0xba, 0x86, 0xc0, 0xa3, 0xa9, 0x87, 0x54, 0x23, 0xad,
0xe1, 0xb2, 0xf1, 0x5a, 0x83, 0x04, 0x83, 0xd6, 0x4f, 0x11, 0x4f, 0x0b, 0xa3, 0x8e, 0x5a, 0x2e,
})) }))
}) })
@@ -31,12 +31,12 @@ var _ = Describe("NullAEAD using AES-GCM", func() {
clientSecret, _ := computeSecrets(connID) clientSecret, _ := computeSecrets(connID)
key, iv := computeNullAEADKeyAndIV(clientSecret) key, iv := computeNullAEADKeyAndIV(clientSecret)
Expect(key).To(Equal([]byte{ Expect(key).To(Equal([]byte{
0x3a, 0xd0, 0x54, 0x2c, 0x4a, 0x85, 0x84, 0x74, 0xf2, 0x92, 0x8f, 0x26, 0x14, 0xad, 0x6c, 0x20,
0x00, 0x63, 0x04, 0x9e, 0x3b, 0x3c, 0xaa, 0xb2, 0xb9, 0xbd, 0x00, 0x8e, 0x9c, 0x89, 0x63, 0x1c,
})) }))
Expect(iv).To(Equal([]byte{ Expect(iv).To(Equal([]byte{
0xd1, 0xfd, 0x26, 0x05, 0x42, 0x75, 0x3a, 0xba, 0xab, 0x95, 0x0b, 0x01, 0x98, 0x63, 0x79, 0x78,
0x38, 0x58, 0x9b, 0xad, 0xcf, 0x44, 0xaa, 0xb9,
})) }))
}) })
@@ -44,12 +44,12 @@ var _ = Describe("NullAEAD using AES-GCM", func() {
_, serverSecret := computeSecrets(connID) _, serverSecret := computeSecrets(connID)
key, iv := computeNullAEADKeyAndIV(serverSecret) key, iv := computeNullAEADKeyAndIV(serverSecret)
Expect(key).To(Equal([]byte{ Expect(key).To(Equal([]byte{
0xbe, 0xe4, 0xc2, 0x4d, 0x2a, 0xf1, 0x33, 0x80, 0xf5, 0x68, 0x17, 0xd0, 0xfc, 0x59, 0x5c, 0xfc,
0xa9, 0xfa, 0x24, 0xa5, 0xe2, 0xba, 0x2c, 0xff, 0x0a, 0x2b, 0x0b, 0xcf, 0xb1, 0x87, 0x35, 0xec,
})) }))
Expect(iv).To(Equal([]byte{ Expect(iv).To(Equal([]byte{
0x25, 0xb5, 0x8e, 0x24, 0x6d, 0x9e, 0x7d, 0x5f, 0x32, 0x05, 0x03, 0x5a, 0x3c, 0x93, 0x7c, 0x90,
0xfe, 0x43, 0x23, 0xfe, 0x2e, 0xe4, 0xf4, 0xd6,
})) }))
}) })
}) })