Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 5de8875281e1 ("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>

authored by

Ovidiu Panait and committed by
Herbert Xu
8fd18343 87e02063

+14 -22
+14 -22
drivers/crypto/sahara.c
··· 43 43 #define FLAGS_MODE_MASK 0x000f 44 44 #define FLAGS_ENCRYPT BIT(0) 45 45 #define FLAGS_CBC BIT(1) 46 - #define FLAGS_NEW_KEY BIT(3) 47 46 48 47 #define SAHARA_HDR_BASE 0x00800000 49 48 #define SAHARA_HDR_SKHA_ALG_AES 0 ··· 140 141 }; 141 142 142 143 struct sahara_ctx { 143 - unsigned long flags; 144 - 145 144 /* AES-specific context */ 146 145 int keylen; 147 146 u8 key[AES_KEYSIZE_128]; ··· 444 447 int i, j; 445 448 int idx = 0; 446 449 447 - /* Copy new key if necessary */ 448 - if (ctx->flags & FLAGS_NEW_KEY) { 449 - memcpy(dev->key_base, ctx->key, ctx->keylen); 450 - ctx->flags &= ~FLAGS_NEW_KEY; 450 + memcpy(dev->key_base, ctx->key, ctx->keylen); 451 451 452 - if (dev->flags & FLAGS_CBC) { 453 - dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE; 454 - dev->hw_desc[idx]->p1 = dev->iv_phys_base; 455 - } else { 456 - dev->hw_desc[idx]->len1 = 0; 457 - dev->hw_desc[idx]->p1 = 0; 458 - } 459 - dev->hw_desc[idx]->len2 = ctx->keylen; 460 - dev->hw_desc[idx]->p2 = dev->key_phys_base; 461 - dev->hw_desc[idx]->next = dev->hw_phys_desc[1]; 462 - 463 - dev->hw_desc[idx]->hdr = sahara_aes_key_hdr(dev); 464 - 465 - idx++; 452 + if (dev->flags & FLAGS_CBC) { 453 + dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE; 454 + dev->hw_desc[idx]->p1 = dev->iv_phys_base; 455 + } else { 456 + dev->hw_desc[idx]->len1 = 0; 457 + dev->hw_desc[idx]->p1 = 0; 466 458 } 459 + dev->hw_desc[idx]->len2 = ctx->keylen; 460 + dev->hw_desc[idx]->p2 = dev->key_phys_base; 461 + dev->hw_desc[idx]->next = dev->hw_phys_desc[1]; 462 + dev->hw_desc[idx]->hdr = sahara_aes_key_hdr(dev); 463 + 464 + idx++; 465 + 467 466 468 467 dev->nb_in_sg = sg_nents_for_len(dev->in_sg, dev->total); 469 468 if (dev->nb_in_sg < 0) { ··· 601 608 /* SAHARA only supports 128bit keys */ 602 609 if (keylen == AES_KEYSIZE_128) { 603 610 memcpy(ctx->key, key, keylen); 604 - ctx->flags |= FLAGS_NEW_KEY; 605 611 return 0; 606 612 } 607 613