All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Lionel Debieve <lionel.debieve@st.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@st.com>,
	linux-crypto@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Benjamin Gaignard <benjamin.gaignard@st.com>,
	Fabien Dessenne <fabien.dessenne@st.com>,
	Ludovic Barre <ludovic.barre@st.com>,
	linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH 1/1] crypto: testmgr - call shash_init in crc32c algo
Date: Mon, 1 Apr 2019 10:30:57 -0700	[thread overview]
Message-ID: <20190401173056.GD131675@gmail.com> (raw)
In-Reply-To: <1554123264-24243-1-git-send-email-lionel.debieve@st.com>

Hi Lionel,

On Mon, Apr 01, 2019 at 02:54:24PM +0200, Lionel Debieve wrote:
> In case of device call required in low level driver,
> the context must be initialized before calling the final
> function.
> 
> Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
> ---
>  crypto/testmgr.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/crypto/testmgr.c b/crypto/testmgr.c
> index 8386038..4a00d7c 100644
> --- a/crypto/testmgr.c
> +++ b/crypto/testmgr.c
> @@ -2181,6 +2181,13 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
>  		shash->tfm = tfm;
>  		shash->flags = 0;
>  
> +		err = crypto_shash_init(shash);
> +		if (err) {
> +			printk(KERN_ERR "alg: crc32c: init failed for "
> +			       "%s: %d\n", driver, err);
> +			break;
> +		}
> +
>  		*ctx = 420553207;
>  		err = crypto_shash_final(shash, (u8 *)&val);
>  		if (err) {
> -- 
> 2.7.4
> 

This defeats the point of the test, which is that crc32c implementations are
expected to use the same shash_desc context format and be usable by calling
crypto_shash_update() directly after initializing the context manually, without
a prior crypto_shash_init().  See for example ext4_chksum() in fs/ext4/ext4.h:

	static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
				      const void *address, unsigned int length)
	{
		struct {
			struct shash_desc shash;
			char ctx[4];
		} desc;

		BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));

		desc.shash.tfm = sbi->s_chksum_driver;
		desc.shash.flags = 0;
		*(u32 *)desc.ctx = crc;

		BUG_ON(crypto_shash_update(&desc.shash, address, length));

		return *(u32 *)desc.ctx;
	}

I think you need to fix the stm32 crc32 driver to not store anything extra in
the shash_desc context, and only use hardware during ->update().

- Eric

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: Lionel Debieve <lionel.debieve@st.com>
Cc: Benjamin Gaignard <benjamin.gaignard@st.com>,
	Alexandre Torgue <alexandre.torgue@st.com>,
	linux-kernel@vger.kernel.org,
	Fabien Dessenne <fabien.dessenne@st.com>,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-crypto@vger.kernel.org,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Ludovic Barre <ludovic.barre@st.com>,
	"David S . Miller" <davem@davemloft.net>,
	linux-arm-kernel@lists.infradead.org,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: Re: [PATCH 1/1] crypto: testmgr - call shash_init in crc32c algo
Date: Mon, 1 Apr 2019 10:30:57 -0700	[thread overview]
Message-ID: <20190401173056.GD131675@gmail.com> (raw)
In-Reply-To: <1554123264-24243-1-git-send-email-lionel.debieve@st.com>

Hi Lionel,

On Mon, Apr 01, 2019 at 02:54:24PM +0200, Lionel Debieve wrote:
> In case of device call required in low level driver,
> the context must be initialized before calling the final
> function.
> 
> Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
> ---
>  crypto/testmgr.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/crypto/testmgr.c b/crypto/testmgr.c
> index 8386038..4a00d7c 100644
> --- a/crypto/testmgr.c
> +++ b/crypto/testmgr.c
> @@ -2181,6 +2181,13 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
>  		shash->tfm = tfm;
>  		shash->flags = 0;
>  
> +		err = crypto_shash_init(shash);
> +		if (err) {
> +			printk(KERN_ERR "alg: crc32c: init failed for "
> +			       "%s: %d\n", driver, err);
> +			break;
> +		}
> +
>  		*ctx = 420553207;
>  		err = crypto_shash_final(shash, (u8 *)&val);
>  		if (err) {
> -- 
> 2.7.4
> 

This defeats the point of the test, which is that crc32c implementations are
expected to use the same shash_desc context format and be usable by calling
crypto_shash_update() directly after initializing the context manually, without
a prior crypto_shash_init().  See for example ext4_chksum() in fs/ext4/ext4.h:

	static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
				      const void *address, unsigned int length)
	{
		struct {
			struct shash_desc shash;
			char ctx[4];
		} desc;

		BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));

		desc.shash.tfm = sbi->s_chksum_driver;
		desc.shash.flags = 0;
		*(u32 *)desc.ctx = crc;

		BUG_ON(crypto_shash_update(&desc.shash, address, length));

		return *(u32 *)desc.ctx;
	}

I think you need to fix the stm32 crc32 driver to not store anything extra in
the shash_desc context, and only use hardware during ->update().

- Eric

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-04-01 17:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 12:54 [PATCH 1/1] crypto: testmgr - call shash_init in crc32c algo Lionel Debieve
2019-04-01 12:54 ` Lionel Debieve
2019-04-01 17:30 ` Eric Biggers [this message]
2019-04-01 17:30   ` Eric Biggers
     [not found]   ` <e1f694bd-e0f7-a3f4-426a-894a45c88a30@st.com>
2019-04-12  6:34     ` Lionel DEBIEVE
2019-04-12  6:34       ` Lionel DEBIEVE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190401173056.GD131675@gmail.com \
    --to=ebiggers@kernel.org \
    --cc=alexandre.torgue@st.com \
    --cc=benjamin.gaignard@st.com \
    --cc=davem@davemloft.net \
    --cc=fabien.dessenne@st.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=lionel.debieve@st.com \
    --cc=ludovic.barre@st.com \
    --cc=mcoquelin.stm32@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.