diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-17 03:00:36 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-17 03:00:36 +0200 |
commit | 36ab585f68295487a0973bde86bcb0ab7577a8ff (patch) | |
tree | 86faf83217ec48ff6135104994313ee03ec3e27d /libbb/sha1.c | |
parent | a971a192e8af4279fb384be9ff0f0e8387b229cb (diff) | |
download | busybox-w32-36ab585f68295487a0973bde86bcb0ab7577a8ff.tar.gz busybox-w32-36ab585f68295487a0973bde86bcb0ab7577a8ff.tar.bz2 busybox-w32-36ab585f68295487a0973bde86bcb0ab7577a8ff.zip |
md5: code shrink
function old new delta
md5_end 125 104 -21
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/sha1.c')
-rw-r--r-- | libbb/sha1.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/libbb/sha1.c b/libbb/sha1.c index 70efd581b..3e61aff6d 100644 --- a/libbb/sha1.c +++ b/libbb/sha1.c | |||
@@ -462,17 +462,15 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) | |||
462 | /* Used also for sha256 */ | 462 | /* Used also for sha256 */ |
463 | void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) | 463 | void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) |
464 | { | 464 | { |
465 | unsigned pad, bufpos; | 465 | unsigned bufpos = ctx->total64 & 63; |
466 | 466 | ||
467 | bufpos = ctx->total64 & 63; | ||
468 | /* Pad the buffer to the next 64-byte boundary with 0x80,0,0,0... */ | 467 | /* Pad the buffer to the next 64-byte boundary with 0x80,0,0,0... */ |
469 | ctx->wbuffer[bufpos++] = 0x80; | 468 | ctx->wbuffer[bufpos++] = 0x80; |
470 | 469 | ||
471 | /* This loop iterates either once or twice, no more, no less */ | 470 | /* This loop iterates either once or twice, no more, no less */ |
472 | while (1) { | 471 | while (1) { |
473 | pad = 64 - bufpos; | 472 | unsigned pad = 64 - bufpos; |
474 | memset(ctx->wbuffer + bufpos, 0, pad); | 473 | memset(ctx->wbuffer + bufpos, 0, pad); |
475 | bufpos = 0; | ||
476 | /* Do we have enough space for the length count? */ | 474 | /* Do we have enough space for the length count? */ |
477 | if (pad >= 8) { | 475 | if (pad >= 8) { |
478 | /* Store the 64-bit counter of bits in the buffer in BE format */ | 476 | /* Store the 64-bit counter of bits in the buffer in BE format */ |
@@ -484,6 +482,7 @@ void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) | |||
484 | ctx->process_block(ctx); | 482 | ctx->process_block(ctx); |
485 | if (pad >= 8) | 483 | if (pad >= 8) |
486 | break; | 484 | break; |
485 | bufpos = 0; | ||
487 | } | 486 | } |
488 | 487 | ||
489 | bufpos = (ctx->process_block == sha1_process_block64) ? 5 : 8; | 488 | bufpos = (ctx->process_block == sha1_process_block64) ? 5 : 8; |
@@ -498,18 +497,14 @@ void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) | |||
498 | 497 | ||
499 | void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) | 498 | void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) |
500 | { | 499 | { |
501 | unsigned pad, bufpos; | 500 | unsigned bufpos = ctx->total64[0] & 127; |
502 | 501 | ||
503 | bufpos = ctx->total64[0] & 127; | 502 | /* Pad the buffer to the next 128-byte boundary with 0x80,0,0,0... */ |
504 | /* Pad the buffer to the next 128-byte boundary with 0x80,0,0,0... | ||
505 | * (FIPS 180-2:5.1.2) | ||
506 | */ | ||
507 | ctx->wbuffer[bufpos++] = 0x80; | 503 | ctx->wbuffer[bufpos++] = 0x80; |
508 | 504 | ||
509 | while (1) { | 505 | while (1) { |
510 | pad = 128 - bufpos; | 506 | unsigned pad = 128 - bufpos; |
511 | memset(ctx->wbuffer + bufpos, 0, pad); | 507 | memset(ctx->wbuffer + bufpos, 0, pad); |
512 | bufpos = 0; | ||
513 | if (pad >= 16) { | 508 | if (pad >= 16) { |
514 | /* Store the 128-bit counter of bits in the buffer in BE format */ | 509 | /* Store the 128-bit counter of bits in the buffer in BE format */ |
515 | uint64_t t; | 510 | uint64_t t; |
@@ -523,6 +518,7 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) | |||
523 | sha512_process_block128(ctx); | 518 | sha512_process_block128(ctx); |
524 | if (pad >= 16) | 519 | if (pad >= 16) |
525 | break; | 520 | break; |
521 | bufpos = 0; | ||
526 | } | 522 | } |
527 | 523 | ||
528 | if (BB_LITTLE_ENDIAN) { | 524 | if (BB_LITTLE_ENDIAN) { |