Skip to content

Commit

Permalink
crypto: qce - Return unsupported if any three keys are same for DES3 …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
tharagopinath authored and herbertx committed Mar 7, 2021
1 parent f0d078d commit 42f730a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions drivers/crypto/qce/skcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 42f730a

Please sign in to comment.