Commit 8fd18343 authored by Ovidiu Panait's avatar Ovidiu Panait Committed by Herbert Xu

crypto: sahara - remove FLAGS_NEW_KEY logic

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>
parent 87e02063
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#define FLAGS_MODE_MASK 0x000f #define FLAGS_MODE_MASK 0x000f
#define FLAGS_ENCRYPT BIT(0) #define FLAGS_ENCRYPT BIT(0)
#define FLAGS_CBC BIT(1) #define FLAGS_CBC BIT(1)
#define FLAGS_NEW_KEY BIT(3)
#define SAHARA_HDR_BASE 0x00800000 #define SAHARA_HDR_BASE 0x00800000
#define SAHARA_HDR_SKHA_ALG_AES 0 #define SAHARA_HDR_SKHA_ALG_AES 0
...@@ -141,8 +140,6 @@ struct sahara_hw_link { ...@@ -141,8 +140,6 @@ struct sahara_hw_link {
}; };
struct sahara_ctx { struct sahara_ctx {
unsigned long flags;
/* AES-specific context */ /* AES-specific context */
int keylen; int keylen;
u8 key[AES_KEYSIZE_128]; u8 key[AES_KEYSIZE_128];
...@@ -447,26 +444,22 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev) ...@@ -447,26 +444,22 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev)
int i, j; int i, j;
int idx = 0; int idx = 0;
/* Copy new key if necessary */ memcpy(dev->key_base, ctx->key, ctx->keylen);
if (ctx->flags & FLAGS_NEW_KEY) {
memcpy(dev->key_base, ctx->key, ctx->keylen);
ctx->flags &= ~FLAGS_NEW_KEY;
if (dev->flags & FLAGS_CBC) { if (dev->flags & FLAGS_CBC) {
dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE; dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE;
dev->hw_desc[idx]->p1 = dev->iv_phys_base; dev->hw_desc[idx]->p1 = dev->iv_phys_base;
} else { } else {
dev->hw_desc[idx]->len1 = 0; dev->hw_desc[idx]->len1 = 0;
dev->hw_desc[idx]->p1 = 0; dev->hw_desc[idx]->p1 = 0;
} }
dev->hw_desc[idx]->len2 = ctx->keylen; dev->hw_desc[idx]->len2 = ctx->keylen;
dev->hw_desc[idx]->p2 = dev->key_phys_base; dev->hw_desc[idx]->p2 = dev->key_phys_base;
dev->hw_desc[idx]->next = dev->hw_phys_desc[1]; dev->hw_desc[idx]->next = dev->hw_phys_desc[1];
dev->hw_desc[idx]->hdr = sahara_aes_key_hdr(dev);
dev->hw_desc[idx]->hdr = sahara_aes_key_hdr(dev); idx++;
idx++;
}
dev->nb_in_sg = sg_nents_for_len(dev->in_sg, dev->total); dev->nb_in_sg = sg_nents_for_len(dev->in_sg, dev->total);
if (dev->nb_in_sg < 0) { if (dev->nb_in_sg < 0) {
...@@ -608,7 +601,6 @@ static int sahara_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, ...@@ -608,7 +601,6 @@ static int sahara_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
/* SAHARA only supports 128bit keys */ /* SAHARA only supports 128bit keys */
if (keylen == AES_KEYSIZE_128) { if (keylen == AES_KEYSIZE_128) {
memcpy(ctx->key, key, keylen); memcpy(ctx->key, key, keylen);
ctx->flags |= FLAGS_NEW_KEY;
return 0; return 0;
} }
......
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