diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-04 15:29:35 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-04 15:29:35 +0000 |
commit | d324e1b808daca7eec5b8700824a886a21508714 (patch) | |
tree | 9aa36cbf7f824b6068fba785bee0eb8262677117 /libbb/pw_encrypt_des.c | |
parent | 9c6d12993f336662c0afcdce4a06f5669c0b8501 (diff) | |
download | busybox-w32-d324e1b808daca7eec5b8700824a886a21508714.tar.gz busybox-w32-d324e1b808daca7eec5b8700824a886a21508714.tar.bz2 busybox-w32-d324e1b808daca7eec5b8700824a886a21508714.zip |
libbb/crypt: code shrink
function old new delta
to64_msb_first - 63 +63
des_crypt 1509 1338 -171
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 63/-171) Total: -108 bytes
Diffstat (limited to 'libbb/pw_encrypt_des.c')
-rw-r--r-- | libbb/pw_encrypt_des.c | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/libbb/pw_encrypt_des.c b/libbb/pw_encrypt_des.c index cd19a63f7..4e506f498 100644 --- a/libbb/pw_encrypt_des.c +++ b/libbb/pw_encrypt_des.c | |||
@@ -696,13 +696,22 @@ do_des(struct des_ctx *ctx, /*uint32_t l_in, uint32_t r_in,*/ uint32_t *l_out, u | |||
696 | 696 | ||
697 | #define DES_OUT_BUFSIZE 21 | 697 | #define DES_OUT_BUFSIZE 21 |
698 | 698 | ||
699 | static void | ||
700 | to64_msb_first(char *s, unsigned v) | ||
701 | { | ||
702 | *s++ = ascii64[(v >> 18) & 0x3f]; /* bits 23..18 */ | ||
703 | *s++ = ascii64[(v >> 12) & 0x3f]; /* bits 17..12 */ | ||
704 | *s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */ | ||
705 | *s = ascii64[v & 0x3f]; /* bits 5..0 */ | ||
706 | } | ||
707 | |||
699 | static char * | 708 | static char * |
700 | NOINLINE | 709 | NOINLINE |
701 | des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE], | 710 | des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE], |
702 | const unsigned char *key, const unsigned char *setting) | 711 | const unsigned char *key, const unsigned char *setting) |
703 | { | 712 | { |
704 | uint32_t salt, l, r0, r1, keybuf[2]; | 713 | uint32_t salt, r0, r1, keybuf[2]; |
705 | uint8_t *p, *q; | 714 | uint8_t *q; |
706 | 715 | ||
707 | /* | 716 | /* |
708 | * Copy the key, shifting each character up by one bit | 717 | * Copy the key, shifting each character up by one bit |
@@ -733,34 +742,39 @@ des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE], | |||
733 | */ | 742 | */ |
734 | output[1] = setting[1] ? setting[1] : output[0]; | 743 | output[1] = setting[1] ? setting[1] : output[0]; |
735 | 744 | ||
736 | p = (uint8_t *)output + 2; | ||
737 | |||
738 | setup_salt(ctx, salt); | 745 | setup_salt(ctx, salt); |
739 | /* | 746 | /* Do it. */ |
740 | * Do it. | ||
741 | */ | ||
742 | do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */); | 747 | do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */); |
743 | 748 | ||
744 | /* | 749 | /* Now encode the result. */ |
745 | * Now encode the result... | 750 | #if 0 |
746 | */ | 751 | { |
747 | l = (r0 >> 8); | 752 | uint32_t l = (r0 >> 8); |
748 | *p++ = ascii64[(l >> 18) & 0x3f]; | 753 | q = (uint8_t *)output + 2; |
749 | *p++ = ascii64[(l >> 12) & 0x3f]; | 754 | *q++ = ascii64[(l >> 18) & 0x3f]; /* bits 31..26 of r0 */ |
750 | *p++ = ascii64[(l >> 6) & 0x3f]; | 755 | *q++ = ascii64[(l >> 12) & 0x3f]; /* bits 25..20 of r0 */ |
751 | *p++ = ascii64[l & 0x3f]; | 756 | *q++ = ascii64[(l >> 6) & 0x3f]; /* bits 19..14 of r0 */ |
752 | 757 | *q++ = ascii64[l & 0x3f]; /* bits 13..8 of r0 */ | |
753 | l = ((r0 << 16) | (r1 >> 16)); | 758 | l = ((r0 << 16) | (r1 >> 16)); |
754 | *p++ = ascii64[(l >> 18) & 0x3f]; | 759 | *q++ = ascii64[(l >> 18) & 0x3f]; /* bits 7..2 of r0 */ |
755 | *p++ = ascii64[(l >> 12) & 0x3f]; | 760 | *q++ = ascii64[(l >> 12) & 0x3f]; /* bits 1..2 of r0 and 31..28 of r1 */ |
756 | *p++ = ascii64[(l >> 6) & 0x3f]; | 761 | *q++ = ascii64[(l >> 6) & 0x3f]; /* bits 27..22 of r1 */ |
757 | *p++ = ascii64[l & 0x3f]; | 762 | *q++ = ascii64[l & 0x3f]; /* bits 21..16 of r1 */ |
758 | |||
759 | l = r1 << 2; | 763 | l = r1 << 2; |
760 | *p++ = ascii64[(l >> 12) & 0x3f]; | 764 | *q++ = ascii64[(l >> 12) & 0x3f]; /* bits 15..10 of r1 */ |
761 | *p++ = ascii64[(l >> 6) & 0x3f]; | 765 | *q++ = ascii64[(l >> 6) & 0x3f]; /* bits 9..4 of r1 */ |
762 | *p++ = ascii64[l & 0x3f]; | 766 | *q++ = ascii64[l & 0x3f]; /* bits 3..0 of r1 + 00 */ |
763 | *p = 0; | 767 | *q = 0; |
768 | } | ||
769 | #else | ||
770 | /* Each call takes low-order 24 bits and stores 4 chars */ | ||
771 | /* bits 31..8 of r0 */ | ||
772 | to64_msb_first(output + 2, (r0 >> 8)); | ||
773 | /* bits 7..0 of r0 and 31..16 of r1 */ | ||
774 | to64_msb_first(output + 6, (r0 << 16) | (r1 >> 16)); | ||
775 | /* (bits 15..0 of r1 + 00) and NUL byte */ | ||
776 | to64_msb_first(output + 10, (r1 << 8)); | ||
777 | #endif | ||
764 | 778 | ||
765 | return output; | 779 | return output; |
766 | } | 780 | } |