diff --git a/aes_siv.go b/aes_siv.go index 7ba706e..3b20458 100644 --- a/aes_siv.go +++ b/aes_siv.go @@ -23,6 +23,8 @@ var ( ErrSivUnWrapSizeUnsupportedCiphertext = errors.New("Siv Unwrap error: ciphertext size is longer than supported") //ErrSivUnWrapUnsupportedAdditionalData indicates that the additionalData elements supplied exceed the maximum number supported ErrSivUnWrapUnsupportedAdditionalData = errors.New("Siv Unwrap error: additionalData elements more than than supported") + //ErrSivUnWrapShortCipherLength indicates that the cipher text is too short + ErrSivUnWrapShortCipherLength = errors.New("Siv Unwrap error: ciphertext is too short") ) const ( @@ -68,6 +70,9 @@ func (c *aesSiv) Unwrap(ciphertext []byte, additionalData ...[]byte) ([]byte, er if len(ciphertext)-ctrBlockSize > (1 << (strconv.IntSize - 3)) { return nil, ErrSivUnWrapSizeUnsupportedCiphertext } + if len(ciphertext) < cmacBlockSize { + return nil, ErrSivUnWrapShortCipherLength + } if len(additionalData) > (cmacBlockSize*8)-2 { return nil, ErrSivUnWrapUnsupportedAdditionalData } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a3284ee --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/ChandraNarreddy/siv + +go 1.16 + +require github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f918b9e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 h1:+JkXLHME8vLJafGhOH4aoV2Iu8bR55nU6iKMVfYVLjY= +github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1/go.mod h1:nuudZmJhzWtx2212z+pkuy7B6nkBqa+xwNXZHL1j8cg=