linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: tcrypt - Add mode to test specified algs
@ 2017-01-18 16:25 Rabin Vincent
  2017-01-23 14:14 ` Herbert Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin Vincent @ 2017-01-18 16:25 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, Rabin Vincent

From: Rabin Vincent <rabinv@axis.com>

tcrypt offers a bunch of mode= values to test various (groups of)
algorithms, but there is no way provided to test a subset of the
algorithms.  This adds a new mode=2000 which interprets alg= as a
colon-separated list of algorithms to test with alg_test().  Colon is
used since the names may contain commas.

This is useful during driver development and also for regression testing
to avoid the errors that are otherwise generated when attempting to test
non-enabled algorithms.

 # insmod tcrypt.ko dyndbg mode=2000 alg="cbc(aes):ecb(aes):hmac(sha256):sha256:xts(aes)"
 [  649.418569] tcrypt: testing cbc(aes)
 [  649.420809] tcrypt: testing ecb(aes)
 [  649.422627] tcrypt: testing hmac(sha256)
 [  649.424861] tcrypt: testing sha256
 [  649.426368] tcrypt: testing xts(aes)
 [  649.430014] tcrypt: all tests passed

Signed-off-by: Rabin Vincent <rabinv@axis.com>
---
 crypto/tcrypt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 9a11f3c..fe5adf6 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -1021,7 +1021,7 @@ static inline int tcrypt_test(const char *alg)
 	return ret;
 }
 
-static int do_test(const char *alg, u32 type, u32 mask, int m)
+static int do_test(char *alg, u32 type, u32 mask, int m)
 {
 	int i;
 	int ret = 0;
@@ -2042,6 +2042,17 @@ static int do_test(const char *alg, u32 type, u32 mask, int m)
 	case 1000:
 		test_available();
 		break;
+
+	case 2000:
+		while (alg) {
+			char *tmp = strsep(&alg, ":");
+
+			if (!tmp || !*tmp)
+				break;
+
+			ret += tcrypt_test(tmp);
+		}
+		break;
 	}
 
 	return ret;
-- 
2.1.4

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

* Re: [PATCH] crypto: tcrypt - Add mode to test specified algs
  2017-01-18 16:25 [PATCH] crypto: tcrypt - Add mode to test specified algs Rabin Vincent
@ 2017-01-23 14:14 ` Herbert Xu
  2017-01-23 15:13   ` Rabin Vincent
  0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2017-01-23 14:14 UTC (permalink / raw)
  To: Rabin Vincent; +Cc: linux-crypto, Rabin Vincent

On Wed, Jan 18, 2017 at 05:25:00PM +0100, Rabin Vincent wrote:
> From: Rabin Vincent <rabinv@axis.com>
> 
> tcrypt offers a bunch of mode= values to test various (groups of)
> algorithms, but there is no way provided to test a subset of the
> algorithms.  This adds a new mode=2000 which interprets alg= as a
> colon-separated list of algorithms to test with alg_test().  Colon is
> used since the names may contain commas.
> 
> This is useful during driver development and also for regression testing
> to avoid the errors that are otherwise generated when attempting to test
> non-enabled algorithms.
> 
>  # insmod tcrypt.ko dyndbg mode=2000 alg="cbc(aes):ecb(aes):hmac(sha256):sha256:xts(aes)"
>  [  649.418569] tcrypt: testing cbc(aes)
>  [  649.420809] tcrypt: testing ecb(aes)
>  [  649.422627] tcrypt: testing hmac(sha256)
>  [  649.424861] tcrypt: testing sha256
>  [  649.426368] tcrypt: testing xts(aes)
>  [  649.430014] tcrypt: all tests passed
> 
> Signed-off-by: Rabin Vincent <rabinv@axis.com>

You can already do this with the existing mode=0 setting, no?

Cheers,
-- 
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] 4+ messages in thread

* Re: [PATCH] crypto: tcrypt - Add mode to test specified algs
  2017-01-23 14:14 ` Herbert Xu
@ 2017-01-23 15:13   ` Rabin Vincent
  2017-02-01 14:03     ` Herbert Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin Vincent @ 2017-01-23 15:13 UTC (permalink / raw)
  To: Herbert Xu; +Cc: linux-crypto

On Mon, Jan 23, 2017 at 10:14:03PM +0800, Herbert Xu wrote:
> On Wed, Jan 18, 2017 at 05:25:00PM +0100, Rabin Vincent wrote:
> > From: Rabin Vincent <rabinv@axis.com>
> > tcrypt offers a bunch of mode= values to test various (groups of)
> > algorithms, but there is no way provided to test a subset of the
> > algorithms.  This adds a new mode=2000 which interprets alg= as a
> > colon-separated list of algorithms to test with alg_test().  Colon is
> > used since the names may contain commas.
> > 
> > This is useful during driver development and also for regression testing
> > to avoid the errors that are otherwise generated when attempting to test
> > non-enabled algorithms.
> > 
> >  # insmod tcrypt.ko dyndbg mode=2000 alg="cbc(aes):ecb(aes):hmac(sha256):sha256:xts(aes)"
> >  [  649.418569] tcrypt: testing cbc(aes)
> >  [  649.420809] tcrypt: testing ecb(aes)
> >  [  649.422627] tcrypt: testing hmac(sha256)
> >  [  649.424861] tcrypt: testing sha256
> >  [  649.426368] tcrypt: testing xts(aes)
> >  [  649.430014] tcrypt: all tests passed
> > 
> > Signed-off-by: Rabin Vincent <rabinv@axis.com>
> 
> You can already do this with the existing mode=0 setting, no?

That's what I thought so too, but that doesn't seem to be the case.  The
mode=0 handling is this:

	switch (m) {
	case 0:
		if (alg) {
			if (!crypto_has_alg(alg, type,
					    mask ?: CRYPTO_ALG_TYPE_MASK))
				ret = -ENOENT;
			break;
		}

		for (i = 1; i < 200; i++)
			ret += do_test(NULL, 0, 0, i);
		break;

So, if alg= is specified, after first checking if the specified alg is
present, it just goes ahead and runs all the tests.  I'm not sure what
mode=0 alg=foo is meant to be used for.

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

* Re: [PATCH] crypto: tcrypt - Add mode to test specified algs
  2017-01-23 15:13   ` Rabin Vincent
@ 2017-02-01 14:03     ` Herbert Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2017-02-01 14:03 UTC (permalink / raw)
  To: Rabin Vincent; +Cc: linux-crypto

On Mon, Jan 23, 2017 at 04:13:04PM +0100, Rabin Vincent wrote:
> 
> That's what I thought so too, but that doesn't seem to be the case.  The
> mode=0 handling is this:
> 
> 	switch (m) {
> 	case 0:
> 		if (alg) {
> 			if (!crypto_has_alg(alg, type,
> 					    mask ?: CRYPTO_ALG_TYPE_MASK))
> 				ret = -ENOENT;
> 			break;
> 		}
> 
> 		for (i = 1; i < 200; i++)
> 			ret += do_test(NULL, 0, 0, i);
> 		break;
> 
> So, if alg= is specified, after first checking if the specified alg is
> present, it just goes ahead and runs all the tests.  I'm not sure what
> mode=0 alg=foo is meant to be used for.

You need to set the type and mask for it to work.

Cheers,
-- 
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] 4+ messages in thread

end of thread, other threads:[~2017-02-01 14:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-18 16:25 [PATCH] crypto: tcrypt - Add mode to test specified algs Rabin Vincent
2017-01-23 14:14 ` Herbert Xu
2017-01-23 15:13   ` Rabin Vincent
2017-02-01 14:03     ` 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).