Skip to content

Commit 827733a

Browse files
author
Eric Biggers
committed
crypto: sha1 - Implement export_core() and import_core()
Since commit 9d7a0ab ("crypto: ahash - Handle partial blocks in API"), the recently-added export_core() and import_core() methods in struct shash_alg have effectively become mandatory (even though it is not tested or enforced), since legacy drivers that need a fallback depend on them. Make crypto/sha1.c compatible with these legacy drivers by adding export_core() and import_core() methods to it. Reported-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Reported-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com> Closes: https://lore.kernel.org/r/aLSnCc9Ws5L9y+8X@gcabiddu-mobl.ger.corp.intel.com Fixes: b10a74a ("crypto: sha1 - Use same state format as legacy drivers") Tested-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Tested-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com> Link: https://lore.kernel.org/r/20250901165013.48649-2-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent fd7e5de commit 827733a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

crypto/sha1.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ static int __crypto_sha1_import(struct sha1_ctx *ctx, const void *in)
4949
return 0;
5050
}
5151

52+
static int __crypto_sha1_export_core(const struct sha1_ctx *ctx, void *out)
53+
{
54+
memcpy(out, ctx, offsetof(struct sha1_ctx, buf));
55+
return 0;
56+
}
57+
58+
static int __crypto_sha1_import_core(struct sha1_ctx *ctx, const void *in)
59+
{
60+
memcpy(ctx, in, offsetof(struct sha1_ctx, buf));
61+
return 0;
62+
}
63+
5264
const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE] = {
5365
0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
5466
0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
@@ -94,6 +106,16 @@ static int crypto_sha1_import(struct shash_desc *desc, const void *in)
94106
return __crypto_sha1_import(SHA1_CTX(desc), in);
95107
}
96108

109+
static int crypto_sha1_export_core(struct shash_desc *desc, void *out)
110+
{
111+
return __crypto_sha1_export_core(SHA1_CTX(desc), out);
112+
}
113+
114+
static int crypto_sha1_import_core(struct shash_desc *desc, const void *in)
115+
{
116+
return __crypto_sha1_import_core(SHA1_CTX(desc), in);
117+
}
118+
97119
#define HMAC_SHA1_KEY(tfm) ((struct hmac_sha1_key *)crypto_shash_ctx(tfm))
98120
#define HMAC_SHA1_CTX(desc) ((struct hmac_sha1_ctx *)shash_desc_ctx(desc))
99121

@@ -143,6 +165,19 @@ static int crypto_hmac_sha1_import(struct shash_desc *desc, const void *in)
143165
return __crypto_sha1_import(&ctx->sha_ctx, in);
144166
}
145167

168+
static int crypto_hmac_sha1_export_core(struct shash_desc *desc, void *out)
169+
{
170+
return __crypto_sha1_export_core(&HMAC_SHA1_CTX(desc)->sha_ctx, out);
171+
}
172+
173+
static int crypto_hmac_sha1_import_core(struct shash_desc *desc, const void *in)
174+
{
175+
struct hmac_sha1_ctx *ctx = HMAC_SHA1_CTX(desc);
176+
177+
ctx->ostate = HMAC_SHA1_KEY(desc->tfm)->ostate;
178+
return __crypto_sha1_import_core(&ctx->sha_ctx, in);
179+
}
180+
146181
static struct shash_alg algs[] = {
147182
{
148183
.base.cra_name = "sha1",
@@ -157,6 +192,8 @@ static struct shash_alg algs[] = {
157192
.digest = crypto_sha1_digest,
158193
.export = crypto_sha1_export,
159194
.import = crypto_sha1_import,
195+
.export_core = crypto_sha1_export_core,
196+
.import_core = crypto_sha1_import_core,
160197
.descsize = sizeof(struct sha1_ctx),
161198
.statesize = SHA1_SHASH_STATE_SIZE,
162199
},
@@ -175,6 +212,8 @@ static struct shash_alg algs[] = {
175212
.digest = crypto_hmac_sha1_digest,
176213
.export = crypto_hmac_sha1_export,
177214
.import = crypto_hmac_sha1_import,
215+
.export_core = crypto_hmac_sha1_export_core,
216+
.import_core = crypto_hmac_sha1_import_core,
178217
.descsize = sizeof(struct hmac_sha1_ctx),
179218
.statesize = SHA1_SHASH_STATE_SIZE,
180219
},

0 commit comments

Comments
 (0)