diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/ahash.c | 82 | ||||
-rw-r--r-- | crypto/shash.c | 8 |
2 files changed, 59 insertions, 31 deletions
diff --git a/crypto/ahash.c b/crypto/ahash.c index f3476374f764..838519386215 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c | |||
@@ -24,6 +24,12 @@ | |||
24 | 24 | ||
25 | #include "internal.h" | 25 | #include "internal.h" |
26 | 26 | ||
27 | static inline struct ahash_alg *crypto_ahash_alg(struct crypto_ahash *hash) | ||
28 | { | ||
29 | return container_of(crypto_hash_alg_common(hash), struct ahash_alg, | ||
30 | halg); | ||
31 | } | ||
32 | |||
27 | static int hash_walk_next(struct crypto_hash_walk *walk) | 33 | static int hash_walk_next(struct crypto_hash_walk *walk) |
28 | { | 34 | { |
29 | unsigned int alignmask = walk->alignmask; | 35 | unsigned int alignmask = walk->alignmask; |
@@ -169,30 +175,11 @@ static int ahash_nosetkey(struct crypto_ahash *tfm, const u8 *key, | |||
169 | return -ENOSYS; | 175 | return -ENOSYS; |
170 | } | 176 | } |
171 | 177 | ||
172 | int crypto_ahash_import(struct ahash_request *req, const u8 *in) | ||
173 | { | ||
174 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); | ||
175 | struct ahash_alg *alg = crypto_ahash_alg(tfm); | ||
176 | |||
177 | memcpy(ahash_request_ctx(req), in, crypto_ahash_reqsize(tfm)); | ||
178 | |||
179 | if (alg->reinit) | ||
180 | alg->reinit(req); | ||
181 | |||
182 | return 0; | ||
183 | } | ||
184 | EXPORT_SYMBOL_GPL(crypto_ahash_import); | ||
185 | |||
186 | static unsigned int crypto_ahash_ctxsize(struct crypto_alg *alg, u32 type, | ||
187 | u32 mask) | ||
188 | { | ||
189 | return alg->cra_ctxsize; | ||
190 | } | ||
191 | |||
192 | static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | 178 | static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) |
193 | { | 179 | { |
194 | struct ahash_alg *alg = &tfm->__crt_alg->cra_ahash; | 180 | struct old_ahash_alg *alg = &tfm->__crt_alg->cra_ahash; |
195 | struct ahash_tfm *crt = &tfm->crt_ahash; | 181 | struct crypto_ahash *crt = __crypto_ahash_cast(tfm); |
182 | struct ahash_alg *nalg = crypto_ahash_alg(crt); | ||
196 | 183 | ||
197 | if (alg->digestsize > PAGE_SIZE / 8) | 184 | if (alg->digestsize > PAGE_SIZE / 8) |
198 | return -EINVAL; | 185 | return -EINVAL; |
@@ -204,9 +191,42 @@ static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | |||
204 | crt->setkey = alg->setkey ? ahash_setkey : ahash_nosetkey; | 191 | crt->setkey = alg->setkey ? ahash_setkey : ahash_nosetkey; |
205 | crt->digestsize = alg->digestsize; | 192 | crt->digestsize = alg->digestsize; |
206 | 193 | ||
194 | nalg->setkey = alg->setkey; | ||
195 | nalg->halg.digestsize = alg->digestsize; | ||
196 | |||
207 | return 0; | 197 | return 0; |
208 | } | 198 | } |
209 | 199 | ||
200 | static int crypto_ahash_init_tfm(struct crypto_tfm *tfm) | ||
201 | { | ||
202 | struct crypto_ahash *hash = __crypto_ahash_cast(tfm); | ||
203 | struct ahash_alg *alg = crypto_ahash_alg(hash); | ||
204 | struct old_ahash_alg *oalg = crypto_old_ahash_alg(hash); | ||
205 | |||
206 | if (tfm->__crt_alg->cra_type != &crypto_ahash_type) | ||
207 | return crypto_init_shash_ops_async(tfm); | ||
208 | |||
209 | if (oalg->init) | ||
210 | return crypto_init_ahash_ops(tfm, 0, 0); | ||
211 | |||
212 | hash->init = alg->init; | ||
213 | hash->update = alg->update; | ||
214 | hash->final = alg->final; | ||
215 | hash->digest = alg->digest; | ||
216 | hash->setkey = alg->setkey ? ahash_setkey : ahash_nosetkey; | ||
217 | hash->digestsize = alg->halg.digestsize; | ||
218 | |||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | static unsigned int crypto_ahash_extsize(struct crypto_alg *alg) | ||
223 | { | ||
224 | if (alg->cra_type == &crypto_ahash_type) | ||
225 | return alg->cra_ctxsize; | ||
226 | |||
227 | return sizeof(struct crypto_shash *); | ||
228 | } | ||
229 | |||
210 | static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg) | 230 | static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg) |
211 | __attribute__ ((unused)); | 231 | __attribute__ ((unused)); |
212 | static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg) | 232 | static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg) |
@@ -215,17 +235,29 @@ static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg) | |||
215 | seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ? | 235 | seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ? |
216 | "yes" : "no"); | 236 | "yes" : "no"); |
217 | seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); | 237 | seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); |
218 | seq_printf(m, "digestsize : %u\n", alg->cra_ahash.digestsize); | 238 | seq_printf(m, "digestsize : %u\n", |
239 | __crypto_hash_alg_common(alg)->digestsize); | ||
219 | } | 240 | } |
220 | 241 | ||
221 | const struct crypto_type crypto_ahash_type = { | 242 | const struct crypto_type crypto_ahash_type = { |
222 | .ctxsize = crypto_ahash_ctxsize, | 243 | .extsize = crypto_ahash_extsize, |
223 | .init = crypto_init_ahash_ops, | 244 | .init_tfm = crypto_ahash_init_tfm, |
224 | #ifdef CONFIG_PROC_FS | 245 | #ifdef CONFIG_PROC_FS |
225 | .show = crypto_ahash_show, | 246 | .show = crypto_ahash_show, |
226 | #endif | 247 | #endif |
248 | .maskclear = ~CRYPTO_ALG_TYPE_MASK, | ||
249 | .maskset = CRYPTO_ALG_TYPE_AHASH_MASK, | ||
250 | .type = CRYPTO_ALG_TYPE_AHASH, | ||
251 | .tfmsize = offsetof(struct crypto_ahash, base), | ||
227 | }; | 252 | }; |
228 | EXPORT_SYMBOL_GPL(crypto_ahash_type); | 253 | EXPORT_SYMBOL_GPL(crypto_ahash_type); |
229 | 254 | ||
255 | struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type, | ||
256 | u32 mask) | ||
257 | { | ||
258 | return crypto_alloc_tfm(alg_name, &crypto_ahash_type, type, mask); | ||
259 | } | ||
260 | EXPORT_SYMBOL_GPL(crypto_alloc_ahash); | ||
261 | |||
230 | MODULE_LICENSE("GPL"); | 262 | MODULE_LICENSE("GPL"); |
231 | MODULE_DESCRIPTION("Asynchronous cryptographic hash type"); | 263 | MODULE_DESCRIPTION("Asynchronous cryptographic hash type"); |
diff --git a/crypto/shash.c b/crypto/shash.c index 7063e1421504..615a5f4d9b7a 100644 --- a/crypto/shash.c +++ b/crypto/shash.c | |||
@@ -267,11 +267,11 @@ static void crypto_exit_shash_ops_async(struct crypto_tfm *tfm) | |||
267 | crypto_free_shash(*ctx); | 267 | crypto_free_shash(*ctx); |
268 | } | 268 | } |
269 | 269 | ||
270 | static int crypto_init_shash_ops_async(struct crypto_tfm *tfm) | 270 | int crypto_init_shash_ops_async(struct crypto_tfm *tfm) |
271 | { | 271 | { |
272 | struct crypto_alg *calg = tfm->__crt_alg; | 272 | struct crypto_alg *calg = tfm->__crt_alg; |
273 | struct shash_alg *alg = __crypto_shash_alg(calg); | 273 | struct shash_alg *alg = __crypto_shash_alg(calg); |
274 | struct ahash_tfm *crt = &tfm->crt_ahash; | 274 | struct crypto_ahash *crt = __crypto_ahash_cast(tfm); |
275 | struct crypto_shash **ctx = crypto_tfm_ctx(tfm); | 275 | struct crypto_shash **ctx = crypto_tfm_ctx(tfm); |
276 | struct crypto_shash *shash; | 276 | struct crypto_shash *shash; |
277 | 277 | ||
@@ -428,8 +428,6 @@ static int crypto_init_shash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | |||
428 | switch (mask & CRYPTO_ALG_TYPE_MASK) { | 428 | switch (mask & CRYPTO_ALG_TYPE_MASK) { |
429 | case CRYPTO_ALG_TYPE_HASH_MASK: | 429 | case CRYPTO_ALG_TYPE_HASH_MASK: |
430 | return crypto_init_shash_ops_compat(tfm); | 430 | return crypto_init_shash_ops_compat(tfm); |
431 | case CRYPTO_ALG_TYPE_AHASH_MASK: | ||
432 | return crypto_init_shash_ops_async(tfm); | ||
433 | } | 431 | } |
434 | 432 | ||
435 | return -EINVAL; | 433 | return -EINVAL; |
@@ -441,8 +439,6 @@ static unsigned int crypto_shash_ctxsize(struct crypto_alg *alg, u32 type, | |||
441 | switch (mask & CRYPTO_ALG_TYPE_MASK) { | 439 | switch (mask & CRYPTO_ALG_TYPE_MASK) { |
442 | case CRYPTO_ALG_TYPE_HASH_MASK: | 440 | case CRYPTO_ALG_TYPE_HASH_MASK: |
443 | return sizeof(struct shash_desc *); | 441 | return sizeof(struct shash_desc *); |
444 | case CRYPTO_ALG_TYPE_AHASH_MASK: | ||
445 | return sizeof(struct crypto_shash *); | ||
446 | } | 442 | } |
447 | 443 | ||
448 | return 0; | 444 | return 0; |