Skip to content

Commit d2c2a85

Browse files
marcelocerriherbertx
authored andcommitted
crypto: ctr - Propagate NEED_FALLBACK bit
When requesting a fallback algorithm, we should propagate the NEED_FALLBACK bit when search for the underlying algorithm. This will prevents drivers from allocating unnecessary fallbacks that are never called. For instance, currently the vmx-crypto driver will use the following chain of calls when calling the fallback implementation: p8_aes_ctr -> ctr(p8_aes) -> aes-generic However p8_aes will always delegate its calls to aes-generic. With this patch, p8_aes_ctr will be able to use ctr(aes-generic) directly as its fallback. The same applies to aes_s390. Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent e6c2e65 commit d2c2a85

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎crypto/ctr.c‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,24 @@ static void crypto_ctr_exit_tfm(struct crypto_tfm *tfm)
181181
static struct crypto_instance *crypto_ctr_alloc(struct rtattr **tb)
182182
{
183183
struct crypto_instance *inst;
184+
struct crypto_attr_type *algt;
184185
struct crypto_alg *alg;
186+
u32 mask;
185187
int err;
186188

187189
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
188190
if (err)
189191
return ERR_PTR(err);
190192

191-
alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
192-
CRYPTO_ALG_TYPE_MASK);
193+
algt = crypto_get_attr_type(tb);
194+
if (IS_ERR(algt))
195+
return ERR_CAST(algt);
196+
197+
mask = CRYPTO_ALG_TYPE_MASK |
198+
crypto_requires_off(algt->type, algt->mask,
199+
CRYPTO_ALG_NEED_FALLBACK);
200+
201+
alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER, mask);
193202
if (IS_ERR(alg))
194203
return ERR_CAST(alg);
195204

@@ -350,6 +359,8 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
350359
struct skcipher_alg *alg;
351360
struct crypto_skcipher_spawn *spawn;
352361
const char *cipher_name;
362+
u32 mask;
363+
353364
int err;
354365

355366
algt = crypto_get_attr_type(tb);
@@ -367,12 +378,14 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
367378
if (!inst)
368379
return -ENOMEM;
369380

381+
mask = crypto_requires_sync(algt->type, algt->mask) |
382+
crypto_requires_off(algt->type, algt->mask,
383+
CRYPTO_ALG_NEED_FALLBACK);
384+
370385
spawn = skcipher_instance_ctx(inst);
371386

372387
crypto_set_skcipher_spawn(spawn, skcipher_crypto_instance(inst));
373-
err = crypto_grab_skcipher(spawn, cipher_name, 0,
374-
crypto_requires_sync(algt->type,
375-
algt->mask));
388+
err = crypto_grab_skcipher(spawn, cipher_name, 0, mask);
376389
if (err)
377390
goto err_free_inst;
378391

0 commit comments

Comments
 (0)