diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2016-11-30 08:14:07 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-12-01 08:06:17 -0500 |
commit | 34bc085c839cef85e3e795b1cee29514f69c3081 (patch) | |
tree | ba6239d07314f1b3bbcef5f6a3fcc4f2a078b65b | |
parent | 81126d1a8bc23c72a13c05c4308dc6951afc3b45 (diff) |
crypto: skcipher - Add separate walker for AEAD decryption
The AEAD decrypt interface includes the authentication tag in
req->cryptlen. Therefore we need to exlucde that when doing
a walk over it.
This patch adds separate walker functions for AEAD encryption
and decryption.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
-rw-r--r-- | crypto/skcipher.c | 33 | ||||
-rw-r--r-- | include/crypto/internal/skcipher.h | 4 |
2 files changed, 34 insertions, 3 deletions
diff --git a/crypto/skcipher.c b/crypto/skcipher.c index 5367f817b40e..aca07c643d41 100644 --- a/crypto/skcipher.c +++ b/crypto/skcipher.c | |||
@@ -500,8 +500,8 @@ int skcipher_walk_async(struct skcipher_walk *walk, | |||
500 | } | 500 | } |
501 | EXPORT_SYMBOL_GPL(skcipher_walk_async); | 501 | EXPORT_SYMBOL_GPL(skcipher_walk_async); |
502 | 502 | ||
503 | int skcipher_walk_aead(struct skcipher_walk *walk, struct aead_request *req, | 503 | static int skcipher_walk_aead_common(struct skcipher_walk *walk, |
504 | bool atomic) | 504 | struct aead_request *req, bool atomic) |
505 | { | 505 | { |
506 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); | 506 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); |
507 | int err; | 507 | int err; |
@@ -514,7 +514,6 @@ int skcipher_walk_aead(struct skcipher_walk *walk, struct aead_request *req, | |||
514 | scatterwalk_copychunks(NULL, &walk->in, req->assoclen, 2); | 514 | scatterwalk_copychunks(NULL, &walk->in, req->assoclen, 2); |
515 | scatterwalk_copychunks(NULL, &walk->out, req->assoclen, 2); | 515 | scatterwalk_copychunks(NULL, &walk->out, req->assoclen, 2); |
516 | 516 | ||
517 | walk->total = req->cryptlen; | ||
518 | walk->iv = req->iv; | 517 | walk->iv = req->iv; |
519 | walk->oiv = req->iv; | 518 | walk->oiv = req->iv; |
520 | 519 | ||
@@ -535,8 +534,36 @@ int skcipher_walk_aead(struct skcipher_walk *walk, struct aead_request *req, | |||
535 | 534 | ||
536 | return err; | 535 | return err; |
537 | } | 536 | } |
537 | |||
538 | int skcipher_walk_aead(struct skcipher_walk *walk, struct aead_request *req, | ||
539 | bool atomic) | ||
540 | { | ||
541 | walk->total = req->cryptlen; | ||
542 | |||
543 | return skcipher_walk_aead_common(walk, req, atomic); | ||
544 | } | ||
538 | EXPORT_SYMBOL_GPL(skcipher_walk_aead); | 545 | EXPORT_SYMBOL_GPL(skcipher_walk_aead); |
539 | 546 | ||
547 | int skcipher_walk_aead_encrypt(struct skcipher_walk *walk, | ||
548 | struct aead_request *req, bool atomic) | ||
549 | { | ||
550 | walk->total = req->cryptlen; | ||
551 | |||
552 | return skcipher_walk_aead_common(walk, req, atomic); | ||
553 | } | ||
554 | EXPORT_SYMBOL_GPL(skcipher_walk_aead_encrypt); | ||
555 | |||
556 | int skcipher_walk_aead_decrypt(struct skcipher_walk *walk, | ||
557 | struct aead_request *req, bool atomic) | ||
558 | { | ||
559 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); | ||
560 | |||
561 | walk->total = req->cryptlen - crypto_aead_authsize(tfm); | ||
562 | |||
563 | return skcipher_walk_aead_common(walk, req, atomic); | ||
564 | } | ||
565 | EXPORT_SYMBOL_GPL(skcipher_walk_aead_decrypt); | ||
566 | |||
540 | static unsigned int crypto_skcipher_extsize(struct crypto_alg *alg) | 567 | static unsigned int crypto_skcipher_extsize(struct crypto_alg *alg) |
541 | { | 568 | { |
542 | if (alg->cra_type == &crypto_blkcipher_type) | 569 | if (alg->cra_type == &crypto_blkcipher_type) |
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h index d55041f45899..8735979ed341 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h | |||
@@ -149,6 +149,10 @@ int skcipher_walk_async(struct skcipher_walk *walk, | |||
149 | struct skcipher_request *req); | 149 | struct skcipher_request *req); |
150 | int skcipher_walk_aead(struct skcipher_walk *walk, struct aead_request *req, | 150 | int skcipher_walk_aead(struct skcipher_walk *walk, struct aead_request *req, |
151 | bool atomic); | 151 | bool atomic); |
152 | int skcipher_walk_aead_encrypt(struct skcipher_walk *walk, | ||
153 | struct aead_request *req, bool atomic); | ||
154 | int skcipher_walk_aead_decrypt(struct skcipher_walk *walk, | ||
155 | struct aead_request *req, bool atomic); | ||
152 | void skcipher_walk_complete(struct skcipher_walk *walk, int err); | 156 | void skcipher_walk_complete(struct skcipher_walk *walk, int err); |
153 | 157 | ||
154 | static inline void ablkcipher_request_complete(struct ablkcipher_request *req, | 158 | static inline void ablkcipher_request_complete(struct ablkcipher_request *req, |