Skip to content

Commit 81bcbb1

Browse files
ebiggersherbertx
authored andcommitted
crypto: skcipher - un-inline encrypt and decrypt functions
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> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent f2fe115 commit 81bcbb1

2 files changed

Lines changed: 36 additions & 30 deletions

File tree

‎crypto/skcipher.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,40 @@ static int skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
842842
return 0;
843843
}
844844

845+
int crypto_skcipher_encrypt(struct skcipher_request *req)
846+
{
847+
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
848+
struct crypto_alg *alg = tfm->base.__crt_alg;
849+
unsigned int cryptlen = req->cryptlen;
850+
int ret;
851+
852+
crypto_stats_get(alg);
853+
if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
854+
ret = -ENOKEY;
855+
else
856+
ret = tfm->encrypt(req);
857+
crypto_stats_skcipher_encrypt(cryptlen, ret, alg);
858+
return ret;
859+
}
860+
EXPORT_SYMBOL_GPL(crypto_skcipher_encrypt);
861+
862+
int crypto_skcipher_decrypt(struct skcipher_request *req)
863+
{
864+
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
865+
struct crypto_alg *alg = tfm->base.__crt_alg;
866+
unsigned int cryptlen = req->cryptlen;
867+
int ret;
868+
869+
crypto_stats_get(alg);
870+
if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
871+
ret = -ENOKEY;
872+
else
873+
ret = tfm->decrypt(req);
874+
crypto_stats_skcipher_decrypt(cryptlen, ret, alg);
875+
return ret;
876+
}
877+
EXPORT_SYMBOL_GPL(crypto_skcipher_decrypt);
878+
845879
static void crypto_skcipher_exit_tfm(struct crypto_tfm *tfm)
846880
{
847881
struct crypto_skcipher *skcipher = __crypto_skcipher_cast(tfm);

‎include/crypto/skcipher.h‎

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -484,21 +484,7 @@ static inline struct crypto_sync_skcipher *crypto_sync_skcipher_reqtfm(
484484
*
485485
* Return: 0 if the cipher operation was successful; < 0 if an error occurred
486486
*/
487-
static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
488-
{
489-
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
490-
struct crypto_alg *alg = tfm->base.__crt_alg;
491-
unsigned int cryptlen = req->cryptlen;
492-
int ret;
493-
494-
crypto_stats_get(alg);
495-
if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
496-
ret = -ENOKEY;
497-
else
498-
ret = tfm->encrypt(req);
499-
crypto_stats_skcipher_encrypt(cryptlen, ret, alg);
500-
return ret;
501-
}
487+
int crypto_skcipher_encrypt(struct skcipher_request *req);
502488

503489
/**
504490
* crypto_skcipher_decrypt() - decrypt ciphertext
@@ -511,21 +497,7 @@ static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
511497
*
512498
* Return: 0 if the cipher operation was successful; < 0 if an error occurred
513499
*/
514-
static inline int crypto_skcipher_decrypt(struct skcipher_request *req)
515-
{
516-
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
517-
struct crypto_alg *alg = tfm->base.__crt_alg;
518-
unsigned int cryptlen = req->cryptlen;
519-
int ret;
520-
521-
crypto_stats_get(alg);
522-
if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
523-
ret = -ENOKEY;
524-
else
525-
ret = tfm->decrypt(req);
526-
crypto_stats_skcipher_decrypt(cryptlen, ret, alg);
527-
return ret;
528-
}
500+
int crypto_skcipher_decrypt(struct skcipher_request *req);
529501

530502
/**
531503
* DOC: Symmetric Key Cipher Request Handle

0 commit comments

Comments
 (0)