Skip to content

Commit 47294fd

Browse files
committed
crypto: atmel-aes: Add blocksize constraint for ECB and CBC modes
NIST 800-38A requires for the ECB and CBC modes that the total number of bits in the plaintext to be a multiple of the block cipher. ------- For CFB mode the requirement is that the plaintext to be a mutiple of the data segments length. CFB's data segment legth is currently represented as blocksize. Add these constraints for the ECB, CBC and CFB modes. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
1 parent eb7e511 commit 47294fd

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

drivers/crypto/atmel-aes.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,11 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode)
10891089
struct atmel_aes_base_ctx *ctx = crypto_skcipher_ctx(skcipher);
10901090
struct atmel_aes_reqctx *rctx;
10911091
struct atmel_aes_dev *dd;
1092+
u32 opmode = mode & AES_FLAGS_OPMODE_MASK;
1093+
1094+
if ((opmode == AES_FLAGS_ECB || opmode == AES_FLAGS_CBC) &&
1095+
!IS_ALIGNED(req->cryptlen, crypto_skcipher_blocksize(skcipher)))
1096+
return -EINVAL;
10921097

10931098
switch (mode & AES_FLAGS_OPMODE_MASK) {
10941099
case AES_FLAGS_CFB8:
@@ -1120,7 +1125,7 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode)
11201125
rctx = skcipher_request_ctx(req);
11211126
rctx->mode = mode;
11221127

1123-
if ((mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_ECB &&
1128+
if (opmode != AES_FLAGS_ECB &&
11241129
!(mode & AES_FLAGS_ENCRYPT) && req->src == req->dst) {
11251130
unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
11261131

0 commit comments

Comments
 (0)