From ec509fb98f93b8965e9f29d835362ec375f6e521 Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Fri, 15 Apr 2016 12:44:31 +0200 Subject: [PATCH] add key derivation test --- crypto/key_derivation_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 crypto/key_derivation_test.go diff --git a/crypto/key_derivation_test.go b/crypto/key_derivation_test.go new file mode 100644 index 00000000..7b0f5d99 --- /dev/null +++ b/crypto/key_derivation_test.go @@ -0,0 +1,26 @@ +package crypto + +import ( + "github.com/lucas-clemente/quic-go/protocol" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("KeyDerivation", func() { + It("derives proper keys", func() { + aead, err := DeriveKeysChacha20( + []byte("0123456789012345678901"), + []byte("nonce"), + protocol.ConnectionID(42), + []byte("chlo"), + []byte("scfg"), + []byte("cert"), + ) + Expect(err).ToNot(HaveOccurred()) + chacha := aead.(*aeadChacha20Poly1305) + // If the IVs match, the keys will match too, since the keys are read earlier + Expect(chacha.myIV).To(Equal([]byte{0xf0, 0xf5, 0x4c, 0xa8})) + Expect(chacha.otherIV).To(Equal([]byte{0x75, 0xd8, 0xa2, 0x8d})) + }) +})