// File: /workspace/github_c_makefile_star2_O0/ajpaulson[P]srogue11/xcrypt.c
// Function: xcrypt
char *xcrypt(const char *key,const char *setting)
{
	int		i;
	unsigned int	count, salt, l, r0, r1, keybuf[2];
	unsigned char		*p, *q;
	static unsigned char	output[21];

	if (!des_initialised)
		des_init();

	/*
	 * Copy the key, shifting each character up by one bit
	 * and padding with zeros.
	 */
	q = (unsigned char *) keybuf;
	while ((q - (unsigned char *) keybuf) < sizeof(keybuf)) {
		if ((*q++ = *key << 1))
			key++;
	}
	if (des_setkey((const char *) keybuf))
		return(NULL);

	if (*setting == _PASSWORD_EFMT1) {
		/*
		 * "new"-style:
		 *	setting - underscore, 4 bytes of count, 4 bytes of salt
		 *	key - unlimited characters
		 */
		for (i = 1, count = 0; i < 5; i++)
			count |= ascii_to_bin(setting[i]) << (i - 1) * 6;

		for (i = 5, salt = 0; i < 9; i++)
			salt |= ascii_to_bin(setting[i]) << (i - 5) * 6;

		while (*key) {
			/*
			 * Encrypt the key with itself.
			 */
			if (des_cipher((const char*)keybuf, (char*)keybuf, 0, 1))
				return(NULL);
			/*
			 * And XOR with the next 8 characters of the key.
			 */
			q = (unsigned char *) keybuf;
			while (((q - (unsigned char *) keybuf) < sizeof(keybuf)) &&
					*key)
				*q++ ^= *key++ << 1;

			if (des_setkey((const char *) keybuf))
				return(NULL);
		}
		strncpy((char *)output, setting, 9);

		/*
		 * Double check that we weren't given a short setting.
		 * If we were, the above code will probably have created
		 * wierd values for count and salt, but we don't really care.
		 * Just make sure the output string doesn't have an extra
		 * NUL in it.
		 */
		output[9] = '\0';
		p = output + strlen((const char *)output);
	} else {
		/*
		 * "old"-style:
		 *	setting - 2 bytes of salt
		 *	key - up to 8 characters
		 */
		count = 25;

		salt = (ascii_to_bin(setting[1]) << 6)
		     |  ascii_to_bin(setting[0]);

		output[0] = setting[0];
		/*
		 * If the encrypted password that the salt was extracted from
		 * is only 1 character long, the salt will be corrupted.  We
		 * need to ensure that the output string doesn't have an extra
		 * NUL in it!
		 */
		output[1] = setting[1] ? setting[1] : output[0];

		p = output + 2;
	}
	setup_salt(salt);
	/*
	 * Do it.
	 */
	if (do_des(0, 0, &r0, &r1, count))
		return(NULL);
	/*
	 * Now encode the result...
	 */
	l = (r0 >> 8);
	*p++ = ascii64[(l >> 18) & 0x3f];
	*p++ = ascii64[(l >> 12) & 0x3f];
	*p++ = ascii64[(l >> 6) & 0x3f];
	*p++ = ascii64[l & 0x3f];

	l = (r0 << 16) | ((r1 >> 16) & 0xffff);
	*p++ = ascii64[(l >> 18) & 0x3f];
	*p++ = ascii64[(l >> 12) & 0x3f];
	*p++ = ascii64[(l >> 6) & 0x3f];
	*p++ = ascii64[l & 0x3f];

	l = r1 << 2;
	*p++ = ascii64[(l >> 12) & 0x3f];
	*p++ = ascii64[(l >> 6) & 0x3f];
	*p++ = ascii64[l & 0x3f];
	*p = 0;

	return((char *)output);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpl $0x0, 0x15991(%rip)     # 0x3c9c8
jne 0x2703e
callq 0x280c0
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
leaq -0x38(%rbp), %rcx
subq %rcx, %rax
cmpq $0x8, %rax
jae 0x27083
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
shll %eax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %al, (%rcx)
cmpb $0x0, %al
je 0x27081
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x27046
leaq -0x38(%rbp), %rdi
callq 0x274c0
cmpl $0x0, %eax
je 0x2709e
movq $0x0, -0x8(%rbp)
jmp 0x274b4
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5f, %eax
jne 0x27223
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x5, -0x1c(%rbp)
jge 0x270ef
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x27940
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
imull $0x6, %ecx, %ecx
shll %cl, %eax
orl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x270bc
movl $0x5, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x9, -0x1c(%rbp)
jge 0x27130
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x27940
movl -0x1c(%rbp), %ecx
subl $0x5, %ecx
imull $0x6, %ecx, %ecx
shll %cl, %eax
orl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x270fd
jmp 0x27132
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x271e8
leaq -0x38(%rbp), %rdi
leaq -0x38(%rbp), %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x279e0
cmpl $0x0, %eax
je 0x27165
movq $0x0, -0x8(%rbp)
jmp 0x274b4
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
leaq -0x38(%rbp), %rax
subq %rax, %rcx
xorl %eax, %eax
cmpq $0x8, %rcx
movb %al, -0x49(%rbp)
jae 0x27193
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x2719c
jmp 0x271c8
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %edx
shll %edx
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movzbl (%rax), %ecx
xorl %edx, %ecx
movb %cl, (%rax)
jmp 0x2716d
leaq -0x38(%rbp), %rdi
callq 0x274c0
cmpl $0x0, %eax
je 0x271e3
movq $0x0, -0x8(%rbp)
jmp 0x274b4
jmp 0x27132
movq -0x18(%rbp), %rsi
leaq 0x157bd(%rip), %rdi     # 0x3c9b0
movl $0x9, %edx
callq 0x60a0
movb $0x0, 0x157b5(%rip)     # 0x3c9b9
leaq 0x157a5(%rip), %rdi     # 0x3c9b0
callq 0x6160
movq %rax, %rcx
leaq 0x15796(%rip), %rax     # 0x3c9b0
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x2729b
movl $0x19, -0x20(%rbp)
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %edi
callq 0x27940
shll $0x6, %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %edi
callq 0x27940
movl %eax, %ecx
movl -0x50(%rbp), %eax
orl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movb (%rax), %al
movb %al, 0x15751(%rip)      # 0x3c9b0
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x27279
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0x27283
movzbl 0x15730(%rip), %eax     # 0x3c9b0
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movb %al, 0x15725(%rip)      # 0x3c9b1
leaq 0x1571d(%rip), %rax     # 0x3c9b0
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movl -0x24(%rbp), %edi
callq 0x27a80
movl -0x20(%rbp), %r8d
xorl %esi, %esi
leaq -0x2c(%rbp), %rdx
leaq -0x30(%rbp), %rcx
movl %esi, %edi
callq 0x27b00
cmpl $0x0, %eax
je 0x272ca
movq $0x0, -0x8(%rbp)
jmp 0x274b4
movl -0x2c(%rbp), %eax
shrl $0x8, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
shrl $0x12, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf3b9(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf391(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf369(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf344(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x2c(%rbp), %eax
shll $0x10, %eax
movl -0x30(%rbp), %ecx
shrl $0x10, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
orl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
shrl $0x12, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf305(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf2dd(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf2b5(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf290(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x30(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf25f(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf237(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x28(%rbp), %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xf212(%rip), %rax      # 0x366a0
movb (%rax,%rcx), %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movq -0x40(%rbp), %rax
movb $0x0, (%rax)
leaq 0x15500(%rip), %rax     # 0x3c9b0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop