Skip to content

Commit d282eee

Browse files
montjoieherbertx
authored andcommitted
crypto: arm64/sha-ce - implement export/import
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 being 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. Fixes: 6ba6c74 ("arm64/crypto: SHA-224/SHA-256 using ARMv8 Crypto Extensions") Fixes: 2c98833 ("arm64/crypto: SHA-1 using ARMv8 Crypto Extensions") Signed-off-by: Corentin Labbe <clabbe@baylibre.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 567be3a commit d282eee

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎arch/arm64/crypto/sha1-ce-glue.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out)
9191
return sha1_base_finish(desc, out);
9292
}
9393

94+
static int sha1_ce_export(struct shash_desc *desc, void *out)
95+
{
96+
struct sha1_ce_state *sctx = shash_desc_ctx(desc);
97+
98+
memcpy(out, &sctx->sst, sizeof(struct sha1_state));
99+
return 0;
100+
}
101+
102+
static int sha1_ce_import(struct shash_desc *desc, const void *in)
103+
{
104+
struct sha1_ce_state *sctx = shash_desc_ctx(desc);
105+
106+
memcpy(&sctx->sst, in, sizeof(struct sha1_state));
107+
sctx->finalize = 0;
108+
return 0;
109+
}
110+
94111
static struct shash_alg alg = {
95112
.init = sha1_base_init,
96113
.update = sha1_ce_update,
97114
.final = sha1_ce_final,
98115
.finup = sha1_ce_finup,
116+
.import = sha1_ce_import,
117+
.export = sha1_ce_export,
99118
.descsize = sizeof(struct sha1_ce_state),
119+
.statesize = sizeof(struct sha1_state),
100120
.digestsize = SHA1_DIGEST_SIZE,
101121
.base = {
102122
.cra_name = "sha1",

‎arch/arm64/crypto/sha2-ce-glue.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,32 @@ static int sha256_ce_final(struct shash_desc *desc, u8 *out)
109109
return sha256_base_finish(desc, out);
110110
}
111111

112+
static int sha256_ce_export(struct shash_desc *desc, void *out)
113+
{
114+
struct sha256_ce_state *sctx = shash_desc_ctx(desc);
115+
116+
memcpy(out, &sctx->sst, sizeof(struct sha256_state));
117+
return 0;
118+
}
119+
120+
static int sha256_ce_import(struct shash_desc *desc, const void *in)
121+
{
122+
struct sha256_ce_state *sctx = shash_desc_ctx(desc);
123+
124+
memcpy(&sctx->sst, in, sizeof(struct sha256_state));
125+
sctx->finalize = 0;
126+
return 0;
127+
}
128+
112129
static struct shash_alg algs[] = { {
113130
.init = sha224_base_init,
114131
.update = sha256_ce_update,
115132
.final = sha256_ce_final,
116133
.finup = sha256_ce_finup,
134+
.export = sha256_ce_export,
135+
.import = sha256_ce_import,
117136
.descsize = sizeof(struct sha256_ce_state),
137+
.statesize = sizeof(struct sha256_state),
118138
.digestsize = SHA224_DIGEST_SIZE,
119139
.base = {
120140
.cra_name = "sha224",
@@ -128,7 +148,10 @@ static struct shash_alg algs[] = { {
128148
.update = sha256_ce_update,
129149
.final = sha256_ce_final,
130150
.finup = sha256_ce_finup,
151+
.export = sha256_ce_export,
152+
.import = sha256_ce_import,
131153
.descsize = sizeof(struct sha256_ce_state),
154+
.statesize = sizeof(struct sha256_state),
132155
.digestsize = SHA256_DIGEST_SIZE,
133156
.base = {
134157
.cra_name = "sha256",

0 commit comments

Comments
 (0)