Skip to content

Commit

Permalink
crypto: arm64/aes - fix handling sub-block CTS-CBC inputs
Browse files Browse the repository at this point in the history
In the new arm64 CTS-CBC implementation, return an error code rather
than crashing on inputs shorter than AES_BLOCK_SIZE bytes.  Also set
cra_blocksize to AES_BLOCK_SIZE (like is done in the cts template) to
indicate the minimum input size.

Fixes: dd597fb ("crypto: arm64/aes-blk - add support for CTS-CBC mode")
Signed-off-by: Eric Biggers <[email protected]>
Reviewed-by: Ard Biesheuvel <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
ebiggers authored and herbertx committed Oct 8, 2018
1 parent 52813ab commit 7ff9036
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions arch/arm64/crypto/aes-glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ static int cts_cbc_encrypt(struct skcipher_request *req)

skcipher_request_set_tfm(&rctx->subreq, tfm);

if (req->cryptlen == AES_BLOCK_SIZE)
if (req->cryptlen <= AES_BLOCK_SIZE) {
if (req->cryptlen < AES_BLOCK_SIZE)
return -EINVAL;
cbc_blocks = 1;
}

if (cbc_blocks > 0) {
unsigned int blocks;
Expand Down Expand Up @@ -305,8 +308,11 @@ static int cts_cbc_decrypt(struct skcipher_request *req)

skcipher_request_set_tfm(&rctx->subreq, tfm);

if (req->cryptlen == AES_BLOCK_SIZE)
if (req->cryptlen <= AES_BLOCK_SIZE) {
if (req->cryptlen < AES_BLOCK_SIZE)
return -EINVAL;
cbc_blocks = 1;
}

if (cbc_blocks > 0) {
unsigned int blocks;
Expand Down Expand Up @@ -486,14 +492,13 @@ static struct skcipher_alg aes_algs[] = { {
.cra_driver_name = "__cts-cbc-aes-" MODE,
.cra_priority = PRIO,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = 1,
.cra_blocksize = AES_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crypto_aes_ctx),
.cra_module = THIS_MODULE,
},
.min_keysize = AES_MIN_KEY_SIZE,
.max_keysize = AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE,
.chunksize = AES_BLOCK_SIZE,
.walksize = 2 * AES_BLOCK_SIZE,
.setkey = skcipher_aes_setkey,
.encrypt = cts_cbc_encrypt,
Expand Down

0 comments on commit 7ff9036

Please sign in to comment.