linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Propagate fallback bit for cbc and ctr
@ 2017-02-27 12:38 Marcelo Henrique Cerri
  2017-02-27 12:38 ` [PATCH v2 1/2] crypto: cbc - Propagate NEED_FALLBACK bit Marcelo Henrique Cerri
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Marcelo Henrique Cerri @ 2017-02-27 12:38 UTC (permalink / raw)
  To: Herbert Xu
  Cc: David S. Miller, linux-crypto, linux-kernel, Marcelo Henrique Cerri

Hi Hebert,

For v2:

- fixed the memory leakage in cbc.
- included crypto/algapi.h in crypto/cbc.c for crypto_requires_off();
- ERR_CAST instead PTR_ERR in ctr.
- Also propagated the fallback bit for rfc3686.

Marcelo Henrique Cerri (2):
  crypto: cbc - Propagate NEED_FALLBACK bit
  crypto: ctr - Propagate NEED_FALLBACK bit

 crypto/cbc.c | 15 +++++++++++++--
 crypto/ctr.c | 23 ++++++++++++++++++-----
 2 files changed, 31 insertions(+), 7 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] crypto: cbc - Propagate NEED_FALLBACK bit
  2017-02-27 12:38 [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Henrique Cerri
@ 2017-02-27 12:38 ` Marcelo Henrique Cerri
  2017-02-27 12:38 ` [PATCH v2 2/2] crypto: ctr " Marcelo Henrique Cerri
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Henrique Cerri @ 2017-02-27 12:38 UTC (permalink / raw)
  To: Herbert Xu
  Cc: David S. Miller, linux-crypto, linux-kernel, Marcelo Henrique Cerri

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_cbc -> cbc(p8_aes) -> aes-generic

However p8_aes will always delegate its calls to aes-generic. With this
patch, p8_aes_cbc will be able to use cbc(aes-generic) directly as its
fallback. The same applies to aes_s390.

Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
---
 crypto/cbc.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/crypto/cbc.c b/crypto/cbc.c
index bc160a3..b761b1f 100644
--- a/crypto/cbc.c
+++ b/crypto/cbc.c
@@ -10,6 +10,7 @@
  *
  */
 
+#include <crypto/algapi.h>
 #include <crypto/cbc.h>
 #include <crypto/internal/skcipher.h>
 #include <linux/err.h>
@@ -108,8 +109,10 @@ static void crypto_cbc_free(struct skcipher_instance *inst)
 static int crypto_cbc_create(struct crypto_template *tmpl, struct rtattr **tb)
 {
 	struct skcipher_instance *inst;
+	struct crypto_attr_type *algt;
 	struct crypto_spawn *spawn;
 	struct crypto_alg *alg;
+	u32 mask;
 	int err;
 
 	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER);
@@ -120,8 +123,16 @@ static int crypto_cbc_create(struct crypto_template *tmpl, struct rtattr **tb)
 	if (!inst)
 		return -ENOMEM;
 
-	alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
-				  CRYPTO_ALG_TYPE_MASK);
+	algt = crypto_get_attr_type(tb);
+	err = PTR_ERR(algt);
+	if (IS_ERR(algt))
+		goto err_free_inst;
+
+	mask = CRYPTO_ALG_TYPE_MASK |
+		crypto_requires_off(algt->type, algt->mask,
+				    CRYPTO_ALG_NEED_FALLBACK);
+
+	alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, mask);
 	err = PTR_ERR(alg);
 	if (IS_ERR(alg))
 		goto err_free_inst;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] crypto: ctr - Propagate NEED_FALLBACK bit
  2017-02-27 12:38 [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Henrique Cerri
  2017-02-27 12:38 ` [PATCH v2 1/2] crypto: cbc - Propagate NEED_FALLBACK bit Marcelo Henrique Cerri
@ 2017-02-27 12:38 ` Marcelo Henrique Cerri
  2017-03-06 12:20 ` [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Cerri
  2017-03-09 10:47 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Henrique Cerri @ 2017-02-27 12:38 UTC (permalink / raw)
  To: Herbert Xu
  Cc: David S. Miller, linux-crypto, linux-kernel, Marcelo Henrique Cerri

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>
---
 crypto/ctr.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/crypto/ctr.c b/crypto/ctr.c
index a4f4a89..477d922 100644
--- a/crypto/ctr.c
+++ b/crypto/ctr.c
@@ -181,15 +181,24 @@ static void crypto_ctr_exit_tfm(struct crypto_tfm *tfm)
 static struct crypto_instance *crypto_ctr_alloc(struct rtattr **tb)
 {
 	struct crypto_instance *inst;
+	struct crypto_attr_type *algt;
 	struct crypto_alg *alg;
+	u32 mask;
 	int err;
 
 	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
 	if (err)
 		return ERR_PTR(err);
 
-	alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
-				  CRYPTO_ALG_TYPE_MASK);
+	algt = crypto_get_attr_type(tb);
+	if (IS_ERR(algt))
+		return ERR_CAST(algt);
+
+	mask = CRYPTO_ALG_TYPE_MASK |
+		crypto_requires_off(algt->type, algt->mask,
+				    CRYPTO_ALG_NEED_FALLBACK);
+
+	alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER, mask);
 	if (IS_ERR(alg))
 		return ERR_CAST(alg);
 
