Commit 27d2a3300755387d2fec231d37944907ff992ce8
1 parent
2e306ee016
Exists in
master
and in
20 other branches
[CRYPTO] api: Allow multiple frontends per backend
This patch adds support for multiple frontend types for each backend algorithm by passing the type and mask through to the backend type init function. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 6 changed files with 24 additions and 20 deletions Side-by-side Diff
crypto/algapi.c
crypto/api.c
... | ... | @@ -212,12 +212,12 @@ |
212 | 212 | } |
213 | 213 | EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup); |
214 | 214 | |
215 | -static int crypto_init_ops(struct crypto_tfm *tfm) | |
215 | +static int crypto_init_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | |
216 | 216 | { |
217 | - const struct crypto_type *type = tfm->__crt_alg->cra_type; | |
217 | + const struct crypto_type *type_obj = tfm->__crt_alg->cra_type; | |
218 | 218 | |
219 | - if (type) | |
220 | - return type->init(tfm); | |
219 | + if (type_obj) | |
220 | + return type_obj->init(tfm, type, mask); | |
221 | 221 | |
222 | 222 | switch (crypto_tfm_alg_type(tfm)) { |
223 | 223 | case CRYPTO_ALG_TYPE_CIPHER: |
224 | 224 | |
225 | 225 | |
... | ... | @@ -266,14 +266,14 @@ |
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
269 | -static unsigned int crypto_ctxsize(struct crypto_alg *alg) | |
269 | +static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) | |
270 | 270 | { |
271 | - const struct crypto_type *type = alg->cra_type; | |
271 | + const struct crypto_type *type_obj = alg->cra_type; | |
272 | 272 | unsigned int len; |
273 | 273 | |
274 | 274 | len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); |
275 | - if (type) | |
276 | - return len + type->ctxsize(alg); | |
275 | + if (type_obj) | |
276 | + return len + type_obj->ctxsize(alg, type, mask); | |
277 | 277 | |
278 | 278 | switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { |
279 | 279 | default: |
280 | 280 | |
281 | 281 | |
... | ... | @@ -303,20 +303,21 @@ |
303 | 303 | } |
304 | 304 | EXPORT_SYMBOL_GPL(crypto_shoot_alg); |
305 | 305 | |
306 | -struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg) | |
306 | +struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, | |
307 | + u32 mask) | |
307 | 308 | { |
308 | 309 | struct crypto_tfm *tfm = NULL; |
309 | 310 | unsigned int tfm_size; |
310 | 311 | int err = -ENOMEM; |
311 | 312 | |
312 | - tfm_size = sizeof(*tfm) + crypto_ctxsize(alg); | |
313 | + tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); | |
313 | 314 | tfm = kzalloc(tfm_size, GFP_KERNEL); |
314 | 315 | if (tfm == NULL) |
315 | 316 | goto out_err; |
316 | 317 | |
317 | 318 | tfm->__crt_alg = alg; |
318 | 319 | |
319 | - err = crypto_init_ops(tfm); | |
320 | + err = crypto_init_ops(tfm, type, mask); | |
320 | 321 | if (err) |
321 | 322 | goto out_free_tfm; |
322 | 323 | |
... | ... | @@ -372,7 +373,7 @@ |
372 | 373 | goto err; |
373 | 374 | } |
374 | 375 | |
375 | - tfm = __crypto_alloc_tfm(alg); | |
376 | + tfm = __crypto_alloc_tfm(alg, type, mask); | |
376 | 377 | if (!IS_ERR(tfm)) |
377 | 378 | return tfm; |
378 | 379 |
crypto/blkcipher.c
... | ... | @@ -349,7 +349,8 @@ |
349 | 349 | return cipher->setkey(tfm, key, keylen); |
350 | 350 | } |
351 | 351 | |
352 | -static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg) | |
352 | +static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type, | |
353 | + u32 mask) | |
353 | 354 | { |
354 | 355 | struct blkcipher_alg *cipher = &alg->cra_blkcipher; |
355 | 356 | unsigned int len = alg->cra_ctxsize; |
... | ... | @@ -362,7 +363,7 @@ |
362 | 363 | return len; |
363 | 364 | } |
364 | 365 | |
365 | -static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm) | |
366 | +static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | |
366 | 367 | { |
367 | 368 | struct blkcipher_tfm *crt = &tfm->crt_blkcipher; |
368 | 369 | struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher; |
crypto/hash.c
... | ... | @@ -16,12 +16,13 @@ |
16 | 16 | |
17 | 17 | #include "internal.h" |
18 | 18 | |
19 | -static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg) | |
19 | +static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg, u32 type, | |
20 | + u32 mask) | |
20 | 21 | { |
21 | 22 | return alg->cra_ctxsize; |
22 | 23 | } |
23 | 24 | |
24 | -static int crypto_init_hash_ops(struct crypto_tfm *tfm) | |
25 | +static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | |
25 | 26 | { |
26 | 27 | struct hash_tfm *crt = &tfm->crt_hash; |
27 | 28 | struct hash_alg *alg = &tfm->__crt_alg->cra_hash; |
crypto/internal.h
... | ... | @@ -120,7 +120,8 @@ |
120 | 120 | void crypto_larval_error(const char *name, u32 type, u32 mask); |
121 | 121 | |
122 | 122 | void crypto_shoot_alg(struct crypto_alg *alg); |
123 | -struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg); | |
123 | +struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, | |
124 | + u32 mask); | |
124 | 125 | |
125 | 126 | int crypto_register_instance(struct crypto_template *tmpl, |
126 | 127 | struct crypto_instance *inst); |
include/crypto/algapi.h
... | ... | @@ -18,8 +18,8 @@ |
18 | 18 | struct seq_file; |
19 | 19 | |
20 | 20 | struct crypto_type { |
21 | - unsigned int (*ctxsize)(struct crypto_alg *alg); | |
22 | - int (*init)(struct crypto_tfm *tfm); | |
21 | + unsigned int (*ctxsize)(struct crypto_alg *alg, u32 type, u32 mask); | |
22 | + int (*init)(struct crypto_tfm *tfm, u32 type, u32 mask); | |
23 | 23 | void (*exit)(struct crypto_tfm *tfm); |
24 | 24 | void (*show)(struct seq_file *m, struct crypto_alg *alg); |
25 | 25 | }; |