diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/sha1.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/libbb/sha1.c b/libbb/sha1.c index ea645b735..5f42532cd 100644 --- a/libbb/sha1.c +++ b/libbb/sha1.c | |||
@@ -408,7 +408,7 @@ void FAST_FUNC sha512_hash(const void *buffer, size_t len, sha512_ctx_t *ctx) | |||
408 | /* Used also for sha256 */ | 408 | /* Used also for sha256 */ |
409 | void FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) | 409 | void FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) |
410 | { | 410 | { |
411 | unsigned i, pad, in_buf; | 411 | unsigned pad, in_buf; |
412 | 412 | ||
413 | in_buf = ctx->total64 & 63; | 413 | in_buf = ctx->total64 & 63; |
414 | /* Pad the buffer to the next 64-byte boundary with 0x80,0,0,0... */ | 414 | /* Pad the buffer to the next 64-byte boundary with 0x80,0,0,0... */ |
@@ -434,16 +434,17 @@ void FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) | |||
434 | 434 | ||
435 | in_buf = (ctx->process_block == sha1_process_block64) ? 5 : 8; | 435 | in_buf = (ctx->process_block == sha1_process_block64) ? 5 : 8; |
436 | /* This way we do not impose alignment constraints on resbuf: */ | 436 | /* This way we do not impose alignment constraints on resbuf: */ |
437 | #if BB_LITTLE_ENDIAN | 437 | if (BB_LITTLE_ENDIAN) { |
438 | for (i = 0; i < in_buf; ++i) | 438 | unsigned i; |
439 | ctx->hash[i] = htonl(ctx->hash[i]); | 439 | for (i = 0; i < in_buf; ++i) |
440 | #endif | 440 | ctx->hash[i] = htonl(ctx->hash[i]); |
441 | } | ||
441 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * in_buf); | 442 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * in_buf); |
442 | } | 443 | } |
443 | 444 | ||
444 | void FAST_FUNC sha512_end(void *resbuf, sha512_ctx_t *ctx) | 445 | void FAST_FUNC sha512_end(void *resbuf, sha512_ctx_t *ctx) |
445 | { | 446 | { |
446 | unsigned i, pad, in_buf; | 447 | unsigned pad, in_buf; |
447 | 448 | ||
448 | in_buf = ctx->total64[0] & 127; | 449 | in_buf = ctx->total64[0] & 127; |
449 | /* Pad the buffer to the next 128-byte boundary with 0x80,0,0,0... | 450 | /* Pad the buffer to the next 128-byte boundary with 0x80,0,0,0... |
@@ -470,9 +471,10 @@ void FAST_FUNC sha512_end(void *resbuf, sha512_ctx_t *ctx) | |||
470 | break; | 471 | break; |
471 | } | 472 | } |
472 | 473 | ||
473 | #if BB_LITTLE_ENDIAN | 474 | if (BB_LITTLE_ENDIAN) { |
474 | for (i = 0; i < ARRAY_SIZE(ctx->hash); ++i) | 475 | unsigned i; |
475 | ctx->hash[i] = hton64(ctx->hash[i]); | 476 | for (i = 0; i < ARRAY_SIZE(ctx->hash); ++i) |
476 | #endif | 477 | ctx->hash[i] = hton64(ctx->hash[i]); |
478 | } | ||
477 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash)); | 479 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash)); |
478 | } | 480 | } |