From 351678026482587e966461f49b9a1d71053972d6 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 27 Sep 2018 18:44:18 -0600 Subject: [PATCH] change the label and the context of HKDF-Expand-Label This now uses the draft-14 test vectors from the QUIC WG wiki. --- internal/crypto/hkdf.go | 4 +-- internal/crypto/null_aead_aesgcm.go | 6 ++--- internal/crypto/null_aead_aesgcm_test.go | 32 ++++++++++++------------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/crypto/hkdf.go b/internal/crypto/hkdf.go index efa5a93d..2501aa79 100644 --- a/internal/crypto/hkdf.go +++ b/internal/crypto/hkdf.go @@ -49,8 +49,8 @@ func hkdfExpand(hash crypto.Hash, prk, info []byte, l int) []byte { // hkdfExpandLabel HKDF expands a label func hkdfExpandLabel(hash crypto.Hash, secret []byte, label string, length int) []byte { - const prefix = "QUIC " - qlabel := make([]byte, 2+1+len(prefix)+len(label)) + const prefix = "quic " + 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)) qlabel[2] = uint8(len(prefix) + len(label)) copy(qlabel[3:], []byte(prefix+label)) diff --git a/internal/crypto/null_aead_aesgcm.go b/internal/crypto/null_aead_aesgcm.go index edc24b97..48dce27e 100644 --- a/internal/crypto/null_aead_aesgcm.go +++ b/internal/crypto/null_aead_aesgcm.go @@ -27,9 +27,9 @@ func newNullAEADAESGCM(connectionID protocol.ConnectionID, pers protocol.Perspec } func computeSecrets(connID protocol.ConnectionID) (clientSecret, serverSecret []byte) { - handshakeSecret := hkdfExtract(crypto.SHA256, connID, quicVersion1Salt) - clientSecret = hkdfExpandLabel(crypto.SHA256, handshakeSecret, "client hs", crypto.SHA256.Size()) - serverSecret = hkdfExpandLabel(crypto.SHA256, handshakeSecret, "server hs", crypto.SHA256.Size()) + initialSecret := hkdfExtract(crypto.SHA256, connID, quicVersion1Salt) + clientSecret = hkdfExpandLabel(crypto.SHA256, initialSecret, "client in", crypto.SHA256.Size()) + serverSecret = hkdfExpandLabel(crypto.SHA256, initialSecret, "server in", crypto.SHA256.Size()) return } diff --git a/internal/crypto/null_aead_aesgcm_test.go b/internal/crypto/null_aead_aesgcm_test.go index 8f45a956..980348b7 100644 --- a/internal/crypto/null_aead_aesgcm_test.go +++ b/internal/crypto/null_aead_aesgcm_test.go @@ -14,16 +14,16 @@ var _ = Describe("NullAEAD using AES-GCM", func() { It("computes the secrets", func() { clientSecret, serverSecret := computeSecrets(connID) Expect(clientSecret).To(Equal([]byte{ - 0x83, 0x55, 0xf2, 0x1a, 0x3d, 0x8f, 0x83, 0xec, - 0xb3, 0xd0, 0xf9, 0x71, 0x08, 0xd3, 0xf9, 0x5e, - 0x0f, 0x65, 0xb4, 0xd8, 0xae, 0x88, 0xa0, 0x61, - 0x1e, 0xe4, 0x9d, 0xb0, 0xb5, 0x23, 0x59, 0x1d, + 0x9f, 0x53, 0x64, 0x57, 0xf3, 0x2a, 0x1e, 0x0a, + 0xe8, 0x64, 0xbc, 0xb3, 0xca, 0xf1, 0x23, 0x51, + 0x10, 0x63, 0x0e, 0x1d, 0x1f, 0xb3, 0x38, 0x35, + 0xbd, 0x05, 0x41, 0x70, 0xf9, 0x9b, 0xf7, 0xdc, })) Expect(serverSecret).To(Equal([]byte{ - 0xf8, 0x0e, 0x57, 0x71, 0x48, 0x4b, 0x21, 0xcd, - 0xeb, 0xb5, 0xaf, 0xe0, 0xa2, 0x56, 0xa3, 0x17, - 0x41, 0xef, 0xe2, 0xb5, 0xc6, 0xb6, 0x17, 0xba, - 0xe1, 0xb2, 0xf1, 0x5a, 0x83, 0x04, 0x83, 0xd6, + 0xb0, 0x87, 0xdc, 0xd7, 0x47, 0x8d, 0xda, 0x8a, + 0x85, 0x8f, 0xbf, 0x3d, 0x60, 0x5c, 0x88, 0x85, + 0x86, 0xc0, 0xa3, 0xa9, 0x87, 0x54, 0x23, 0xad, + 0x4f, 0x11, 0x4f, 0x0b, 0xa3, 0x8e, 0x5a, 0x2e, })) }) @@ -31,12 +31,12 @@ var _ = Describe("NullAEAD using AES-GCM", func() { clientSecret, _ := computeSecrets(connID) key, iv := computeNullAEADKeyAndIV(clientSecret) Expect(key).To(Equal([]byte{ - 0x3a, 0xd0, 0x54, 0x2c, 0x4a, 0x85, 0x84, 0x74, - 0x00, 0x63, 0x04, 0x9e, 0x3b, 0x3c, 0xaa, 0xb2, + 0xf2, 0x92, 0x8f, 0x26, 0x14, 0xad, 0x6c, 0x20, + 0xb9, 0xbd, 0x00, 0x8e, 0x9c, 0x89, 0x63, 0x1c, })) Expect(iv).To(Equal([]byte{ - 0xd1, 0xfd, 0x26, 0x05, 0x42, 0x75, 0x3a, 0xba, - 0x38, 0x58, 0x9b, 0xad, + 0xab, 0x95, 0x0b, 0x01, 0x98, 0x63, 0x79, 0x78, + 0xcf, 0x44, 0xaa, 0xb9, })) }) @@ -44,12 +44,12 @@ var _ = Describe("NullAEAD using AES-GCM", func() { _, serverSecret := computeSecrets(connID) key, iv := computeNullAEADKeyAndIV(serverSecret) Expect(key).To(Equal([]byte{ - 0xbe, 0xe4, 0xc2, 0x4d, 0x2a, 0xf1, 0x33, 0x80, - 0xa9, 0xfa, 0x24, 0xa5, 0xe2, 0xba, 0x2c, 0xff, + 0xf5, 0x68, 0x17, 0xd0, 0xfc, 0x59, 0x5c, 0xfc, + 0x0a, 0x2b, 0x0b, 0xcf, 0xb1, 0x87, 0x35, 0xec, })) Expect(iv).To(Equal([]byte{ - 0x25, 0xb5, 0x8e, 0x24, 0x6d, 0x9e, 0x7d, 0x5f, - 0xfe, 0x43, 0x23, 0xfe, + 0x32, 0x05, 0x03, 0x5a, 0x3c, 0x93, 0x7c, 0x90, + 0x2e, 0xe4, 0xf4, 0xd6, })) }) })