diff options
author | Steffen Trumtrar <s.trumtrar@pengutronix.de> | 2015-04-07 11:13:42 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-04-08 10:20:06 -0400 |
commit | 1711045fb11b4aa9afda066ce5fe68b2345d52c5 (patch) | |
tree | 4d115fdff3d9753606e553c2ee2340018f758c14 /drivers/crypto/sahara.c | |
parent | ddacc621f6597d503ed6a06e2beb1ed21df759f6 (diff) |
crypto: sahara - fix AES descriptor create
The AES implementation still assumes, that the hw_desc[0] has a valid
key as long as no new key needs to be set; consequentialy it always
sets the AES key header for the first descriptor and puts data into
the second one (hw_desc[1]).
Change this to only update the key in the hardware, when a new key is
to be set and use the first descriptor for data otherwise.
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/sahara.c')
-rw-r--r-- | drivers/crypto/sahara.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c index 052562dcd302..6be377f6b9e7 100644 --- a/drivers/crypto/sahara.c +++ b/drivers/crypto/sahara.c | |||
@@ -479,6 +479,7 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev) | |||
479 | struct scatterlist *sg; | 479 | struct scatterlist *sg; |
480 | int ret; | 480 | int ret; |
481 | int i, j; | 481 | int i, j; |
482 | int idx = 0; | ||
482 | 483 | ||
483 | /* Copy new key if necessary */ | 484 | /* Copy new key if necessary */ |
484 | if (ctx->flags & FLAGS_NEW_KEY) { | 485 | if (ctx->flags & FLAGS_NEW_KEY) { |
@@ -486,17 +487,20 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev) | |||
486 | ctx->flags &= ~FLAGS_NEW_KEY; | 487 | ctx->flags &= ~FLAGS_NEW_KEY; |
487 | 488 | ||
488 | if (dev->flags & FLAGS_CBC) { | 489 | if (dev->flags & FLAGS_CBC) { |
489 | dev->hw_desc[0]->len1 = AES_BLOCK_SIZE; | 490 | dev->hw_desc[idx]->len1 = AES_BLOCK_SIZE; |
490 | dev->hw_desc[0]->p1 = dev->iv_phys_base; | 491 | dev->hw_desc[idx]->p1 = dev->iv_phys_base; |
491 | } else { | 492 | } else { |
492 | dev->hw_desc[0]->len1 = 0; | 493 | dev->hw_desc[idx]->len1 = 0; |
493 | dev->hw_desc[0]->p1 = 0; | 494 | dev->hw_desc[idx]->p1 = 0; |
494 | } | 495 | } |
495 | dev->hw_desc[0]->len2 = ctx->keylen; | 496 | dev->hw_desc[idx]->len2 = ctx->keylen; |
496 | dev->hw_desc[0]->p2 = dev->key_phys_base; | 497 | dev->hw_desc[idx]->p2 = dev->key_phys_base; |
497 | dev->hw_desc[0]->next = dev->hw_phys_desc[1]; | 498 | dev->hw_desc[idx]->next = dev->hw_phys_desc[1]; |
499 | |||
500 | dev->hw_desc[idx]->hdr = sahara_aes_key_hdr(dev); | ||
501 | |||
502 | idx++; | ||
498 | } | 503 | } |
499 | dev->hw_desc[0]->hdr = sahara_aes_key_hdr(dev); | ||
500 | 504 | ||
501 | dev->nb_in_sg = sahara_sg_length(dev->in_sg, dev->total); | 505 | dev->nb_in_sg = sahara_sg_length(dev->in_sg, dev->total); |
502 | dev->nb_out_sg = sahara_sg_length(dev->out_sg, dev->total); | 506 | dev->nb_out_sg = sahara_sg_length(dev->out_sg, dev->total); |
@@ -520,7 +524,7 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev) | |||
520 | } | 524 | } |
521 | 525 | ||
522 | /* Create input links */ | 526 | /* Create input links */ |
523 | dev->hw_desc[1]->p1 = dev->hw_phys_link[0]; | 527 | dev->hw_desc[idx]->p1 = dev->hw_phys_link[0]; |
524 | sg = dev->in_sg; | 528 | sg = dev->in_sg; |
525 | for (i = 0; i < dev->nb_in_sg; i++) { | 529 | for (i = 0; i < dev->nb_in_sg; i++) { |
526 | dev->hw_link[i]->len = sg->length; | 530 | dev->hw_link[i]->len = sg->length; |
@@ -534,7 +538,7 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev) | |||
534 | } | 538 | } |
535 | 539 | ||
536 | /* Create output links */ | 540 | /* Create output links */ |
537 | dev->hw_desc[1]->p2 = dev->hw_phys_link[i]; | 541 | dev->hw_desc[idx]->p2 = dev->hw_phys_link[i]; |
538 | sg = dev->out_sg; | 542 | sg = dev->out_sg; |
539 | for (j = i; j < dev->nb_out_sg + i; j++) { | 543 | for (j = i; j < dev->nb_out_sg + i; j++) { |
540 | dev->hw_link[j]->len = sg->length; | 544 | dev->hw_link[j]->len = sg->length; |
@@ -548,10 +552,10 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev) | |||
548 | } | 552 | } |
549 | 553 | ||
550 | /* Fill remaining fields of hw_desc[1] */ | 554 | /* Fill remaining fields of hw_desc[1] */ |
551 | dev->hw_desc[1]->hdr = sahara_aes_data_link_hdr(dev); | 555 | dev->hw_desc[idx]->hdr = sahara_aes_data_link_hdr(dev); |
552 | dev->hw_desc[1]->len1 = dev->total; | 556 | dev->hw_desc[idx]->len1 = dev->total; |
553 | dev->hw_desc[1]->len2 = dev->total; | 557 | dev->hw_desc[idx]->len2 = dev->total; |
554 | dev->hw_desc[1]->next = 0; | 558 | dev->hw_desc[idx]->next = 0; |
555 | 559 | ||
556 | sahara_dump_descriptors(dev); | 560 | sahara_dump_descriptors(dev); |
557 | sahara_dump_links(dev); | 561 | sahara_dump_links(dev); |