mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	crypto: api - Add crypto_alloc_instance2
This patch adds a new argument to crypto_alloc_instance which sets aside some space before the instance for use by algorithms such as shash that place type-specific data before crypto_alg. For compatibility the function has been renamed so that existing users aren't affected. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
		
							parent
							
								
									f2ac72e826
								
							
						
					
					
						commit
						70ec7bb91a
					
				
					 2 changed files with 33 additions and 6 deletions
				
			
		| 
						 | 
					@ -627,17 +627,20 @@ int crypto_attr_u32(struct rtattr *rta, u32 *num)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(crypto_attr_u32);
 | 
					EXPORT_SYMBOL_GPL(crypto_attr_u32);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct crypto_instance *crypto_alloc_instance(const char *name,
 | 
					void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg,
 | 
				
			||||||
					      struct crypto_alg *alg)
 | 
								     unsigned int head)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct crypto_instance *inst;
 | 
						struct crypto_instance *inst;
 | 
				
			||||||
	struct crypto_spawn *spawn;
 | 
						char *p;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
 | 
						p = kzalloc(head + sizeof(*inst) + sizeof(struct crypto_spawn),
 | 
				
			||||||
	if (!inst)
 | 
							    GFP_KERNEL);
 | 
				
			||||||
 | 
						if (!p)
 | 
				
			||||||
		return ERR_PTR(-ENOMEM);
 | 
							return ERR_PTR(-ENOMEM);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						inst = (void *)(p + head);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = -ENAMETOOLONG;
 | 
						err = -ENAMETOOLONG;
 | 
				
			||||||
	if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name,
 | 
						if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name,
 | 
				
			||||||
		     alg->cra_name) >= CRYPTO_MAX_ALG_NAME)
 | 
							     alg->cra_name) >= CRYPTO_MAX_ALG_NAME)
 | 
				
			||||||
| 
						 | 
					@ -647,6 +650,25 @@ struct crypto_instance *crypto_alloc_instance(const char *name,
 | 
				
			||||||
		     name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
 | 
							     name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
 | 
				
			||||||
		goto err_free_inst;
 | 
							goto err_free_inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_free_inst:
 | 
				
			||||||
 | 
						kfree(p);
 | 
				
			||||||
 | 
						return ERR_PTR(err);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(crypto_alloc_instance2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct crypto_instance *crypto_alloc_instance(const char *name,
 | 
				
			||||||
 | 
										      struct crypto_alg *alg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct crypto_instance *inst;
 | 
				
			||||||
 | 
						struct crypto_spawn *spawn;
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						inst = crypto_alloc_instance2(name, alg, 0);
 | 
				
			||||||
 | 
						if (IS_ERR(inst))
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spawn = crypto_instance_ctx(inst);
 | 
						spawn = crypto_instance_ctx(inst);
 | 
				
			||||||
	err = crypto_init_spawn(spawn, alg, inst,
 | 
						err = crypto_init_spawn(spawn, alg, inst,
 | 
				
			||||||
				CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
 | 
									CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
 | 
				
			||||||
| 
						 | 
					@ -658,7 +680,10 @@ struct crypto_instance *crypto_alloc_instance(const char *name,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
err_free_inst:
 | 
					err_free_inst:
 | 
				
			||||||
	kfree(inst);
 | 
						kfree(inst);
 | 
				
			||||||
	return ERR_PTR(err);
 | 
						inst = ERR_PTR(err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						return inst;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(crypto_alloc_instance);
 | 
					EXPORT_SYMBOL_GPL(crypto_alloc_instance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,6 +132,8 @@ int crypto_check_attr_type(struct rtattr **tb, u32 type);
 | 
				
			||||||
const char *crypto_attr_alg_name(struct rtattr *rta);
 | 
					const char *crypto_attr_alg_name(struct rtattr *rta);
 | 
				
			||||||
struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask);
 | 
					struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask);
 | 
				
			||||||
int crypto_attr_u32(struct rtattr *rta, u32 *num);
 | 
					int crypto_attr_u32(struct rtattr *rta, u32 *num);
 | 
				
			||||||
 | 
					void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg,
 | 
				
			||||||
 | 
								     unsigned int head);
 | 
				
			||||||
struct crypto_instance *crypto_alloc_instance(const char *name,
 | 
					struct crypto_instance *crypto_alloc_instance(const char *name,
 | 
				
			||||||
					      struct crypto_alg *alg);
 | 
										      struct crypto_alg *alg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue