aboutsummaryrefslogtreecommitdiffstats
path: root/include
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
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')
-rw-r--r--include/crypto/hash.h104
-rw-r--r--include/crypto/internal/hash.h8
-rw-r--r--include/linux/crypto.h1
3 files changed, 113 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 */
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h
index 917ae57bad4a..32d3a8ed06de 100644
--- a/include/crypto/internal/hash.h
+++ b/include/crypto/internal/hash.h
@@ -40,6 +40,9 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err);
40int crypto_hash_walk_first(struct ahash_request *req, 40int crypto_hash_walk_first(struct ahash_request *req,
41 struct crypto_hash_walk *walk); 41 struct crypto_hash_walk *walk);
42 42
43int crypto_register_shash(struct shash_alg *alg);
44int crypto_unregister_shash(struct shash_alg *alg);
45
43static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) 46static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
44{ 47{
45 return crypto_tfm_ctx(&tfm->base); 48 return crypto_tfm_ctx(&tfm->base);
@@ -74,5 +77,10 @@ static inline int ahash_tfm_in_queue(struct crypto_queue *queue,
74 return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm)); 77 return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm));
75} 78}
76 79
80static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
81{
82 return crypto_tfm_ctx(&tfm->base);
83}
84
77#endif /* _CRYPTO_INTERNAL_HASH_H */ 85#endif /* _CRYPTO_INTERNAL_HASH_H */
78 86
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index ffaaa418cf59..ee95c748695c 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -39,6 +39,7 @@
39#define CRYPTO_ALG_TYPE_HASH 0x00000009 39#define CRYPTO_ALG_TYPE_HASH 0x00000009
40#define CRYPTO_ALG_TYPE_AHASH 0x0000000a 40#define CRYPTO_ALG_TYPE_AHASH 0x0000000a
41#define CRYPTO_ALG_TYPE_RNG 0x0000000c 41#define CRYPTO_ALG_TYPE_RNG 0x0000000c
42#define CRYPTO_ALG_TYPE_SHASH 0x0000000d
42 43
43#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e 44#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
44#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c 45#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c