diff options
Diffstat (limited to 'crypto/sha256.c')
-rw-r--r-- | crypto/sha256.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/crypto/sha256.c b/crypto/sha256.c index c78da50a9b7a..9d5ef674d6a9 100644 --- a/crypto/sha256.c +++ b/crypto/sha256.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/mm.h> | 21 | #include <linux/mm.h> |
22 | #include <linux/crypto.h> | 22 | #include <linux/crypto.h> |
23 | #include <linux/types.h> | ||
23 | #include <asm/scatterlist.h> | 24 | #include <asm/scatterlist.h> |
24 | #include <asm/byteorder.h> | 25 | #include <asm/byteorder.h> |
25 | 26 | ||
@@ -279,22 +280,15 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len) | |||
279 | static void sha256_final(void* ctx, u8 *out) | 280 | static void sha256_final(void* ctx, u8 *out) |
280 | { | 281 | { |
281 | struct sha256_ctx *sctx = ctx; | 282 | struct sha256_ctx *sctx = ctx; |
282 | u8 bits[8]; | 283 | __be32 *dst = (__be32 *)out; |
283 | unsigned int index, pad_len, t; | 284 | __be32 bits[2]; |
284 | int i, j; | 285 | unsigned int index, pad_len; |
286 | int i; | ||
285 | static const u8 padding[64] = { 0x80, }; | 287 | static const u8 padding[64] = { 0x80, }; |
286 | 288 | ||
287 | /* Save number of bits */ | 289 | /* Save number of bits */ |
288 | t = sctx->count[0]; | 290 | bits[1] = cpu_to_be32(sctx->count[0]); |
289 | bits[7] = t; t >>= 8; | 291 | bits[0] = cpu_to_be32(sctx->count[1]); |
290 | bits[6] = t; t >>= 8; | ||
291 | bits[5] = t; t >>= 8; | ||
292 | bits[4] = t; | ||
293 | t = sctx->count[1]; | ||
294 | bits[3] = t; t >>= 8; | ||
295 | bits[2] = t; t >>= 8; | ||
296 | bits[1] = t; t >>= 8; | ||
297 | bits[0] = t; | ||
298 | 292 | ||
299 | /* Pad out to 56 mod 64. */ | 293 | /* Pad out to 56 mod 64. */ |
300 | index = (sctx->count[0] >> 3) & 0x3f; | 294 | index = (sctx->count[0] >> 3) & 0x3f; |
@@ -302,16 +296,11 @@ static void sha256_final(void* ctx, u8 *out) | |||
302 | sha256_update(sctx, padding, pad_len); | 296 | sha256_update(sctx, padding, pad_len); |
303 | 297 | ||
304 | /* Append length (before padding) */ | 298 | /* Append length (before padding) */ |
305 | sha256_update(sctx, bits, 8); | 299 | sha256_update(sctx, (const u8 *)bits, sizeof(bits)); |
306 | 300 | ||
307 | /* Store state in digest */ | 301 | /* Store state in digest */ |
308 | for (i = j = 0; i < 8; i++, j += 4) { | 302 | for (i = 0; i < 8; i++) |
309 | t = sctx->state[i]; | 303 | dst[i] = cpu_to_be32(sctx->state[i]); |
310 | out[j+3] = t; t >>= 8; | ||
311 | out[j+2] = t; t >>= 8; | ||
312 | out[j+1] = t; t >>= 8; | ||
313 | out[j ] = t; | ||
314 | } | ||
315 | 304 | ||
316 | /* Zeroize sensitive information. */ | 305 | /* Zeroize sensitive information. */ |
317 | memset(sctx, 0, sizeof(*sctx)); | 306 | memset(sctx, 0, sizeof(*sctx)); |