aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto/hash.h
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-08-31 01:47:27 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2008-12-24 19:01:26 -0500
commit7b5a080b3c46f0cac71c0d0262634c6517d4ee4f (patch)
tree41ba9e7051d1ecd47eb5cd371209229db3202ab6 /include/crypto/hash.h
parent7b0bac64cd5b74d6f1147524c26216de13a501fd (diff)
crypto: hash - Add shash interface
The shash interface replaces the current synchronous hash interface. It improves over hash in two ways. Firstly shash is reentrant, meaning that the same tfm may be used by two threads simultaneously as all hashing state is stored in a local descriptor. The other enhancement is that shash no longer takes scatter list entries. This is because shash is specifically designed for synchronous algorithms and as such scatter lists are unnecessary. All existing hash users will be converted to shash once the algorithms have been completely converted. There is also a new finup function that combines update with final. This will be extended to ahash once the algorithm conversion is done. This is also the first time that an algorithm type has their own registration function. Existing algorithm types will be converted to this way in due course. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto/hash.h')
-rw-r--r--include/crypto/hash.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index ee48ef8fb2ea..f9b51d408953 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -15,10 +15,39 @@
15 15
16#include <linux/crypto.h> 16#include <linux/crypto.h>
17 17
18struct shash_desc {
19 struct crypto_shash *tfm;
20 u32 flags;
21
22 void *__ctx[] CRYPTO_MINALIGN_ATTR;
23};
24
25struct shash_alg {
26 int (*init)(struct shash_desc *desc);
27 int (*update)(struct shash_desc *desc, const u8 *data,
28 unsigned int len);
29 int (*final)(struct shash_desc *desc, u8 *out);
30 int (*finup)(struct shash_desc *desc, const u8 *data,
31 unsigned int len, u8 *out);
32 int (*digest)(struct shash_desc *desc, const u8 *data,
33 unsigned int len, u8 *out);
34 int (*setkey)(struct crypto_shash *tfm, const u8 *key,
35 unsigned int keylen);
36
37 unsigned int descsize;
38 unsigned int digestsize;
39
40 struct crypto_alg base;
41};
42
18struct crypto_ahash { 43struct crypto_ahash {
19 struct crypto_tfm base; 44 struct crypto_tfm base;
20}; 45};
21 46
47struct crypto_shash {
48 struct crypto_tfm base;
49};
50
22static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) 51static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm)
23{ 52{
24 return (struct crypto_ahash *)tfm; 53 return (struct crypto_ahash *)tfm;
@@ -169,4 +198,79 @@ static inline void ahash_request_set_crypt(struct ahash_request *req,
169 req->result = result; 198 req->result = result;
170} 199}
171 200
201struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type,
202 u32 mask);
203
204static inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm)
205{
206 return &tfm->base;
207}
208
209static inline void crypto_free_shash(struct crypto_shash *tfm)
210{
211 crypto_free_tfm(crypto_shash_tfm(tfm));
212}
213
214static inline unsigned int crypto_shash_alignmask(
215 struct crypto_shash *tfm)
216{
217 return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm));
218}
219
220static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg)
221{
222 return container_of(alg, struct shash_alg, base);
223}
224
225static inline struct shash_alg *crypto_shash_alg(struct crypto_shash *tfm)
226{
227 return __crypto_shash_alg(crypto_shash_tfm(tfm)->__crt_alg);
228}
229
230static inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm)
231{
232 return crypto_shash_alg(tfm)->digestsize;
233}
234
235static inline u32 crypto_shash_get_flags(struct crypto_shash *tfm)
236{
237 return crypto_tfm_get_flags(crypto_shash_tfm(tfm));
238}
239
240static inline void crypto_shash_set_flags(struct crypto_shash *tfm, u32 flags)
241{
242 crypto_tfm_set_flags(crypto_shash_tfm(tfm), flags);
243}
244
245static inline void crypto_shash_clear_flags(struct crypto_shash *tfm, u32 flags)
246{
247 crypto_tfm_clear_flags(crypto_shash_tfm(tfm), flags);
248}
249
250static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm)
251{
252 return crypto_shash_alg(tfm)->descsize;
253}
254
255static inline void *shash_desc_ctx(struct shash_desc *desc)
256{
257 return desc->__ctx;
258}
259
260int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key,
261 unsigned int keylen);
262int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
263 unsigned int len, u8 *out);
264
265static inline int crypto_shash_init(struct shash_desc *desc)
266{
267 return crypto_shash_alg(desc->tfm)->init(desc);
268}
269
270int crypto_shash_update(struct shash_desc *desc, const u8 *data,
271 unsigned int len);
272int crypto_shash_final(struct shash_desc *desc, u8 *out);
273int crypto_shash_finup(struct shash_desc *desc, const u8 *data,
274 unsigned int len, u8 *out);
275
172#endif /* _CRYPTO_HASH_H */ 276#endif /* _CRYPTO_HASH_H */