aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/sha1.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2005-10-30 05:25:15 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-01-09 17:15:34 -0500
commit06ace7a9bafeb9047352707eb79e8eaa0dfdf5f2 (patch)
treefa22bbc2e8ea5bee00b6aec353783144b6f8735a /crypto/sha1.c
parent2df15fffc612b53b2c8e4ff3c981a82441bc00ae (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/sha1.c')
-rw-r--r--crypto/sha1.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/crypto/sha1.c b/crypto/sha1.c
index 4016f3b8ce9b..c686e7826174 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -21,6 +21,7 @@
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/crypto.h> 22#include <linux/crypto.h>
23#include <linux/cryptohash.h> 23#include <linux/cryptohash.h>
24#include <linux/types.h>
24#include <asm/scatterlist.h> 25#include <asm/scatterlist.h>
25#include <asm/byteorder.h> 26#include <asm/byteorder.h>
26 27
@@ -72,20 +73,12 @@ static void sha1_update(void *ctx, const u8 *data, unsigned int len)
72static void sha1_final(void* ctx, u8 *out) 73static void sha1_final(void* ctx, u8 *out)
73{ 74{
74 struct sha1_ctx *sctx = ctx; 75 struct sha1_ctx *sctx = ctx;
75 u32 i, j, index, padlen; 76 __be32 *dst = (__be32 *)out;
76 u64 t; 77 u32 i, index, padlen;
77 u8 bits[8] = { 0, }; 78 __be64 bits;
78 static const u8 padding[64] = { 0x80, }; 79 static const u8 padding[64] = { 0x80, };
79 80
80 t = sctx->count; 81 bits = cpu_to_be64(sctx->count);
81 bits[7] = 0xff & t; t>>=8;
82 bits[6] = 0xff & t; t>>=8;
83 bits[5] = 0xff & t; t>>=8;
84 bits[4] = 0xff & t; t>>=8;
85 bits[3] = 0xff & t; t>>=8;
86 bits[2] = 0xff & t; t>>=8;
87 bits[1] = 0xff & t; t>>=8;
88 bits[0] = 0xff & t;
89 82
90 /* Pad out to 56 mod 64 */ 83 /* Pad out to 56 mod 64 */
91 index = (sctx->count >> 3) & 0x3f; 84 index = (sctx->count >> 3) & 0x3f;
@@ -93,16 +86,11 @@ static void sha1_final(void* ctx, u8 *out)
93 sha1_update(sctx, padding, padlen); 86 sha1_update(sctx, padding, padlen);
94 87
95 /* Append length */ 88 /* Append length */
96 sha1_update(sctx, bits, sizeof bits); 89 sha1_update(sctx, (const u8 *)&bits, sizeof(bits));
97 90
98 /* Store state in digest */ 91 /* Store state in digest */
99 for (i = j = 0; i < 5; i++, j += 4) { 92 for (i = 0; i < 5; i++)
100 u32 t2 = sctx->state[i]; 93 dst[i] = cpu_to_be32(sctx->state[i]);
101 out[j+3] = t2 & 0xff; t2>>=8;
102 out[j+2] = t2 & 0xff; t2>>=8;
103 out[j+1] = t2 & 0xff; t2>>=8;
104 out[j ] = t2 & 0xff;
105 }
106 94
107 /* Wipe context */ 95 /* Wipe context */
108 memset(sctx, 0, sizeof *sctx); 96 memset(sctx, 0, sizeof *sctx);