Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit beb815a0 authored by Ovidiu Panait's avatar Ovidiu Panait Committed by Greg Kroah-Hartman
Browse files

crypto: sahara - remove FLAGS_NEW_KEY logic



[ Upstream commit 8fd183435728b139248a77978ea3732039341779 ]

Remove the FLAGS_NEW_KEY logic as it has the following issues:
- the wrong key may end up being used when there are multiple data streams:
       t1            t2
    setkey()
    encrypt()
                   setkey()
                   encrypt()

    encrypt() <--- key from t2 is used
- switching between encryption and decryption with the same key is not
  possible, as the hdr flags are only updated when a new setkey() is
  performed

With this change, the key is always sent along with the cryptdata when
performing encryption/decryption operations.

Fixes: 5de88752 ("crypto: sahara - Add driver for SAHARA2 accelerator.")
Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 4c10928e
Loading
Loading
Loading
Loading
+13 −21
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@
#define FLAGS_MODE_MASK		0x000f
#define FLAGS_ENCRYPT		BIT(0)
#define FLAGS_CBC		BIT(1)
#define FLAGS_NEW_KEY		BIT(3)

#define SAHARA_HDR_BASE			0x00800000
#define SAHARA_HDR_SKHA_ALG_AES	0
@@ -141,8 +140,6 @@ struct sahara_hw_link {
};

struct sahara_ctx {
	unsigned long flags;

	/* AES-specific context */
	int keylen;
	u8 key[AES_KEYSIZE_128];
@@ -446,10 +443,7 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev)
	int i, j;
	int idx = 0;

	/* Copy new key if necessary */
	if (ctx->flags & FLAGS_NEW_KEY) {
	memcpy(dev->key_base, ctx->key, ctx->keylen);
		ctx->flags &= ~FLAGS_NEW_KEY;

	if (dev->flags & FLAGS_CBC) {
		dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE;
@@ -461,11 +455,10 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev)
	dev->hw_desc[idx]->len2 = ctx->keylen;
	dev->hw_desc[idx]->p2 = dev->key_phys_base;
	dev->hw_desc[idx]->next = dev->hw_phys_desc[1];

	dev->hw_desc[idx]->hdr = sahara_aes_key_hdr(dev);

	idx++;
	}


	dev->nb_in_sg = sg_nents_for_len(dev->in_sg, dev->total);
	if (dev->nb_in_sg < 0) {
@@ -608,7 +601,6 @@ static int sahara_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
	/* SAHARA only supports 128bit keys */
	if (keylen == AES_KEYSIZE_128) {
		memcpy(ctx->key, key, keylen);
		ctx->flags |= FLAGS_NEW_KEY;
		return 0;
	}