696 |
|
|
697 |
#define DES_OUT_BUFSIZE 21 |
#define DES_OUT_BUFSIZE 21 |
698 |
|
|
699 |
|
static void |
700 |
|
to64_msb_first(char *s, unsigned v) |
701 |
|
{ |
702 |
|
#if 0 |
703 |
|
*s++ = ascii64[(v >> 18) & 0x3f]; /* bits 23..18 */ |
704 |
|
*s++ = ascii64[(v >> 12) & 0x3f]; /* bits 17..12 */ |
705 |
|
*s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */ |
706 |
|
*s = ascii64[v & 0x3f]; /* bits 5..0 */ |
707 |
|
#endif |
708 |
|
*s++ = i64c(v >> 18); /* bits 23..18 */ |
709 |
|
*s++ = i64c(v >> 12); /* bits 17..12 */ |
710 |
|
*s++ = i64c(v >> 6); /* bits 11..6 */ |
711 |
|
*s = i64c(v); /* bits 5..0 */ |
712 |
|
} |
713 |
|
|
714 |
static char * |
static char * |
715 |
NOINLINE |
NOINLINE |
716 |
des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE], |
des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE], |
717 |
const unsigned char *key, const unsigned char *setting) |
const unsigned char *key, const unsigned char *setting) |
718 |
{ |
{ |
719 |
uint32_t salt, l, r0, r1, keybuf[2]; |
uint32_t salt, r0, r1, keybuf[2]; |
720 |
uint8_t *p, *q; |
uint8_t *q; |
721 |
|
|
722 |
/* |
/* |
723 |
* Copy the key, shifting each character up by one bit |
* Copy the key, shifting each character up by one bit |
748 |
*/ |
*/ |
749 |
output[1] = setting[1] ? setting[1] : output[0]; |
output[1] = setting[1] ? setting[1] : output[0]; |
750 |
|
|
|
p = (uint8_t *)output + 2; |
|
|
|
|
751 |
setup_salt(ctx, salt); |
setup_salt(ctx, salt); |
752 |
/* |
/* Do it. */ |
|
* Do it. |
|
|
*/ |
|
753 |
do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */); |
do_des(ctx, /*0, 0,*/ &r0, &r1, 25 /* count */); |
754 |
|
|
755 |
/* |
/* Now encode the result. */ |
756 |
* Now encode the result... |
#if 0 |
757 |
*/ |
{ |
758 |
l = (r0 >> 8); |
uint32_t l = (r0 >> 8); |
759 |
*p++ = ascii64[(l >> 18) & 0x3f]; |
q = (uint8_t *)output + 2; |
760 |
*p++ = ascii64[(l >> 12) & 0x3f]; |
*q++ = ascii64[(l >> 18) & 0x3f]; /* bits 31..26 of r0 */ |
761 |
*p++ = ascii64[(l >> 6) & 0x3f]; |
*q++ = ascii64[(l >> 12) & 0x3f]; /* bits 25..20 of r0 */ |
762 |
*p++ = ascii64[l & 0x3f]; |
*q++ = ascii64[(l >> 6) & 0x3f]; /* bits 19..14 of r0 */ |
763 |
|
*q++ = ascii64[l & 0x3f]; /* bits 13..8 of r0 */ |
764 |
l = ((r0 << 16) | (r1 >> 16)); |
l = ((r0 << 16) | (r1 >> 16)); |
765 |
*p++ = ascii64[(l >> 18) & 0x3f]; |
*q++ = ascii64[(l >> 18) & 0x3f]; /* bits 7..2 of r0 */ |
766 |
*p++ = ascii64[(l >> 12) & 0x3f]; |
*q++ = ascii64[(l >> 12) & 0x3f]; /* bits 1..2 of r0 and 31..28 of r1 */ |
767 |
*p++ = ascii64[(l >> 6) & 0x3f]; |
*q++ = ascii64[(l >> 6) & 0x3f]; /* bits 27..22 of r1 */ |
768 |
*p++ = ascii64[l & 0x3f]; |
*q++ = ascii64[l & 0x3f]; /* bits 21..16 of r1 */ |
|
|
|
769 |
l = r1 << 2; |
l = r1 << 2; |
770 |
*p++ = ascii64[(l >> 12) & 0x3f]; |
*q++ = ascii64[(l >> 12) & 0x3f]; /* bits 15..10 of r1 */ |
771 |
*p++ = ascii64[(l >> 6) & 0x3f]; |
*q++ = ascii64[(l >> 6) & 0x3f]; /* bits 9..4 of r1 */ |
772 |
*p++ = ascii64[l & 0x3f]; |
*q++ = ascii64[l & 0x3f]; /* bits 3..0 of r1 + 00 */ |
773 |
*p = 0; |
*q = 0; |
774 |
|
} |
775 |
|
#else |
776 |
|
/* Each call takes low-order 24 bits and stores 4 chars */ |
777 |
|
/* bits 31..8 of r0 */ |
778 |
|
to64_msb_first(output + 2, (r0 >> 8)); |
779 |
|
/* bits 7..0 of r0 and 31..16 of r1 */ |
780 |
|
to64_msb_first(output + 6, (r0 << 16) | (r1 >> 16)); |
781 |
|
/* bits 15..0 of r1 and two zero bits (plus extra zero byte) */ |
782 |
|
to64_msb_first(output + 10, (r1 << 8)); |
783 |
|
/* extra zero byte is encoded as '.', fixing it */ |
784 |
|
output[13] = '\0'; |
785 |
|
#endif |
786 |
|
|
787 |
return output; |
return output; |
788 |
} |
} |