From c0e9faa505256a6dcc98d9fabee040d2bfa31af5 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 5 Jan 2019 13:43:34 +0700 Subject: [PATCH] use the initial test vectors from the draft --- internal/handshake/initial_aead_test.go | 74 +++++++++++-------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/internal/handshake/initial_aead_test.go b/internal/handshake/initial_aead_test.go index 2f3959ad8..83e64174f 100644 --- a/internal/handshake/initial_aead_test.go +++ b/internal/handshake/initial_aead_test.go @@ -1,7 +1,9 @@ package handshake import ( + "encoding/hex" "math/rand" + "strings" "github.com/lucas-clemente/quic-go/internal/protocol" @@ -10,58 +12,48 @@ import ( ) var _ = Describe("Initial AEAD using AES-GCM", func() { - // values taken from https://github.com/quicwg/base-drafts/wiki/Test-Vector-for-the-Clear-Text-AEAD-key-derivation - Context("using the test vector from the QUIC WG Wiki", func() { - connID := protocol.ConnectionID([]byte{0xc6, 0x54, 0xef, 0xd8, 0xa3, 0x1b, 0x47, 0x92}) + split := func(s string) (slice []byte) { + for _, ss := range strings.Split(s, " ") { + if ss[0:2] == "0x" { + ss = ss[2:] + } + d, err := hex.DecodeString(ss) + Expect(err).ToNot(HaveOccurred()) + slice = append(slice, d...) + } + return + } - It("computes the secrets", func() { - clientSecret, serverSecret := computeSecrets(connID) - Expect(clientSecret).To(Equal([]byte{ - 0x0c, 0x74, 0xbb, 0x95, 0xa1, 0x04, 0x8e, 0x52, - 0xef, 0x3b, 0x72, 0xe1, 0x28, 0x89, 0x35, 0x1c, - 0xd7, 0x3a, 0x55, 0x0f, 0xb6, 0x2c, 0x4b, 0xb0, - 0x87, 0xe9, 0x15, 0xcc, 0xe9, 0x6c, 0xe3, 0xa0, - })) - Expect(serverSecret).To(Equal([]byte{ - 0x4c, 0x9e, 0xdf, 0x24, 0xb0, 0xe5, 0xe5, 0x06, - 0xdd, 0x3b, 0xfa, 0x4e, 0x0a, 0x03, 0x11, 0xe8, - 0xc4, 0x1f, 0x35, 0x42, 0x73, 0xd8, 0xcb, 0x49, - 0xdd, 0xd8, 0x46, 0x41, 0x38, 0xd4, 0x7e, 0xc6, - })) + It("converts the string representation used in the draft into byte slices", func() { + Expect(split("0xdeadbeef")).To(Equal([]byte{0xde, 0xad, 0xbe, 0xef})) + Expect(split("deadbeef")).To(Equal([]byte{0xde, 0xad, 0xbe, 0xef})) + Expect(split("dead beef")).To(Equal([]byte{0xde, 0xad, 0xbe, 0xef})) + }) + + // values taken from https://github.com/quicwg/base-drafts/wiki/Test-Vector-for-the-Clear-Text-AEAD-key-derivation + Context("using the test vector from the QUIC draft", func() { + var connID protocol.ConnectionID + + BeforeEach(func() { + connID = protocol.ConnectionID(split("0x8394c8f03e515708")) }) It("computes the client key and IV", func() { clientSecret, _ := computeSecrets(connID) + Expect(clientSecret).To(Equal(split("8a3515a14ae3c31b9c2d6d5bc58538ca 5cd2baa119087143e60887428dcb52f6"))) key, hpKey, iv := computeInitialKeyAndIV(clientSecret) - Expect(key).To(Equal([]byte{ - 0x86, 0xd1, 0x83, 0x04, 0x80, 0xb4, 0x0f, 0x86, - 0xcf, 0x9d, 0x68, 0xdc, 0xad, 0xf3, 0x5d, 0xfe, - })) - Expect(hpKey).To(Equal([]byte{ - 0xcd, 0x25, 0x3a, 0x36, 0xff, 0x93, 0x93, 0x7c, - 0x46, 0x93, 0x84, 0xa8, 0x23, 0xaf, 0x6c, 0x56, - })) - Expect(iv).To(Equal([]byte{ - 0x12, 0xf3, 0x93, 0x8a, 0xca, 0x34, 0xaa, 0x02, - 0x54, 0x31, 0x63, 0xd4, - })) + Expect(key).To(Equal(split("98b0d7e5e7a402c67c33f350fa65ea54"))) + Expect(iv).To(Equal(split("19e94387805eb0b46c03a788"))) + Expect(hpKey).To(Equal(split("0edd982a6ac527f2eddcbb7348dea5d7"))) }) It("computes the server key and IV", func() { _, serverSecret := computeSecrets(connID) + Expect(serverSecret).To(Equal(split("47b2eaea6c266e32c0697a9e2a898bdf 5c4fb3e5ac34f0e549bf2c58581a3811"))) key, hpKey, iv := computeInitialKeyAndIV(serverSecret) - Expect(key).To(Equal([]byte{ - 0x2c, 0x78, 0x63, 0x3e, 0x20, 0x6e, 0x99, 0xad, - 0x25, 0x19, 0x64, 0xf1, 0x9f, 0x6d, 0xcd, 0x6d, - })) - Expect(hpKey).To(Equal([]byte{ - 0x25, 0x79, 0xd8, 0x69, 0x6f, 0x85, 0xed, 0xa6, - 0x8d, 0x35, 0x02, 0xb6, 0x55, 0x96, 0x58, 0x6b, - })) - Expect(iv).To(Equal([]byte{ - 0x7b, 0x50, 0xbf, 0x36, 0x98, 0xa0, 0x6d, 0xfa, - 0xbf, 0x75, 0xf2, 0x87, - })) + Expect(key).To(Equal(split("9a8be902a9bdd91d16064ca118045fb4"))) + Expect(iv).To(Equal(split("0a82086d32205ba22241d8dc"))) + Expect(hpKey).To(Equal(split("94b9452d2b3c7c7f6da7fdd8593537fd"))) }) })