aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/pw_encrypt_des.c15
-rw-r--r--libbb/pw_encrypt_md5.c17
2 files changed, 11 insertions, 21 deletions
diff --git a/libbb/pw_encrypt_des.c b/libbb/pw_encrypt_des.c
index ab217d8e9..66e607955 100644
--- a/libbb/pw_encrypt_des.c
+++ b/libbb/pw_encrypt_des.c
@@ -400,7 +400,6 @@ des_init(struct des_ctx *ctx, const struct const_des_ctx *cctx)
400static void 400static void
401setup_salt(struct des_ctx *ctx, uint32_t salt) 401setup_salt(struct des_ctx *ctx, uint32_t salt)
402{ 402{
403// const struct const_des_ctx *cctx = const_ctx;
404 uint32_t obit, saltbit; 403 uint32_t obit, saltbit;
405 int i; 404 int i;
406 405
@@ -422,7 +421,6 @@ setup_salt(struct des_ctx *ctx, uint32_t salt)
422static void 421static void
423des_setkey(struct des_ctx *ctx, const char *key) 422des_setkey(struct des_ctx *ctx, const char *key)
424{ 423{
425// const struct const_des_ctx *cctx = const_ctx;
426 uint32_t k0, k1, rawkey0, rawkey1; 424 uint32_t k0, k1, rawkey0, rawkey1;
427 int shifts, round; 425 int shifts, round;
428 426
@@ -498,7 +496,7 @@ des_setkey(struct des_ctx *ctx, const char *key)
498} 496}
499 497
500 498
501static int 499static void
502do_des(struct des_ctx *ctx, uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int count) 500do_des(struct des_ctx *ctx, uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int count)
503{ 501{
504 const struct const_des_ctx *cctx = const_ctx; 502 const struct const_des_ctx *cctx = const_ctx;
@@ -602,12 +600,12 @@ do_des(struct des_ctx *ctx, uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint3
602 | fp_maskr[5][(r >> 16) & 0xff] 600 | fp_maskr[5][(r >> 16) & 0xff]
603 | fp_maskr[6][(r >> 8) & 0xff] 601 | fp_maskr[6][(r >> 8) & 0xff]
604 | fp_maskr[7][r & 0xff]; 602 | fp_maskr[7][r & 0xff];
605 return 0;
606} 603}
607 604
608#define DES_OUT_BUFSIZE 21 605#define DES_OUT_BUFSIZE 21
609 606
610static char * 607static char *
608NOINLINE
611des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const unsigned char *setting) 609des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const unsigned char *setting)
612{ 610{
613 uint32_t salt, l, r0, r1, keybuf[2]; 611 uint32_t salt, l, r0, r1, keybuf[2];
@@ -618,10 +616,11 @@ des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const
618 * and padding with zeros. 616 * and padding with zeros.
619 */ 617 */
620 q = (uint8_t *)keybuf; 618 q = (uint8_t *)keybuf;
621 while (q - (uint8_t *)keybuf - 8) { 619 while (q - (uint8_t *)keybuf != 8) {
622 *q++ = *key << 1; 620 *q = *key << 1;
623 if (*(q - 1)) 621 if (*q)
624 key++; 622 key++;
623 q++;
625 } 624 }
626 des_setkey(ctx, (char *)keybuf); 625 des_setkey(ctx, (char *)keybuf);
627 626
@@ -658,7 +657,7 @@ des_crypt(struct des_ctx *ctx, char output[21], const unsigned char *key, const
658 *p++ = ascii64[(l >> 6) & 0x3f]; 657 *p++ = ascii64[(l >> 6) & 0x3f];
659 *p++ = ascii64[l & 0x3f]; 658 *p++ = ascii64[l & 0x3f];
660 659
661 l = (r0 << 16) | ((r1 >> 16) & 0xffff); 660 l = ((r0 << 16) | (r1 >> 16));
662 *p++ = ascii64[(l >> 18) & 0x3f]; 661 *p++ = ascii64[(l >> 18) & 0x3f];
663 *p++ = ascii64[(l >> 12) & 0x3f]; 662 *p++ = ascii64[(l >> 12) & 0x3f];
664 *p++ = ascii64[(l >> 6) & 0x3f]; 663 *p++ = ascii64[(l >> 6) & 0x3f];
diff --git a/libbb/pw_encrypt_md5.c b/libbb/pw_encrypt_md5.c
index 6c94d2d29..8d0a516cf 100644
--- a/libbb/pw_encrypt_md5.c
+++ b/libbb/pw_encrypt_md5.c
@@ -101,7 +101,6 @@ static const unsigned char __md5__magic[] = MD5_MAGIC_STR;
101 * __md5_Encodes input (uint32_t) into output (unsigned char). Assumes len is 101 * __md5_Encodes input (uint32_t) into output (unsigned char). Assumes len is
102 * a multiple of 4. 102 * a multiple of 4.
103 */ 103 */
104
105static void 104static void
106__md5_Encode(unsigned char *output, uint32_t *input, unsigned int len) 105__md5_Encode(unsigned char *output, uint32_t *input, unsigned int len)
107{ 106{
@@ -119,7 +118,6 @@ __md5_Encode(unsigned char *output, uint32_t *input, unsigned int len)
119 * __md5_Decodes input (unsigned char) into output (uint32_t). Assumes len is 118 * __md5_Decodes input (unsigned char) into output (uint32_t). Assumes len is
120 * a multiple of 4. 119 * a multiple of 4.
121 */ 120 */
122
123static void 121static void
124__md5_Decode(uint32_t *output, const unsigned char *input, unsigned int len) 122__md5_Decode(uint32_t *output, const unsigned char *input, unsigned int len)
125{ 123{
@@ -166,7 +164,6 @@ __md5_Decode(uint32_t *output, const unsigned char *input, unsigned int len)
166 } 164 }
167 165
168/* MD5 initialization. Begins an MD5 operation, writing a new context. */ 166/* MD5 initialization. Begins an MD5 operation, writing a new context. */
169
170static void __md5_Init(struct MD5Context *context) 167static void __md5_Init(struct MD5Context *context)
171{ 168{
172 context->count[0] = context->count[1] = 0; 169 context->count[0] = context->count[1] = 0;
@@ -183,7 +180,6 @@ static void __md5_Init(struct MD5Context *context)
183 * operation, processing another message block, and updating the 180 * operation, processing another message block, and updating the
184 * context. 181 * context.
185 */ 182 */
186
187static void __md5_Update(struct MD5Context *context, const unsigned char *input, unsigned int inputLen) 183static void __md5_Update(struct MD5Context *context, const unsigned char *input, unsigned int inputLen)
188{ 184{
189 unsigned int i, idx, partLen; 185 unsigned int i, idx, partLen;
@@ -218,7 +214,6 @@ static void __md5_Update(struct MD5Context *context, const unsigned char *input,
218/* 214/*
219 * MD5 padding. Adds padding followed by original length. 215 * MD5 padding. Adds padding followed by original length.
220 */ 216 */
221
222static void __md5_Pad(struct MD5Context *context) 217static void __md5_Pad(struct MD5Context *context)
223{ 218{
224 unsigned char bits[8]; 219 unsigned char bits[8];
@@ -244,7 +239,6 @@ static void __md5_Pad(struct MD5Context *context)
244 * MD5 finalization. Ends an MD5 message-digest operation, writing the 239 * MD5 finalization. Ends an MD5 message-digest operation, writing the
245 * the message digest and zeroizing the context. 240 * the message digest and zeroizing the context.
246 */ 241 */
247
248static void __md5_Final(unsigned char digest[16], struct MD5Context *context) 242static void __md5_Final(unsigned char digest[16], struct MD5Context *context)
249{ 243{
250 /* Do padding. */ 244 /* Do padding. */
@@ -258,7 +252,6 @@ static void __md5_Final(unsigned char digest[16], struct MD5Context *context)
258} 252}
259 253
260/* MD5 basic transformation. Transforms state based on block. */ 254/* MD5 basic transformation. Transforms state based on block. */
261
262static void __md5_Transform(uint32_t state[4], const unsigned char block[64]) 255static void __md5_Transform(uint32_t state[4], const unsigned char block[64])
263{ 256{
264 uint32_t a, b, c, d, x[16]; 257 uint32_t a, b, c, d, x[16];
@@ -517,16 +510,15 @@ __md5_to64(char *s, unsigned v, int n)
517 * Use MD5 for what it is best at... 510 * Use MD5 for what it is best at...
518 */ 511 */
519#define MD5_OUT_BUFSIZE 36 512#define MD5_OUT_BUFSIZE 36
520
521static char * 513static char *
522md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt) 514NOINLINE
515md5_crypt(char passwd[MD5_OUT_BUFSIZE], const unsigned char *pw, const unsigned char *salt)
523{ 516{
524 const unsigned char *sp, *ep; 517 const unsigned char *sp, *ep;
525 char *p; 518 char *p;
526 unsigned char final[17]; /* final[16] exists only to aid in looping */ 519 unsigned char final[17]; /* final[16] exists only to aid in looping */
527 int sl, pl, i, pw_len; 520 int sl, pl, i, pw_len;
528 struct MD5Context ctx, ctx1; 521 struct MD5Context ctx, ctx1;
529 unsigned long l;
530 522
531 /* Refine the Salt first */ 523 /* Refine the Salt first */
532 sp = salt; 524 sp = salt;
@@ -612,11 +604,10 @@ md5_crypt(char passwd[120], const unsigned char *pw, const unsigned char *salt)
612 /* Add 5*4+2 = 22 bytes of hash, + NUL byte. */ 604 /* Add 5*4+2 = 22 bytes of hash, + NUL byte. */
613 final[16] = final[5]; 605 final[16] = final[5];
614 for (i = 0; i < 5; i++) { 606 for (i = 0; i < 5; i++) {
615 l = (final[i] << 16) | (final[i+6] << 8) | final[i+12]; 607 unsigned l = (final[i] << 16) | (final[i+6] << 8) | final[i+12];
616 p = __md5_to64(p, l, 4); 608 p = __md5_to64(p, l, 4);
617 } 609 }
618 l = final[11]; 610 p = __md5_to64(p, final[11], 2);
619 p = __md5_to64(p, l, 2);
620 *p = '\0'; 611 *p = '\0';
621 612
622 /* Don't leave anything around in vm they could use. */ 613 /* Don't leave anything around in vm they could use. */