aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/sha512.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/sha512.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/sha512.c')
-rw-r--r--crypto/sha512.c54
1 files changed, 12 insertions, 42 deletions
diff --git a/crypto/sha512.c b/crypto/sha512.c
index c663438322e9..3e6e9392310c 100644
--- a/crypto/sha512.c
+++ b/crypto/sha512.c
@@ -17,6 +17,7 @@
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/crypto.h> 19#include <linux/crypto.h>
20#include <linux/types.h>
20 21
21#include <asm/scatterlist.h> 22#include <asm/scatterlist.h>
22#include <asm/byteorder.h> 23#include <asm/byteorder.h>
@@ -235,39 +236,17 @@ static void
235sha512_final(void *ctx, u8 *hash) 236sha512_final(void *ctx, u8 *hash)
236{ 237{
237 struct sha512_ctx *sctx = ctx; 238 struct sha512_ctx *sctx = ctx;
238
239 static u8 padding[128] = { 0x80, }; 239 static u8 padding[128] = { 0x80, };
240 240 __be64 *dst = (__be64 *)hash;
241 u32 t; 241 __be32 bits[4];
242 u64 t2;
243 u8 bits[128];
244 unsigned int index, pad_len; 242 unsigned int index, pad_len;
245 int i, j; 243 int i;
246
247 index = pad_len = t = i = j = 0;
248 t2 = 0;
249 244
250 /* Save number of bits */ 245 /* Save number of bits */
251 t = sctx->count[0]; 246 bits[3] = cpu_to_be32(sctx->count[0]);
252 bits[15] = t; t>>=8; 247 bits[2] = cpu_to_be32(sctx->count[1]);
253 bits[14] = t; t>>=8; 248 bits[1] = cpu_to_be32(sctx->count[2]);
254 bits[13] = t; t>>=8; 249 bits[0] = cpu_to_be32(sctx->count[3]);
255 bits[12] = t;
256 t = sctx->count[1];
257 bits[11] = t; t>>=8;
258 bits[10] = t; t>>=8;
259 bits[9 ] = t; t>>=8;
260 bits[8 ] = t;
261 t = sctx->count[2];
262 bits[7 ] = t; t>>=8;
263 bits[6 ] = t; t>>=8;
264 bits[5 ] = t; t>>=8;
265 bits[4 ] = t;
266 t = sctx->count[3];
267 bits[3 ] = t; t>>=8;
268 bits[2 ] = t; t>>=8;
269 bits[1 ] = t; t>>=8;
270 bits[0 ] = t;
271 250
272 /* Pad out to 112 mod 128. */ 251 /* Pad out to 112 mod 128. */
273 index = (sctx->count[0] >> 3) & 0x7f; 252 index = (sctx->count[0] >> 3) & 0x7f;
@@ -275,21 +254,12 @@ sha512_final(void *ctx, u8 *hash)
275 sha512_update(sctx, padding, pad_len); 254 sha512_update(sctx, padding, pad_len);
276 255
277 /* Append length (before padding) */ 256 /* Append length (before padding) */
278 sha512_update(sctx, bits, 16); 257 sha512_update(sctx, (const u8 *)bits, sizeof(bits));
279 258
280 /* Store state in digest */ 259 /* Store state in digest */
281 for (i = j = 0; i < 8; i++, j += 8) { 260 for (i = 0; i < 8; i++)
282 t2 = sctx->state[i]; 261 dst[i] = cpu_to_be64(sctx->state[i]);
283 hash[j+7] = (char)t2 & 0xff; t2>>=8; 262
284 hash[j+6] = (char)t2 & 0xff; t2>>=8;
285 hash[j+5] = (char)t2 & 0xff; t2>>=8;
286 hash[j+4] = (char)t2 & 0xff; t2>>=8;
287 hash[j+3] = (char)t2 & 0xff; t2>>=8;
288 hash[j+2] = (char)t2 & 0xff; t2>>=8;
289 hash[j+1] = (char)t2 & 0xff; t2>>=8;
290 hash[j ] = (char)t2 & 0xff;
291 }
292
293 /* Zeroize sensitive information. */ 263 /* Zeroize sensitive information. */
294 memset(sctx, 0, sizeof(struct sha512_ctx)); 264 memset(sctx, 0, sizeof(struct sha512_ctx));
295} 265}