summaryrefslogtreecommitdiffstats
path: root/include/linux/crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/crypto.h')
-rw-r--r--include/linux/crypto.h105
1 files changed, 71 insertions, 34 deletions
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index b109b50906e7..e2fd24714e00 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -557,6 +557,69 @@ struct crypto_alg {
557 557
558} CRYPTO_MINALIGN_ATTR; 558} CRYPTO_MINALIGN_ATTR;
559 559
560#ifdef CONFIG_CRYPTO_STATS
561void crypto_stats_get(struct crypto_alg *alg);
562void crypto_stats_ablkcipher_encrypt(unsigned int nbytes, int ret, struct crypto_alg *alg);
563void crypto_stats_ablkcipher_decrypt(unsigned int nbytes, int ret, struct crypto_alg *alg);
564void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret);
565void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret);
566void crypto_stats_ahash_update(unsigned int nbytes, int ret, struct crypto_alg *alg);
567void crypto_stats_ahash_final(unsigned int nbytes, int ret, struct crypto_alg *alg);
568void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret, struct crypto_alg *alg);
569void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret, struct crypto_alg *alg);
570void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg);
571void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg);
572void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg);
573void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg);
574void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret);
575void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret);
576void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret);
577void crypto_stats_rng_seed(struct crypto_alg *alg, int ret);
578void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, int ret);
579void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg);
580void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg);
581#else
582static inline void crypto_stats_get(struct crypto_alg *alg)
583{}
584static inline void crypto_stats_ablkcipher_encrypt(unsigned int nbytes, int ret, struct crypto_alg *alg)
585{}
586static inline void crypto_stats_ablkcipher_decrypt(unsigned int nbytes, int ret, struct crypto_alg *alg)
587{}
588static inline void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret)
589{}
590static inline void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret)
591{}
592static inline void crypto_stats_ahash_update(unsigned int nbytes, int ret, struct crypto_alg *alg)
593{}
594static inline void crypto_stats_ahash_final(unsigned int nbytes, int ret, struct crypto_alg *alg)
595{}
596static inline void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret, struct crypto_alg *alg)
597{}
598static inline void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret, struct crypto_alg *alg)
599{}
600static inline void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg)
601{}
602static inline void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg)
603{}
604static inline void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg)
605{}
606static inline void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg)
607{}
608static inline void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret)
609{}
610static inline void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret)
611{}
612static inline void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret)
613{}
614static inline void crypto_stats_rng_seed(struct crypto_alg *alg, int ret)
615{}
616static inline void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, int ret)
617{}
618static inline void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg)
619{}
620static inline void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg)
621{}
622#endif
560/* 623/*
561 * A helper struct for waiting for completion of async crypto ops 624 * A helper struct for waiting for completion of async crypto ops
562 */ 625 */
@@ -975,38 +1038,6 @@ static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
975 return __crypto_ablkcipher_cast(req->base.tfm); 1038 return __crypto_ablkcipher_cast(req->base.tfm);
976} 1039}
977 1040
978static inline void crypto_stat_ablkcipher_encrypt(struct ablkcipher_request *req,
979 int ret)
980{
981#ifdef CONFIG_CRYPTO_STATS
982 struct ablkcipher_tfm *crt =
983 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
984
985 if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
986 atomic64_inc(&crt->base->base.__crt_alg->cipher_err_cnt);
987 } else {
988 atomic64_inc(&crt->base->base.__crt_alg->encrypt_cnt);
989 atomic64_add(req->nbytes, &crt->base->base.__crt_alg->encrypt_tlen);
990 }
991#endif
992}
993
994static inline void crypto_stat_ablkcipher_decrypt(struct ablkcipher_request *req,
995 int ret)
996{
997#ifdef CONFIG_CRYPTO_STATS
998 struct ablkcipher_tfm *crt =
999 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
1000
1001 if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
1002 atomic64_inc(&crt->base->base.__crt_alg->cipher_err_cnt);
1003 } else {
1004 atomic64_inc(&crt->base->base.__crt_alg->decrypt_cnt);
1005 atomic64_add(req->nbytes, &crt->base->base.__crt_alg->decrypt_tlen);
1006 }
1007#endif
1008}
1009
1010/** 1041/**
1011 * crypto_ablkcipher_encrypt() - encrypt plaintext 1042 * crypto_ablkcipher_encrypt() - encrypt plaintext
1012 * @req: reference to the ablkcipher_request handle that holds all information 1043 * @req: reference to the ablkcipher_request handle that holds all information
@@ -1022,10 +1053,13 @@ static inline int crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
1022{ 1053{
1023 struct ablkcipher_tfm *crt = 1054 struct ablkcipher_tfm *crt =
1024 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req)); 1055 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
1056 struct crypto_alg *alg = crt->base->base.__crt_alg;
1057 unsigned int nbytes = req->nbytes;
1025 int ret; 1058 int ret;
1026 1059
1060 crypto_stats_get(alg);
1027 ret = crt->encrypt(req); 1061 ret = crt->encrypt(req);
1028 crypto_stat_ablkcipher_encrypt(req, ret); 1062 crypto_stats_ablkcipher_encrypt(nbytes, ret, alg);
1029 return ret; 1063 return ret;
1030} 1064}
1031 1065
@@ -1044,10 +1078,13 @@ static inline int crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
1044{ 1078{
1045 struct ablkcipher_tfm *crt = 1079 struct ablkcipher_tfm *crt =
1046 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req)); 1080 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
1081 struct crypto_alg *alg = crt->base->base.__crt_alg;
1082 unsigned int nbytes = req->nbytes;
1047 int ret; 1083 int ret;
1048 1084
1085 crypto_stats_get(alg);
1049 ret = crt->decrypt(req); 1086 ret = crt->decrypt(req);
1050 crypto_stat_ablkcipher_decrypt(req, ret); 1087 crypto_stats_ablkcipher_decrypt(nbytes, ret, alg);
1051 return ret; 1088 return ret;
1052} 1089}
1053 1090