mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	crypto: lskcipher - Add compatibility wrapper around ECB
As an aid to the transition from cipher algorithm implementations to lskcipher, add a temporary wrapper when creating simple lskcipher templates by using ecb(X) instead of X if an lskcipher implementation of X cannot be found. This can be reverted once all cipher implementations have switched over to lskcipher. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
		
							parent
							
								
									31865c4c4d
								
							
						
					
					
						commit
						8aee5d4ebd
					
				
					 1 changed files with 52 additions and 5 deletions
				
			
		| 
						 | 
					@ -536,13 +536,19 @@ struct lskcipher_instance *lskcipher_alloc_instance_simple(
 | 
				
			||||||
	u32 mask;
 | 
						u32 mask;
 | 
				
			||||||
	struct lskcipher_instance *inst;
 | 
						struct lskcipher_instance *inst;
 | 
				
			||||||
	struct crypto_lskcipher_spawn *spawn;
 | 
						struct crypto_lskcipher_spawn *spawn;
 | 
				
			||||||
 | 
						char ecb_name[CRYPTO_MAX_ALG_NAME];
 | 
				
			||||||
	struct lskcipher_alg *cipher_alg;
 | 
						struct lskcipher_alg *cipher_alg;
 | 
				
			||||||
 | 
						const char *cipher_name;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_LSKCIPHER, &mask);
 | 
						err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_LSKCIPHER, &mask);
 | 
				
			||||||
	if (err)
 | 
						if (err)
 | 
				
			||||||
		return ERR_PTR(err);
 | 
							return ERR_PTR(err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cipher_name = crypto_attr_alg_name(tb[1]);
 | 
				
			||||||
 | 
						if (IS_ERR(cipher_name))
 | 
				
			||||||
 | 
							return ERR_CAST(cipher_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
 | 
						inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
 | 
				
			||||||
	if (!inst)
 | 
						if (!inst)
 | 
				
			||||||
		return ERR_PTR(-ENOMEM);
 | 
							return ERR_PTR(-ENOMEM);
 | 
				
			||||||
| 
						 | 
					@ -550,9 +556,23 @@ struct lskcipher_instance *lskcipher_alloc_instance_simple(
 | 
				
			||||||
	spawn = lskcipher_instance_ctx(inst);
 | 
						spawn = lskcipher_instance_ctx(inst);
 | 
				
			||||||
	err = crypto_grab_lskcipher(spawn,
 | 
						err = crypto_grab_lskcipher(spawn,
 | 
				
			||||||
				    lskcipher_crypto_instance(inst),
 | 
									    lskcipher_crypto_instance(inst),
 | 
				
			||||||
				    crypto_attr_alg_name(tb[1]), 0, mask);
 | 
									    cipher_name, 0, mask);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ecb_name[0] = 0;
 | 
				
			||||||
 | 
						if (err == -ENOENT && !!memcmp(tmpl->name, "ecb", 4)) {
 | 
				
			||||||
 | 
							err = -ENAMETOOLONG;
 | 
				
			||||||
 | 
							if (snprintf(ecb_name, CRYPTO_MAX_ALG_NAME, "ecb(%s)",
 | 
				
			||||||
 | 
								     cipher_name) >= CRYPTO_MAX_ALG_NAME)
 | 
				
			||||||
 | 
								goto err_free_inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = crypto_grab_lskcipher(spawn,
 | 
				
			||||||
 | 
										    lskcipher_crypto_instance(inst),
 | 
				
			||||||
 | 
										    ecb_name, 0, mask);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (err)
 | 
						if (err)
 | 
				
			||||||
		goto err_free_inst;
 | 
							goto err_free_inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cipher_alg = crypto_lskcipher_spawn_alg(spawn);
 | 
						cipher_alg = crypto_lskcipher_spawn_alg(spawn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = crypto_inst_setname(lskcipher_crypto_instance(inst), tmpl->name,
 | 
						err = crypto_inst_setname(lskcipher_crypto_instance(inst), tmpl->name,
 | 
				
			||||||
| 
						 | 
					@ -560,10 +580,37 @@ struct lskcipher_instance *lskcipher_alloc_instance_simple(
 | 
				
			||||||
	if (err)
 | 
						if (err)
 | 
				
			||||||
		goto err_free_inst;
 | 
							goto err_free_inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Don't allow nesting. */
 | 
						if (ecb_name[0]) {
 | 
				
			||||||
	err = -ELOOP;
 | 
							int len;
 | 
				
			||||||
	if ((cipher_alg->co.base.cra_flags & CRYPTO_ALG_INSTANCE))
 | 
					
 | 
				
			||||||
		goto err_free_inst;
 | 
							len = strscpy(ecb_name, &cipher_alg->co.base.cra_name[4],
 | 
				
			||||||
 | 
								      sizeof(ecb_name));
 | 
				
			||||||
 | 
							if (len < 2)
 | 
				
			||||||
 | 
								goto err_free_inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (ecb_name[len - 1] != ')')
 | 
				
			||||||
 | 
								goto err_free_inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ecb_name[len - 1] = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = -ENAMETOOLONG;
 | 
				
			||||||
 | 
							if (snprintf(inst->alg.co.base.cra_name, CRYPTO_MAX_ALG_NAME,
 | 
				
			||||||
 | 
								     "%s(%s)", tmpl->name, ecb_name) >=
 | 
				
			||||||
 | 
							    CRYPTO_MAX_ALG_NAME)
 | 
				
			||||||
 | 
								goto err_free_inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (strcmp(ecb_name, cipher_name) &&
 | 
				
			||||||
 | 
							    snprintf(inst->alg.co.base.cra_driver_name,
 | 
				
			||||||
 | 
								     CRYPTO_MAX_ALG_NAME,
 | 
				
			||||||
 | 
								     "%s(%s)", tmpl->name, cipher_name) >=
 | 
				
			||||||
 | 
							    CRYPTO_MAX_ALG_NAME)
 | 
				
			||||||
 | 
								goto err_free_inst;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							/* Don't allow nesting. */
 | 
				
			||||||
 | 
							err = -ELOOP;
 | 
				
			||||||
 | 
							if ((cipher_alg->co.base.cra_flags & CRYPTO_ALG_INSTANCE))
 | 
				
			||||||
 | 
								goto err_free_inst;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = -EINVAL;
 | 
						err = -EINVAL;
 | 
				
			||||||
	if (cipher_alg->co.ivsize)
 | 
						if (cipher_alg->co.ivsize)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue