diff options
Diffstat (limited to 'include/linux/crypto.h')
-rw-r--r-- | include/linux/crypto.h | 105 |
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 | ||
561 | void crypto_stats_get(struct crypto_alg *alg); | ||
562 | void crypto_stats_ablkcipher_encrypt(unsigned int nbytes, int ret, struct crypto_alg *alg); | ||
563 | void crypto_stats_ablkcipher_decrypt(unsigned int nbytes, int ret, struct crypto_alg *alg); | ||
564 | void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret); | ||
565 | void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret); | ||
566 | void crypto_stats_ahash_update(unsigned int nbytes, int ret, struct crypto_alg *alg); | ||
567 | void crypto_stats_ahash_final(unsigned int nbytes, int ret, struct crypto_alg *alg); | ||
568 | void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret, struct crypto_alg *alg); | ||
569 | void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret, struct crypto_alg *alg); | ||
570 | void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg); | ||
571 | void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg); | ||
572 | void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg); | ||
573 | void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg); | ||
574 | void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret); | ||
575 | void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret); | ||
576 | void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret); | ||
577 | void crypto_stats_rng_seed(struct crypto_alg *alg, int ret); | ||
578 | void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, int ret); | ||
579 | void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg); | ||
580 | void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg); | ||
581 | #else | ||
582 | static inline void crypto_stats_get(struct crypto_alg *alg) | ||
583 | {} | ||
584 | static inline void crypto_stats_ablkcipher_encrypt(unsigned int nbytes, int ret, struct crypto_alg *alg) | ||
585 | {} | ||
586 | static inline void crypto_stats_ablkcipher_decrypt(unsigned int nbytes, int ret, struct crypto_alg *alg) | ||
587 | {} | ||
588 | static inline void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret) | ||
589 | {} | ||
590 | static inline void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, int ret) | ||
591 | {} | ||
592 | static inline void crypto_stats_ahash_update(unsigned int nbytes, int ret, struct crypto_alg *alg) | ||
593 | {} | ||
594 | static inline void crypto_stats_ahash_final(unsigned int nbytes, int ret, struct crypto_alg *alg) | ||
595 | {} | ||
596 | static inline void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret, struct crypto_alg *alg) | ||
597 | {} | ||
598 | static inline void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret, struct crypto_alg *alg) | ||
599 | {} | ||
600 | static inline void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg) | ||
601 | {} | ||
602 | static inline void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg) | ||
603 | {} | ||
604 | static inline void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg) | ||
605 | {} | ||
606 | static inline void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg) | ||
607 | {} | ||
608 | static inline void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret) | ||
609 | {} | ||
610 | static inline void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret) | ||
611 | {} | ||
612 | static inline void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret) | ||
613 | {} | ||
614 | static inline void crypto_stats_rng_seed(struct crypto_alg *alg, int ret) | ||
615 | {} | ||
616 | static inline void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, int ret) | ||
617 | {} | ||
618 | static inline void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret, struct crypto_alg *alg) | ||
619 | {} | ||
620 | static 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 | ||
978 | static 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 | |||
994 | static 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 | ||