@@ -203,9 +203,10 @@ int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
203
203
}
204
204
EXPORT_SYMBOL_GPL (crypto_shash_tfm_digest );
205
205
206
- int crypto_shash_export_core (struct shash_desc * desc , void * out )
206
+ static int __crypto_shash_export (struct shash_desc * desc , void * out ,
207
+ int (* export )(struct shash_desc * desc ,
208
+ void * out ))
207
209
{
208
- int (* export )(struct shash_desc * desc , void * out );
209
210
struct crypto_shash * tfm = desc -> tfm ;
210
211
u8 * buf = shash_desc_ctx (desc );
211
212
unsigned int plen , ss ;
@@ -214,14 +215,19 @@ int crypto_shash_export_core(struct shash_desc *desc, void *out)
214
215
ss = crypto_shash_statesize (tfm );
215
216
if (crypto_shash_block_only (tfm ))
216
217
ss -= plen ;
217
- export = crypto_shash_alg (tfm )-> export ;
218
218
if (!export ) {
219
219
memcpy (out , buf , ss );
220
220
return 0 ;
221
221
}
222
222
223
223
return export (desc , out );
224
224
}
225
+
226
+ int crypto_shash_export_core (struct shash_desc * desc , void * out )
227
+ {
228
+ return __crypto_shash_export (desc , out ,
229
+ crypto_shash_alg (desc -> tfm )-> export_core );
230
+ }
225
231
EXPORT_SYMBOL_GPL (crypto_shash_export_core );
226
232
227
233
int crypto_shash_export (struct shash_desc * desc , void * out )
@@ -236,13 +242,14 @@ int crypto_shash_export(struct shash_desc *desc, void *out)
236
242
237
243
memcpy (out + ss - plen , buf + descsize - plen , plen );
238
244
}
239
- return crypto_shash_export_core (desc , out );
245
+ return __crypto_shash_export (desc , out , crypto_shash_alg ( tfm ) -> export );
240
246
}
241
247
EXPORT_SYMBOL_GPL (crypto_shash_export );
242
248
243
- int crypto_shash_import_core (struct shash_desc * desc , const void * in )
249
+ static int __crypto_shash_import (struct shash_desc * desc , const void * in ,
250
+ int (* import )(struct shash_desc * desc ,
251
+ const void * in ))
244
252
{
245
- int (* import )(struct shash_desc * desc , const void * in );
246
253
struct crypto_shash * tfm = desc -> tfm ;
247
254
unsigned int descsize , plen , ss ;
248
255
u8 * buf = shash_desc_ctx (desc );
@@ -256,22 +263,27 @@ int crypto_shash_import_core(struct shash_desc *desc, const void *in)
256
263
buf [descsize - 1 ] = 0 ;
257
264
if (crypto_shash_block_only (tfm ))
258
265
ss -= plen ;
259
- import = crypto_shash_alg (tfm )-> import ;
260
266
if (!import ) {
261
267
memcpy (buf , in , ss );
262
268
return 0 ;
263
269
}
264
270
265
271
return import (desc , in );
266
272
}
273
+
274
+ int crypto_shash_import_core (struct shash_desc * desc , const void * in )
275
+ {
276
+ return __crypto_shash_import (desc , in ,
277
+ crypto_shash_alg (desc -> tfm )-> import_core );
278
+ }
267
279
EXPORT_SYMBOL_GPL (crypto_shash_import_core );
268
280
269
281
int crypto_shash_import (struct shash_desc * desc , const void * in )
270
282
{
271
283
struct crypto_shash * tfm = desc -> tfm ;
272
284
int err ;
273
285
274
- err = crypto_shash_import_core (desc , in );
286
+ err = __crypto_shash_import (desc , in , crypto_shash_alg ( tfm ) -> import );
275
287
if (crypto_shash_block_only (tfm )) {
276
288
unsigned int plen = crypto_shash_blocksize (tfm ) + 1 ;
277
289
unsigned int descsize = crypto_shash_descsize (tfm );
@@ -436,6 +448,16 @@ int hash_prepare_alg(struct hash_alg_common *alg)
436
448
return 0 ;
437
449
}
438
450
451
+ static int shash_default_export_core (struct shash_desc * desc , void * out )
452
+ {
453
+ return - ENOSYS ;
454
+ }
455
+
456
+ static int shash_default_import_core (struct shash_desc * desc , const void * in )
457
+ {
458
+ return - ENOSYS ;
459
+ }
460
+
439
461
static int shash_prepare_alg (struct shash_alg * alg )
440
462
{
441
463
struct crypto_alg * base = & alg -> halg .base ;
@@ -476,6 +498,12 @@ static int shash_prepare_alg(struct shash_alg *alg)
476
498
BUILD_BUG_ON (MAX_ALGAPI_BLOCKSIZE >= 256 );
477
499
alg -> descsize += base -> cra_blocksize + 1 ;
478
500
alg -> statesize += base -> cra_blocksize + 1 ;
501
+ alg -> export_core = alg -> export ;
502
+ alg -> import_core = alg -> import ;
503
+ } else if (!alg -> export_core || !alg -> import_core ) {
504
+ alg -> export_core = shash_default_export_core ;
505
+ alg -> import_core = shash_default_import_core ;
506
+ base -> cra_flags |= CRYPTO_AHASH_ALG_NO_EXPORT_CORE ;
479
507
}
480
508
481
509
if (alg -> descsize > HASH_MAX_DESCSIZE )
0 commit comments