diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/hash.h | 109 | ||||
-rw-r--r-- | include/crypto/internal/hash.h | 11 | ||||
-rw-r--r-- | include/linux/crypto.h | 29 |
3 files changed, 89 insertions, 60 deletions
diff --git a/include/crypto/hash.h b/include/crypto/hash.h index fcc02d978231..262861d8f0cb 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h | |||
@@ -15,6 +15,39 @@ | |||
15 | 15 | ||
16 | #include <linux/crypto.h> | 16 | #include <linux/crypto.h> |
17 | 17 | ||
18 | struct crypto_ahash; | ||
19 | |||
20 | struct hash_alg_common { | ||
21 | unsigned int digestsize; | ||
22 | unsigned int statesize; | ||
23 | |||
24 | struct crypto_alg base; | ||
25 | }; | ||
26 | |||
27 | struct ahash_request { | ||
28 | struct crypto_async_request base; | ||
29 | |||
30 | unsigned int nbytes; | ||
31 | struct scatterlist *src; | ||
32 | u8 *result; | ||
33 | |||
34 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
35 | }; | ||
36 | |||
37 | struct ahash_alg { | ||
38 | int (*init)(struct ahash_request *req); | ||
39 | int (*update)(struct ahash_request *req); | ||
40 | int (*final)(struct ahash_request *req); | ||
41 | int (*finup)(struct ahash_request *req); | ||
42 | int (*digest)(struct ahash_request *req); | ||
43 | int (*export)(struct ahash_request *req, void *out); | ||
44 | int (*import)(struct ahash_request *req, const void *in); | ||
45 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
46 | unsigned int keylen); | ||
47 | |||
48 | struct hash_alg_common halg; | ||
49 | }; | ||
50 | |||
18 | struct shash_desc { | 51 | struct shash_desc { |
19 | struct crypto_shash *tfm; | 52 | struct crypto_shash *tfm; |
20 | u32 flags; | 53 | u32 flags; |
@@ -37,6 +70,8 @@ struct shash_alg { | |||
37 | unsigned int keylen); | 70 | unsigned int keylen); |
38 | 71 | ||
39 | unsigned int descsize; | 72 | unsigned int descsize; |
73 | |||
74 | /* These fields must match hash_alg_common. */ | ||
40 | unsigned int digestsize; | 75 | unsigned int digestsize; |
41 | unsigned int statesize; | 76 | unsigned int statesize; |
42 | 77 | ||
@@ -44,6 +79,18 @@ struct shash_alg { | |||
44 | }; | 79 | }; |
45 | 80 | ||
46 | struct crypto_ahash { | 81 | struct crypto_ahash { |
82 | int (*init)(struct ahash_request *req); | ||
83 | int (*update)(struct ahash_request *req); | ||
84 | int (*final)(struct ahash_request *req); | ||
85 | int (*finup)(struct ahash_request *req); | ||
86 | int (*digest)(struct ahash_request *req); | ||
87 | int (*export)(struct ahash_request *req, void *out); | ||
88 | int (*import)(struct ahash_request *req, const void *in); | ||
89 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
90 | unsigned int keylen); | ||
91 | |||
92 | unsigned int digestsize; | ||
93 | unsigned int reqsize; | ||
47 | struct crypto_tfm base; | 94 | struct crypto_tfm base; |
48 | }; | 95 | }; |
49 | 96 | ||
@@ -54,19 +101,11 @@ struct crypto_shash { | |||
54 | 101 | ||
55 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | 102 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) |
56 | { | 103 | { |
57 | return (struct crypto_ahash *)tfm; | 104 | return container_of(tfm, struct crypto_ahash, base); |
58 | } | 105 | } |
59 | 106 | ||
60 | static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, | 107 | struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type, |
61 | u32 type, u32 mask) | 108 | u32 mask); |
62 | { | ||
63 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
64 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
65 | type |= CRYPTO_ALG_TYPE_AHASH; | ||
66 | mask |= CRYPTO_ALG_TYPE_AHASH_MASK; | ||
67 | |||
68 | return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
69 | } | ||
70 | 109 | ||
71 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | 110 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) |
72 | { | 111 | { |
@@ -75,7 +114,7 @@ static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | |||
75 | 114 | ||
76 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) | 115 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) |
77 | { | 116 | { |
78 | crypto_free_tfm(crypto_ahash_tfm(tfm)); | 117 | crypto_destroy_tfm(tfm, crypto_ahash_tfm(tfm)); |
79 | } | 118 | } |
80 | 119 | ||
81 | static inline unsigned int crypto_ahash_alignmask( | 120 | static inline unsigned int crypto_ahash_alignmask( |
@@ -84,14 +123,26 @@ static inline unsigned int crypto_ahash_alignmask( | |||
84 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); | 123 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); |
85 | } | 124 | } |
86 | 125 | ||
87 | static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm) | 126 | static inline struct hash_alg_common *__crypto_hash_alg_common( |
127 | struct crypto_alg *alg) | ||
88 | { | 128 | { |
89 | return &crypto_ahash_tfm(tfm)->crt_ahash; | 129 | return container_of(alg, struct hash_alg_common, base); |
130 | } | ||
131 | |||
132 | static inline struct hash_alg_common *crypto_hash_alg_common( | ||
133 | struct crypto_ahash *tfm) | ||
134 | { | ||
135 | return __crypto_hash_alg_common(crypto_ahash_tfm(tfm)->__crt_alg); | ||
90 | } | 136 | } |
91 | 137 | ||
92 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) | 138 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) |
93 | { | 139 | { |
94 | return crypto_ahash_crt(tfm)->digestsize; | 140 | return tfm->digestsize; |
141 | } | ||
142 | |||
143 | static inline unsigned int crypto_ahash_statesize(struct crypto_ahash *tfm) | ||
144 | { | ||
145 | return crypto_hash_alg_common(tfm)->statesize; | ||
95 | } | 146 | } |
96 | 147 | ||
97 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) | 148 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) |
@@ -117,7 +168,7 @@ static inline struct crypto_ahash *crypto_ahash_reqtfm( | |||
117 | 168 | ||
118 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) | 169 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) |
119 | { | 170 | { |
120 | return crypto_ahash_crt(tfm)->reqsize; | 171 | return tfm->reqsize; |
121 | } | 172 | } |
122 | 173 | ||
123 | static inline void *ahash_request_ctx(struct ahash_request *req) | 174 | static inline void *ahash_request_ctx(struct ahash_request *req) |
@@ -128,41 +179,37 @@ static inline void *ahash_request_ctx(struct ahash_request *req) | |||
128 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, | 179 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, |
129 | const u8 *key, unsigned int keylen) | 180 | const u8 *key, unsigned int keylen) |
130 | { | 181 | { |
131 | struct ahash_tfm *crt = crypto_ahash_crt(tfm); | 182 | return tfm->setkey(tfm, key, keylen); |
132 | |||
133 | return crt->setkey(tfm, key, keylen); | ||
134 | } | 183 | } |
135 | 184 | ||
136 | static inline int crypto_ahash_digest(struct ahash_request *req) | 185 | static inline int crypto_ahash_digest(struct ahash_request *req) |
137 | { | 186 | { |
138 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 187 | return crypto_ahash_reqtfm(req)->digest(req); |
139 | return crt->digest(req); | ||
140 | } | 188 | } |
141 | 189 | ||
142 | static inline void crypto_ahash_export(struct ahash_request *req, u8 *out) | 190 | static inline int crypto_ahash_export(struct ahash_request *req, void *out) |
143 | { | 191 | { |
144 | memcpy(out, ahash_request_ctx(req), | 192 | return crypto_ahash_reqtfm(req)->export(req, out); |
145 | crypto_ahash_reqsize(crypto_ahash_reqtfm(req))); | ||
146 | } | 193 | } |
147 | 194 | ||
148 | int crypto_ahash_import(struct ahash_request *req, const u8 *in); | 195 | static inline int crypto_ahash_import(struct ahash_request *req, const void *in) |
196 | { | ||
197 | return crypto_ahash_reqtfm(req)->import(req, in); | ||
198 | } | ||
149 | 199 | ||
150 | static inline int crypto_ahash_init(struct ahash_request *req) | 200 | static inline int crypto_ahash_init(struct ahash_request *req) |
151 | { | 201 | { |
152 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 202 | return crypto_ahash_reqtfm(req)->init(req); |
153 | return crt->init(req); | ||
154 | } | 203 | } |
155 | 204 | ||
156 | static inline int crypto_ahash_update(struct ahash_request *req) | 205 | static inline int crypto_ahash_update(struct ahash_request *req) |
157 | { | 206 | { |
158 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 207 | return crypto_ahash_reqtfm(req)->update(req); |
159 | return crt->update(req); | ||
160 | } | 208 | } |
161 | 209 | ||
162 | static inline int crypto_ahash_final(struct ahash_request *req) | 210 | static inline int crypto_ahash_final(struct ahash_request *req) |
163 | { | 211 | { |
164 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 212 | return crypto_ahash_reqtfm(req)->final(req); |
165 | return crt->final(req); | ||
166 | } | 213 | } |
167 | 214 | ||
168 | static inline void ahash_request_set_tfm(struct ahash_request *req, | 215 | static inline void ahash_request_set_tfm(struct ahash_request *req, |
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 5e45818f3351..08bdffafefad 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h | |||
@@ -51,6 +51,9 @@ int crypto_hash_walk_first_compat(struct hash_desc *hdesc, | |||
51 | struct crypto_hash_walk *walk, | 51 | struct crypto_hash_walk *walk, |
52 | struct scatterlist *sg, unsigned int len); | 52 | struct scatterlist *sg, unsigned int len); |
53 | 53 | ||
54 | int crypto_register_ahash(struct ahash_alg *alg); | ||
55 | int crypto_unregister_ahash(struct ahash_alg *alg); | ||
56 | |||
54 | int crypto_register_shash(struct shash_alg *alg); | 57 | int crypto_register_shash(struct shash_alg *alg); |
55 | int crypto_unregister_shash(struct shash_alg *alg); | 58 | int crypto_unregister_shash(struct shash_alg *alg); |
56 | int shash_register_instance(struct crypto_template *tmpl, | 59 | int shash_register_instance(struct crypto_template *tmpl, |
@@ -66,12 +69,14 @@ struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask); | |||
66 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); | 69 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); |
67 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc); | 70 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc); |
68 | 71 | ||
72 | int crypto_init_shash_ops_async(struct crypto_tfm *tfm); | ||
73 | |||
69 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | 74 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) |
70 | { | 75 | { |
71 | return crypto_tfm_ctx(&tfm->base); | 76 | return crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
72 | } | 77 | } |
73 | 78 | ||
74 | static inline struct ahash_alg *crypto_ahash_alg( | 79 | static inline struct old_ahash_alg *crypto_old_ahash_alg( |
75 | struct crypto_ahash *tfm) | 80 | struct crypto_ahash *tfm) |
76 | { | 81 | { |
77 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; | 82 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; |
@@ -80,7 +85,7 @@ static inline struct ahash_alg *crypto_ahash_alg( | |||
80 | static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, | 85 | static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, |
81 | unsigned int reqsize) | 86 | unsigned int reqsize) |
82 | { | 87 | { |
83 | crypto_ahash_crt(tfm)->reqsize = reqsize; | 88 | tfm->reqsize = reqsize; |
84 | } | 89 | } |
85 | 90 | ||
86 | static inline int ahash_enqueue_request(struct crypto_queue *queue, | 91 | static inline int ahash_enqueue_request(struct crypto_queue *queue, |
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 274f9c7da90c..9e7e9b62a3dc 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -120,6 +120,7 @@ struct crypto_rng; | |||
120 | struct crypto_tfm; | 120 | struct crypto_tfm; |
121 | struct crypto_type; | 121 | struct crypto_type; |
122 | struct aead_givcrypt_request; | 122 | struct aead_givcrypt_request; |
123 | struct ahash_request; | ||
123 | struct skcipher_givcrypt_request; | 124 | struct skcipher_givcrypt_request; |
124 | 125 | ||
125 | typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); | 126 | typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); |
@@ -146,16 +147,6 @@ struct ablkcipher_request { | |||
146 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | 147 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
147 | }; | 148 | }; |
148 | 149 | ||
149 | struct ahash_request { | ||
150 | struct crypto_async_request base; | ||
151 | |||
152 | unsigned int nbytes; | ||
153 | struct scatterlist *src; | ||
154 | u8 *result; | ||
155 | |||
156 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
157 | }; | ||
158 | |||
159 | /** | 150 | /** |
160 | * struct aead_request - AEAD request | 151 | * struct aead_request - AEAD request |
161 | * @base: Common attributes for async crypto requests | 152 | * @base: Common attributes for async crypto requests |
@@ -220,7 +211,7 @@ struct ablkcipher_alg { | |||
220 | unsigned int ivsize; | 211 | unsigned int ivsize; |
221 | }; | 212 | }; |
222 | 213 | ||
223 | struct ahash_alg { | 214 | struct old_ahash_alg { |
224 | int (*init)(struct ahash_request *req); | 215 | int (*init)(struct ahash_request *req); |
225 | int (*reinit)(struct ahash_request *req); | 216 | int (*reinit)(struct ahash_request *req); |
226 | int (*update)(struct ahash_request *req); | 217 | int (*update)(struct ahash_request *req); |
@@ -346,7 +337,7 @@ struct crypto_alg { | |||
346 | struct cipher_alg cipher; | 337 | struct cipher_alg cipher; |
347 | struct digest_alg digest; | 338 | struct digest_alg digest; |
348 | struct hash_alg hash; | 339 | struct hash_alg hash; |
349 | struct ahash_alg ahash; | 340 | struct old_ahash_alg ahash; |
350 | struct compress_alg compress; | 341 | struct compress_alg compress; |
351 | struct rng_alg rng; | 342 | struct rng_alg rng; |
352 | } cra_u; | 343 | } cra_u; |
@@ -433,18 +424,6 @@ struct hash_tfm { | |||
433 | unsigned int digestsize; | 424 | unsigned int digestsize; |
434 | }; | 425 | }; |
435 | 426 | ||
436 | struct ahash_tfm { | ||
437 | int (*init)(struct ahash_request *req); | ||
438 | int (*update)(struct ahash_request *req); | ||
439 | int (*final)(struct ahash_request *req); | ||
440 | int (*digest)(struct ahash_request *req); | ||
441 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
442 | unsigned int keylen); | ||
443 | |||
444 | unsigned int digestsize; | ||
445 | unsigned int reqsize; | ||
446 | }; | ||
447 | |||
448 | struct compress_tfm { | 427 | struct compress_tfm { |
449 | int (*cot_compress)(struct crypto_tfm *tfm, | 428 | int (*cot_compress)(struct crypto_tfm *tfm, |
450 | const u8 *src, unsigned int slen, | 429 | const u8 *src, unsigned int slen, |
@@ -465,7 +444,6 @@ struct rng_tfm { | |||
465 | #define crt_blkcipher crt_u.blkcipher | 444 | #define crt_blkcipher crt_u.blkcipher |
466 | #define crt_cipher crt_u.cipher | 445 | #define crt_cipher crt_u.cipher |
467 | #define crt_hash crt_u.hash | 446 | #define crt_hash crt_u.hash |
468 | #define crt_ahash crt_u.ahash | ||
469 | #define crt_compress crt_u.compress | 447 | #define crt_compress crt_u.compress |
470 | #define crt_rng crt_u.rng | 448 | #define crt_rng crt_u.rng |
471 | 449 | ||
@@ -479,7 +457,6 @@ struct crypto_tfm { | |||
479 | struct blkcipher_tfm blkcipher; | 457 | struct blkcipher_tfm blkcipher; |
480 | struct cipher_tfm cipher; | 458 | struct cipher_tfm cipher; |
481 | struct hash_tfm hash; | 459 | struct hash_tfm hash; |
482 | struct ahash_tfm ahash; | ||
483 | struct compress_tfm compress; | 460 | struct compress_tfm compress; |
484 | struct rng_tfm rng; | 461 | struct rng_tfm rng; |
485 | } crt_u; | 462 | } crt_u; |