Revert "crypto: remove CONFIG_CRYPTO_STATS"
[linux-2.6-microblaze.git] / include / crypto / akcipher.h
index 18a10ca..31c111b 100644 (file)
@@ -54,6 +54,26 @@ struct crypto_akcipher {
        struct crypto_tfm base;
 };
 
+/*
+ * struct crypto_istat_akcipher - statistics for akcipher algorithm
+ * @encrypt_cnt:       number of encrypt requests
+ * @encrypt_tlen:      total data size handled by encrypt requests
+ * @decrypt_cnt:       number of decrypt requests
+ * @decrypt_tlen:      total data size handled by decrypt requests
+ * @verify_cnt:                number of verify operation
+ * @sign_cnt:          number of sign requests
+ * @err_cnt:           number of error for akcipher requests
+ */
+struct crypto_istat_akcipher {
+       atomic64_t encrypt_cnt;
+       atomic64_t encrypt_tlen;
+       atomic64_t decrypt_cnt;
+       atomic64_t decrypt_tlen;
+       atomic64_t verify_cnt;
+       atomic64_t sign_cnt;
+       atomic64_t err_cnt;
+};
+
 /**
  * struct akcipher_alg - generic public key algorithm
  *
@@ -90,6 +110,7 @@ struct crypto_akcipher {
  * @exit:      Deinitialize the cryptographic transformation object. This is a
  *             counterpart to @init, used to remove various changes set in
  *             @init.
+ * @stat:      Statistics for akcipher algorithm
  *
  * @base:      Common crypto API algorithm data structure
  */
@@ -106,6 +127,10 @@ struct akcipher_alg {
        int (*init)(struct crypto_akcipher *tfm);
        void (*exit)(struct crypto_akcipher *tfm);
 
+#ifdef CONFIG_CRYPTO_STATS
+       struct crypto_istat_akcipher stat;
+#endif
+
        struct crypto_alg base;
 };
 
@@ -277,6 +302,27 @@ static inline unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)
        return alg->max_size(tfm);
 }
 
+static inline struct crypto_istat_akcipher *akcipher_get_stat(
+       struct akcipher_alg *alg)
+{
+#ifdef CONFIG_CRYPTO_STATS
+       return &alg->stat;
+#else
+       return NULL;
+#endif
+}
+
+static inline int crypto_akcipher_errstat(struct akcipher_alg *alg, int err)
+{
+       if (!IS_ENABLED(CONFIG_CRYPTO_STATS))
+               return err;
+
+       if (err && err != -EINPROGRESS && err != -EBUSY)
+               atomic64_inc(&akcipher_get_stat(alg)->err_cnt);
+
+       return err;
+}
+
 /**
  * crypto_akcipher_encrypt() - Invoke public key encrypt operation
  *
@@ -290,8 +336,16 @@ static inline unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)
 static inline int crypto_akcipher_encrypt(struct akcipher_request *req)
 {
        struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
+       struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
 
-       return crypto_akcipher_alg(tfm)->encrypt(req);
+       if (IS_ENABLED(CONFIG_CRYPTO_STATS)) {
+               struct crypto_istat_akcipher *istat = akcipher_get_stat(alg);
+
+               atomic64_inc(&istat->encrypt_cnt);
+               atomic64_add(req->src_len, &istat->encrypt_tlen);
+       }
+
+       return crypto_akcipher_errstat(alg, alg->encrypt(req));
 }
 
 /**
@@ -307,8 +361,16 @@ static inline int crypto_akcipher_encrypt(struct akcipher_request *req)
 static inline int crypto_akcipher_decrypt(struct akcipher_request *req)
 {
        struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
+       struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
 
-       return crypto_akcipher_alg(tfm)->decrypt(req);
+       if (IS_ENABLED(CONFIG_CRYPTO_STATS)) {
+               struct crypto_istat_akcipher *istat = akcipher_get_stat(alg);
+
+               atomic64_inc(&istat->decrypt_cnt);
+               atomic64_add(req->src_len, &istat->decrypt_tlen);
+       }
+
+       return crypto_akcipher_errstat(alg, alg->decrypt(req));
 }
 
 /**
@@ -360,8 +422,12 @@ int crypto_akcipher_sync_decrypt(struct crypto_akcipher *tfm,
 static inline int crypto_akcipher_sign(struct akcipher_request *req)
 {
        struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
+       struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
 
-       return crypto_akcipher_alg(tfm)->sign(req);
+       if (IS_ENABLED(CONFIG_CRYPTO_STATS))
+               atomic64_inc(&akcipher_get_stat(alg)->sign_cnt);
+
+       return crypto_akcipher_errstat(alg, alg->sign(req));
 }
 
 /**
@@ -381,8 +447,12 @@ static inline int crypto_akcipher_sign(struct akcipher_request *req)
 static inline int crypto_akcipher_verify(struct akcipher_request *req)
 {
        struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
+       struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
+
+       if (IS_ENABLED(CONFIG_CRYPTO_STATS))
+               atomic64_inc(&akcipher_get_stat(alg)->verify_cnt);
 
-       return crypto_akcipher_alg(tfm)->verify(req);
+       return crypto_akcipher_errstat(alg, alg->verify(req));
 }
 
 /**