diff --git a/crypto/AEAD.go b/crypto/AEAD.go index d68041796..f92b90b42 100644 --- a/crypto/AEAD.go +++ b/crypto/AEAD.go @@ -1,8 +1,11 @@ package crypto -import "io" +import ( + "bytes" + "io" +) // An AEAD implements QUIC's authenticated encryption and associated data type AEAD interface { - Open(associatedData []byte, ciphertext io.Reader) (io.Reader, error) + Open(associatedData []byte, ciphertext io.Reader) (*bytes.Reader, error) } diff --git a/crypto/NullAEAD.go b/crypto/NullAEAD.go index 90c34b3e0..7b726ac34 100644 --- a/crypto/NullAEAD.go +++ b/crypto/NullAEAD.go @@ -14,7 +14,7 @@ type NullAEAD struct{} var _ AEAD = &NullAEAD{} // Open and verify the ciphertext -func (*NullAEAD) Open(associatedData []byte, r io.Reader) (io.Reader, error) { +func (*NullAEAD) Open(associatedData []byte, r io.Reader) (*bytes.Reader, error) { ciphertext, err := ioutil.ReadAll(r) if err != nil { return nil, err diff --git a/crypto/NullAEAD_test.go b/crypto/NullAEAD_test.go index acd3da107..25952613a 100644 --- a/crypto/NullAEAD_test.go +++ b/crypto/NullAEAD_test.go @@ -22,4 +22,14 @@ var _ = Describe("Crypto/NullAEAD", func() { Expect(err).ToNot(HaveOccurred()) Expect(res).To(Equal([]byte("They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood."))) }) + + It("fails", func() { + aad := []byte("All human beings are born free and equal in dignity and rights..") + plainText := []byte("They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.") + hash := []byte{0x98, 0x9b, 0x33, 0x3f, 0xe8, 0xde, 0x32, 0x5c, 0xa6, 0x7f, 0x9c, 0xf7} + cipherText := append(hash, plainText...) + aead := &crypto.NullAEAD{} + _, err := aead.Open(aad, bytes.NewReader(cipherText)) + Expect(err).To(HaveOccurred()) + }) }) diff --git a/crypto/fnv.go b/crypto/fnv.go index 3fb99b28e..932f2fd52 100644 --- a/crypto/fnv.go +++ b/crypto/fnv.go @@ -4,6 +4,8 @@ package crypto // created by Glenn Fowler, Landon Curt Noll, and Phong Vo. // See https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function. +// Write() algorithm taken and modified from github.com/romain-jacotin/quic + import "hash" // Hash128 is the common interface implemented by all 128-bit hash functions. @@ -38,7 +40,6 @@ func (s *sum128a) Sum128() (uint64, uint64) { func (s *sum128a) Write(data []byte) (int, error) { var t0, t1, t2, t3 uint64 - // Taken and slightly modified from github.com/romain-jacotin/quic const fnv128PrimeLow = 0x0000013B const fnv128PrimeShift = 24