diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-13 15:13:41 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-13 15:13:41 +0000 |
commit | 76f812803b72b5ccca764cdc7bfc42276fd70413 (patch) | |
tree | 9dab038f326aea3076875c4c60a52e5f62a0ed1b /libbb/pw_encrypt_md5.c | |
parent | aa9cd89c67a67e485fb5d9e51c1c2ced5face211 (diff) | |
download | busybox-w32-76f812803b72b5ccca764cdc7bfc42276fd70413.tar.gz busybox-w32-76f812803b72b5ccca764cdc7bfc42276fd70413.tar.bz2 busybox-w32-76f812803b72b5ccca764cdc7bfc42276fd70413.zip |
trivial crypt shrinkage
function old new delta
__md5_to64 27 29 +2
pw_encrypt 3631 3608 -23
Diffstat (limited to 'libbb/pw_encrypt_md5.c')
-rw-r--r-- | libbb/pw_encrypt_md5.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/libbb/pw_encrypt_md5.c b/libbb/pw_encrypt_md5.c index 42eb13440..6c94d2d29 100644 --- a/libbb/pw_encrypt_md5.c +++ b/libbb/pw_encrypt_md5.c | |||
@@ -501,13 +501,14 @@ static void __md5_Transform(uint32_t state[4], const unsigned char block[64]) | |||
501 | } | 501 | } |
502 | 502 | ||
503 | 503 | ||
504 | static void | 504 | static char* |
505 | __md5_to64(char *s, unsigned long v, int n) | 505 | __md5_to64(char *s, unsigned v, int n) |
506 | { | 506 | { |
507 | while (--n >= 0) { | 507 | while (--n >= 0) { |
508 | *s++ = ascii64[v & 0x3f]; | 508 | *s++ = ascii64[v & 0x3f]; |
509 | v >>= 6; | 509 | v >>= 6; |
510 | } | 510 | } |
511 | return s; | ||
511 | } | 512 | } |
512 | 513 | ||
513 | /* | 514 | /* |
@@ -515,7 +516,7 @@ __md5_to64(char *s, unsigned long v, int n) | |||
515 | * | 516 | * |
516 | * Use MD5 for what it is best at... | 517 | * Use MD5 for what it is best at... |
517 | */ | 518 | */ |
518 | #define MD5_OUT_BUFSIZE 120 | 519 | #define MD5_OUT_BUFSIZE 36 |
519 | 520 | ||
520 | static char * | 521 | static char * |
521 | md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt) | 522 | md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt) |
@@ -578,7 +579,6 @@ md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt) | |||
578 | passwd[2] = '$'; | 579 | passwd[2] = '$'; |
579 | strncpy(passwd + 3, (char*)sp, sl); | 580 | strncpy(passwd + 3, (char*)sp, sl); |
580 | passwd[sl + 3] = '$'; | 581 | passwd[sl + 3] = '$'; |
581 | passwd[sl + 4] = '\0'; | ||
582 | 582 | ||
583 | __md5_Final(final, &ctx); | 583 | __md5_Final(final, &ctx); |
584 | 584 | ||
@@ -607,15 +607,16 @@ md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt) | |||
607 | __md5_Final(final, &ctx1); | 607 | __md5_Final(final, &ctx1); |
608 | } | 608 | } |
609 | 609 | ||
610 | p = passwd + sl + 4; /*strlen(passwd);*/ | 610 | p = passwd + sl + 4; /* 12 bytes max (sl is up to 8 bytes) */ |
611 | 611 | ||
612 | /* Add 5*4+2 = 22 bytes of hash, + NUL byte. */ | ||
612 | final[16] = final[5]; | 613 | final[16] = final[5]; |
613 | for (i = 0; i < 5; i++) { | 614 | for (i = 0; i < 5; i++) { |
614 | l = (final[i] << 16) | (final[i+6] << 8) | final[i+12]; | 615 | l = (final[i] << 16) | (final[i+6] << 8) | final[i+12]; |
615 | __md5_to64(p, l, 4); p += 4; | 616 | p = __md5_to64(p, l, 4); |
616 | } | 617 | } |
617 | l = final[11]; | 618 | l = final[11]; |
618 | __md5_to64(p, l, 2); p += 2; | 619 | p = __md5_to64(p, l, 2); |
619 | *p = '\0'; | 620 | *p = '\0'; |
620 | 621 | ||
621 | /* Don't leave anything around in vm they could use. */ | 622 | /* Don't leave anything around in vm they could use. */ |