Message ID | 1570695707-46528-1-git-send-email-wangzhou1@hisilicon.com |
---|---|
State | New |
Headers | show |
Series | crypto: zlib-deflate - add zlib-deflate test case in tcrypt | expand |
On 2019/10/10 16:21, Zhou Wang wrote: > As a type CRYPTO_ALG_TYPE_ACOMPRESS is needed to trigger crypto acomp test, > we introduce a new help function tcrypto_test_extend to pass type and mask > to alg_test. > > Then tcrypto module can be used to do basic acomp test by: > insmod tcrypto.ko alg="zlib-deflate" mode=55 type=10 > > Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com> > --- > crypto/tcrypt.c | 19 ++++++++++++++++++- > 1 file changed, 18 insertions(+), 1 deletion(-) > > diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c > index 83ad0b1..6ad821c 100644 > --- a/crypto/tcrypt.c > +++ b/crypto/tcrypt.c > @@ -72,7 +72,7 @@ static char *check[] = { > "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", > "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", > "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384", > - "sha3-512", "streebog256", "streebog512", > + "sha3-512", "streebog256", "streebog512", "zlib-deflate", > NULL > }; > > @@ -1657,6 +1657,19 @@ static inline int tcrypt_test(const char *alg) > return ret; > } > > +static inline int tcrypt_test_extend(const char *alg, u32 type, u32 mask) > +{ > + int ret; > + > + pr_debug("testing %s\n", alg); > + > + ret = alg_test(alg, alg, type, mask); > + /* non-fips algs return -EINVAL in fips mode */ > + if (fips_enabled && ret == -EINVAL) > + ret = 0; > + return ret; > +} > + > static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) > { > int i; > @@ -1919,6 +1932,10 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) > ret += tcrypt_test("streebog512"); > break; > > + case 55: > + ret += tcrypt_test_extend("zlib-deflate", type, mask); > + break; > + > case 100: > ret += tcrypt_test("hmac(md5)"); > break; > Any feedback about this patch? Best, Zhou
On Thu, Oct 10, 2019 at 04:21:47PM +0800, Zhou Wang wrote: > As a type CRYPTO_ALG_TYPE_ACOMPRESS is needed to trigger crypto acomp test, > we introduce a new help function tcrypto_test_extend to pass type and mask > to alg_test. > > Then tcrypto module can be used to do basic acomp test by: > insmod tcrypto.ko alg="zlib-deflate" mode=55 type=10 > > Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com> > --- > crypto/tcrypt.c | 19 ++++++++++++++++++- > 1 file changed, 18 insertions(+), 1 deletion(-) > > diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c > index 83ad0b1..6ad821c 100644 > --- a/crypto/tcrypt.c > +++ b/crypto/tcrypt.c > @@ -72,7 +72,7 @@ static char *check[] = { > "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", > "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", > "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384", > - "sha3-512", "streebog256", "streebog512", > + "sha3-512", "streebog256", "streebog512", "zlib-deflate", > NULL > }; > > @@ -1657,6 +1657,19 @@ static inline int tcrypt_test(const char *alg) > return ret; > } > > +static inline int tcrypt_test_extend(const char *alg, u32 type, u32 mask) > +{ > + int ret; > + > + pr_debug("testing %s\n", alg); > + > + ret = alg_test(alg, alg, type, mask); > + /* non-fips algs return -EINVAL in fips mode */ > + if (fips_enabled && ret == -EINVAL) > + ret = 0; > + return ret; > +} > + > static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) > { > int i; > @@ -1919,6 +1932,10 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) > ret += tcrypt_test("streebog512"); > break; > > + case 55: > + ret += tcrypt_test_extend("zlib-deflate", type, mask); > + break; > + Is this really needed? When you do modprobe tcrypt alg="zlib-deflate" type=10 mask=15 It should cause zlib-defalte to be registered as acomp and therefore tested automatically. 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
On 2019/10/18 15:14, Herbert Xu wrote: > On Thu, Oct 10, 2019 at 04:21:47PM +0800, Zhou Wang wrote: >> As a type CRYPTO_ALG_TYPE_ACOMPRESS is needed to trigger crypto acomp test, >> we introduce a new help function tcrypto_test_extend to pass type and mask >> to alg_test. >> >> Then tcrypto module can be used to do basic acomp test by: >> insmod tcrypto.ko alg="zlib-deflate" mode=55 type=10 >> >> Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com> >> --- >> crypto/tcrypt.c | 19 ++++++++++++++++++- >> 1 file changed, 18 insertions(+), 1 deletion(-) >> >> diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c >> index 83ad0b1..6ad821c 100644 >> --- a/crypto/tcrypt.c >> +++ b/crypto/tcrypt.c >> @@ -72,7 +72,7 @@ static char *check[] = { >> "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", >> "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", >> "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384", >> - "sha3-512", "streebog256", "streebog512", >> + "sha3-512", "streebog256", "streebog512", "zlib-deflate", >> NULL >> }; >> >> @@ -1657,6 +1657,19 @@ static inline int tcrypt_test(const char *alg) >> return ret; >> } >> >> +static inline int tcrypt_test_extend(const char *alg, u32 type, u32 mask) >> +{ >> + int ret; >> + >> + pr_debug("testing %s\n", alg); >> + >> + ret = alg_test(alg, alg, type, mask); >> + /* non-fips algs return -EINVAL in fips mode */ >> + if (fips_enabled && ret == -EINVAL) >> + ret = 0; >> + return ret; >> +} >> + >> static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) >> { >> int i; >> @@ -1919,6 +1932,10 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) >> ret += tcrypt_test("streebog512"); >> break; >> >> + case 55: >> + ret += tcrypt_test_extend("zlib-deflate", type, mask); >> + break; >> + > > Is this really needed? When you do > > modprobe tcrypt alg="zlib-deflate" type=10 mask=15 > > It should cause zlib-defalte to be registered as acomp and therefore > tested automatically. seems it can not work, when I run insmod tcrypt.ko alg="zlib-deflate" type=10 mask=15 I got: insmod: can't insert 'tcrypt.ko': Resource temporarily unavailable crypto_has_alg in case 0 in do_test does find "zlib-deflate", however, it breaks and do nothing about test. Best, Zhou > > Cheers, >
On Mon, Oct 21, 2019 at 12:00:00PM +0800, Zhou Wang wrote: > > seems it can not work, when I run insmod tcrypt.ko alg="zlib-deflate" type=10 mask=15 > I got: insmod: can't insert 'tcrypt.ko': Resource temporarily unavailable This error is intentional. This is so that you can test again without having to unload the module. > crypto_has_alg in case 0 in do_test does find "zlib-deflate", however, it breaks and > do nothing about test. It doesn't have to do anything. As long as it causes the algorithm to be registered the crypto API will test it automatically. So after doing the modprobe, can you find the algorithm in /proc/crypto and if so what does its test status say? 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
On 2019/10/21 13:45, Herbert Xu wrote: > On Mon, Oct 21, 2019 at 12:00:00PM +0800, Zhou Wang wrote: >> >> seems it can not work, when I run insmod tcrypt.ko alg="zlib-deflate" type=10 mask=15 >> I got: insmod: can't insert 'tcrypt.ko': Resource temporarily unavailable > > This error is intentional. This is so that you can test again > without having to unload the module. Yes. > >> crypto_has_alg in case 0 in do_test does find "zlib-deflate", however, it breaks and >> do nothing about test. > > It doesn't have to do anything. As long as it causes the algorithm > to be registered the crypto API will test it automatically. So > after doing the modprobe, can you find the algorithm in /proc/crypto > and if so what does its test status say? I made CRYPTO_MANAGER_DISABLE_TESTS=n and CRYPTO_TEST=m. After loading hisi_qm and hisi_zip modules, I got: [ 138.232605] hisi_zip 0000:75:00.0: Adding to iommu group 40 [ 138.239325] hisi_zip 0000:75:00.0: enabling device (0000 -> 0002) [ 138.245896] hisi_zip 0000:b5:00.0: Adding to iommu group 41 [ 138.252435] hisi_zip 0000:b5:00.0: enabling device (0000 -> 0002) [ 138.260393] alg: No test for gzip (hisi-gzip-acomp) This is OK: as the test of zlib-deflate of hisi_zip was successful, so it was quiet, as there is no test case for gzip, so it printed above message. cat /proc/crypto, I got: name : gzip driver : hisi-gzip-acomp module : hisi_zip priority : 300 refcnt : 1 selftest : passed internal : no type : acomp name : zlib-deflate driver : hisi-zlib-acomp module : hisi_zip priority : 300 refcnt : 1 selftest : passed internal : no type : acomp [...] However, seems we can not trigger a test by loading tcrypto. Do you mean as crypto_has_alg can detect if an alg has already been tested, so it directly breaks in the case 0 in do test in tcrypto? Best, Zhou > > Cheers, >
On Mon, Oct 21, 2019 at 04:45:14PM +0800, Zhou Wang wrote: > > I made CRYPTO_MANAGER_DISABLE_TESTS=n and CRYPTO_TEST=m. After loading > hisi_qm and hisi_zip modules, I got: > > [ 138.232605] hisi_zip 0000:75:00.0: Adding to iommu group 40 > [ 138.239325] hisi_zip 0000:75:00.0: enabling device (0000 -> 0002) > [ 138.245896] hisi_zip 0000:b5:00.0: Adding to iommu group 41 > [ 138.252435] hisi_zip 0000:b5:00.0: enabling device (0000 -> 0002) > [ 138.260393] alg: No test for gzip (hisi-gzip-acomp) > > This is OK: as the test of zlib-deflate of hisi_zip was successful, so > it was quiet, as there is no test case for gzip, so it printed above message. > > cat /proc/crypto, I got: > name : gzip > driver : hisi-gzip-acomp > module : hisi_zip > priority : 300 > refcnt : 1 > selftest : passed > internal : no > type : acomp > > name : zlib-deflate > driver : hisi-zlib-acomp > module : hisi_zip > priority : 300 > refcnt : 1 > selftest : passed > internal : no > type : acomp > [...] > > However, seems we can not trigger a test by loading tcrypto. The test has already been carried out when the algorithm is registered. Testing twice doesn't change anything. To trigger a new test, unload the algorithm and then run tcrypt again. > Do you mean as crypto_has_alg can detect if an alg has already > been tested, so it directly breaks in the case 0 in do test in tcrypto? As I said, tests are always carried out at registration time so by triggering the registration tcrypt knows that the test would have already occured. In fact this tcrypt code exists only for legacy reasons. You can also trigger the registration directly by loading your modules or for templates use crconf. 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
On 2019/10/22 14:15, Herbert Xu wrote: > On Mon, Oct 21, 2019 at 04:45:14PM +0800, Zhou Wang wrote: >> >> I made CRYPTO_MANAGER_DISABLE_TESTS=n and CRYPTO_TEST=m. After loading >> hisi_qm and hisi_zip modules, I got: >> >> [ 138.232605] hisi_zip 0000:75:00.0: Adding to iommu group 40 >> [ 138.239325] hisi_zip 0000:75:00.0: enabling device (0000 -> 0002) >> [ 138.245896] hisi_zip 0000:b5:00.0: Adding to iommu group 41 >> [ 138.252435] hisi_zip 0000:b5:00.0: enabling device (0000 -> 0002) >> [ 138.260393] alg: No test for gzip (hisi-gzip-acomp) >> >> This is OK: as the test of zlib-deflate of hisi_zip was successful, so >> it was quiet, as there is no test case for gzip, so it printed above message. >> >> cat /proc/crypto, I got: >> name : gzip >> driver : hisi-gzip-acomp >> module : hisi_zip >> priority : 300 >> refcnt : 1 >> selftest : passed >> internal : no >> type : acomp >> >> name : zlib-deflate >> driver : hisi-zlib-acomp >> module : hisi_zip >> priority : 300 >> refcnt : 1 >> selftest : passed >> internal : no >> type : acomp >> [...] >> >> However, seems we can not trigger a test by loading tcrypto. > > The test has already been carried out when the algorithm is > registered. Testing twice doesn't change anything. To trigger > a new test, unload the algorithm and then run tcrypt again. > >> Do you mean as crypto_has_alg can detect if an alg has already >> been tested, so it directly breaks in the case 0 in do test in tcrypto? > > As I said, tests are always carried out at registration time so > by triggering the registration tcrypt knows that the test would > have already occured. > > In fact this tcrypt code exists only for legacy reasons. You can > also trigger the registration directly by loading your modules or > for templates use crconf. I got it, thanks for your explanation. Will stop to do this. Best, Zhou > > Cheers, >
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 83ad0b1..6ad821c 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -72,7 +72,7 @@ static char *check[] = { "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384", - "sha3-512", "streebog256", "streebog512", + "sha3-512", "streebog256", "streebog512", "zlib-deflate", NULL }; @@ -1657,6 +1657,19 @@ static inline int tcrypt_test(const char *alg) return ret; } +static inline int tcrypt_test_extend(const char *alg, u32 type, u32 mask) +{ + int ret; + + pr_debug("testing %s\n", alg); + + ret = alg_test(alg, alg, type, mask); + /* non-fips algs return -EINVAL in fips mode */ + if (fips_enabled && ret == -EINVAL) + ret = 0; + return ret; +} + static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) { int i; @@ -1919,6 +1932,10 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) ret += tcrypt_test("streebog512"); break; + case 55: + ret += tcrypt_test_extend("zlib-deflate", type, mask); + break; + case 100: ret += tcrypt_test("hmac(md5)"); break;
As a type CRYPTO_ALG_TYPE_ACOMPRESS is needed to trigger crypto acomp test, we introduce a new help function tcrypto_test_extend to pass type and mask to alg_test. Then tcrypto module can be used to do basic acomp test by: insmod tcrypto.ko alg="zlib-deflate" mode=55 type=10 Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com> --- crypto/tcrypt.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) -- 2.8.1