While calculating a hash over large amount of data it is necessary
to call update() function multiple times.
Old implementation always reset the hash upon calling crypto operation.
This patch introduces the flag which allows to disable hash initialization
upon every call to crypto API.
Also it allows to retrieve final hash by requesting using 0 length.

Signed-off-by: Dmitry Kasatkin <dmitry.kasat...@nokia.com>
---
 cryptodev.h      |    1 +
 cryptodev_main.c |   15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/cryptodev.h b/cryptodev.h
index ea6503f..e2a8484 100644
--- a/cryptodev.h
+++ b/cryptodev.h
@@ -102,6 +102,7 @@ struct session_op {
 /* struct crypt_op flags */
 
 #define COP_FLAG_NONE          (0 << 0) /* totally no flag */
+#define COP_FLAG_UPDATE                (1 << 0) /* multi-update hash mode */
 
 /* Stuff for bignum arithmetic and public key
  * cryptography - not supported yet by linux
diff --git a/cryptodev_main.c b/cryptodev_main.c
index 2618c61..a27da96 100644
--- a/cryptodev_main.c
+++ b/cryptodev_main.c
@@ -658,7 +658,7 @@ static int crypto_run(struct fcrypt *fcr, struct crypt_op 
*cop)
                return -EINVAL;
        }
 
-       if (ses_ptr->hdata.init != 0) {
+       if (ses_ptr->hdata.init != 0 && !(cop->flags & COP_FLAG_UPDATE)) {
                ret = cryptodev_hash_reset(&ses_ptr->hdata);
                if (unlikely(ret)) {
                        dprintk(1, KERN_ERR,
@@ -698,15 +698,18 @@ static int crypto_run(struct fcrypt *fcr, struct crypt_op 
*cop)
                }
        }
 
+       if (!(cop->flags & COP_FLAG_UPDATE) || cop->len != 0) {
 #ifdef DISABLE_ZCOPY
-       ret = __crypto_run_std(ses_ptr, cop);
+               ret = __crypto_run_std(ses_ptr, cop);
 #else /* normal */
-       ret = __crypto_run_zc(ses_ptr, cop);
+               ret = __crypto_run_zc(ses_ptr, cop);
 #endif
-       if (unlikely(ret))
-               goto out_unlock;
+               if (unlikely(ret))
+                       goto out_unlock;
+       }
 
-       if (ses_ptr->hdata.init != 0) {
+       if (ses_ptr->hdata.init != 0 &&
+               (!(cop->flags & COP_FLAG_UPDATE) || cop->len == 0)) {
                ret = cryptodev_hash_final(&ses_ptr->hdata, hash_output);
                if (unlikely(ret)) {
                        dprintk(0, KERN_ERR, "CryptoAPI failure: %d\n", ret);
-- 
1.7.0.4


_______________________________________________
Cryptodev-linux-devel mailing list
Cryptodev-linux-devel@gna.org
https://mail.gna.org/listinfo/cryptodev-linux-devel

Reply via email to