diff options
-rw-r--r-- | crypto/sha512_generic.c | 28 | ||||
-rw-r--r-- | include/crypto/sha.h | 6 |
2 files changed, 14 insertions, 20 deletions
diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c index 4fe95eb03226..9ed9f60316e5 100644 --- a/crypto/sha512_generic.c +++ b/crypto/sha512_generic.c | |||
@@ -144,7 +144,7 @@ sha512_init(struct shash_desc *desc) | |||
144 | sctx->state[5] = SHA512_H5; | 144 | sctx->state[5] = SHA512_H5; |
145 | sctx->state[6] = SHA512_H6; | 145 | sctx->state[6] = SHA512_H6; |
146 | sctx->state[7] = SHA512_H7; | 146 | sctx->state[7] = SHA512_H7; |
147 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 147 | sctx->count[0] = sctx->count[1] = 0; |
148 | 148 | ||
149 | return 0; | 149 | return 0; |
150 | } | 150 | } |
@@ -161,7 +161,7 @@ sha384_init(struct shash_desc *desc) | |||
161 | sctx->state[5] = SHA384_H5; | 161 | sctx->state[5] = SHA384_H5; |
162 | sctx->state[6] = SHA384_H6; | 162 | sctx->state[6] = SHA384_H6; |
163 | sctx->state[7] = SHA384_H7; | 163 | sctx->state[7] = SHA384_H7; |
164 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 164 | sctx->count[0] = sctx->count[1] = 0; |
165 | 165 | ||
166 | return 0; | 166 | return 0; |
167 | } | 167 | } |
@@ -174,15 +174,11 @@ sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len) | |||
174 | unsigned int i, index, part_len; | 174 | unsigned int i, index, part_len; |
175 | 175 | ||
176 | /* Compute number of bytes mod 128 */ | 176 | /* Compute number of bytes mod 128 */ |
177 | index = (unsigned int)((sctx->count[0] >> 3) & 0x7F); | 177 | index = sctx->count[0] & 0x7f; |
178 | 178 | ||
179 | /* Update number of bits */ | 179 | /* Update number of bytes */ |
180 | if ((sctx->count[0] += (len << 3)) < (len << 3)) { | 180 | if (!(sctx->count[0] += len)) |
181 | if ((sctx->count[1] += 1) < 1) | 181 | sctx->count[1]++; |
182 | if ((sctx->count[2] += 1) < 1) | ||
183 | sctx->count[3]++; | ||
184 | sctx->count[1] += (len >> 29); | ||
185 | } | ||
186 | 182 | ||
187 | part_len = 128 - index; | 183 | part_len = 128 - index; |
188 | 184 | ||
@@ -211,18 +207,16 @@ sha512_final(struct shash_desc *desc, u8 *hash) | |||
211 | struct sha512_state *sctx = shash_desc_ctx(desc); | 207 | struct sha512_state *sctx = shash_desc_ctx(desc); |
212 | static u8 padding[128] = { 0x80, }; | 208 | static u8 padding[128] = { 0x80, }; |
213 | __be64 *dst = (__be64 *)hash; | 209 | __be64 *dst = (__be64 *)hash; |
214 | __be32 bits[4]; | 210 | __be64 bits[2]; |
215 | unsigned int index, pad_len; | 211 | unsigned int index, pad_len; |
216 | int i; | 212 | int i; |
217 | 213 | ||
218 | /* Save number of bits */ | 214 | /* Save number of bits */ |
219 | bits[3] = cpu_to_be32(sctx->count[0]); | 215 | bits[1] = cpu_to_be64(sctx->count[0] << 3); |
220 | bits[2] = cpu_to_be32(sctx->count[1]); | 216 | bits[0] = cpu_to_be64(sctx->count[1] << 3 | sctx->count[0] >> 61); |
221 | bits[1] = cpu_to_be32(sctx->count[2]); | ||
222 | bits[0] = cpu_to_be32(sctx->count[3]); | ||
223 | 217 | ||
224 | /* Pad out to 112 mod 128. */ | 218 | /* Pad out to 112 mod 128. */ |
225 | index = (sctx->count[0] >> 3) & 0x7f; | 219 | index = sctx->count[0] & 0x7f; |
226 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); | 220 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); |
227 | sha512_update(desc, padding, pad_len); | 221 | sha512_update(desc, padding, pad_len); |
228 | 222 | ||
diff --git a/include/crypto/sha.h b/include/crypto/sha.h index 45b25ccf7cc6..069e85ba97e1 100644 --- a/include/crypto/sha.h +++ b/include/crypto/sha.h | |||
@@ -77,9 +77,9 @@ struct sha256_state { | |||
77 | }; | 77 | }; |
78 | 78 | ||
79 | struct sha512_state { | 79 | struct sha512_state { |
80 | u64 state[8]; | 80 | u64 count[2]; |
81 | u32 count[4]; | 81 | u64 state[SHA512_DIGEST_SIZE / 8]; |
82 | u8 buf[128]; | 82 | u8 buf[SHA512_BLOCK_SIZE]; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | #endif | 85 | #endif |