// File: rellla[P]E3DC-Rscp/AES.cpp
// Function: AES::KeyExpansion(unsigned char const*)
void AES::KeyExpansion(const unsigned char * key)
	{
	int i;
	unsigned long temp, * Wb = reinterpret_cast<unsigned long*>(W); // todo not portable - Endian problems
	if (Nk <= 6)
		{
		// todo - memcpy
		for (i = 0; i < 4*Nk; i++)
			W[i] = key[i];
		for (i = Nk; i < Nb*(Nr+1); i++)
			{
			temp = Wb[i-1];
			if ((i%Nk) == 0)
				temp = SubByte(RotByte(temp)) ^ Rcon[i/Nk];
			Wb[i] = Wb[i - Nk]^temp;
			}
		}
	else
		{
		// todo - memcpy
		for (i = 0; i < 4*Nk; i++)
			W[i] = key[i];
		for (i = Nk; i < Nb*(Nr+1); i++)
			{
			temp = Wb[i-1];
			if ((i%Nk) == 0)
				temp = SubByte(RotByte(temp)) ^ Rcon[i/Nk];
			else if ((i%Nk) == 4)
				temp = SubByte(temp);
			Wb[i] = Wb[i - Nk]^temp;
			}
		}
	}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rax, %rcx
addq $0xc, %rcx
movq %rcx, 0x20(%rsp)
cmpl $0x6, 0x4(%rax)
jg 0xa959
movl $0x0, 0x34(%rsp)
movq 0x18(%rsp), %rcx
movl 0x34(%rsp), %eax
movl 0x4(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0xa881
movq 0x18(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x34(%rsp), %rdx
movb (%rcx,%rdx), %dl
movslq 0x34(%rsp), %rcx
movb %dl, 0xc(%rax,%rcx)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0xa846
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x34(%rsp)
movq 0x18(%rsp), %rdx
movl 0x34(%rsp), %eax
movl (%rdx), %ecx
movl 0x8(%rdx), %edx
addl $0x1, %edx
imull %edx, %ecx
cmpl %ecx, %eax
jge 0xa954
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movl 0x34(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %eax
cltd
idivl 0x4(%rcx)
cmpl $0x0, %edx
jne 0xa919
movq 0x28(%rsp), %rdi
shlq $0x18, %rdi
movq 0x28(%rsp), %rax
shrq $0x8, %rax
orq %rax, %rdi
callq 0xaaa0
movq 0x18(%rsp), %rcx
movq %rax, 0x10(%rsp)
movl 0x34(%rsp), %eax
cltd
idivl 0x4(%rcx)
movl %eax, %ecx
movq 0x10(%rsp), %rax
movslq %ecx, %rdx
leaq 0x19e00(%rip), %rcx     # 0x24710
xorq (%rcx,%rdx,8), %rax
movq %rax, 0x28(%rsp)
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rax
movl 0x34(%rsp), %ecx
subl 0x4(%rdx), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
xorq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rax
movslq 0x34(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0xa88d
jmp 0xaa96
movl $0x0, 0x34(%rsp)
movq 0x18(%rsp), %rcx
movl 0x34(%rsp), %eax
movl 0x4(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0xa99c
movq 0x18(%rsp), %rax
movq 0x38(%rsp), %rcx
movslq 0x34(%rsp), %rdx
movb (%rcx,%rdx), %dl
movslq 0x34(%rsp), %rcx
movb %dl, 0xc(%rax,%rcx)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0xa961
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x34(%rsp)
movq 0x18(%rsp), %rdx
movl 0x34(%rsp), %eax
movl (%rdx), %ecx
movl 0x8(%rdx), %edx
addl $0x1, %edx
imull %edx, %ecx
cmpl %ecx, %eax
jge 0xaa94
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movl 0x34(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %eax
cltd
idivl 0x4(%rcx)
cmpl $0x0, %edx
jne 0xaa36
movq 0x28(%rsp), %rdi
shlq $0x18, %rdi
movq 0x28(%rsp), %rax
shrq $0x8, %rax
orq %rax, %rdi
callq 0xaaa0
movq 0x18(%rsp), %rcx
movq %rax, 0x8(%rsp)
movl 0x34(%rsp), %eax
cltd
idivl 0x4(%rcx)
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rdx
leaq 0x19ce5(%rip), %rcx     # 0x24710
xorq (%rcx,%rdx,8), %rax
movq %rax, 0x28(%rsp)
jmp 0xaa59
movq 0x18(%rsp), %rcx
movl 0x34(%rsp), %eax
cltd
idivl 0x4(%rcx)
cmpl $0x4, %edx
jne 0xaa57
movq 0x28(%rsp), %rdi
callq 0xaaa0
movq %rax, 0x28(%rsp)
jmp 0xaa59
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rax
movl 0x34(%rsp), %ecx
subl 0x4(%rdx), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
xorq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rax
movslq 0x34(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0xa9a8
jmp 0xaa96
addq $0x48, %rsp
retq
nopl (%rax,%rax)