* [PATCH] crypto: arm64: CE: implement export/import
@ 2020-02-19 16:00 ` Corentin Labbe
0 siblings, 0 replies; 6+ messages in thread
From: Corentin Labbe @ 2020-02-19 16:00 UTC (permalink / raw)
To: catalin.marinas, davem, herbert, will
Cc: linux-arm-kernel, linux-crypto, linux-kernel, linux-sunxi,
Corentin Labbe
When an ahash algorithm fallback to another ahash and that fallback is
shaXXX-CE, doing export/import lead to error like this:
alg: ahash: sha1-sun8i-ce export() overran state buffer on test vector 0, cfg=\"import/export\"
This is due to the descsize of shaxxx-ce larger than struct shaxxx_state off by an u32.
For fixing this, let's implement export/import which rip the finalize
variant instead of using generic export/import.
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
arch/arm64/crypto/sha1-ce-glue.c | 20 ++++++++++++++++++++
arch/arm64/crypto/sha2-ce-glue.c | 23 +++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
index 63c875d3314b..dc44d48415cd 100644
--- a/arch/arm64/crypto/sha1-ce-glue.c
+++ b/arch/arm64/crypto/sha1-ce-glue.c
@@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out)
return sha1_base_finish(desc, out);
}
+static int sha1_ce_export(struct shash_desc *desc, void *out)
+{
+ struct sha1_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(out, sctx, sizeof(struct sha1_state));
+ return 0;
+}
+
+static int sha1_ce_import(struct shash_desc *desc, const void *in)
+{
+ struct sha1_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(sctx, in, sizeof(struct sha1_state));
+ sctx->finalize = 0;
+ return 0;
+}
+
static struct shash_alg alg = {
.init = sha1_base_init,
.update = sha1_ce_update,
.final = sha1_ce_final,
.finup = sha1_ce_finup,
+ .import = sha1_ce_import,
+ .export = sha1_ce_export,
.descsize = sizeof(struct sha1_ce_state),
+ .statesize = sizeof(struct sha1_state),
.digestsize = SHA1_DIGEST_SIZE,
.base = {
.cra_name = "sha1",
diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c
index a8e67bafba3d..f986d4a323b3 100644
--- a/arch/arm64/crypto/sha2-ce-glue.c
+++ b/arch/arm64/crypto/sha2-ce-glue.c
@@ -109,12 +109,32 @@ static int sha256_ce_final(struct shash_desc *desc, u8 *out)
return sha256_base_finish(desc, out);
}
+static int sha256_ce_export(struct shash_desc *desc, void *out)
+{
+ struct sha256_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(out, sctx, sizeof(struct sha256_state));
+ return 0;
+}
+
+static int sha256_ce_import(struct shash_desc *desc, const void *in)
+{
+ struct sha256_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(sctx, in, sizeof(struct sha256_state));
+ sctx->finalize = 0;
+ return 0;
+}
+
static struct shash_alg algs[] = { {
.init = sha224_base_init,
.update = sha256_ce_update,
.final = sha256_ce_final,
.finup = sha256_ce_finup,
+ .export = sha256_ce_export,
+ .import = sha256_ce_import,
.descsize = sizeof(struct sha256_ce_state),
+ .statesize = sizeof(struct sha256_state),
.digestsize = SHA224_DIGEST_SIZE,
.base = {
.cra_name = "sha224",
@@ -128,7 +148,10 @@ static struct shash_alg algs[] = { {
.update = sha256_ce_update,
.final = sha256_ce_final,
.finup = sha256_ce_finup,
+ .export = sha256_ce_export,
+ .import = sha256_ce_import,
.descsize = sizeof(struct sha256_ce_state),
+ .statesize = sizeof(struct sha256_state),
.digestsize = SHA256_DIGEST_SIZE,
.base = {
.cra_name = "sha256",
--
2.24.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] crypto: arm64: CE: implement export/import
@ 2020-02-19 16:00 ` Corentin Labbe
0 siblings, 0 replies; 6+ messages in thread
From: Corentin Labbe @ 2020-02-19 16:00 UTC (permalink / raw)
To: catalin.marinas, davem, herbert, will
Cc: Corentin Labbe, linux-sunxi, linux-crypto, linux-arm-kernel,
linux-kernel
When an ahash algorithm fallback to another ahash and that fallback is
shaXXX-CE, doing export/import lead to error like this:
alg: ahash: sha1-sun8i-ce export() overran state buffer on test vector 0, cfg=\"import/export\"
This is due to the descsize of shaxxx-ce larger than struct shaxxx_state off by an u32.
For fixing this, let's implement export/import which rip the finalize
variant instead of using generic export/import.
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
arch/arm64/crypto/sha1-ce-glue.c | 20 ++++++++++++++++++++
arch/arm64/crypto/sha2-ce-glue.c | 23 +++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
index 63c875d3314b..dc44d48415cd 100644
--- a/arch/arm64/crypto/sha1-ce-glue.c
+++ b/arch/arm64/crypto/sha1-ce-glue.c
@@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out)
return sha1_base_finish(desc, out);
}
+static int sha1_ce_export(struct shash_desc *desc, void *out)
+{
+ struct sha1_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(out, sctx, sizeof(struct sha1_state));
+ return 0;
+}
+
+static int sha1_ce_import(struct shash_desc *desc, const void *in)
+{
+ struct sha1_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(sctx, in, sizeof(struct sha1_state));
+ sctx->finalize = 0;
+ return 0;
+}
+
static struct shash_alg alg = {
.init = sha1_base_init,
.update = sha1_ce_update,
.final = sha1_ce_final,
.finup = sha1_ce_finup,
+ .import = sha1_ce_import,
+ .export = sha1_ce_export,
.descsize = sizeof(struct sha1_ce_state),
+ .statesize = sizeof(struct sha1_state),
.digestsize = SHA1_DIGEST_SIZE,
.base = {
.cra_name = "sha1",
diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c
index a8e67bafba3d..f986d4a323b3 100644
--- a/arch/arm64/crypto/sha2-ce-glue.c
+++ b/arch/arm64/crypto/sha2-ce-glue.c
@@ -109,12 +109,32 @@ static int sha256_ce_final(struct shash_desc *desc, u8 *out)
return sha256_base_finish(desc, out);
}
+static int sha256_ce_export(struct shash_desc *desc, void *out)
+{
+ struct sha256_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(out, sctx, sizeof(struct sha256_state));
+ return 0;
+}
+
+static int sha256_ce_import(struct shash_desc *desc, const void *in)
+{
+ struct sha256_ce_state *sctx = shash_desc_ctx(desc);
+
+ memcpy(sctx, in, sizeof(struct sha256_state));
+ sctx->finalize = 0;
+ return 0;
+}
+
static struct shash_alg algs[] = { {
.init = sha224_base_init,
.update = sha256_ce_update,
.final = sha256_ce_final,
.finup = sha256_ce_finup,
+ .export = sha256_ce_export,
+ .import = sha256_ce_import,
.descsize = sizeof(struct sha256_ce_state),
+ .statesize = sizeof(struct sha256_state),
.digestsize = SHA224_DIGEST_SIZE,
.base = {
.cra_name = "sha224",
@@ -128,7 +148,10 @@ static struct shash_alg algs[] = { {
.update = sha256_ce_update,
.final = sha256_ce_final,
.finup = sha256_ce_finup,
+ .export = sha256_ce_export,
+ .import = sha256_ce_import,
.descsize = sizeof(struct sha256_ce_state),
+ .statesize = sizeof(struct sha256_state),
.digestsize = SHA256_DIGEST_SIZE,
.base = {
.cra_name = "sha256",
--
2.24.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: arm64: CE: implement export/import
2020-02-19 16:00 ` Corentin Labbe
@ 2020-02-19 18:16 ` Eric Biggers
-1 siblings, 0 replies; 6+ messages in thread
From: Eric Biggers @ 2020-02-19 18:16 UTC (permalink / raw)
To: Corentin Labbe
Cc: catalin.marinas, davem, herbert, will, linux-arm-kernel,
linux-crypto, linux-kernel, linux-sunxi
On Wed, Feb 19, 2020 at 04:00:37PM +0000, Corentin Labbe wrote:
> When an ahash algorithm fallback to another ahash and that fallback is
> shaXXX-CE, doing export/import lead to error like this:
> alg: ahash: sha1-sun8i-ce export() overran state buffer on test vector 0, cfg=\"import/export\"
>
> This is due to the descsize of shaxxx-ce larger than struct shaxxx_state off by an u32.
> For fixing this, let's implement export/import which rip the finalize
> variant instead of using generic export/import.
>
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
> arch/arm64/crypto/sha1-ce-glue.c | 20 ++++++++++++++++++++
> arch/arm64/crypto/sha2-ce-glue.c | 23 +++++++++++++++++++++++
> 2 files changed, 43 insertions(+)
>
> diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
> index 63c875d3314b..dc44d48415cd 100644
> --- a/arch/arm64/crypto/sha1-ce-glue.c
> +++ b/arch/arm64/crypto/sha1-ce-glue.c
> @@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out)
> return sha1_base_finish(desc, out);
> }
>
> +static int sha1_ce_export(struct shash_desc *desc, void *out)
> +{
> + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> +
> + memcpy(out, sctx, sizeof(struct sha1_state));
> + return 0;
> +}
> +
> +static int sha1_ce_import(struct shash_desc *desc, const void *in)
> +{
> + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> +
> + memcpy(sctx, in, sizeof(struct sha1_state));
> + sctx->finalize = 0;
> + return 0;
> +}
Can you use '&sctx->sst' instead of 'sctx' so that we aren't relying on the
'struct sha1_state' being located at the beginning of the struct?
Likewise for SHA-2.
- Eric
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: arm64: CE: implement export/import
@ 2020-02-19 18:16 ` Eric Biggers
0 siblings, 0 replies; 6+ messages in thread
From: Eric Biggers @ 2020-02-19 18:16 UTC (permalink / raw)
To: Corentin Labbe
Cc: herbert, catalin.marinas, linux-kernel, linux-sunxi,
linux-crypto, will, davem, linux-arm-kernel
On Wed, Feb 19, 2020 at 04:00:37PM +0000, Corentin Labbe wrote:
> When an ahash algorithm fallback to another ahash and that fallback is
> shaXXX-CE, doing export/import lead to error like this:
> alg: ahash: sha1-sun8i-ce export() overran state buffer on test vector 0, cfg=\"import/export\"
>
> This is due to the descsize of shaxxx-ce larger than struct shaxxx_state off by an u32.
> For fixing this, let's implement export/import which rip the finalize
> variant instead of using generic export/import.
>
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
> arch/arm64/crypto/sha1-ce-glue.c | 20 ++++++++++++++++++++
> arch/arm64/crypto/sha2-ce-glue.c | 23 +++++++++++++++++++++++
> 2 files changed, 43 insertions(+)
>
> diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
> index 63c875d3314b..dc44d48415cd 100644
> --- a/arch/arm64/crypto/sha1-ce-glue.c
> +++ b/arch/arm64/crypto/sha1-ce-glue.c
> @@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out)
> return sha1_base_finish(desc, out);
> }
>
> +static int sha1_ce_export(struct shash_desc *desc, void *out)
> +{
> + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> +
> + memcpy(out, sctx, sizeof(struct sha1_state));
> + return 0;
> +}
> +
> +static int sha1_ce_import(struct shash_desc *desc, const void *in)
> +{
> + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> +
> + memcpy(sctx, in, sizeof(struct sha1_state));
> + sctx->finalize = 0;
> + return 0;
> +}
Can you use '&sctx->sst' instead of 'sctx' so that we aren't relying on the
'struct sha1_state' being located at the beginning of the struct?
Likewise for SHA-2.
- Eric
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: arm64: CE: implement export/import
2020-02-19 18:16 ` Eric Biggers
@ 2020-02-21 19:55 ` LABBE Corentin
-1 siblings, 0 replies; 6+ messages in thread
From: LABBE Corentin @ 2020-02-21 19:55 UTC (permalink / raw)
To: Eric Biggers
Cc: catalin.marinas, davem, herbert, will, linux-arm-kernel,
linux-crypto, linux-kernel, linux-sunxi
On Wed, Feb 19, 2020 at 10:16:54AM -0800, Eric Biggers wrote:
> On Wed, Feb 19, 2020 at 04:00:37PM +0000, Corentin Labbe wrote:
> > When an ahash algorithm fallback to another ahash and that fallback is
> > shaXXX-CE, doing export/import lead to error like this:
> > alg: ahash: sha1-sun8i-ce export() overran state buffer on test vector 0, cfg=\"import/export\"
> >
> > This is due to the descsize of shaxxx-ce larger than struct shaxxx_state off by an u32.
> > For fixing this, let's implement export/import which rip the finalize
> > variant instead of using generic export/import.
> >
> > Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> > ---
> > arch/arm64/crypto/sha1-ce-glue.c | 20 ++++++++++++++++++++
> > arch/arm64/crypto/sha2-ce-glue.c | 23 +++++++++++++++++++++++
> > 2 files changed, 43 insertions(+)
> >
> > diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
> > index 63c875d3314b..dc44d48415cd 100644
> > --- a/arch/arm64/crypto/sha1-ce-glue.c
> > +++ b/arch/arm64/crypto/sha1-ce-glue.c
> > @@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out)
> > return sha1_base_finish(desc, out);
> > }
> >
> > +static int sha1_ce_export(struct shash_desc *desc, void *out)
> > +{
> > + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> > +
> > + memcpy(out, sctx, sizeof(struct sha1_state));
> > + return 0;
> > +}
> > +
> > +static int sha1_ce_import(struct shash_desc *desc, const void *in)
> > +{
> > + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> > +
> > + memcpy(sctx, in, sizeof(struct sha1_state));
> > + sctx->finalize = 0;
> > + return 0;
> > +}
>
> Can you use '&sctx->sst' instead of 'sctx' so that we aren't relying on the
> 'struct sha1_state' being located at the beginning of the struct?
>
> Likewise for SHA-2.
Yes, I will do that, it is better.
thanks
Regards
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: arm64: CE: implement export/import
@ 2020-02-21 19:55 ` LABBE Corentin
0 siblings, 0 replies; 6+ messages in thread
From: LABBE Corentin @ 2020-02-21 19:55 UTC (permalink / raw)
To: Eric Biggers
Cc: herbert, catalin.marinas, linux-kernel, linux-sunxi,
linux-crypto, will, davem, linux-arm-kernel
On Wed, Feb 19, 2020 at 10:16:54AM -0800, Eric Biggers wrote:
> On Wed, Feb 19, 2020 at 04:00:37PM +0000, Corentin Labbe wrote:
> > When an ahash algorithm fallback to another ahash and that fallback is
> > shaXXX-CE, doing export/import lead to error like this:
> > alg: ahash: sha1-sun8i-ce export() overran state buffer on test vector 0, cfg=\"import/export\"
> >
> > This is due to the descsize of shaxxx-ce larger than struct shaxxx_state off by an u32.
> > For fixing this, let's implement export/import which rip the finalize
> > variant instead of using generic export/import.
> >
> > Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> > ---
> > arch/arm64/crypto/sha1-ce-glue.c | 20 ++++++++++++++++++++
> > arch/arm64/crypto/sha2-ce-glue.c | 23 +++++++++++++++++++++++
> > 2 files changed, 43 insertions(+)
> >
> > diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
> > index 63c875d3314b..dc44d48415cd 100644
> > --- a/arch/arm64/crypto/sha1-ce-glue.c
> > +++ b/arch/arm64/crypto/sha1-ce-glue.c
> > @@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out)
> > return sha1_base_finish(desc, out);
> > }
> >
> > +static int sha1_ce_export(struct shash_desc *desc, void *out)
> > +{
> > + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> > +
> > + memcpy(out, sctx, sizeof(struct sha1_state));
> > + return 0;
> > +}
> > +
> > +static int sha1_ce_import(struct shash_desc *desc, const void *in)
> > +{
> > + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
> > +
> > + memcpy(sctx, in, sizeof(struct sha1_state));
> > + sctx->finalize = 0;
> > + return 0;
> > +}
>
> Can you use '&sctx->sst' instead of 'sctx' so that we aren't relying on the
> 'struct sha1_state' being located at the beginning of the struct?
>
> Likewise for SHA-2.
Yes, I will do that, it is better.
thanks
Regards
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-02-21 19:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-19 16:00 [PATCH] crypto: arm64: CE: implement export/import Corentin Labbe
2020-02-19 16:00 ` Corentin Labbe
2020-02-19 18:16 ` Eric Biggers
2020-02-19 18:16 ` Eric Biggers
2020-02-21 19:55 ` LABBE Corentin
2020-02-21 19:55 ` LABBE Corentin
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.