summaryrefslogtreecommitdiff
path: root/crypto/hash.h
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2023-10-22 01:11:00 -0700
committerHerbert Xu <herbert@gondor.apana.org.au>2023-10-27 18:04:30 +0800
commit2f1f34c1bf7b309b296bc04321a09e6b5dba0673 (patch)
tree1a46a145076582506baecbf1b0c91da451f23c5b /crypto/hash.h
parent85b84327b3f0df32be19e01257fb375972be115c (diff)
crypto: ahash - optimize performance when wrapping shash
The "ahash" API provides access to both CPU-based and hardware offload- based implementations of hash algorithms. Typically the former are implemented as "shash" algorithms under the hood, while the latter are implemented as "ahash" algorithms. The "ahash" API provides access to both. Various kernel subsystems use the ahash API because they want to support hashing hardware offload without using a separate API for it. Yet, the common case is that a crypto accelerator is not actually being used, and ahash is just wrapping a CPU-based shash algorithm. This patch optimizes the ahash API for that common case by eliminating the extra indirect call for each ahash operation on top of shash. It also fixes the double-counting of crypto stats in this scenario (though CONFIG_CRYPTO_STATS should *not* be enabled by anyone interested in performance anyway...), and it eliminates redundant checking of CRYPTO_TFM_NEED_KEY. As a bonus, it also shrinks struct crypto_ahash. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/hash.h')
-rw-r--r--crypto/hash.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/crypto/hash.h b/crypto/hash.h
index de2ee2f4ae30..93f6ba0df263 100644
--- a/crypto/hash.h
+++ b/crypto/hash.h
@@ -12,6 +12,16 @@
#include "internal.h"
+static inline struct crypto_istat_hash *hash_get_stat(
+ struct hash_alg_common *alg)
+{
+#ifdef CONFIG_CRYPTO_STATS
+ return &alg->stat;
+#else
+ return NULL;
+#endif
+}
+
static inline int crypto_hash_report_stat(struct sk_buff *skb,
struct crypto_alg *alg,
const char *type)