summaryrefslogtreecommitdiffstats
path: root/drivers/crypto/atmel-aes.c
diff options
context:
space:
mode:
authorTudor Ambarus <tudor.ambarus@microchip.com>2021-07-20 10:55:31 +0200
committerHerbert Xu <herbert@gondor.apana.org.au>2021-07-30 04:58:33 +0200
commit0d0433599d84bf7db8caa8fb76915dc0ff818150 (patch)
tree6271ca01676fa698d9629e7bb44d17e0aa4bbada /drivers/crypto/atmel-aes.c
parentcrypto: atmel-aes - Add XTS input length constraint (diff)
downloadlinux-0d0433599d84bf7db8caa8fb76915dc0ff818150.tar.xz
linux-0d0433599d84bf7db8caa8fb76915dc0ff818150.zip
crypto: atmel-aes - Add NIST 800-38A's zero length cryptlen constraint
NIST 800-38A requires for the ECB, CBC, CFB, OFB and CTR modes that the plaintext and ciphertext to have a positive integer length. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--drivers/crypto/atmel-aes.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index 4e9515e8dd25..8ea873bf6b86 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -1094,6 +1094,13 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode)
if (opmode == AES_FLAGS_XTS && req->cryptlen < XTS_BLOCK_SIZE)
return -EINVAL;
+ /*
+ * ECB, CBC, CFB, OFB or CTR mode require the plaintext and ciphertext
+ * to have a positve integer length.
+ */
+ if (!req->cryptlen && opmode != AES_FLAGS_XTS)
+ return 0;
+
if ((opmode == AES_FLAGS_ECB || opmode == AES_FLAGS_CBC) &&
!IS_ALIGNED(req->cryptlen, crypto_skcipher_blocksize(skcipher)))
return -EINVAL;