summaryrefslogtreecommitdiffstats
path: root/drivers/crypto/qce
diff options
context:
space:
mode:
authorThara Gopinath <thara.gopinath@linaro.org>2021-02-11 15:01:21 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2021-03-07 15:13:16 +1100
commit42f730a47beee3b8df9a55ed8a3009eb0fe5bd3f (patch)
treed0825d748b79a17782840306e7a56071ed9305d4 /drivers/crypto/qce
parentf0d078dd6c490535ccd7f1694813295dae99814e (diff)
downloadlinux-stable-42f730a47beee3b8df9a55ed8a3009eb0fe5bd3f.tar.gz
linux-stable-42f730a47beee3b8df9a55ed8a3009eb0fe5bd3f.tar.bz2
linux-stable-42f730a47beee3b8df9a55ed8a3009eb0fe5bd3f.zip
crypto: qce - Return unsupported if any three keys are same for DES3 algorithms
Return unsupported if any three keys are same for DES3 algorithms since CE does not support this and the operation causes the engine to hang. Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/qce')
-rw-r--r--drivers/crypto/qce/skcipher.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c
index 12955dcd53dd..8aeb741ca5a3 100644
--- a/drivers/crypto/qce/skcipher.c
+++ b/drivers/crypto/qce/skcipher.c
@@ -221,12 +221,27 @@ static int qce_des3_setkey(struct crypto_skcipher *ablk, const u8 *key,
unsigned int keylen)
{
struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(ablk);
+ u32 _key[6];
int err;
err = verify_skcipher_des3_key(ablk, key);
if (err)
return err;
+ /*
+ * The crypto engine does not support any two keys
+ * being the same for triple des algorithms. The
+ * verify_skcipher_des3_key does not check for all the
+ * below conditions. Return -ENOKEY in case any two keys
+ * are the same. Revisit to see if a fallback cipher
+ * is needed to handle this condition.
+ */
+ memcpy(_key, key, DES3_EDE_KEY_SIZE);
+ if (!((_key[0] ^ _key[2]) | (_key[1] ^ _key[3])) ||
+ !((_key[2] ^ _key[4]) | (_key[3] ^ _key[5])) ||
+ !((_key[0] ^ _key[4]) | (_key[1] ^ _key[5])))
+ return -ENOKEY;
+
ctx->enc_keylen = keylen;
memcpy(ctx->enc_key, key, keylen);
return 0;