Currently, shash spawns are initialized by using shash_attr_alg() or crypto_alg_mod_lookup() to look up the shash algorithm, then calling crypto_init_shash_spawn(). This is different from how skcipher, aead, and akcipher spawns are initialized (they use crypto_grab_*()), and for no good reason. This difference introduces unnecessary complexity. The crypto_grab_*() functions used to have some problems, like not holding a reference to the algorithm and requiring the caller to initialize spawn->base.inst. But those problems are fixed now. So, let's introduce crypto_grab_shash() so that we can convert all templates to the same way of initializing their spawns.
Unified · Split
| @@ -469,6 +469,15 @@ static const struct crypto_type crypto_shash_type = { · 468 unmodified lines | |||
| 469 | .tfmsize = offsetof(struct crypto_shash, base), | 469 | .tfmsize = offsetof(struct crypto_shash, base), |
| 470 | }; | 470 | }; |
| 471 | 471 | ||
| 472 | int crypto_grab_shash(struct crypto_shash_spawn *spawn, | ||
| 473 | struct crypto_instance *inst, | ||
| 474 | const char *name, u32 type, u32 mask) | ||
| 475 | { | ||
| 476 | spawn->base.frontend = &crypto_shash_type; | ||
| 477 | return crypto_grab_spawn(&spawn->base, inst, name, type, mask); | ||
| 478 | } | ||
| 479 | EXPORT_SYMBOL_GPL(crypto_grab_shash); | ||
| 480 | |||
| 472 | struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, | 481 | struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, |
| 473 | u32 mask) | 482 | u32 mask) |
| 474 | { | 483 | { |
| @@ -128,11 +128,21 @@ int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn, · 127 unmodified lines | |||
| 128 | struct shash_alg *alg, | 128 | struct shash_alg *alg, |
| 129 | struct crypto_instance *inst); | 129 | struct crypto_instance *inst); |
| 130 | 130 | ||
| 131 | int crypto_grab_shash(struct crypto_shash_spawn *spawn, | ||
| 132 | struct crypto_instance *inst, | ||
| 133 | const char *name, u32 type, u32 mask); | ||
| 134 | |||
| 131 | static inline void crypto_drop_shash(struct crypto_shash_spawn *spawn) | 135 | static inline void crypto_drop_shash(struct crypto_shash_spawn *spawn) |
| 132 | { | 136 | { |
| 133 | crypto_drop_spawn(&spawn->base); | 137 | crypto_drop_spawn(&spawn->base); |
| 134 | } | 138 | } |
| 135 | 139 | ||
| 140 | static inline struct shash_alg *crypto_spawn_shash_alg( | ||
| 141 | struct crypto_shash_spawn *spawn) | ||
| 142 | { | ||
| 143 | return __crypto_shash_alg(spawn->base.alg); | ||
| 144 | } | ||
| 145 | |||
| 136 | struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask); | 146 | struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask); |
| 137 | 147 | ||
| 138 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); | 148 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); |