crypto: user - Implement a generic crypto statistics
This patch implement a generic way to get statistics about all crypto usages. Signed-off-by: Corentin Labbe <clabbe@baylibre.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:

committed by
Herbert Xu

parent
a9cbfe4c78
commit
cac5818c25
@@ -486,6 +486,32 @@ static inline struct crypto_sync_skcipher *crypto_sync_skcipher_reqtfm(
|
||||
return container_of(tfm, struct crypto_sync_skcipher, base);
|
||||
}
|
||||
|
||||
static inline void crypto_stat_skcipher_encrypt(struct skcipher_request *req,
|
||||
int ret, struct crypto_alg *alg)
|
||||
{
|
||||
#ifdef CONFIG_CRYPTO_STATS
|
||||
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
||||
atomic_inc(&alg->cipher_err_cnt);
|
||||
} else {
|
||||
atomic_inc(&alg->encrypt_cnt);
|
||||
atomic64_add(req->cryptlen, &alg->encrypt_tlen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void crypto_stat_skcipher_decrypt(struct skcipher_request *req,
|
||||
int ret, struct crypto_alg *alg)
|
||||
{
|
||||
#ifdef CONFIG_CRYPTO_STATS
|
||||
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
||||
atomic_inc(&alg->cipher_err_cnt);
|
||||
} else {
|
||||
atomic_inc(&alg->decrypt_cnt);
|
||||
atomic64_add(req->cryptlen, &alg->decrypt_tlen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* crypto_skcipher_encrypt() - encrypt plaintext
|
||||
* @req: reference to the skcipher_request handle that holds all information
|
||||
@@ -500,11 +526,14 @@ static inline struct crypto_sync_skcipher *crypto_sync_skcipher_reqtfm(
|
||||
static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
|
||||
{
|
||||
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
|
||||
int ret;
|
||||
|
||||
if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
|
||||
return -ENOKEY;
|
||||
|
||||
return tfm->encrypt(req);
|
||||
ret = -ENOKEY;
|
||||
else
|
||||
ret = tfm->encrypt(req);
|
||||
crypto_stat_skcipher_encrypt(req, ret, tfm->base.__crt_alg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -521,11 +550,14 @@ static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
|
||||
static inline int crypto_skcipher_decrypt(struct skcipher_request *req)
|
||||
{
|
||||
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
|
||||
int ret;
|
||||
|
||||
if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
|
||||
return -ENOKEY;
|
||||
|
||||
return tfm->decrypt(req);
|
||||
ret = -ENOKEY;
|
||||
else
|
||||
ret = tfm->decrypt(req);
|
||||
crypto_stat_skcipher_decrypt(req, ret, tfm->base.__crt_alg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user