* [PATCH] crypto: skcipher - un-inline encrypt and decrypt functions
@ 2019-06-03 5:45 Eric Biggers
2019-06-03 6:48 ` Ard Biesheuvel
2019-06-13 6:55 ` Herbert Xu
0 siblings, 2 replies; 3+ messages in thread
From: Eric Biggers @ 2019-06-03 5:45 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
crypto_skcipher_encrypt() and crypto_skcipher_decrypt() have grown to be
more than a single indirect function call. They now also check whether
a key has been set, and with CONFIG_CRYPTO_STATS=y they also update the
crypto statistics. That can add up to a lot of bloat at every call
site. Moreover, these always involve a function call anyway, which
greatly limits the benefits of inlining.
So change them to be non-inline.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/skcipher.c | 34 ++++++++++++++++++++++++++++++++++
include/crypto/skcipher.h | 32 ++------------------------------
2 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index 2e66f312e2c4f..2828e27d7fbc0 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -842,6 +842,40 @@ static int skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
return 0;
}
+int crypto_skcipher_encrypt(struct skcipher_request *req)
+{
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
+ struct crypto_alg *alg = tfm->base.__crt_alg;
+ unsigned int cryptlen = req->cryptlen;
+ int ret;
+
+ crypto_stats_get(alg);
+ if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
+ ret = -ENOKEY;
+ else
+ ret = tfm->encrypt(req);
+ crypto_stats_skcipher_encrypt(cryptlen, ret, alg);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(crypto_skcipher_encrypt);
+
+int crypto_skcipher_decrypt(struct skcipher_request *req)
+{
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
+ struct crypto_alg *alg = tfm->base.__crt_alg;
+ unsigned int cryptlen = req->cryptlen;
+ int ret;
+
+ crypto_stats_get(alg);
+ if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
+ ret = -ENOKEY;
+ else
+ ret = tfm->decrypt(req);
+ crypto_stats_skcipher_decrypt(cryptlen, ret, alg);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(crypto_skcipher_decrypt);
+
static void crypto_skcipher_exit_tfm(struct crypto_tfm *tfm)
{
struct crypto_skcipher *skcipher = __crypto_skcipher_cast(tfm);
diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
index e555294ed77fe..98547d1f18c53 100644
--- a/include/crypto/skcipher.h
+++ b/include/crypto/skcipher.h
@@ -484,21 +484,7 @@ static inline struct crypto_sync_skcipher *crypto_sync_skcipher_reqtfm(
*
* Return: 0 if the cipher operation was successful; < 0 if an error occurred
*/
-static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
-{
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- struct crypto_alg *alg = tfm->base.__crt_alg;
- unsigned int cryptlen = req->cryptlen;
- int ret;
-
- crypto_stats_get(alg);
- if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
- ret = -ENOKEY;
- else
- ret = tfm->encrypt(req);
- crypto_stats_skcipher_encrypt(cryptlen, ret, alg);
- return ret;
-}
+int crypto_skcipher_encrypt(struct skcipher_request *req);
/**
* crypto_skcipher_decrypt() - decrypt ciphertext
@@ -511,21 +497,7 @@ static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
*
* Return: 0 if the cipher operation was successful; < 0 if an error occurred
*/
-static inline int crypto_skcipher_decrypt(struct skcipher_request *req)
-{
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- struct crypto_alg *alg = tfm->base.__crt_alg;
- unsigned int cryptlen = req->cryptlen;
- int ret;
-
- crypto_stats_get(alg);
- if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
- ret = -ENOKEY;
- else
- ret = tfm->decrypt(req);
- crypto_stats_skcipher_decrypt(cryptlen, ret, alg);
- return ret;
-}
+int crypto_skcipher_decrypt(struct skcipher_request *req);
/**
* DOC: Symmetric Key Cipher Request Handle
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: skcipher - un-inline encrypt and decrypt functions
2019-06-03 5:45 [PATCH] crypto: skcipher - un-inline encrypt and decrypt functions Eric Biggers
@ 2019-06-03 6:48 ` Ard Biesheuvel
2019-06-13 6:55 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2019-06-03 6:48 UTC (permalink / raw)
To: Eric Biggers; +Cc: open list:HARDWARE RANDOM NUMBER GENERATOR CORE
On Mon, 3 Jun 2019 at 07:46, Eric Biggers <ebiggers@kernel.org> wrote:
>
> From: Eric Biggers <ebiggers@google.com>
>
> crypto_skcipher_encrypt() and crypto_skcipher_decrypt() have grown to be
> more than a single indirect function call. They now also check whether
> a key has been set, and with CONFIG_CRYPTO_STATS=y they also update the
> crypto statistics. That can add up to a lot of bloat at every call
> site. Moreover, these always involve a function call anyway, which
> greatly limits the benefits of inlining.
>
> So change them to be non-inline.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> crypto/skcipher.c | 34 ++++++++++++++++++++++++++++++++++
> include/crypto/skcipher.h | 32 ++------------------------------
> 2 files changed, 36 insertions(+), 30 deletions(-)
>
> diff --git a/crypto/skcipher.c b/crypto/skcipher.c
> index 2e66f312e2c4f..2828e27d7fbc0 100644
> --- a/crypto/skcipher.c
> +++ b/crypto/skcipher.c
> @@ -842,6 +842,40 @@ static int skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
> return 0;
> }
>
> +int crypto_skcipher_encrypt(struct skcipher_request *req)
> +{
> + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
> + struct crypto_alg *alg = tfm->base.__crt_alg;
> + unsigned int cryptlen = req->cryptlen;
> + int ret;
> +
> + crypto_stats_get(alg);
> + if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
> + ret = -ENOKEY;
> + else
> + ret = tfm->encrypt(req);
> + crypto_stats_skcipher_encrypt(cryptlen, ret, alg);
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(crypto_skcipher_encrypt);
> +
> +int crypto_skcipher_decrypt(struct skcipher_request *req)
> +{
> + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
> + struct crypto_alg *alg = tfm->base.__crt_alg;
> + unsigned int cryptlen = req->cryptlen;
> + int ret;
> +
> + crypto_stats_get(alg);
> + if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
> + ret = -ENOKEY;
> + else
> + ret = tfm->decrypt(req);
> + crypto_stats_skcipher_decrypt(cryptlen, ret, alg);
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(crypto_skcipher_decrypt);
> +
> static void crypto_skcipher_exit_tfm(struct crypto_tfm *tfm)
> {
> struct crypto_skcipher *skcipher = __crypto_skcipher_cast(tfm);
> diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
> index e555294ed77fe..98547d1f18c53 100644
> --- a/include/crypto/skcipher.h
> +++ b/include/crypto/skcipher.h
> @@ -484,21 +484,7 @@ static inline struct crypto_sync_skcipher *crypto_sync_skcipher_reqtfm(
> *
> * Return: 0 if the cipher operation was successful; < 0 if an error occurred
> */
> -static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
> -{
> - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
> - struct crypto_alg *alg = tfm->base.__crt_alg;
> - unsigned int cryptlen = req->cryptlen;
> - int ret;
> -
> - crypto_stats_get(alg);
> - if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
> - ret = -ENOKEY;
> - else
> - ret = tfm->encrypt(req);
> - crypto_stats_skcipher_encrypt(cryptlen, ret, alg);
> - return ret;
> -}
> +int crypto_skcipher_encrypt(struct skcipher_request *req);
>
> /**
> * crypto_skcipher_decrypt() - decrypt ciphertext
> @@ -511,21 +497,7 @@ static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
> *
> * Return: 0 if the cipher operation was successful; < 0 if an error occurred
> */
> -static inline int crypto_skcipher_decrypt(struct skcipher_request *req)
> -{
> - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
> - struct crypto_alg *alg = tfm->base.__crt_alg;
> - unsigned int cryptlen = req->cryptlen;
> - int ret;
> -
> - crypto_stats_get(alg);
> - if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
> - ret = -ENOKEY;
> - else
> - ret = tfm->decrypt(req);
> - crypto_stats_skcipher_decrypt(cryptlen, ret, alg);
> - return ret;
> -}
> +int crypto_skcipher_decrypt(struct skcipher_request *req);
>
> /**
> * DOC: Symmetric Key Cipher Request Handle
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: skcipher - un-inline encrypt and decrypt functions
2019-06-03 5:45 [PATCH] crypto: skcipher - un-inline encrypt and decrypt functions Eric Biggers
2019-06-03 6:48 ` Ard Biesheuvel
@ 2019-06-13 6:55 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2019-06-13 6:55 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto
Eric Biggers <ebiggers@kernel.org> wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> crypto_skcipher_encrypt() and crypto_skcipher_decrypt() have grown to be
> more than a single indirect function call. They now also check whether
> a key has been set, and with CONFIG_CRYPTO_STATS=y they also update the
> crypto statistics. That can add up to a lot of bloat at every call
> site. Moreover, these always involve a function call anyway, which
> greatly limits the benefits of inlining.
>
> So change them to be non-inline.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> crypto/skcipher.c | 34 ++++++++++++++++++++++++++++++++++
> include/crypto/skcipher.h | 32 ++------------------------------
> 2 files changed, 36 insertions(+), 30 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-13 16:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 5:45 [PATCH] crypto: skcipher - un-inline encrypt and decrypt functions Eric Biggers
2019-06-03 6:48 ` Ard Biesheuvel
2019-06-13 6:55 ` Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.