diff options
Diffstat (limited to 'include/crypto/hash.h')
-rw-r--r-- | include/crypto/hash.h | 104 |
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 | ||
18 | struct shash_desc { | ||
19 | struct crypto_shash *tfm; | ||
20 | u32 flags; | ||
21 | |||
22 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
23 | }; | ||
24 | |||
25 | struct 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 | |||
18 | struct crypto_ahash { | 43 | struct crypto_ahash { |
19 | struct crypto_tfm base; | 44 | struct crypto_tfm base; |
20 | }; | 45 | }; |
21 | 46 | ||
47 | struct crypto_shash { | ||
48 | struct crypto_tfm base; | ||
49 | }; | ||
50 | |||
22 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | 51 | static 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 | ||
201 | struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, | ||
202 | u32 mask); | ||
203 | |||
204 | static inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm) | ||
205 | { | ||
206 | return &tfm->base; | ||
207 | } | ||
208 | |||
209 | static inline void crypto_free_shash(struct crypto_shash *tfm) | ||
210 | { | ||
211 | crypto_free_tfm(crypto_shash_tfm(tfm)); | ||
212 | } | ||
213 | |||
214 | static inline unsigned int crypto_shash_alignmask( | ||
215 | struct crypto_shash *tfm) | ||
216 | { | ||
217 | return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm)); | ||
218 | } | ||
219 | |||
220 | static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg) | ||
221 | { | ||
222 | return container_of(alg, struct shash_alg, base); | ||
223 | } | ||
224 | |||
225 | static 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 | |||
230 | static inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm) | ||
231 | { | ||
232 | return crypto_shash_alg(tfm)->digestsize; | ||
233 | } | ||
234 | |||
235 | static inline u32 crypto_shash_get_flags(struct crypto_shash *tfm) | ||
236 | { | ||
237 | return crypto_tfm_get_flags(crypto_shash_tfm(tfm)); | ||
238 | } | ||
239 | |||
240 | static 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 | |||
245 | static 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 | |||
250 | static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm) | ||
251 | { | ||
252 | return crypto_shash_alg(tfm)->descsize; | ||
253 | } | ||
254 | |||
255 | static inline void *shash_desc_ctx(struct shash_desc *desc) | ||
256 | { | ||
257 | return desc->__ctx; | ||
258 | } | ||
259 | |||
260 | int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key, | ||
261 | unsigned int keylen); | ||
262 | int crypto_shash_digest(struct shash_desc *desc, const u8 *data, | ||
263 | unsigned int len, u8 *out); | ||
264 | |||
265 | static inline int crypto_shash_init(struct shash_desc *desc) | ||
266 | { | ||
267 | return crypto_shash_alg(desc->tfm)->init(desc); | ||
268 | } | ||
269 | |||
270 | int crypto_shash_update(struct shash_desc *desc, const u8 *data, | ||
271 | unsigned int len); | ||
272 | int crypto_shash_final(struct shash_desc *desc, u8 *out); | ||
273 | int 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 */ |