Re: [PATCH 1/6] drivers: crypto: qce: sha: Restore/save sha1_state/sha256_state with qce_sha_reqctx in export/import

From: Thara Gopinath
Date: Fri Jan 08 2021 - 10:51:12 EST




On 1/2/21 4:25 PM, Herbert Xu wrote:
On Fri, Dec 18, 2020 at 10:30:22PM -0500, Thara Gopinath wrote:
Export and import interfaces save and restore partial transformation
states. The partial states were being stored and restored in struct
sha1_state for sha1/hmac(sha1) transformations and sha256_state for
sha256/hmac(sha256) transformations.This led to a bunch of corner cases
where improper state was being stored and restored. A few of the corner
cases that turned up during testing are:

- wrong byte_count restored if export/import is called twice without h/w
transaction in between
- wrong buflen restored back if the pending buffer
length is exactly the block size.
- wrong state restored if buffer length is 0.

To fix these issues, save and restore the entire qce_sha_rctx structure
instead of parts of it in sha1_state and sha256_state structures.
This in turn simplifies the export and import apis.

Signed-off-by: Thara Gopinath <thara.gopinath@xxxxxxxxxx>
---
drivers/crypto/qce/sha.c | 93 ++++------------------------------------
1 file changed, 8 insertions(+), 85 deletions(-)

How is this safe when the reqctx structure contains pointers?

Hi Herbert,

You are right. Also more I think about this, it is better to have another struct to export and import the relevant pieces.
I will fix this and send across a v2.


Cheers,


--
Warm Regards
Thara