]> Cypherpunks.ru repositories - gogost.git/blobdiff - mgm/mode.go
No panic during too short MGM message
[gogost.git] / mgm / mode.go
index 065bff50edd0b96e5a01aff22be9f4270398d2f9..c281567fbaf9ceb8dc33777314e2122788064a7b 100644 (file)
@@ -234,7 +234,9 @@ func (mgm *MGM) Seal(dst, nonce, plaintext, additionalData []byte) []byte {
 func (mgm *MGM) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
        mgm.validateNonce(nonce)
        mgm.validateSizes(ciphertext, additionalData)
-       if uint64(len(ciphertext)-mgm.tagSize) > mgm.maxSize {
+       if len(ciphertext) < mgm.TagSize {
+               return nil, errors.New("ciphertext is too short")
+       }
        if uint64(len(ciphertext)-mgm.TagSize) > mgm.MaxSize {
                panic("ciphertext is too big")
        }