diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2005-10-30 05:25:15 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-01-09 17:15:34 -0500 |
commit | 06ace7a9bafeb9047352707eb79e8eaa0dfdf5f2 (patch) | |
tree | fa22bbc2e8ea5bee00b6aec353783144b6f8735a /crypto/sha256.c | |
parent | 2df15fffc612b53b2c8e4ff3c981a82441bc00ae (diff) |
[CRYPTO] Use standard byte order macros wherever possible
A lot of crypto code needs to read/write a 32-bit/64-bit words in a
specific gender. Many of them open code them by reading/writing one
byte at a time. This patch converts all the applicable usages over
to use the standard byte order macros.
This is based on a previous patch by Denis Vlasenko.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
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)); |