Skip to content

Commit f2fe115

Browse files
ebiggersherbertx
authored andcommitted
crypto: aead - un-inline encrypt and decrypt functions
crypto_aead_encrypt() and crypto_aead_decrypt() have grown to be more than a single indirect function call. They now also check whether a key has been set, the decryption side checks whether the input is at least as long as the authentication tag length, 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 0726955 commit f2fe115

2 files changed

Lines changed: 38 additions & 32 deletions

File tree

‎crypto/aead.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
8989
}
9090
EXPORT_SYMBOL_GPL(crypto_aead_setauthsize);
9191

92+
int crypto_aead_encrypt(struct aead_request *req)
93+
{
94+
struct crypto_aead *aead = crypto_aead_reqtfm(req);
95+
struct crypto_alg *alg = aead->base.__crt_alg;
96+
unsigned int cryptlen = req->cryptlen;
97+
int ret;
98+
99+
crypto_stats_get(alg);
100+
if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY)
101+
ret = -ENOKEY;
102+
else
103+
ret = crypto_aead_alg(aead)->encrypt(req);
104+
crypto_stats_aead_encrypt(cryptlen, alg, ret);
105+
return ret;
106+
}
107+
EXPORT_SYMBOL_GPL(crypto_aead_encrypt);
108+
109+
int crypto_aead_decrypt(struct aead_request *req)
110+
{
111+
struct crypto_aead *aead = crypto_aead_reqtfm(req);
112+
struct crypto_alg *alg = aead->base.__crt_alg;
113+
unsigned int cryptlen = req->cryptlen;
114+
int ret;
115+
116+
crypto_stats_get(alg);
117+
if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY)
118+
ret = -ENOKEY;
119+
else if (req->cryptlen < crypto_aead_authsize(aead))
120+
ret = -EINVAL;
121+
else
122+
ret = crypto_aead_alg(aead)->decrypt(req);
123+
crypto_stats_aead_decrypt(cryptlen, alg, ret);
124+
return ret;
125+
}
126+
EXPORT_SYMBOL_GPL(crypto_aead_decrypt);
127+
92128
static void crypto_aead_exit_tfm(struct crypto_tfm *tfm)
93129
{
94130
struct crypto_aead *aead = __crypto_aead_cast(tfm);

‎include/crypto/aead.h‎

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -322,21 +322,7 @@ static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req)
322322
*
323323
* Return: 0 if the cipher operation was successful; < 0 if an error occurred
324324
*/
325-
static inline int crypto_aead_encrypt(struct aead_request *req)
326-
{
327-
struct crypto_aead *aead = crypto_aead_reqtfm(req);
328-
struct crypto_alg *alg = aead->base.__crt_alg;
329-
unsigned int cryptlen = req->cryptlen;
330-
int ret;
331-
332-
crypto_stats_get(alg);
333-
if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY)
334-
ret = -ENOKEY;
335-
else
336-
ret = crypto_aead_alg(aead)->encrypt(req);
337-
crypto_stats_aead_encrypt(cryptlen, alg, ret);
338-
return ret;
339-
}
325+
int crypto_aead_encrypt(struct aead_request *req);
340326

341327
/**
342328
* crypto_aead_decrypt() - decrypt ciphertext
@@ -360,23 +346,7 @@ static inline int crypto_aead_encrypt(struct aead_request *req)
360346
* integrity of the ciphertext or the associated data was violated);
361347
* < 0 if an error occurred.
362348
*/
363-
static inline int crypto_aead_decrypt(struct aead_request *req)
364-
{
365-
struct crypto_aead *aead = crypto_aead_reqtfm(req);
366-
struct crypto_alg *alg = aead->base.__crt_alg;
367-
unsigned int cryptlen = req->cryptlen;
368-
int ret;
369-
370-
crypto_stats_get(alg);
371-
if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY)
372-
ret = -ENOKEY;
373-
else if (req->cryptlen < crypto_aead_authsize(aead))
374-
ret = -EINVAL;
375-
else
376-
ret = crypto_aead_alg(aead)->decrypt(req);
377-
crypto_stats_aead_decrypt(cryptlen, alg, ret);
378-
return ret;
379-
}
349+
int crypto_aead_decrypt(struct aead_request *req);
380350

381351
/**
382352
* DOC: Asynchronous AEAD Request Handle

0 commit comments

Comments
 (0)