// File: rellla[P]E3DC-Rscp/AES.cpp
// Function: AES::StartDecryption(unsigned char const*)
void AES::StartDecryption(const unsigned char * key)
	{
	memset(iv, 0xff, sizeof(iv));
	KeyExpansion(key);

	unsigned char a0,a1,a2,a3,b0,b1,b2,b3, * W_ptr = W;

	for (int col = Nb; col < (Nr)*Nb; col++) // do all but first and last round
		{
		a0 = W_ptr[4*col+0];
		a1 = W_ptr[4*col+1];
		a2 = W_ptr[4*col+2];
		a3 = W_ptr[4*col+3];

		b0 = GF2_8_mult(0x0E,a0)^GF2_8_mult(0x0B,a1)^
		     GF2_8_mult(0x0D,a2)^GF2_8_mult(0x09,a3);
		b1 = GF2_8_mult(0x09,a0)^GF2_8_mult(0x0E,a1)^
		     GF2_8_mult(0x0B,a2)^GF2_8_mult(0x0D,a3);
		b2 = GF2_8_mult(0x0D,a0)^GF2_8_mult(0x09,a1)^
		     GF2_8_mult(0x0E,a2)^GF2_8_mult(0x0B,a3);
		b3 = GF2_8_mult(0x0B,a0)^GF2_8_mult(0x0D,a1)^
		     GF2_8_mult(0x09,a2)^GF2_8_mult(0x0E,a3);

		W_ptr[4*col+0] = b0;
		W_ptr[4*col+1] = b1;
		W_ptr[4*col+2] = b2;
		W_ptr[4*col+3] = b3;
		}

	// we reverse the rounds to make decryption faster
	unsigned long * WL = reinterpret_cast<unsigned long*>(W);
	for (int pos = 0; pos < Nr/2; pos++)
		for (int col = 0; col < Nb; col++)
			swap(WL[col+pos*Nb],WL[col+(Nr-pos)*Nb]);
	}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rdi
movq %rdi, 0x38(%rsp)
addq $0x1ec, %rdi            # imm = 0x1EC
movl $0xff, %esi
movl $0x20, %edx
callq 0x20e0
movq 0x38(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0xa810
movq 0x38(%rsp), %rax
movq %rax, %rcx
addq $0xc, %rcx
movq %rcx, 0x58(%rsp)
movl (%rax), %eax
movl %eax, 0x54(%rsp)
movq 0x38(%rsp), %rdx
movl 0x54(%rsp), %eax
movl 0x8(%rdx), %ecx
imull (%rdx), %ecx
cmpl %ecx, %eax
jge 0x14983
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, 0x67(%rsp)
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, 0x66(%rsp)
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, 0x65(%rsp)
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, 0x64(%rsp)
movl $0xe, %edi
movzbl 0x67(%rsp), %esi
callq 0x14a40
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movl $0xb, %edi
movzbl 0x66(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x8(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0xc(%rsp)
movl $0xd, %edi
movzbl 0x65(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0xc(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0x10(%rsp)
movl $0x9, %edi
movzbl 0x64(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x10(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movb %al, 0x63(%rsp)
movl $0x9, %edi
movzbl 0x67(%rsp), %esi
callq 0x14a40
movzbl %al, %eax
movl %eax, 0x14(%rsp)
movl $0xe, %edi
movzbl 0x66(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x14(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0x18(%rsp)
movl $0xb, %edi
movzbl 0x65(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x18(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0x1c(%rsp)
movl $0xd, %edi
movzbl 0x64(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x1c(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movb %al, 0x62(%rsp)
movl $0xd, %edi
movzbl 0x67(%rsp), %esi
callq 0x14a40
movzbl %al, %eax
movl %eax, 0x20(%rsp)
movl $0x9, %edi
movzbl 0x66(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x20(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0x24(%rsp)
movl $0xe, %edi
movzbl 0x65(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x24(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0x28(%rsp)
movl $0xb, %edi
movzbl 0x64(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x28(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movb %al, 0x61(%rsp)
movl $0xb, %edi
movzbl 0x67(%rsp), %esi
callq 0x14a40
movzbl %al, %eax
movl %eax, 0x2c(%rsp)
movl $0xd, %edi
movzbl 0x66(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x2c(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0x30(%rsp)
movl $0x9, %edi
movzbl 0x65(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x30(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, 0x34(%rsp)
movl $0xe, %edi
movzbl 0x64(%rsp), %esi
callq 0x14a40
movb %al, %cl
movl 0x34(%rsp), %eax
movzbl %cl, %ecx
xorl %ecx, %eax
movb %al, 0x60(%rsp)
movb 0x63(%rsp), %dl
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movb 0x62(%rsp), %dl
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movb 0x61(%rsp), %dl
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movb 0x60(%rsp), %dl
movq 0x58(%rsp), %rax
movl 0x54(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x146d4
movq 0x38(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movq 0x38(%rsp), %rax
movl 0x44(%rsp), %ecx
movl %ecx, 0x4(%rsp)
movl 0x8(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0x14a32
movl $0x0, 0x40(%rsp)
movq 0x38(%rsp), %rcx
movl 0x40(%rsp), %eax
cmpl (%rcx), %eax
jge 0x14a20
movq 0x38(%rsp), %rdx
movq 0x48(%rsp), %rdi
movl 0x40(%rsp), %eax
movl 0x44(%rsp), %ecx
imull (%rdx), %ecx
addl %ecx, %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
movq 0x48(%rsp), %rsi
movl 0x40(%rsp), %eax
movl 0x8(%rdx), %ecx
subl 0x44(%rsp), %ecx
imull (%rdx), %ecx
addl %ecx, %eax
cltq
shlq $0x3, %rax
addq %rax, %rsi
callq 0x1f490
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x149c3
jmp 0x14a22
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x14999
addq $0x78, %rsp
retq
nopw (%rax,%rax)