aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-07-06 19:30:58 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-07-06 19:30:58 +0200
commit447eb6bf71cf9d73a23f15c11b62e9e886e712ff (patch)
treee9fdf54c0ecd9cc5114fb4cfedf65967a745d81f /libbb
parent82bbbd2e538c29a585a6cb00be2e999f50bf865c (diff)
downloadbusybox-w32-447eb6bf71cf9d73a23f15c11b62e9e886e712ff.tar.gz
busybox-w32-447eb6bf71cf9d73a23f15c11b62e9e886e712ff.tar.bz2
busybox-w32-447eb6bf71cf9d73a23f15c11b62e9e886e712ff.zip
libbb: in DES crypt, error out on invalid salt chars
function old new delta des_crypt 1308 1327 +19 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/pw_encrypt_des.c36
1 files changed, 7 insertions, 29 deletions
diff --git a/libbb/pw_encrypt_des.c b/libbb/pw_encrypt_des.c
index 38c76a15c..bfa039bb5 100644
--- a/libbb/pw_encrypt_des.c
+++ b/libbb/pw_encrypt_des.c
@@ -674,12 +674,6 @@ do_des(struct des_ctx *ctx, /*uint32_t l_in, uint32_t r_in,*/ uint32_t *l_out, u
674static void 674static void
675to64_msb_first(char *s, unsigned v) 675to64_msb_first(char *s, unsigned v)
676{ 676{
677#if 0
678 *s++ = ascii64[(v >> 18) & 0x3f]; /* bits 23..18 */
679 *s++ = ascii64[(v >> 12) & 0x3f]; /* bits 17..12 */
680 *s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */
681 *s = ascii64[v & 0x3f]; /* bits 5..0 */
682#endif
683 *s++ = i2a64(v >> 18); /* bits 23..18 */ 677 *s++ = i2a64(v >> 18); /* bits 23..18 */
684 *s++ = i2a64(v >> 12); /* bits 17..12 */ 678 *s++ = i2a64(v >> 12); /* bits 17..12 */
685 *s++ = i2a64(v >> 6); /* bits 11..6 */ 679 *s++ = i2a64(v >> 6); /* bits 11..6 */
@@ -717,34 +711,19 @@ des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE],
717 */ 711 */
718 output[0] = salt_str[0]; 712 output[0] = salt_str[0];
719 output[1] = salt_str[1]; 713 output[1] = salt_str[1];
720 salt = (a2i64(salt_str[1]) << 6) 714
721 | a2i64(salt_str[0]); 715 salt = a2i64(salt_str[0]);
716 if (salt >= 64)
717 return NULL; /* bad salt char */
718 salt |= (a2i64(salt_str[1]) << 6);
719 if (salt >= (64 << 6))
720 return NULL; /* bad salt char */
722 setup_salt(ctx, salt); /* set ctx->saltbits for do_des() */ 721 setup_salt(ctx, salt); /* set ctx->saltbits for do_des() */
723 722
724 /* Do it. */ 723 /* Do it. */
725 do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */); 724 do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */);
726 725
727 /* Now encode the result. */ 726 /* Now encode the result. */
728#if 0
729{
730 uint32_t l = (r0 >> 8);
731 q = (uint8_t *)output + 2;
732 *q++ = ascii64[(l >> 18) & 0x3f]; /* bits 31..26 of r0 */
733 *q++ = ascii64[(l >> 12) & 0x3f]; /* bits 25..20 of r0 */
734 *q++ = ascii64[(l >> 6) & 0x3f]; /* bits 19..14 of r0 */
735 *q++ = ascii64[l & 0x3f]; /* bits 13..8 of r0 */
736 l = ((r0 << 16) | (r1 >> 16));
737 *q++ = ascii64[(l >> 18) & 0x3f]; /* bits 7..2 of r0 */
738 *q++ = ascii64[(l >> 12) & 0x3f]; /* bits 1..2 of r0 and 31..28 of r1 */
739 *q++ = ascii64[(l >> 6) & 0x3f]; /* bits 27..22 of r1 */
740 *q++ = ascii64[l & 0x3f]; /* bits 21..16 of r1 */
741 l = r1 << 2;
742 *q++ = ascii64[(l >> 12) & 0x3f]; /* bits 15..10 of r1 */
743 *q++ = ascii64[(l >> 6) & 0x3f]; /* bits 9..4 of r1 */
744 *q++ = ascii64[l & 0x3f]; /* bits 3..0 of r1 + 00 */
745 *q = 0;
746}
747#else
748 /* Each call takes low-order 24 bits and stores 4 chars */ 727 /* Each call takes low-order 24 bits and stores 4 chars */
749 /* bits 31..8 of r0 */ 728 /* bits 31..8 of r0 */
750 to64_msb_first(output + 2, (r0 >> 8)); 729 to64_msb_first(output + 2, (r0 >> 8));
@@ -754,7 +733,6 @@ des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE],
754 to64_msb_first(output + 10, (r1 << 8)); 733 to64_msb_first(output + 10, (r1 << 8));
755 /* extra zero byte is encoded as '.', fixing it */ 734 /* extra zero byte is encoded as '.', fixing it */
756 output[13] = '\0'; 735 output[13] = '\0';
757#endif
758 736
759 return output; 737 return output;
760} 738}