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: 5de8875281
("crypto: sahara - Add driver for SAHARA2 accelerator.")
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
8084b788c2
commit
dd31964d9e
|
@ -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];
|
||||
|
@ -447,26 +444,22 @@ 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;
|
||||
memcpy(dev->key_base, ctx->key, ctx->keylen);
|
||||
|
||||
if (dev->flags & FLAGS_CBC) {
|
||||
dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE;
|
||||
dev->hw_desc[idx]->p1 = dev->iv_phys_base;
|
||||
} else {
|
||||
dev->hw_desc[idx]->len1 = 0;
|
||||
dev->hw_desc[idx]->p1 = 0;
|
||||
}
|
||||
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++;
|
||||
if (dev->flags & FLAGS_CBC) {
|
||||
dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE;
|
||||
dev->hw_desc[idx]->p1 = dev->iv_phys_base;
|
||||
} else {
|
||||
dev->hw_desc[idx]->len1 = 0;
|
||||
dev->hw_desc[idx]->p1 = 0;
|
||||
}
|
||||
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_skcipher *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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue