Skip to content

Commit 01c93aa

Browse files
committed
Merge tag 'libcrypto-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux
Pull crypto library fixes from Eric Biggers: "Fix a regression caused by my commits that reimplemented the sha1, sha256, and sha512 crypto_shash algorithms on top of the library API. Specifically, the export_core and import_core methods stopped being supported, which broke some hardware offload drivers (such as qat) that recently started depending on these for fallback functionality. Later I'd like to make these drivers just use the library API for their fallback. Then these methods won't be needed anymore. But for now, this fixes the regression for 6.17" * tag 'libcrypto-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux: crypto: sha512 - Implement export_core() and import_core() crypto: sha256 - Implement export_core() and import_core() crypto: sha1 - Implement export_core() and import_core()
2 parents 4e47e46 + cdb03b6 commit 01c93aa

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed

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
},

crypto/sha256.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ static int __crypto_sha256_import(struct __sha256_ctx *ctx, const void *in)
5050
return 0;
5151
}
5252

53+
static int __crypto_sha256_export_core(const struct __sha256_ctx *ctx,
54+
void *out)
55+
{
56+
memcpy(out, ctx, offsetof(struct __sha256_ctx, buf));
57+
return 0;
58+
}
59+
60+
static int __crypto_sha256_import_core(struct __sha256_ctx *ctx, const void *in)
61+
{
62+
memcpy(ctx, in, offsetof(struct __sha256_ctx, buf));
63+
return 0;
64+
}
65+
5366
/* SHA-224 */
5467

5568
const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE] = {
@@ -98,6 +111,16 @@ static int crypto_sha224_import(struct shash_desc *desc, const void *in)
98111
return __crypto_sha256_import(&SHA224_CTX(desc)->ctx, in);
99112
}
100113

114+
static int crypto_sha224_export_core(struct shash_desc *desc, void *out)
115+
{
116+
return __crypto_sha256_export_core(&SHA224_CTX(desc)->ctx, out);
117+
}
118+
119+
static int crypto_sha224_import_core(struct shash_desc *desc, const void *in)
120+
{
121+
return __crypto_sha256_import_core(&SHA224_CTX(desc)->ctx, in);
122+
}
123+
101124
/* SHA-256 */
102125

103126
const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE] = {
@@ -146,6 +169,16 @@ static int crypto_sha256_import(struct shash_desc *desc, const void *in)
146169
return __crypto_sha256_import(&SHA256_CTX(desc)->ctx, in);
147170
}
148171

172+
static int crypto_sha256_export_core(struct shash_desc *desc, void *out)
173+
{
174+
return __crypto_sha256_export_core(&SHA256_CTX(desc)->ctx, out);
175+
}
176+
177+
static int crypto_sha256_import_core(struct shash_desc *desc, const void *in)
178+
{
179+
return __crypto_sha256_import_core(&SHA256_CTX(desc)->ctx, in);
180+
}
181+
149182
/* HMAC-SHA224 */
150183

151184
#define HMAC_SHA224_KEY(tfm) ((struct hmac_sha224_key *)crypto_shash_ctx(tfm))
@@ -198,6 +231,21 @@ static int crypto_hmac_sha224_import(struct shash_desc *desc, const void *in)
198231
return __crypto_sha256_import(&ctx->ctx.sha_ctx, in);
199232
}
200233

234+
static int crypto_hmac_sha224_export_core(struct shash_desc *desc, void *out)
235+
{
236+
return __crypto_sha256_export_core(&HMAC_SHA224_CTX(desc)->ctx.sha_ctx,
237+
out);
238+
}
239+
240+
static int crypto_hmac_sha224_import_core(struct shash_desc *desc,
241+
const void *in)
242+
{
243+
struct hmac_sha224_ctx *ctx = HMAC_SHA224_CTX(desc);
244+
245+
ctx->ctx.ostate = HMAC_SHA224_KEY(desc->tfm)->key.ostate;
246+
return __crypto_sha256_import_core(&ctx->ctx.sha_ctx, in);
247+
}
248+
201249
/* HMAC-SHA256 */
202250

203251
#define HMAC_SHA256_KEY(tfm) ((struct hmac_sha256_key *)crypto_shash_ctx(tfm))
@@ -250,6 +298,21 @@ static int crypto_hmac_sha256_import(struct shash_desc *desc, const void *in)
250298
return __crypto_sha256_import(&ctx->ctx.sha_ctx, in);
251299
}
252300

301+
static int crypto_hmac_sha256_export_core(struct shash_desc *desc, void *out)
302+
{
303+
return __crypto_sha256_export_core(&HMAC_SHA256_CTX(desc)->ctx.sha_ctx,
304+
out);
305+
}
306+
307+
static int crypto_hmac_sha256_import_core(struct shash_desc *desc,
308+
const void *in)
309+
{
310+
struct hmac_sha256_ctx *ctx = HMAC_SHA256_CTX(desc);
311+
312+
ctx->ctx.ostate = HMAC_SHA256_KEY(desc->tfm)->key.ostate;
313+
return __crypto_sha256_import_core(&ctx->ctx.sha_ctx, in);
314+
}
315+
253316
/* Algorithm definitions */
254317

255318
static struct shash_alg algs[] = {
@@ -266,6 +329,8 @@ static struct shash_alg algs[] = {
266329
.digest = crypto_sha224_digest,
267330
.export = crypto_sha224_export,
268331
.import = crypto_sha224_import,
332+
.export_core = crypto_sha224_export_core,
333+
.import_core = crypto_sha224_import_core,
269334
.descsize = sizeof(struct sha224_ctx),
270335
.statesize = SHA256_SHASH_STATE_SIZE,
271336
},
@@ -282,6 +347,8 @@ static struct shash_alg algs[] = {
282347
.digest = crypto_sha256_digest,
283348
.export = crypto_sha256_export,
284349
.import = crypto_sha256_import,
350+
.export_core = crypto_sha256_export_core,
351+
.import_core = crypto_sha256_import_core,
285352
.descsize = sizeof(struct sha256_ctx),
286353
.statesize = SHA256_SHASH_STATE_SIZE,
287354
},
@@ -300,6 +367,8 @@ static struct shash_alg algs[] = {
300367
.digest = crypto_hmac_sha224_digest,
301368
.export = crypto_hmac_sha224_export,
302369
.import = crypto_hmac_sha224_import,
370+
.export_core = crypto_hmac_sha224_export_core,
371+
.import_core = crypto_hmac_sha224_import_core,
303372
.descsize = sizeof(struct hmac_sha224_ctx),
304373
.statesize = SHA256_SHASH_STATE_SIZE,
305374
},
@@ -318,6 +387,8 @@ static struct shash_alg algs[] = {
318387
.digest = crypto_hmac_sha256_digest,
319388
.export = crypto_hmac_sha256_export,
320389
.import = crypto_hmac_sha256_import,
390+
.export_core = crypto_hmac_sha256_export_core,
391+
.import_core = crypto_hmac_sha256_import_core,
321392
.descsize = sizeof(struct hmac_sha256_ctx),
322393
.statesize = SHA256_SHASH_STATE_SIZE,
323394
},

crypto/sha512.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ static int __crypto_sha512_import(struct __sha512_ctx *ctx, const void *in)
5050
return 0;
5151
}
5252

53+
static int __crypto_sha512_export_core(const struct __sha512_ctx *ctx,
54+
void *out)
55+
{
56+
memcpy(out, ctx, offsetof(struct __sha512_ctx, buf));
57+
return 0;
58+
}
59+
60+
static int __crypto_sha512_import_core(struct __sha512_ctx *ctx, const void *in)
61+
{
62+
memcpy(ctx, in, offsetof(struct __sha512_ctx, buf));
63+
return 0;
64+
}
65+
5366
/* SHA-384 */
5467

5568
const u8 sha384_zero_message_hash[SHA384_DIGEST_SIZE] = {
@@ -100,6 +113,16 @@ static int crypto_sha384_import(struct shash_desc *desc, const void *in)
100113
return __crypto_sha512_import(&SHA384_CTX(desc)->ctx, in);
101114
}
102115

116+
static int crypto_sha384_export_core(struct shash_desc *desc, void *out)
117+
{
118+
return __crypto_sha512_export_core(&SHA384_CTX(desc)->ctx, out);
119+
}
120+
121+
static int crypto_sha384_import_core(struct shash_desc *desc, const void *in)
122+
{
123+
return __crypto_sha512_import_core(&SHA384_CTX(desc)->ctx, in);
124+
}
125+
103126
/* SHA-512 */
104127

105128
const u8 sha512_zero_message_hash[SHA512_DIGEST_SIZE] = {
@@ -152,6 +175,16 @@ static int crypto_sha512_import(struct shash_desc *desc, const void *in)
152175
return __crypto_sha512_import(&SHA512_CTX(desc)->ctx, in);
153176
}
154177

