// File: bummelbaerchen[P]e3dc/AES.cpp
// Function: AES::KeyExpansion(unsigned char const*)
void AES::KeyExpansion(const unsigned char * key)
	{
	int i;
	uint32_t temp, * Wb = reinterpret_cast<uint32_t*>(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 $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rax, %rcx
addq $0xc, %rcx
movq %rcx, 0x18(%rsp)
cmpl $0x6, 0x4(%rax)
jg 0xdefb
movl $0x0, 0x24(%rsp)
movq 0x10(%rsp), %rcx
movl 0x24(%rsp), %eax
movl 0x4(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0xde31
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
movslq 0x24(%rsp), %rdx
movb (%rcx,%rdx), %dl
movslq 0x24(%rsp), %rcx
movb %dl, 0xc(%rax,%rcx)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0xddf6
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdx
movl 0x24(%rsp), %eax
movl (%rdx), %ecx
movl 0x8(%rdx), %edx
addl $0x1, %edx
imull %edx, %ecx
cmpl %ecx, %eax
jge 0xdef6
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movl 0x24(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %eax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
cltd
idivl 0x4(%rcx)
cmpl $0x0, %edx
jne 0xdebe
movl 0x20(%rsp), %edi
shll $0x18, %edi
movl 0x20(%rsp), %eax
shrl $0x8, %eax
orl %eax, %edi
callq 0xe030
movq 0x10(%rsp), %rcx
movl %eax, 0xc(%rsp)
movl 0x24(%rsp), %eax
cltd
idivl 0x4(%rcx)
movl %eax, %ecx
movl 0xc(%rsp), %eax
movslq %ecx, %rdx
leaq 0x18c09(%rip), %rcx     # 0x26ac0
xorl (%rcx,%rdx,4), %eax
movl %eax, 0x20(%rsp)
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
movl 0x24(%rsp), %ecx
subl 0x4(%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
xorl 0x20(%rsp), %edx
movq 0x18(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0xde3d
jmp 0xe028
movl $0x0, 0x24(%rsp)
movq 0x10(%rsp), %rcx
movl 0x24(%rsp), %eax
movl 0x4(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0xdf3e
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
movslq 0x24(%rsp), %rdx
movb (%rcx,%rdx), %dl
movslq 0x24(%rsp), %rcx
movb %dl, 0xc(%rax,%rcx)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0xdf03
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdx
movl 0x24(%rsp), %eax
movl (%rdx), %ecx
movl 0x8(%rdx), %edx
addl $0x1, %edx
imull %edx, %ecx
cmpl %ecx, %eax
jge 0xe026
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movl 0x24(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %eax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
cltd
idivl 0x4(%rcx)
cmpl $0x0, %edx
jne 0xdfcd
movl 0x20(%rsp), %edi
shll $0x18, %edi
movl 0x20(%rsp), %eax
shrl $0x8, %eax
orl %eax, %edi
callq 0xe030
movq 0x10(%rsp), %rcx
movl %eax, 0x8(%rsp)
movl 0x24(%rsp), %eax
cltd
idivl 0x4(%rcx)
movl %eax, %ecx
movl 0x8(%rsp), %eax
movslq %ecx, %rdx
leaq 0x18afc(%rip), %rcx     # 0x26ac0
xorl (%rcx,%rdx,4), %eax
movl %eax, 0x20(%rsp)
jmp 0xdfee
movq 0x10(%rsp), %rcx
movl 0x24(%rsp), %eax
cltd
idivl 0x4(%rcx)
cmpl $0x4, %edx
jne 0xdfec
movl 0x20(%rsp), %edi
callq 0xe030
movl %eax, 0x20(%rsp)
jmp 0xdfee
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
movl 0x24(%rsp), %ecx
subl 0x4(%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
xorl 0x20(%rsp), %edx
movq 0x18(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0xdf4a
jmp 0xe028
addq $0x38, %rsp
retq
nopl (%rax)