diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-18 11:39:47 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-18 11:39:47 +0200 |
commit | b102e12253078e8c0ebdeeb5e1893ea6a025a700 (patch) | |
tree | 63ad7f83781bea9185d72b75c28a9cb19cb04515 | |
parent | 06f719fd79fe15ce6fd5431bc58fcb22851de24d (diff) | |
download | busybox-w32-b102e12253078e8c0ebdeeb5e1893ea6a025a700.tar.gz busybox-w32-b102e12253078e8c0ebdeeb5e1893ea6a025a700.tar.bz2 busybox-w32-b102e12253078e8c0ebdeeb5e1893ea6a025a700.zip |
*: use SWAP_BE64 instead of open-coding it
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/hash_md5.c | 8 | ||||
-rw-r--r-- | libbb/hash_sha.c | 10 | ||||
-rw-r--r-- | networking/udhcp/dumpleases.c | 2 | ||||
-rw-r--r-- | networking/udhcp/files.c | 2 |
5 files changed, 11 insertions, 13 deletions
diff --git a/include/libbb.h b/include/libbb.h index dec4e3af5..b16157d46 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1540,7 +1540,7 @@ typedef struct md5_ctx_t { | |||
1540 | uint32_t C; | 1540 | uint32_t C; |
1541 | uint32_t D; | 1541 | uint32_t D; |
1542 | uint64_t total64; | 1542 | uint64_t total64; |
1543 | char wbuffer[64]; | 1543 | char wbuffer[64]; /* NB: always correctly aligned for uint64_t */ |
1544 | } md5_ctx_t; | 1544 | } md5_ctx_t; |
1545 | #else | 1545 | #else |
1546 | /* libbb/md5prime.c uses a bit different one: */ | 1546 | /* libbb/md5prime.c uses a bit different one: */ |
diff --git a/libbb/hash_md5.c b/libbb/hash_md5.c index 051c8ede4..9de27f1d9 100644 --- a/libbb/hash_md5.c +++ b/libbb/hash_md5.c | |||
@@ -417,11 +417,9 @@ void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) | |||
417 | if (remaining >= 8) { | 417 | if (remaining >= 8) { |
418 | /* Store the 64-bit counter of bits in the buffer in BE format */ | 418 | /* Store the 64-bit counter of bits in the buffer in BE format */ |
419 | uint64_t t = ctx->total64 << 3; | 419 | uint64_t t = ctx->total64 << 3; |
420 | unsigned i; | 420 | t = SWAP_BE64(t); |
421 | for (i = 0; i < 8; i++) { | 421 | /* wbuffer is suitably aligned for this */ |
422 | ctx->wbuffer[56 + i] = t; | 422 | *(uint64_t *) (&ctx->wbuffer[64 - 8]) = t; |
423 | t >>= 8; | ||
424 | } | ||
425 | } | 423 | } |
426 | md5_process_block64(ctx); | 424 | md5_process_block64(ctx); |
427 | if (remaining >= 8) | 425 | if (remaining >= 8) |
diff --git a/libbb/hash_sha.c b/libbb/hash_sha.c index d79291148..e7199d317 100644 --- a/libbb/hash_sha.c +++ b/libbb/hash_sha.c | |||
@@ -52,10 +52,10 @@ static ALWAYS_INLINE uint64_t rotr64(uint64_t x, unsigned n) | |||
52 | return (x >> n) | (x << (64 - n)); | 52 | return (x >> n) | (x << (64 - n)); |
53 | } | 53 | } |
54 | #if BB_LITTLE_ENDIAN | 54 | #if BB_LITTLE_ENDIAN |
55 | /* ALWAYS_INLINE below would hurt code size, using plain inline: */ | 55 | /* ALWAYS_INLINE below sometimes hurts code size, using plain inline: */ |
56 | static inline uint64_t hton64(uint64_t v) | 56 | static inline uint64_t hton64(uint64_t v) |
57 | { | 57 | { |
58 | return (((uint64_t)htonl(v)) << 32) | htonl(v >> 32); | 58 | return SWAP_BE64(v); |
59 | } | 59 | } |
60 | #else | 60 | #else |
61 | #define hton64(v) (v) | 61 | #define hton64(v) (v) |
@@ -76,7 +76,7 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) | |||
76 | const uint32_t *words = (uint32_t*) ctx->wbuffer; | 76 | const uint32_t *words = (uint32_t*) ctx->wbuffer; |
77 | 77 | ||
78 | for (t = 0; t < 16; ++t) | 78 | for (t = 0; t < 16; ++t) |
79 | W[t] = ntohl(words[t]); | 79 | W[t] = SWAP_BE32(words[t]); |
80 | for (/*t = 16*/; t < 80; ++t) { | 80 | for (/*t = 16*/; t < 80; ++t) { |
81 | uint32_t T = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]; | 81 | uint32_t T = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]; |
82 | W[t] = rotl32(T, 1); | 82 | W[t] = rotl32(T, 1); |
@@ -198,7 +198,7 @@ static void FAST_FUNC sha256_process_block64(sha256_ctx_t *ctx) | |||
198 | 198 | ||
199 | /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */ | 199 | /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */ |
200 | for (t = 0; t < 16; ++t) | 200 | for (t = 0; t < 16; ++t) |
201 | W[t] = ntohl(words[t]); | 201 | W[t] = SWAP_BE32(words[t]); |
202 | for (/*t = 16*/; t < 64; ++t) | 202 | for (/*t = 16*/; t < 64; ++t) |
203 | W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16]; | 203 | W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16]; |
204 | 204 | ||
@@ -490,7 +490,7 @@ void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) | |||
490 | if (BB_LITTLE_ENDIAN) { | 490 | if (BB_LITTLE_ENDIAN) { |
491 | unsigned i; | 491 | unsigned i; |
492 | for (i = 0; i < bufpos; ++i) | 492 | for (i = 0; i < bufpos; ++i) |
493 | ctx->hash[i] = htonl(ctx->hash[i]); | 493 | ctx->hash[i] = SWAP_BE32(ctx->hash[i]); |
494 | } | 494 | } |
495 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * bufpos); | 495 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * bufpos); |
496 | } | 496 | } |
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 2eaadb6eb..341815a69 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c | |||
@@ -9,7 +9,7 @@ | |||
9 | #if BB_LITTLE_ENDIAN | 9 | #if BB_LITTLE_ENDIAN |
10 | static inline uint64_t hton64(uint64_t v) | 10 | static inline uint64_t hton64(uint64_t v) |
11 | { | 11 | { |
12 | return (((uint64_t)htonl(v)) << 32) | htonl(v >> 32); | 12 | return SWAP_BE64(v); |
13 | } | 13 | } |
14 | #else | 14 | #else |
15 | #define hton64(v) (v) | 15 | #define hton64(v) (v) |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index f5348f658..68b2085a9 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -14,7 +14,7 @@ | |||
14 | #if BB_LITTLE_ENDIAN | 14 | #if BB_LITTLE_ENDIAN |
15 | static inline uint64_t hton64(uint64_t v) | 15 | static inline uint64_t hton64(uint64_t v) |
16 | { | 16 | { |
17 | return (((uint64_t)htonl(v)) << 32) | htonl(v >> 32); | 17 | return SWAP_BE64(v); |
18 | } | 18 | } |
19 | #else | 19 | #else |
20 | #define hton64(v) (v) | 20 | #define hton64(v) (v) |