diff mbox series

[PATCHv2,11/22] crypto: omap-aes - reject invalid input sizes for block modes

Message ID 20191105140111.20285-12-t-kristo@ti.com
State New
Headers show
Series None | expand

Commit Message

Tero Kristo Nov. 5, 2019, 2:01 p.m. UTC
From: Ard Biesheuvel <ardb@kernel.org>


Block modes such as ECB and CBC only support input sizes that are
a round multiple of the block size, so align with the generic code
which returns -EINVAL when encountering inputs that violate this
rule.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

Reviewed-by: Tero Kristo <t-kristo@ti.com>

Tested-by: Tero Kristo <t-kristo@ti.com>

---
 drivers/crypto/omap-aes.c | 3 +++
 1 file changed, 3 insertions(+)

-- 
2.17.1

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
diff mbox series

Patch

diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index de05b35283bf..067f4cd7c005 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -525,6 +525,9 @@  static int omap_aes_crypt(struct skcipher_request *req, unsigned long mode)
 	struct omap_aes_dev *dd;
 	int ret;
 
+	if ((req->cryptlen % AES_BLOCK_SIZE) && !(mode & FLAGS_CTR))
+		return -EINVAL;
+
 	pr_debug("nbytes: %d, enc: %d, cbc: %d\n", req->cryptlen,
 		  !!(mode & FLAGS_ENCRYPT),
 		  !!(mode & FLAGS_CBC));