crypto: sha-mb - Fix total_len for correct hash when larger than 512MB
authorGreg Tucker <greg.b.tucker@intel.com>
Mon, 14 Nov 2016 23:11:44 +0000 (16:11 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 17 Nov 2016 15:35:00 +0000 (23:35 +0800)
Current multi-buffer hash implementations have a restriction on the total
length of a hash job to 512MB. Hashing larger buffers will result in an
incorrect hash. This extends the limit to 2^62 - 1.

Signed-off-by: Greg Tucker <greg.b.tucker@intel.com>
Acked-by: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/x86/crypto/sha1-mb/sha1_mb.c
arch/x86/crypto/sha1-mb/sha1_mb_ctx.h
arch/x86/crypto/sha256-mb/sha256_mb.c
arch/x86/crypto/sha256-mb/sha256_mb_ctx.h
arch/x86/crypto/sha512-mb/sha512_mb.c
arch/x86/crypto/sha512-mb/sha512_mb_ctx.h

index 9e5b67127a094f3f3dbf61d2bc93a011e64731bc..acf9fdf0167106a93a88c7ba2bd1cfc79fbcf706 100644 (file)
@@ -114,7 +114,7 @@ static inline void sha1_init_digest(uint32_t *digest)
 }
 
 static inline uint32_t sha1_pad(uint8_t padblock[SHA1_BLOCK_SIZE * 2],
-                        uint32_t total_len)
+                        uint64_t total_len)
 {
        uint32_t i = total_len & (SHA1_BLOCK_SIZE - 1);
 
index 98a35bcc6f4ad4feb4c967d4e6f0f1b1882fe8c6..13590ccf965c35948755d6006e576f5bcc4be0d7 100644 (file)
@@ -125,7 +125,7 @@ struct sha1_hash_ctx {
        /* error flag */
        int error;
 
-       uint32_t        total_length;
+       uint64_t        total_length;
        const void      *incoming_buffer;
        uint32_t        incoming_buffer_length;
        uint8_t         partial_block_buffer[SHA1_BLOCK_SIZE * 2];
index 6f97fb33ae216d9129d42261b5a10226868caab0..7926a226b120b97bd8fb8708db0360bf6f4f0b5e 100644 (file)
@@ -115,7 +115,7 @@ inline void sha256_init_digest(uint32_t *digest)
 }
 
 inline uint32_t sha256_pad(uint8_t padblock[SHA256_BLOCK_SIZE * 2],
-                        uint32_t total_len)
+                        uint64_t total_len)
 {
        uint32_t i = total_len & (SHA256_BLOCK_SIZE - 1);
 
index edd252b732067033df0c3dcff6d7985c0a8677b1..aabb30320af0dd4c11263bdfd8ce490d8ee726fa 100644 (file)
@@ -125,7 +125,7 @@ struct sha256_hash_ctx {
        /* error flag */
        int error;
 
-       uint32_t        total_length;
+       uint64_t        total_length;
        const void      *incoming_buffer;
        uint32_t        incoming_buffer_length;
        uint8_t         partial_block_buffer[SHA256_BLOCK_SIZE * 2];
index d210174a52b0e933983f8b253e679eb6b4336632..9c1bb6d58141c9012d1d78e7227de267da582e49 100644 (file)
@@ -117,7 +117,7 @@ inline void sha512_init_digest(uint64_t *digest)
 }
 
 inline uint32_t sha512_pad(uint8_t padblock[SHA512_BLOCK_SIZE * 2],
-                        uint32_t total_len)
+                        uint64_t total_len)
 {
        uint32_t i = total_len & (SHA512_BLOCK_SIZE - 1);
 
index 9d4b2c8208d50cfd2cc9006932debfbef6f42ef0..e4653f5eec3fd87d88b32d22247106f6f4cdefc4 100644 (file)
@@ -119,7 +119,7 @@ struct sha512_hash_ctx {
        /* error flag */
        int error;
 
-       uint32_t        total_length;
+       uint64_t        total_length;
        const void      *incoming_buffer;
        uint32_t        incoming_buffer_length;
        uint8_t         partial_block_buffer[SHA512_BLOCK_SIZE * 2];