summaryrefslogtreecommitdiff
path: root/drivers/crypto/atmel-aes.c
diff options
context:
space:
mode:
authorTudor Ambarus <tudor.ambarus@microchip.com>2021-07-20 11:55:31 +0300
committerHerbert Xu <herbert@gondor.apana.org.au>2021-07-30 10:58:33 +0800
commit0d0433599d84bf7db8caa8fb76915dc0ff818150 (patch)
tree6271ca01676fa698d9629e7bb44d17e0aa4bbada /drivers/crypto/atmel-aes.c
parent26d769ae90907e6f4724b800ba16f11681079f23 (diff)
downloadlwn-0d0433599d84bf7db8caa8fb76915dc0ff818150.tar.gz
lwn-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 'drivers/crypto/atmel-aes.c')
-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;