aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/pw_encrypt_des.c2
-rw-r--r--libbb/pw_encrypt_md5.c15
2 files changed, 8 insertions, 9 deletions
diff --git a/libbb/pw_encrypt_des.c b/libbb/pw_encrypt_des.c
index 637765ead..ab217d8e9 100644
--- a/libbb/pw_encrypt_des.c
+++ b/libbb/pw_encrypt_des.c
@@ -673,8 +673,6 @@ des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const
673 return output; 673 return output;
674} 674}
675 675
676// des_setkey never fails
677
678#undef C 676#undef C
679#undef init_perm 677#undef init_perm
680#undef final_perm 678#undef final_perm
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
504static void 504static 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
520static char * 521static char *
521md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt) 522md5_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. */