Re: [v2 PATCH 6/16] crypto: cryptd - Add support for skcipher

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Nov 13, 2016 at 07:45:37PM +0800, Herbert Xu wrote:
> +static void cryptd_skcipher_encrypt(struct crypto_async_request *base,
> +				    int err)
> +{
> +	struct skcipher_request *req = skcipher_request_cast(base);
> +	struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
> +	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
> +	struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
> +	struct crypto_skcipher *child = ctx->child;
> +	SKCIPHER_REQUEST_ON_STACK(subreq, child);
> +
> +	if (unlikely(err == -EINPROGRESS))
> +		goto out;
> +
> +	skcipher_request_set_tfm(subreq, child);
> +	skcipher_request_set_callback(subreq, CRYPTO_TFM_REQ_MAY_SLEEP,
> +				      NULL, NULL);
> +	skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
> +				   req->iv);
> +
> +	err = crypto_skcipher_encrypt(subreq);
> +	skcipher_request_zero(subreq);
> +
> +	req->base.complete = rctx->complete;
> +
> +out:
> +	cryptd_skcipher_complete(req, err);
> +}
> +
> +static void cryptd_skcipher_decrypt(struct crypto_async_request *base,
> +				    int err)
> +{
> +	struct skcipher_request *req = skcipher_request_cast(base);
> +	struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
> +	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
> +	struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
> +	struct crypto_skcipher *child = ctx->child;
> +	SKCIPHER_REQUEST_ON_STACK(subreq, child);
> +
> +	if (unlikely(err == -EINPROGRESS))
> +		goto out;
> +
> +	skcipher_request_set_tfm(subreq, child);
> +	skcipher_request_set_callback(subreq, CRYPTO_TFM_REQ_MAY_SLEEP,
> +				      NULL, NULL);
> +	skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
> +				   req->iv);
> +
> +	err = crypto_skcipher_decrypt(subreq);
> +	skcipher_request_zero(subreq);
> +
> +	req->base.complete = rctx->complete;
> +
> +out:
> +	cryptd_skcipher_complete(req, err);
> +}

cryptd_skcipher_encrypt() and cryptd_skcipher_decrypt() are identical except for
whether crypto_skcipher_encrypt() or crypto_skcipher_decrypt() is used.  I
suggest having them wrap a function cryptd_skcipher_crypt() that takes in a
function pointer to crypto_skcipher_encrypt or crypto_skcipher_decrypt.
Alternatively a bool would be okay too.

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



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux