@@ -300,14 +300,16 @@ static int crypto_init_shash_ops_async(struct crypto_tfm *tfm)
300300static int shash_compat_setkey (struct crypto_hash * tfm , const u8 * key ,
301301 unsigned int keylen )
302302{
303- struct shash_desc * desc = crypto_hash_ctx (tfm );
303+ struct shash_desc * * descp = crypto_hash_ctx (tfm );
304+ struct shash_desc * desc = * descp ;
304305
305306 return crypto_shash_setkey (desc -> tfm , key , keylen );
306307}
307308
308309static int shash_compat_init (struct hash_desc * hdesc )
309310{
310- struct shash_desc * desc = crypto_hash_ctx (hdesc -> tfm );
311+ struct shash_desc * * descp = crypto_hash_ctx (hdesc -> tfm );
312+ struct shash_desc * desc = * descp ;
311313
312314 desc -> flags = hdesc -> flags ;
313315
@@ -317,7 +319,8 @@ static int shash_compat_init(struct hash_desc *hdesc)
317319static int shash_compat_update (struct hash_desc * hdesc , struct scatterlist * sg ,
318320 unsigned int len )
319321{
320- struct shash_desc * desc = crypto_hash_ctx (hdesc -> tfm );
322+ struct shash_desc * * descp = crypto_hash_ctx (hdesc -> tfm );
323+ struct shash_desc * desc = * descp ;
321324 struct crypto_hash_walk walk ;
322325 int nbytes ;
323326
@@ -330,7 +333,9 @@ static int shash_compat_update(struct hash_desc *hdesc, struct scatterlist *sg,
330333
331334static int shash_compat_final (struct hash_desc * hdesc , u8 * out )
332335{
333- return crypto_shash_final (crypto_hash_ctx (hdesc -> tfm ), out );
336+ struct shash_desc * * descp = crypto_hash_ctx (hdesc -> tfm );
337+
338+ return crypto_shash_final (* descp , out );
334339}
335340
336341static int shash_compat_digest (struct hash_desc * hdesc , struct scatterlist * sg ,
@@ -340,7 +345,8 @@ static int shash_compat_digest(struct hash_desc *hdesc, struct scatterlist *sg,
340345 int err ;
341346
342347 if (nbytes < min (sg -> length , ((unsigned int )(PAGE_SIZE )) - offset )) {
343- struct shash_desc * desc = crypto_hash_ctx (hdesc -> tfm );
348+ struct shash_desc * * descp = crypto_hash_ctx (hdesc -> tfm );
349+ struct shash_desc * desc = * descp ;
344350 void * data ;
345351
346352 desc -> flags = hdesc -> flags ;
@@ -368,18 +374,21 @@ static int shash_compat_digest(struct hash_desc *hdesc, struct scatterlist *sg,
368374
369375static void crypto_exit_shash_ops_compat (struct crypto_tfm * tfm )
370376{
371- struct shash_desc * desc = crypto_tfm_ctx (tfm );
377+ struct shash_desc * * descp = crypto_tfm_ctx (tfm );
378+ struct shash_desc * desc = * descp ;
372379
373380 crypto_free_shash (desc -> tfm );
381+ kzfree (desc );
374382}
375383
376384static int crypto_init_shash_ops_compat (struct crypto_tfm * tfm )
377385{
378386 struct hash_tfm * crt = & tfm -> crt_hash ;
379387 struct crypto_alg * calg = tfm -> __crt_alg ;
380388 struct shash_alg * alg = __crypto_shash_alg (calg );
381- struct shash_desc * desc = crypto_tfm_ctx (tfm );
389+ struct shash_desc * * descp = crypto_tfm_ctx (tfm );
382390 struct crypto_shash * shash ;
391+ struct shash_desc * desc ;
383392
384393 if (!crypto_mod_get (calg ))
385394 return - EAGAIN ;
@@ -390,6 +399,14 @@ static int crypto_init_shash_ops_compat(struct crypto_tfm *tfm)
390399 return PTR_ERR (shash );
391400 }
392401
402+ desc = kmalloc (sizeof (* desc ) + crypto_shash_descsize (shash ),
403+ GFP_KERNEL );
404+ if (!desc ) {
405+ crypto_free_shash (shash );
406+ return - ENOMEM ;
407+ }
408+
409+ * descp = desc ;
393410 desc -> tfm = shash ;
394411 tfm -> exit = crypto_exit_shash_ops_compat ;
395412
@@ -419,11 +436,9 @@ static int crypto_init_shash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
419436static unsigned int crypto_shash_ctxsize (struct crypto_alg * alg , u32 type ,
420437 u32 mask )
421438{
422- struct shash_alg * salg = __crypto_shash_alg (alg );
423-
424439 switch (mask & CRYPTO_ALG_TYPE_MASK ) {
425440 case CRYPTO_ALG_TYPE_HASH_MASK :
426- return sizeof (struct shash_desc ) + salg -> descsize ;
441+ return sizeof (struct shash_desc * ) ;
427442 case CRYPTO_ALG_TYPE_AHASH_MASK :
428443 return sizeof (struct crypto_shash * );
429444 }
@@ -434,6 +449,9 @@ static unsigned int crypto_shash_ctxsize(struct crypto_alg *alg, u32 type,
434449static int crypto_shash_init_tfm (struct crypto_tfm * tfm ,
435450 const struct crypto_type * frontend )
436451{
452+ struct crypto_shash * hash = __crypto_shash_cast (tfm );
453+
454+ hash -> descsize = crypto_shash_alg (hash )-> descsize ;
437455 return 0 ;
438456}
439457
@@ -452,7 +470,6 @@ static void crypto_shash_show(struct seq_file *m, struct crypto_alg *alg)
452470 seq_printf (m , "type : shash\n" );
453471 seq_printf (m , "blocksize : %u\n" , alg -> cra_blocksize );
454472 seq_printf (m , "digestsize : %u\n" , salg -> digestsize );
455- seq_printf (m , "descsize : %u\n" , salg -> descsize );
456473}
457474
458475static const struct crypto_type crypto_shash_type = {
0 commit comments