Subject: [PATCH] crypto: acomp - search acomp with scomp backend in crypto_has_acomp

users may call crypto_has_acomp to confirm the existence of acomp before using
crypto_acomp APIs. Right now, many of acomp have scomp backend, for example,
lz4, lzo, deflate etc. crypto_has_acomp will return false for them even though
they support acomp APIs.

One possible way to make has_acomp true for them is calling this APIs like
crypto_has_acomp("xxx", CRYPTO_ALG_TYPE_SCOMPRESS, 0);
But it looks quite weird.

Signed-off-by: Barry Song <[email protected]>
---
include/crypto/acompress.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
index d873f999b334..a7170848e6c2 100644
--- a/include/crypto/acompress.h
+++ b/include/crypto/acompress.h
@@ -156,7 +156,7 @@ static inline void crypto_free_acomp(struct crypto_acomp *tfm)
static inline int crypto_has_acomp(const char *alg_name, u32 type, u32 mask)
{
type &= ~CRYPTO_ALG_TYPE_MASK;
- type |= CRYPTO_ALG_TYPE_ACOMPRESS;
+ type |= CRYPTO_ALG_TYPE_ACOMPRESS | CRYPTO_ALG_TYPE_SCOMPRESS;
mask |= CRYPTO_ALG_TYPE_MASK;

return crypto_has_alg(alg_name, type, mask);
--
2.23.0



2020-04-30 04:30:37

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: acomp - search acomp with scomp backend in crypto_has_acomp

On Thu, Apr 30, 2020 at 12:47:32PM +1200, Barry Song wrote:
>
> diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
> index d873f999b334..a7170848e6c2 100644
> --- a/include/crypto/acompress.h
> +++ b/include/crypto/acompress.h
> @@ -156,7 +156,7 @@ static inline void crypto_free_acomp(struct crypto_acomp *tfm)
> static inline int crypto_has_acomp(const char *alg_name, u32 type, u32 mask)
> {
> type &= ~CRYPTO_ALG_TYPE_MASK;
> - type |= CRYPTO_ALG_TYPE_ACOMPRESS;
> + type |= CRYPTO_ALG_TYPE_ACOMPRESS | CRYPTO_ALG_TYPE_SCOMPRESS;
> mask |= CRYPTO_ALG_TYPE_MASK;

I don't think this does what you think it does. To find both
ACOMP and SCOMP, you should keep the type as is, but change the
mask to CRYPTO_ALG_TYPE_ACOMPRESS_MASK.

Cheers,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt