diff options
Diffstat (limited to 'libbb/hash_sha.c')
-rw-r--r-- | libbb/hash_sha.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/libbb/hash_sha.c b/libbb/hash_sha.c index e7199d317..72d50928b 100644 --- a/libbb/hash_sha.c +++ b/libbb/hash_sha.c | |||
@@ -51,16 +51,6 @@ static ALWAYS_INLINE uint64_t rotr64(uint64_t x, unsigned n) | |||
51 | { | 51 | { |
52 | return (x >> n) | (x << (64 - n)); | 52 | return (x >> n) | (x << (64 - n)); |
53 | } | 53 | } |
54 | #if BB_LITTLE_ENDIAN | ||
55 | /* ALWAYS_INLINE below sometimes hurts code size, using plain inline: */ | ||
56 | static inline uint64_t hton64(uint64_t v) | ||
57 | { | ||
58 | return SWAP_BE64(v); | ||
59 | } | ||
60 | #else | ||
61 | #define hton64(v) (v) | ||
62 | #endif | ||
63 | #define ntoh64(v) hton64(v) | ||
64 | 54 | ||
65 | 55 | ||
66 | /* Some arch headers have conflicting defines */ | 56 | /* Some arch headers have conflicting defines */ |
@@ -274,7 +264,7 @@ static void FAST_FUNC sha512_process_block128(sha512_ctx_t *ctx) | |||
274 | 264 | ||
275 | /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */ | 265 | /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */ |
276 | for (t = 0; t < 16; ++t) | 266 | for (t = 0; t < 16; ++t) |
277 | W[t] = ntoh64(words[t]); | 267 | W[t] = SWAP_BE64(words[t]); |
278 | for (/*t = 16*/; t < 80; ++t) | 268 | for (/*t = 16*/; t < 80; ++t) |
279 | W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16]; | 269 | W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16]; |
280 | 270 | ||
@@ -475,7 +465,7 @@ void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) | |||
475 | if (remaining >= 8) { | 465 | if (remaining >= 8) { |
476 | /* Store the 64-bit counter of bits in the buffer in BE format */ | 466 | /* Store the 64-bit counter of bits in the buffer in BE format */ |
477 | uint64_t t = ctx->total64 << 3; | 467 | uint64_t t = ctx->total64 << 3; |
478 | t = hton64(t); | 468 | t = SWAP_BE64(t); |
479 | /* wbuffer is suitably aligned for this */ | 469 | /* wbuffer is suitably aligned for this */ |
480 | *(uint64_t *) (&ctx->wbuffer[64 - 8]) = t; | 470 | *(uint64_t *) (&ctx->wbuffer[64 - 8]) = t; |
481 | } | 471 | } |
@@ -509,10 +499,10 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) | |||
509 | /* Store the 128-bit counter of bits in the buffer in BE format */ | 499 | /* Store the 128-bit counter of bits in the buffer in BE format */ |
510 | uint64_t t; | 500 | uint64_t t; |
511 | t = ctx->total64[0] << 3; | 501 | t = ctx->total64[0] << 3; |
512 | t = hton64(t); | 502 | t = SWAP_BE64(t); |
513 | *(uint64_t *) (&ctx->wbuffer[128 - 8]) = t; | 503 | *(uint64_t *) (&ctx->wbuffer[128 - 8]) = t; |
514 | t = (ctx->total64[1] << 3) | (ctx->total64[0] >> 61); | 504 | t = (ctx->total64[1] << 3) | (ctx->total64[0] >> 61); |
515 | t = hton64(t); | 505 | t = SWAP_BE64(t); |
516 | *(uint64_t *) (&ctx->wbuffer[128 - 16]) = t; | 506 | *(uint64_t *) (&ctx->wbuffer[128 - 16]) = t; |
517 | } | 507 | } |
518 | sha512_process_block128(ctx); | 508 | sha512_process_block128(ctx); |
@@ -524,7 +514,7 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) | |||
524 | if (BB_LITTLE_ENDIAN) { | 514 | if (BB_LITTLE_ENDIAN) { |
525 | unsigned i; | 515 | unsigned i; |
526 | for (i = 0; i < ARRAY_SIZE(ctx->hash); ++i) | 516 | for (i = 0; i < ARRAY_SIZE(ctx->hash); ++i) |
527 | ctx->hash[i] = hton64(ctx->hash[i]); | 517 | ctx->hash[i] = SWAP_BE64(ctx->hash[i]); |
528 | } | 518 | } |
529 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash)); | 519 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash)); |
530 | } | 520 | } |