@@ -350,6 +359,8 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
 	struct skcipher_alg *alg;
 	struct crypto_skcipher_spawn *spawn;
 	const char *cipher_name;
+	u32 mask;
+
 	int err;
 
 	algt = crypto_get_attr_type(tb);
@@ -367,12 +378,14 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
 	if (!inst)
 		return -ENOMEM;
 
+	mask = crypto_requires_sync(algt->type, algt->mask) |
+		crypto_requires_off(algt->type, algt->mask,
+				    CRYPTO_ALG_NEED_FALLBACK);
+
 	spawn = skcipher_instance_ctx(inst);
 
 	crypto_set_skcipher_spawn(spawn, skcipher_crypto_instance(inst));
-	err = crypto_grab_skcipher(spawn, cipher_name, 0,
-				   crypto_requires_sync(algt->type,
-							algt->mask));
+	err = crypto_grab_skcipher(spawn, cipher_name, 0, mask);
 	if (err)
 		goto err_free_inst;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] Propagate fallback bit for cbc and ctr
  2017-02-27 12:38 [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Henrique Cerri
  2017-02-27 12:38 ` [PATCH v2 1/2] crypto: cbc - Propagate NEED_FALLBACK bit Marcelo Henrique Cerri
  2017-02-27 12:38 ` [PATCH v2 2/2] crypto: ctr " Marcelo Henrique Cerri
@ 2017-03-06 12:20 ` Marcelo Cerri
  2017-03-09 10:47 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Cerri @ 2017-03-06 12:20 UTC (permalink / raw)
  To: Herbert Xu; +Cc: David S. Miller, linux-crypto, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 669 bytes --]

Hi Herbert,

Any thoughts on this?

On Mon, Feb 27, 2017 at 09:38:24AM -0300, Marcelo Henrique Cerri wrote:
> Hi Hebert,
> 
> For v2:
> 
> - fixed the memory leakage in cbc.
> - included crypto/algapi.h in crypto/cbc.c for crypto_requires_off();
> - ERR_CAST instead PTR_ERR in ctr.
> - Also propagated the fallback bit for rfc3686.
> 
> Marcelo Henrique Cerri (2):
>   crypto: cbc - Propagate NEED_FALLBACK bit
>   crypto: ctr - Propagate NEED_FALLBACK bit
> 
>  crypto/cbc.c | 15 +++++++++++++--
>  crypto/ctr.c | 23 ++++++++++++++++++-----
>  2 files changed, 31 insertions(+), 7 deletions(-)
> 
> -- 
> 2.7.4
> 

-- 
Regards,
Marcelo


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] Propagate fallback bit for cbc and ctr
  2017-02-27 12:38 [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Henrique Cerri
                   ` (2 preceding siblings ...)
  2017-03-06 12:20 ` [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Cerri
@ 2017-03-09 10:47 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2017-03-09 10:47 UTC (permalink / raw)
  To: Marcelo Henrique Cerri; +Cc: David S. Miller, linux-crypto, linux-kernel

On Mon, Feb 27, 2017 at 09:38:24AM -0300, Marcelo Henrique Cerri wrote:
> Hi Hebert,
> 
> For v2:
> 
> - fixed the memory leakage in cbc.
> - included crypto/algapi.h in crypto/cbc.c for crypto_requires_off();
> - ERR_CAST instead PTR_ERR in ctr.
> - Also propagated the fallback bit for rfc3686.
> 
> Marcelo Henrique Cerri (2):
>   crypto: cbc - Propagate NEED_FALLBACK bit
>   crypto: ctr - Propagate NEED_FALLBACK bit
> 
>  crypto/cbc.c | 15 +++++++++++++--
>  crypto/ctr.c | 23 ++++++++++++++++++-----
>  2 files changed, 31 insertions(+), 7 deletions(-)

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-03-09 10:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27 12:38 [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Henrique Cerri
2017-02-27 12:38 ` [PATCH v2 1/2] crypto: cbc - Propagate NEED_FALLBACK bit Marcelo Henrique Cerri
2017-02-27 12:38 ` [PATCH v2 2/2] crypto: ctr " Marcelo Henrique Cerri
2017-03-06 12:20 ` [PATCH v2 0/2] Propagate fallback bit for cbc and ctr Marcelo Cerri
2017-03-09 10:47 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).