From 23f3432b9d4a0b6191f710d26515d2dc1b4c9818 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 7 Sep 2017 20:06:58 +0300 Subject: [PATCH] select the right null AEAD algorithm depending on the version --- crypto/null_aead.go | 14 ++++++++++++++ crypto/null_aead_fnv128a.go | 8 -------- crypto/null_aead_test.go | 17 +++++++++++++++++ internal/protocol/version.go | 1 + 4 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 crypto/null_aead.go create mode 100644 crypto/null_aead_test.go diff --git a/crypto/null_aead.go b/crypto/null_aead.go new file mode 100644 index 00000000..fe194343 --- /dev/null +++ b/crypto/null_aead.go @@ -0,0 +1,14 @@ +package crypto + +import "github.com/lucas-clemente/quic-go/internal/protocol" + +// NewNullAEAD creates a NullAEAD +func NewNullAEAD(p protocol.Perspective, v protocol.VersionNumber) AEAD { + if v == protocol.VersionTLS { + return &nullAEADFNV64a{} + } + return &nullAEADFNV128a{ + perspective: p, + version: v, + } +} diff --git a/crypto/null_aead_fnv128a.go b/crypto/null_aead_fnv128a.go index 2f3a31d6..55d1120c 100644 --- a/crypto/null_aead_fnv128a.go +++ b/crypto/null_aead_fnv128a.go @@ -16,14 +16,6 @@ type nullAEADFNV128a struct { var _ AEAD = &nullAEADFNV128a{} -// NewNullAEAD creates a NullAEAD -func NewNullAEAD(p protocol.Perspective, v protocol.VersionNumber) AEAD { - return &nullAEADFNV128a{ - perspective: p, - version: v, - } -} - // Open and verify the ciphertext func (n *nullAEADFNV128a) Open(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) ([]byte, error) { if len(src) < 12 { diff --git a/crypto/null_aead_test.go b/crypto/null_aead_test.go new file mode 100644 index 00000000..a456f541 --- /dev/null +++ b/crypto/null_aead_test.go @@ -0,0 +1,17 @@ +package crypto + +import ( + "github.com/lucas-clemente/quic-go/internal/protocol" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("NullAEAD", func() { + It("selects the right FVN variant", func() { + Expect(NewNullAEAD(protocol.PerspectiveClient, protocol.Version39)).To(Equal(&nullAEADFNV128a{ + perspective: protocol.PerspectiveClient, + version: protocol.Version39, + })) + Expect(NewNullAEAD(protocol.PerspectiveClient, protocol.VersionTLS)).To(Equal(&nullAEADFNV64a{})) + }) +}) diff --git a/internal/protocol/version.go b/internal/protocol/version.go index fc1ba9b7..f4e4af9f 100644 --- a/internal/protocol/version.go +++ b/internal/protocol/version.go @@ -10,6 +10,7 @@ const ( Version37 Version38 Version39 + VersionTLS VersionNumber = 101 VersionWhatever VersionNumber = 0 // for when the version doesn't matter VersionUnsupported VersionNumber = -1 VersionUnknown VersionNumber = -2