178+
static int crypto_sha512_export_core(struct shash_desc *desc, void *out)
179+
{
180+
return __crypto_sha512_export_core(&SHA512_CTX(desc)->ctx, out);
181+
}
182+
183+
static int crypto_sha512_import_core(struct shash_desc *desc, const void *in)
184+
{
185+
return __crypto_sha512_import_core(&SHA512_CTX(desc)->ctx, in);
186+
}
187+
155188
/* HMAC-SHA384 */
156189

157190
#define HMAC_SHA384_KEY(tfm) ((struct hmac_sha384_key *)crypto_shash_ctx(tfm))
@@ -204,6 +237,21 @@ static int crypto_hmac_sha384_import(struct shash_desc *desc, const void *in)
204237
return __crypto_sha512_import(&ctx->ctx.sha_ctx, in);
205238
}
206239

240+
static int crypto_hmac_sha384_export_core(struct shash_desc *desc, void *out)
241+
{
242+
return __crypto_sha512_export_core(&HMAC_SHA384_CTX(desc)->ctx.sha_ctx,
243+
out);
244+
}
245+
246+
static int crypto_hmac_sha384_import_core(struct shash_desc *desc,
247+
const void *in)
248+
{
249+
struct hmac_sha384_ctx *ctx = HMAC_SHA384_CTX(desc);
250+
251+
ctx->ctx.ostate = HMAC_SHA384_KEY(desc->tfm)->key.ostate;
252+
return __crypto_sha512_import_core(&ctx->ctx.sha_ctx, in);
253+
}
254+
207255
/* HMAC-SHA512 */
208256

209257
#define HMAC_SHA512_KEY(tfm) ((struct hmac_sha512_key *)crypto_shash_ctx(tfm))
@@ -256,6 +304,21 @@ static int crypto_hmac_sha512_import(struct shash_desc *desc, const void *in)
256304
return __crypto_sha512_import(&ctx->ctx.sha_ctx, in);
257305
}
258306

307+
static int crypto_hmac_sha512_export_core(struct shash_desc *desc, void *out)
308+
{
309+
return __crypto_sha512_export_core(&HMAC_SHA512_CTX(desc)->ctx.sha_ctx,
310+
out);
311+
}
312+
313+
static int crypto_hmac_sha512_import_core(struct shash_desc *desc,
314+
const void *in)
315+
{
316+
struct hmac_sha512_ctx *ctx = HMAC_SHA512_CTX(desc);
317+
318+
ctx->ctx.ostate = HMAC_SHA512_KEY(desc->tfm)->key.ostate;
319+
return __crypto_sha512_import_core(&ctx->ctx.sha_ctx, in);
320+
}
321+
259322
/* Algorithm definitions */
260323

261324
static struct shash_alg algs[] = {
@@ -272,6 +335,8 @@ static struct shash_alg algs[] = {
272335
.digest = crypto_sha384_digest,
273336
.export = crypto_sha384_export,
274337
.import = crypto_sha384_import,
338+
.export_core = crypto_sha384_export_core,
339+
.import_core = crypto_sha384_import_core,
275340
.descsize = sizeof(struct sha384_ctx),
276341
.statesize = SHA512_SHASH_STATE_SIZE,
277342
},
@@ -288,6 +353,8 @@ static struct shash_alg algs[] = {
288353
.digest = crypto_sha512_digest,
289354
.export = crypto_sha512_export,
290355
.import = crypto_sha512_import,
356+
.export_core = crypto_sha512_export_core,
357+
.import_core = crypto_sha512_import_core,
291358
.descsize = sizeof(struct sha512_ctx),
292359
.statesize = SHA512_SHASH_STATE_SIZE,
293360
},
@@ -306,6 +373,8 @@ static struct shash_alg algs[] = {
306373
.digest = crypto_hmac_sha384_digest,
307374
.export = crypto_hmac_sha384_export,
308375
.import = crypto_hmac_sha384_import,
376+
.export_core = crypto_hmac_sha384_export_core,
377+
.import_core = crypto_hmac_sha384_import_core,
309378
.descsize = sizeof(struct hmac_sha384_ctx),
310379
.statesize = SHA512_SHASH_STATE_SIZE,
311380
},
@@ -324,6 +393,8 @@ static struct shash_alg algs[] = {
324393
.digest = crypto_hmac_sha512_digest,
325394
.export = crypto_hmac_sha512_export,
326395
.import = crypto_hmac_sha512_import,
396+
.export_core = crypto_hmac_sha512_export_core,
397+
.import_core = crypto_hmac_sha512_import_core,
327398
.descsize = sizeof(struct hmac_sha512_ctx),
328399
.statesize = SHA512_SHASH_STATE_SIZE,
329400
},

0 commit comments

Comments
 (0)