xref: /linux/crypto/hash.h (revision 79997eda0d31bc68203c95ecb978773ee6ce7a1f)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Cryptographic API.
4  *
5  * Copyright (c) 2023 Herbert Xu <herbert@gondor.apana.org.au>
6  */
7 #ifndef _LOCAL_CRYPTO_HASH_H
8 #define _LOCAL_CRYPTO_HASH_H
9 
10 #include <crypto/internal/hash.h>
11 #include <linux/cryptouser.h>
12 
13 #include "internal.h"
14 
15 static inline struct crypto_istat_hash *hash_get_stat(
16 	struct hash_alg_common *alg)
17 {
18 #ifdef CONFIG_CRYPTO_STATS
19 	return &alg->stat;
20 #else
21 	return NULL;
22 #endif
23 }
24 
25 static inline int crypto_hash_report_stat(struct sk_buff *skb,
26 					  struct crypto_alg *alg,
27 					  const char *type)
28 {
29 	struct hash_alg_common *halg = __crypto_hash_alg_common(alg);
30 	struct crypto_istat_hash *istat = hash_get_stat(halg);
31 	struct crypto_stat_hash rhash;
32 
33 	memset(&rhash, 0, sizeof(rhash));
34 
35 	strscpy(rhash.type, type, sizeof(rhash.type));
36 
37 	rhash.stat_hash_cnt = atomic64_read(&istat->hash_cnt);
38 	rhash.stat_hash_tlen = atomic64_read(&istat->hash_tlen);
39 	rhash.stat_err_cnt = atomic64_read(&istat->err_cnt);
40 
41 	return nla_put(skb, CRYPTOCFGA_STAT_HASH, sizeof(rhash), &rhash);
42 }
43 
44 extern const struct crypto_type crypto_shash_type;
45 
46 int hash_prepare_alg(struct hash_alg_common *alg);
47 
48 #endif	/* _LOCAL_CRYPTO_HASH_H */
49