Commit 7a0b86b1 authored by Greg Tucker's avatar Greg Tucker Committed by Herbert Xu

crypto: sha-mb - Fix total_len for correct hash when larger than 512MB

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: default avatarGreg Tucker <greg.b.tucker@intel.com>
Acked-by: default avatarTim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 75aa0a7c
...@@ -114,7 +114,7 @@ static inline void sha1_init_digest(uint32_t *digest) ...@@ -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], 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); uint32_t i = total_len & (SHA1_BLOCK_SIZE - 1);
......
...@@ -125,7 +125,7 @@ struct sha1_hash_ctx { ...@@ -125,7 +125,7 @@ struct sha1_hash_ctx {
/* error flag */ /* error flag */
int error; int error;
uint32_t total_length; uint64_t total_length;
const void *incoming_buffer; const void *incoming_buffer;
uint32_t incoming_buffer_length; uint32_t incoming_buffer_length;
uint8_t partial_block_buffer[SHA1_BLOCK_SIZE * 2]; uint8_t partial_block_buffer[SHA1_BLOCK_SIZE * 2];
......
...@@ -115,7 +115,7 @@ inline void sha256_init_digest(uint32_t *digest) ...@@ -115,7 +115,7 @@ inline void sha256_init_digest(uint32_t *digest)
} }
inline uint32_t sha256_pad(uint8_t padblock[SHA256_BLOCK_SIZE * 2], 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); uint32_t i = total_len & (SHA256_BLOCK_SIZE - 1);
......
...@@ -125,7 +125,7 @@ struct sha256_hash_ctx { ...@@ -125,7 +125,7 @@ struct sha256_hash_ctx {
/* error flag */ /* error flag */
int error; int error;
uint32_t total_length; uint64_t total_length;
const void *incoming_buffer; const void *incoming_buffer;
uint32_t incoming_buffer_length; uint32_t incoming_buffer_length;
uint8_t partial_block_buffer[SHA256_BLOCK_SIZE * 2]; uint8_t partial_block_buffer[SHA256_BLOCK_SIZE * 2];
......
...@@ -117,7 +117,7 @@ inline void sha512_init_digest(uint64_t *digest) ...@@ -117,7 +117,7 @@ inline void sha512_init_digest(uint64_t *digest)
} }
inline uint32_t sha512_pad(uint8_t padblock[SHA512_BLOCK_SIZE * 2], 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); uint32_t i = total_len & (SHA512_BLOCK_SIZE - 1);
......
...@@ -119,7 +119,7 @@ struct sha512_hash_ctx { ...@@ -119,7 +119,7 @@ struct sha512_hash_ctx {
/* error flag */ /* error flag */
int error; int error;
uint32_t total_length; uint64_t total_length;
const void *incoming_buffer; const void *incoming_buffer;
uint32_t incoming_buffer_length; uint32_t incoming_buffer_length;
uint8_t partial_block_buffer[SHA512_BLOCK_SIZE * 2]; uint8_t partial_block_buffer[SHA512_BLOCK_SIZE * 2];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment