diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/hash.h | 154 | ||||
-rw-r--r-- | include/crypto/internal/hash.h | 78 | ||||
-rw-r--r-- | include/linux/crypto.h | 48 |
3 files changed, 276 insertions, 4 deletions
diff --git a/include/crypto/hash.h b/include/crypto/hash.h new file mode 100644 index 000000000000..d12498ec8a4e --- /dev/null +++ b/include/crypto/hash.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | * Hash: Hash algorithms under the crypto API | ||
3 | * | ||
4 | * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the Free | ||
8 | * Software Foundation; either version 2 of the License, or (at your option) | ||
9 | * any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef _CRYPTO_HASH_H | ||
14 | #define _CRYPTO_HASH_H | ||
15 | |||
16 | #include <linux/crypto.h> | ||
17 | |||
18 | struct crypto_ahash { | ||
19 | struct crypto_tfm base; | ||
20 | }; | ||
21 | |||
22 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | ||
23 | { | ||
24 | return (struct crypto_ahash *)tfm; | ||
25 | } | ||
26 | |||
27 | static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, | ||
28 | u32 type, u32 mask) | ||
29 | { | ||
30 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
31 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
32 | type |= CRYPTO_ALG_TYPE_AHASH; | ||
33 | mask |= CRYPTO_ALG_TYPE_AHASH_MASK; | ||
34 | |||
35 | return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
36 | } | ||
37 | |||
38 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | ||
39 | { | ||
40 | return &tfm->base; | ||
41 | } | ||
42 | |||
43 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) | ||
44 | { | ||
45 | crypto_free_tfm(crypto_ahash_tfm(tfm)); | ||
46 | } | ||
47 | |||
48 | static inline unsigned int crypto_ahash_alignmask( | ||
49 | struct crypto_ahash *tfm) | ||
50 | { | ||
51 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); | ||
52 | } | ||
53 | |||
54 | static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm) | ||
55 | { | ||
56 | return &crypto_ahash_tfm(tfm)->crt_ahash; | ||
57 | } | ||
58 | |||
59 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) | ||
60 | { | ||
61 | return crypto_ahash_crt(tfm)->digestsize; | ||
62 | } | ||
63 | |||
64 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) | ||
65 | { | ||
66 | return crypto_tfm_get_flags(crypto_ahash_tfm(tfm)); | ||
67 | } | ||
68 | |||
69 | static inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags) | ||
70 | { | ||
71 | crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags); | ||
72 | } | ||
73 | |||
74 | static inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags) | ||
75 | { | ||
76 | crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags); | ||
77 | } | ||
78 | |||
79 | static inline struct crypto_ahash *crypto_ahash_reqtfm( | ||
80 | struct ahash_request *req) | ||
81 | { | ||
82 | return __crypto_ahash_cast(req->base.tfm); | ||
83 | } | ||
84 | |||
85 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) | ||
86 | { | ||
87 | return crypto_ahash_crt(tfm)->reqsize; | ||
88 | } | ||
89 | |||
90 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, | ||
91 | const u8 *key, unsigned int keylen) | ||
92 | { | ||
93 | struct ahash_tfm *crt = crypto_ahash_crt(tfm); | ||
94 | |||
95 | return crt->setkey(tfm, key, keylen); | ||
96 | } | ||
97 | |||
98 | static inline int crypto_ahash_digest(struct ahash_request *req) | ||
99 | { | ||
100 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | ||
101 | return crt->digest(req); | ||
102 | } | ||
103 | |||
104 | static inline void ahash_request_set_tfm(struct ahash_request *req, | ||
105 | struct crypto_ahash *tfm) | ||
106 | { | ||
107 | req->base.tfm = crypto_ahash_tfm(tfm); | ||
108 | } | ||
109 | |||
110 | static inline struct ahash_request *ahash_request_alloc( | ||
111 | struct crypto_ahash *tfm, gfp_t gfp) | ||
112 | { | ||
113 | struct ahash_request *req; | ||
114 | |||
115 | req = kmalloc(sizeof(struct ahash_request) + | ||
116 | crypto_ahash_reqsize(tfm), gfp); | ||
117 | |||
118 | if (likely(req)) | ||
119 | ahash_request_set_tfm(req, tfm); | ||
120 | |||
121 | return req; | ||
122 | } | ||
123 | |||
124 | static inline void ahash_request_free(struct ahash_request *req) | ||
125 | { | ||
126 | kfree(req); | ||
127 | } | ||
128 | |||
129 | static inline struct ahash_request *ahash_request_cast( | ||
130 | struct crypto_async_request *req) | ||
131 | { | ||
132 | return container_of(req, struct ahash_request, base); | ||
133 | } | ||
134 | |||
135 | static inline void ahash_request_set_callback(struct ahash_request *req, | ||
136 | u32 flags, | ||
137 | crypto_completion_t complete, | ||
138 | void *data) | ||
139 | { | ||
140 | req->base.complete = complete; | ||
141 | req->base.data = data; | ||
142 | req->base.flags = flags; | ||
143 | } | ||
144 | |||
145 | static inline void ahash_request_set_crypt(struct ahash_request *req, | ||
146 | struct scatterlist *src, u8 *result, | ||
147 | unsigned int nbytes) | ||
148 | { | ||
149 | req->src = src; | ||
150 | req->nbytes = nbytes; | ||
151 | req->result = result; | ||
152 | } | ||
153 | |||
154 | #endif /* _CRYPTO_HASH_H */ | ||
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h new file mode 100644 index 000000000000..917ae57bad4a --- /dev/null +++ b/include/crypto/internal/hash.h | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | * Hash algorithms. | ||
3 | * | ||
4 | * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the Free | ||
8 | * Software Foundation; either version 2 of the License, or (at your option) | ||
9 | * any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef _CRYPTO_INTERNAL_HASH_H | ||
14 | #define _CRYPTO_INTERNAL_HASH_H | ||
15 | |||
16 | #include <crypto/algapi.h> | ||
17 | #include <crypto/hash.h> | ||
18 | |||
19 | struct ahash_request; | ||
20 | struct scatterlist; | ||
21 | |||
22 | struct crypto_hash_walk { | ||
23 | char *data; | ||
24 | |||
25 | unsigned int offset; | ||
26 | unsigned int alignmask; | ||
27 | |||
28 | struct page *pg; | ||
29 | unsigned int entrylen; | ||
30 | |||
31 | unsigned int total; | ||
32 | struct scatterlist *sg; | ||
33 | |||
34 | unsigned int flags; | ||
35 | }; | ||
36 | |||
37 | extern const struct crypto_type crypto_ahash_type; | ||
38 | |||
39 | int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err); | ||
40 | int crypto_hash_walk_first(struct ahash_request *req, | ||
41 | struct crypto_hash_walk *walk); | ||
42 | |||
43 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | ||
44 | { | ||
45 | return crypto_tfm_ctx(&tfm->base); | ||
46 | } | ||
47 | |||
48 | static inline struct ahash_alg *crypto_ahash_alg( | ||
49 | struct crypto_ahash *tfm) | ||
50 | { | ||
51 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; | ||
52 | } | ||
53 | |||
54 | static inline int ahash_enqueue_request(struct crypto_queue *queue, | ||
55 | struct ahash_request *request) | ||
56 | { | ||
57 | return crypto_enqueue_request(queue, &request->base); | ||
58 | } | ||
59 | |||
60 | static inline struct ahash_request *ahash_dequeue_request( | ||
61 | struct crypto_queue *queue) | ||
62 | { | ||
63 | return ahash_request_cast(crypto_dequeue_request(queue)); | ||
64 | } | ||
65 | |||
66 | static inline void *ahash_request_ctx(struct ahash_request *req) | ||
67 | { | ||
68 | return req->__ctx; | ||
69 | } | ||
70 | |||
71 | static inline int ahash_tfm_in_queue(struct crypto_queue *queue, | ||
72 | struct crypto_ahash *tfm) | ||
73 | { | ||
74 | return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm)); | ||
75 | } | ||
76 | |||
77 | #endif /* _CRYPTO_INTERNAL_HASH_H */ | ||
78 | |||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 425824bd49f3..c43dc47fdf75 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -30,15 +30,17 @@ | |||
30 | */ | 30 | */ |
31 | #define CRYPTO_ALG_TYPE_MASK 0x0000000f | 31 | #define CRYPTO_ALG_TYPE_MASK 0x0000000f |
32 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 | 32 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 |
33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 | 33 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000002 |
34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 | 34 | #define CRYPTO_ALG_TYPE_AEAD 0x00000003 |
35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 | 35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 |
36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 | 36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 |
37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 | 37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 |
38 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000008 | 38 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000008 |
39 | #define CRYPTO_ALG_TYPE_AEAD 0x00000009 | 39 | #define CRYPTO_ALG_TYPE_HASH 0x00000009 |
40 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a | ||
40 | 41 | ||
41 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | 42 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
43 | #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c | ||
42 | #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c | 44 | #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c |
43 | 45 | ||
44 | #define CRYPTO_ALG_LARVAL 0x00000010 | 46 | #define CRYPTO_ALG_LARVAL 0x00000010 |
@@ -102,6 +104,7 @@ struct crypto_async_request; | |||
102 | struct crypto_aead; | 104 | struct crypto_aead; |
103 | struct crypto_blkcipher; | 105 | struct crypto_blkcipher; |
104 | struct crypto_hash; | 106 | struct crypto_hash; |
107 | struct crypto_ahash; | ||
105 | struct crypto_tfm; | 108 | struct crypto_tfm; |
106 | struct crypto_type; | 109 | struct crypto_type; |
107 | struct aead_givcrypt_request; | 110 | struct aead_givcrypt_request; |
@@ -131,6 +134,16 @@ struct ablkcipher_request { | |||
131 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | 134 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
132 | }; | 135 | }; |
133 | 136 | ||
137 | struct ahash_request { | ||
138 | struct crypto_async_request base; | ||
139 | |||
140 | unsigned int nbytes; | ||
141 | struct scatterlist *src; | ||
142 | u8 *result; | ||
143 | |||
144 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
145 | }; | ||
146 | |||
134 | /** | 147 | /** |
135 | * struct aead_request - AEAD request | 148 | * struct aead_request - AEAD request |
136 | * @base: Common attributes for async crypto requests | 149 | * @base: Common attributes for async crypto requests |
@@ -195,6 +208,17 @@ struct ablkcipher_alg { | |||
195 | unsigned int ivsize; | 208 | unsigned int ivsize; |
196 | }; | 209 | }; |
197 | 210 | ||
211 | struct ahash_alg { | ||
212 | int (*init)(struct ahash_request *req); | ||
213 | int (*update)(struct ahash_request *req); | ||
214 | int (*final)(struct ahash_request *req); | ||
215 | int (*digest)(struct ahash_request *req); | ||
216 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
217 | unsigned int keylen); | ||
218 | |||
219 | unsigned int digestsize; | ||
220 | }; | ||
221 | |||
198 | struct aead_alg { | 222 | struct aead_alg { |
199 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | 223 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, |
200 | unsigned int keylen); | 224 | unsigned int keylen); |
@@ -272,6 +296,7 @@ struct compress_alg { | |||
272 | #define cra_cipher cra_u.cipher | 296 | #define cra_cipher cra_u.cipher |
273 | #define cra_digest cra_u.digest | 297 | #define cra_digest cra_u.digest |
274 | #define cra_hash cra_u.hash | 298 | #define cra_hash cra_u.hash |
299 | #define cra_ahash cra_u.ahash | ||
275 | #define cra_compress cra_u.compress | 300 | #define cra_compress cra_u.compress |
276 | 301 | ||
277 | struct crypto_alg { | 302 | struct crypto_alg { |
@@ -298,6 +323,7 @@ struct crypto_alg { | |||
298 | struct cipher_alg cipher; | 323 | struct cipher_alg cipher; |
299 | struct digest_alg digest; | 324 | struct digest_alg digest; |
300 | struct hash_alg hash; | 325 | struct hash_alg hash; |
326 | struct ahash_alg ahash; | ||
301 | struct compress_alg compress; | 327 | struct compress_alg compress; |
302 | } cra_u; | 328 | } cra_u; |
303 | 329 | ||
@@ -383,6 +409,18 @@ struct hash_tfm { | |||
383 | unsigned int digestsize; | 409 | unsigned int digestsize; |
384 | }; | 410 | }; |
385 | 411 | ||
412 | struct ahash_tfm { | ||
413 | int (*init)(struct ahash_request *req); | ||
414 | int (*update)(struct ahash_request *req); | ||
415 | int (*final)(struct ahash_request *req); | ||
416 | int (*digest)(struct ahash_request *req); | ||
417 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
418 | unsigned int keylen); | ||
419 | |||
420 | unsigned int digestsize; | ||
421 | unsigned int reqsize; | ||
422 | }; | ||
423 | |||
386 | struct compress_tfm { | 424 | struct compress_tfm { |
387 | int (*cot_compress)(struct crypto_tfm *tfm, | 425 | int (*cot_compress)(struct crypto_tfm *tfm, |
388 | const u8 *src, unsigned int slen, | 426 | const u8 *src, unsigned int slen, |
@@ -397,6 +435,7 @@ struct compress_tfm { | |||
397 | #define crt_blkcipher crt_u.blkcipher | 435 | #define crt_blkcipher crt_u.blkcipher |
398 | #define crt_cipher crt_u.cipher | 436 | #define crt_cipher crt_u.cipher |
399 | #define crt_hash crt_u.hash | 437 | #define crt_hash crt_u.hash |
438 | #define crt_ahash crt_u.ahash | ||
400 | #define crt_compress crt_u.compress | 439 | #define crt_compress crt_u.compress |
401 | 440 | ||
402 | struct crypto_tfm { | 441 | struct crypto_tfm { |
@@ -409,6 +448,7 @@ struct crypto_tfm { | |||
409 | struct blkcipher_tfm blkcipher; | 448 | struct blkcipher_tfm blkcipher; |
410 | struct cipher_tfm cipher; | 449 | struct cipher_tfm cipher; |
411 | struct hash_tfm hash; | 450 | struct hash_tfm hash; |
451 | struct ahash_tfm ahash; | ||
412 | struct compress_tfm compress; | 452 | struct compress_tfm compress; |
413 | } crt_u; | 453 | } crt_u; |
414 | 454 | ||