@@ -296,6 +296,44 @@ static void tegra_sha_paste_hash_result(struct tegra_se *se, struct tegra_sha_re
296296 se -> base + se -> hw -> regs -> result + (i * 4 ));
297297}
298298
299+ static int tegra_sha_do_init (struct ahash_request * req )
300+ {
301+ struct tegra_sha_reqctx * rctx = ahash_request_ctx (req );
302+ struct crypto_ahash * tfm = crypto_ahash_reqtfm (req );
303+ struct tegra_sha_ctx * ctx = crypto_ahash_ctx (tfm );
304+ struct tegra_se * se = ctx -> se ;
305+
306+ if (ctx -> fallback )
307+ return tegra_sha_fallback_init (req );
308+
309+ rctx -> total_len = 0 ;
310+ rctx -> datbuf .size = 0 ;
311+ rctx -> residue .size = 0 ;
312+ rctx -> key_id = ctx -> key_id ;
313+ rctx -> task |= SHA_FIRST ;
314+ rctx -> alg = ctx -> alg ;
315+ rctx -> blk_size = crypto_ahash_blocksize (tfm );
316+ rctx -> digest .size = crypto_ahash_digestsize (tfm );
317+
318+ rctx -> digest .buf = dma_alloc_coherent (se -> dev , rctx -> digest .size ,
319+ & rctx -> digest .addr , GFP_KERNEL );
320+ if (!rctx -> digest .buf )
321+ goto digbuf_fail ;
322+
323+ rctx -> residue .buf = dma_alloc_coherent (se -> dev , rctx -> blk_size ,
324+ & rctx -> residue .addr , GFP_KERNEL );
325+ if (!rctx -> residue .buf )
326+ goto resbuf_fail ;
327+
328+ return 0 ;
329+
330+ resbuf_fail :
331+ dma_free_coherent (se -> dev , rctx -> digest .size , rctx -> digest .buf ,
332+ rctx -> digest .addr );
333+ digbuf_fail :
334+ return - ENOMEM ;
335+ }
336+
299337static int tegra_sha_do_update (struct ahash_request * req )
300338{
301339 struct tegra_sha_ctx * ctx = crypto_ahash_ctx (crypto_ahash_reqtfm (req ));
@@ -435,6 +473,14 @@ static int tegra_sha_do_one_req(struct crypto_engine *engine, void *areq)
435473 struct tegra_se * se = ctx -> se ;
436474 int ret = 0 ;
437475
476+ if (rctx -> task & SHA_INIT ) {
477+ ret = tegra_sha_do_init (req );
478+ if (ret )
479+ goto out ;
480+
481+ rctx -> task &= ~SHA_INIT ;
482+ }
483+
438484 if (rctx -> task & SHA_UPDATE ) {
439485 ret = tegra_sha_do_update (req );
440486 if (ret )
@@ -525,44 +571,6 @@ static void tegra_sha_cra_exit(struct crypto_tfm *tfm)
525571 tegra_key_invalidate (ctx -> se , ctx -> key_id , ctx -> alg );
526572}
527573
528- static int tegra_sha_init (struct ahash_request * req )
529- {
530- struct tegra_sha_reqctx * rctx = ahash_request_ctx (req );
531- struct crypto_ahash * tfm = crypto_ahash_reqtfm (req );
532- struct tegra_sha_ctx * ctx = crypto_ahash_ctx (tfm );
533- struct tegra_se * se = ctx -> se ;
534-
535- if (ctx -> fallback )
536- return tegra_sha_fallback_init (req );
537-
538- rctx -> total_len = 0 ;
539- rctx -> datbuf .size = 0 ;
540- rctx -> residue .size = 0 ;
541- rctx -> key_id = ctx -> key_id ;
542- rctx -> task = SHA_FIRST ;
543- rctx -> alg = ctx -> alg ;
544- rctx -> blk_size = crypto_ahash_blocksize (tfm );
545- rctx -> digest .size = crypto_ahash_digestsize (tfm );
546-
547- rctx -> digest .buf = dma_alloc_coherent (se -> dev , rctx -> digest .size ,
548- & rctx -> digest .addr , GFP_KERNEL );
549- if (!rctx -> digest .buf )
550- goto digbuf_fail ;
551-
552- rctx -> residue .buf = dma_alloc_coherent (se -> dev , rctx -> blk_size ,
553- & rctx -> residue .addr , GFP_KERNEL );
554- if (!rctx -> residue .buf )
555- goto resbuf_fail ;
556-
557- return 0 ;
558-
559- resbuf_fail :
560- dma_free_coherent (se -> dev , rctx -> digest .size , rctx -> digest .buf ,
561- rctx -> digest .addr );
562- digbuf_fail :
563- return - ENOMEM ;
564- }
565-
566574static int tegra_hmac_fallback_setkey (struct tegra_sha_ctx * ctx , const u8 * key ,
567575 unsigned int keylen )
568576{
@@ -588,6 +596,17 @@ static int tegra_hmac_setkey(struct crypto_ahash *tfm, const u8 *key,
588596 return tegra_key_submit (ctx -> se , key , keylen , ctx -> alg , & ctx -> key_id );
589597}
590598
599+ static int tegra_sha_init (struct ahash_request * req )
600+ {
601+ struct tegra_sha_reqctx * rctx = ahash_request_ctx (req );
602+ struct crypto_ahash * tfm = crypto_ahash_reqtfm (req );
603+ struct tegra_sha_ctx * ctx = crypto_ahash_ctx (tfm );
604+
605+ rctx -> task = SHA_INIT ;
606+
607+ return crypto_transfer_hash_request_to_engine (ctx -> se -> engine , req );
608+ }
609+
591610static int tegra_sha_update (struct ahash_request * req )
592611{
593612 struct tegra_sha_reqctx * rctx = ahash_request_ctx (req );
@@ -635,16 +654,12 @@ static int tegra_sha_digest(struct ahash_request *req)
635654 struct tegra_sha_reqctx * rctx = ahash_request_ctx (req );
636655 struct crypto_ahash * tfm = crypto_ahash_reqtfm (req );
637656 struct tegra_sha_ctx * ctx = crypto_ahash_ctx (tfm );
638- int ret ;
639657
640658 if (ctx -> fallback )
641659 return tegra_sha_fallback_digest (req );
642660
643- ret = tegra_sha_init (req );
644- if (ret )
645- return ret ;
661+ rctx -> task |= SHA_INIT | SHA_UPDATE | SHA_FINAL ;
646662
647- rctx -> task |= SHA_UPDATE | SHA_FINAL ;
648663 return crypto_transfer_hash_request_to_engine (ctx -> se -> engine , req );
649664}
650665
0 commit comments