aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-05-29 05:51:12 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-05-29 05:51:12 +0000
commit2684187601d4f087e36d2810fc8f67ca0daf9989 (patch)
treed2f6adda7dc120be2aa64c7a984f12c8ecf608f2 /libbb
parentec890bc1e05269be205cc1218bae5e090d150a2f (diff)
downloadbusybox-w32-2684187601d4f087e36d2810fc8f67ca0daf9989.tar.gz
busybox-w32-2684187601d4f087e36d2810fc8f67ca0daf9989.tar.bz2
busybox-w32-2684187601d4f087e36d2810fc8f67ca0daf9989.zip
Add SWAP_LE?? and SWAP_BE?? macros, and make things use them. Converts values
to/from little endian or big endian, which is a NOP if that's what the current platform already is. git-svn-id: svn://busybox.net/trunk/busybox@15215 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/md5.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/libbb/md5.c b/libbb/md5.c
index 584f5fe6f..58be40b6a 100644
--- a/libbb/md5.c
+++ b/libbb/md5.c
@@ -27,15 +27,6 @@
27# define MD5_SIZE_VS_SPEED CONFIG_MD5_SIZE_VS_SPEED 27# define MD5_SIZE_VS_SPEED CONFIG_MD5_SIZE_VS_SPEED
28# endif 28# endif
29 29
30/* Handle endian-ness */
31# if !BB_BIG_ENDIAN
32# define SWAP(n) (n)
33# elif defined(bswap_32)
34# define SWAP(n) bswap_32(n)
35# else
36# define SWAP(n) ((n << 24) | ((n&0xFF00)<<8) | ((n&0xFF0000)>>8) | (n>>24))
37# endif
38
39/* Initialize structure containing state of computation. 30/* Initialize structure containing state of computation.
40 * (RFC 1321, 3.3: Step 3) 31 * (RFC 1321, 3.3: Step 3)
41 */ 32 */
@@ -132,7 +123,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
132 uint32_t temp; 123 uint32_t temp;
133 124
134 for (i = 0; i < 16; i++) { 125 for (i = 0; i < 16; i++) {
135 cwp[i] = SWAP(words[i]); 126 cwp[i] = SWAP_LE32(words[i]);
136 } 127 }
137 words += 16; 128 words += 16;
138 129
@@ -224,7 +215,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
224# define OP(a, b, c, d, s, T) \ 215# define OP(a, b, c, d, s, T) \
225 do \ 216 do \
226 { \ 217 { \
227 a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ 218 a += FF (b, c, d) + (*cwp++ = SWAP_LE32(*words)) + T; \
228 ++words; \ 219 ++words; \
229 CYCLIC (a, s); \ 220 CYCLIC (a, s); \
230 a += b; \ 221 a += b; \
@@ -455,10 +446,10 @@ void *md5_end(void *resbuf, md5_ctx_t *ctx)
455 * IMPORTANT: On some systems it is required that RESBUF is correctly 446 * IMPORTANT: On some systems it is required that RESBUF is correctly
456 * aligned for a 32 bits value. 447 * aligned for a 32 bits value.
457 */ 448 */
458 ((uint32_t *) resbuf)[0] = SWAP(ctx->A); 449 ((uint32_t *) resbuf)[0] = SWAP_LE32(ctx->A);
459 ((uint32_t *) resbuf)[1] = SWAP(ctx->B); 450 ((uint32_t *) resbuf)[1] = SWAP_LE32(ctx->B);
460 ((uint32_t *) resbuf)[2] = SWAP(ctx->C); 451 ((uint32_t *) resbuf)[2] = SWAP_LE32(ctx->C);
461 ((uint32_t *) resbuf)[3] = SWAP(ctx->D); 452 ((uint32_t *) resbuf)[3] = SWAP_LE32(ctx->D);
462 453
463 return resbuf; 454 return resbuf;
464} 455}