Commit 96ee111a authored by Giovanni Cabiddu's avatar Giovanni Cabiddu Committed by Herbert Xu

crypto: qat - return error for block ciphers for invalid requests

Return -EINVAL if a request for a block cipher is not multiple of the
size of the block.

This problem was found with by the new extra run-time crypto self test.
Reviewed-by: default avatarConor Mcloughlin <conor.mcloughlin@intel.com>
Tested-by: default avatarSergey Portnoy <sergey.portnoy@intel.com>
Signed-off-by: default avatarGiovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 92fec16d
...@@ -1096,6 +1096,14 @@ static int qat_alg_ablkcipher_encrypt(struct ablkcipher_request *req) ...@@ -1096,6 +1096,14 @@ static int qat_alg_ablkcipher_encrypt(struct ablkcipher_request *req)
return -EINPROGRESS; return -EINPROGRESS;
} }
static int qat_alg_ablkcipher_blk_encrypt(struct ablkcipher_request *req)
{
if (req->nbytes % AES_BLOCK_SIZE != 0)
return -EINVAL;
return qat_alg_ablkcipher_encrypt(req);
}
static int qat_alg_ablkcipher_decrypt(struct ablkcipher_request *req) static int qat_alg_ablkcipher_decrypt(struct ablkcipher_request *req)
{ {
struct crypto_ablkcipher *atfm = crypto_ablkcipher_reqtfm(req); struct crypto_ablkcipher *atfm = crypto_ablkcipher_reqtfm(req);
...@@ -1145,6 +1153,13 @@ static int qat_alg_ablkcipher_decrypt(struct ablkcipher_request *req) ...@@ -1145,6 +1153,13 @@ static int qat_alg_ablkcipher_decrypt(struct ablkcipher_request *req)
return -EINPROGRESS; return -EINPROGRESS;
} }
static int qat_alg_ablkcipher_blk_decrypt(struct ablkcipher_request *req)
{
if (req->nbytes % AES_BLOCK_SIZE != 0)
return -EINVAL;
return qat_alg_ablkcipher_decrypt(req);
}
static int qat_alg_aead_init(struct crypto_aead *tfm, static int qat_alg_aead_init(struct crypto_aead *tfm,
enum icp_qat_hw_auth_algo hash, enum icp_qat_hw_auth_algo hash,
const char *hash_name) const char *hash_name)
...@@ -1304,8 +1319,8 @@ static struct crypto_alg qat_algs[] = { { ...@@ -1304,8 +1319,8 @@ static struct crypto_alg qat_algs[] = { {
.cra_u = { .cra_u = {
.ablkcipher = { .ablkcipher = {
.setkey = qat_alg_ablkcipher_cbc_setkey, .setkey = qat_alg_ablkcipher_cbc_setkey,
.decrypt = qat_alg_ablkcipher_decrypt, .decrypt = qat_alg_ablkcipher_blk_decrypt,
.encrypt = qat_alg_ablkcipher_encrypt, .encrypt = qat_alg_ablkcipher_blk_encrypt,
.min_keysize = AES_MIN_KEY_SIZE, .min_keysize = AES_MIN_KEY_SIZE,
.max_keysize = AES_MAX_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
...@@ -1348,8 +1363,8 @@ static struct crypto_alg qat_algs[] = { { ...@@ -1348,8 +1363,8 @@ static struct crypto_alg qat_algs[] = { {
.cra_u = { .cra_u = {
.ablkcipher = { .ablkcipher = {
.setkey = qat_alg_ablkcipher_xts_setkey, .setkey = qat_alg_ablkcipher_xts_setkey,
.decrypt = qat_alg_ablkcipher_decrypt, .decrypt = qat_alg_ablkcipher_blk_decrypt,
.encrypt = qat_alg_ablkcipher_encrypt, .encrypt = qat_alg_ablkcipher_blk_encrypt,
.min_keysize = 2 * AES_MIN_KEY_SIZE, .min_keysize = 2 * AES_MIN_KEY_SIZE,
.max_keysize = 2 * AES_MAX_KEY_SIZE, .max_keysize = 2 * AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment