diff mbox

[1/3] crypto: skcipher - return the correct request to the user

Message ID 20160127171355.32579.12218.stgit@tstruk-mobl1 (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show

Commit Message

Tadeusz Struk Jan. 27, 2016, 5:13 p.m. UTC
A user of the skcipher api may have some private context associated with
a request, like for instance the algif_skcipher does, so the api needs to
return the original skcipher_request in the callback instead of the
ablkcipher_request subtype.

Cc: <stable@vger.kernel.org> # 4.4.x-
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
---
 crypto/skcipher.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Herbert Xu Jan. 28, 2016, 4:53 a.m. UTC | #1
On Wed, Jan 27, 2016 at 09:13:56AM -0800, Tadeusz Struk wrote:
>
> diff --git a/crypto/skcipher.c b/crypto/skcipher.c
> index 69230e9..a9d54c0 100644
> --- a/crypto/skcipher.c
> +++ b/crypto/skcipher.c
> @@ -142,6 +142,15 @@ static int skcipher_setkey_ablkcipher(struct crypto_skcipher *tfm,
>  	return err;
>  }
>  
> +static void skcipher_complete(struct crypto_async_request *req_base, int err)
> +{
> +	void *subreq = ablkcipher_request_cast(req_base);
> +	struct skcipher_request *req =
> +			container_of(subreq, struct skcipher_request, __ctx);
> +
> +	req->base.complete(&req->base, err);
> +}
> +
>  static int skcipher_crypt_ablkcipher(struct skcipher_request *req,
>  				     int (*crypt)(struct ablkcipher_request *))
>  {
> @@ -151,7 +160,7 @@ static int skcipher_crypt_ablkcipher(struct skcipher_request *req,
>  
>  	ablkcipher_request_set_tfm(subreq, *ctx);
>  	ablkcipher_request_set_callback(subreq, skcipher_request_flags(req),
> -					req->base.complete, req->base.data);
> +					skcipher_complete, req->base.data);
>  	ablkcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
>  				     req->iv);

Rather than playing with lots of casts, just set the ablkcipher
callback data to req and be done with it.

Thanks,
diff mbox

Patch

diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index 69230e9..a9d54c0 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -142,6 +142,15 @@  static int skcipher_setkey_ablkcipher(struct crypto_skcipher *tfm,
 	return err;
 }
 
+static void skcipher_complete(struct crypto_async_request *req_base, int err)
+{
+	void *subreq = ablkcipher_request_cast(req_base);
+	struct skcipher_request *req =
+			container_of(subreq, struct skcipher_request, __ctx);
+
+	req->base.complete(&req->base, err);
+}
+
 static int skcipher_crypt_ablkcipher(struct skcipher_request *req,
 				     int (*crypt)(struct ablkcipher_request *))
 {
@@ -151,7 +160,7 @@  static int skcipher_crypt_ablkcipher(struct skcipher_request *req,
 
 	ablkcipher_request_set_tfm(subreq, *ctx);
 	ablkcipher_request_set_callback(subreq, skcipher_request_flags(req),
-					req->base.complete, req->base.data);
+					skcipher_complete, req->base.data);
 	ablkcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
 				     req->iv);