Commit 1ba34e71 authored by Christophe Leroy's avatar Christophe Leroy Committed by Herbert Xu

crypto: talitos - check AES key size

Although the HW accepts any size and silently truncates
it to the correct length, the extra tests expects EINVAL
to be returned when the key size is not valid.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Fixes: 4de9d0b5 ("crypto: talitos - Add ablkcipher algorithms")
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent b8fbdc2b
...@@ -1622,6 +1622,18 @@ static int ablkcipher_des3_setkey(struct crypto_ablkcipher *cipher, ...@@ -1622,6 +1622,18 @@ static int ablkcipher_des3_setkey(struct crypto_ablkcipher *cipher,
return ablkcipher_setkey(cipher, key, keylen); return ablkcipher_setkey(cipher, key, keylen);
} }
static int ablkcipher_aes_setkey(struct crypto_ablkcipher *cipher,
const u8 *key, unsigned int keylen)
{
if (keylen == AES_KEYSIZE_128 || keylen == AES_KEYSIZE_192 ||
keylen == AES_KEYSIZE_256)
return ablkcipher_setkey(cipher, key, keylen);
crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
}
static void common_nonsnoop_unmap(struct device *dev, static void common_nonsnoop_unmap(struct device *dev,
struct talitos_edesc *edesc, struct talitos_edesc *edesc,
struct ablkcipher_request *areq) struct ablkcipher_request *areq)
...@@ -2782,6 +2794,7 @@ static struct talitos_alg_template driver_algs[] = { ...@@ -2782,6 +2794,7 @@ static struct talitos_alg_template driver_algs[] = {
.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,
.setkey = ablkcipher_aes_setkey,
} }
}, },
.desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
...@@ -2798,6 +2811,7 @@ static struct talitos_alg_template driver_algs[] = { ...@@ -2798,6 +2811,7 @@ static struct talitos_alg_template driver_algs[] = {
.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,
.setkey = ablkcipher_aes_setkey,
} }
}, },
.desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
...@@ -2815,6 +2829,7 @@ static struct talitos_alg_template driver_algs[] = { ...@@ -2815,6 +2829,7 @@ static struct talitos_alg_template driver_algs[] = {
.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,
.setkey = ablkcipher_aes_setkey,
} }
}, },
.desc_hdr_template = DESC_HDR_TYPE_AESU_CTR_NONSNOOP | .desc_hdr_template = DESC_HDR_TYPE_AESU_CTR_NONSNOOP |
......
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