]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
crypto: marvell/cesa - keep creq->state in CPU endian format at all times
authorRussell King <rmk+kernel@arm.linux.org.uk>
Sun, 18 Oct 2015 16:23:35 +0000 (17:23 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 20 Oct 2015 14:10:50 +0000 (22:10 +0800)
Currently, we read/write the state in CPU endian, but on the final
request, we convert its endian according to the requested algorithm.
(md5 is little endian, SHA are big endian.)

Always keep creq->state in CPU native endian format, and perform the
necessary conversion when copying the hash to the result.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/marvell/cesa.h
drivers/crypto/marvell/hash.c

index b60698b30d30a2e30b24b3cc625a9821254fc980..5a1fabdd67788f1f61742f00b4ec6a941d5c318c 100644 (file)
@@ -612,7 +612,7 @@ struct mv_cesa_ahash_req {
        u64 len;
        int src_nents;
        bool last_req;
-       __be32 state[8];
+       u32 state[8];
 };
 
 /* CESA functions */
index 40241fd822c61b01025464b003f42622afd61e4f..78941266e01f6c10375bc7afbd1f834c860890f1 100644 (file)
@@ -347,18 +347,21 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status)
                                   ahashreq->nbytes - creq->cache_ptr);
 
        if (creq->last_req) {
-               for (i = 0; i < digsize / 4; i++) {
-                       /*
-                        * Hardware provides MD5 digest in a different
-                        * endianness than SHA-1 and SHA-256 ones.
-                        */
-                       if (digsize == MD5_DIGEST_SIZE)
-                               creq->state[i] = cpu_to_le32(creq->state[i]);
-                       else
-                               creq->state[i] = cpu_to_be32(creq->state[i]);
-               }
+               /*
+                * Hardware's MD5 digest is in little endian format, but
+                * SHA in big endian format
+                */
+               if (digsize == MD5_DIGEST_SIZE) {
+                       __le32 *result = (void *)ahashreq->result;
+
+                       for (i = 0; i < digsize / 4; i++)
+                               result[i] = cpu_to_le32(creq->state[i]);
+               } else {
+                       __be32 *result = (void *)ahashreq->result;
 
-               memcpy(ahashreq->result, creq->state, digsize);
+                       for (i = 0; i < digsize / 4; i++)
+                               result[i] = cpu_to_be32(creq->state[i]);
+               }
        }
 
        return ret;