// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/ref/shellaes.c
// Function: KeySetupEnc
void KeySetupEnc(u32 mk[], u32 sk[], u8 L[], u8 Lprime[], u8 keyprime[], const u32 rk[], const u8 key[]){

    u8 pt[16];
    u8 ct[16];

    int i;


    /* generate Keyprime for CENC*/
    for(i=0; i<16; ++i){
        keyprime[i]=key[i]^0xF0;
    }

    /* produce L for masks of AES*/
    memset(pt, 0x00, 16);
    aesEncrypt(rk, pt, L);

    /*produce the subkeys for auxiliary permutations*/
    for(i=1; i<=3*d; ++i){
        pt[15]=i;
        aesEncrypt(rk, pt, ct);

        sk[0]=GETU32(ct);
        sk[1]=GETU32(ct+4);
        sk[2]=GETU32(ct+8);
        sk[3]=GETU32(ct+12);

        sk=sk+4;
    }

    /*produce the mask keys for auxiliary permutations*/
    for(i=3*d+1; i<=4*d; ++i){
        pt[15]=i;

        aesEncrypt(rk, pt, ct);

        mk[0]=GETU32(ct);
        mk[1]=GETU32(ct+4);
        mk[2]=GETU32(ct+8);
        mk[3]=GETU32(ct+12);

        mk=mk+4;
    }

    /*produce Lprime for XEX layer*/

    memset(pt, 0xFF, 16);
    aesEncrypt(rk, pt, Lprime);
}

// Assembly:
subq $0x68, %rsp
movq 0x70(%rsp), %rax
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x38(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x10, 0xc(%rsp)
jge 0x53f5
movq 0x70(%rsp), %rax
movslq 0xc(%rsp), %rcx
movzbl (%rax,%rcx), %eax
xorl $0xf0, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x53bf
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
movq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x2200
movl $0x1, 0xc(%rsp)
cmpl $0xf, 0xc(%rsp)
jg 0x5512
movl 0xc(%rsp), %eax
movb %al, 0x2f(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2200
movzbl 0x10(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x11(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x12(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x13(%rsp), %eax
xorl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, (%rax)
movzbl 0x14(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x15(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x16(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x17(%rsp), %eax
xorl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x4(%rax)
movzbl 0x18(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x19(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x1a(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x1b(%rsp), %eax
xorl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x8(%rax)
movzbl 0x1c(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x1d(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x1e(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x1f(%rsp), %eax
xorl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x58(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x58(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5422
movl $0x10, 0xc(%rsp)
cmpl $0x14, 0xc(%rsp)
jg 0x560a
movl 0xc(%rsp), %eax
movb %al, 0x2f(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2200
movzbl 0x10(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x11(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x12(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x13(%rsp), %eax
xorl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, (%rax)
movzbl 0x14(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x15(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x16(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x17(%rsp), %eax
xorl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, 0x4(%rax)
movzbl 0x18(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x19(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x1a(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x1b(%rsp), %eax
xorl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, 0x8(%rax)
movzbl 0x1c(%rsp), %ecx
shll $0x18, %ecx
movzbl 0x1d(%rsp), %eax
shll $0x10, %eax
xorl %eax, %ecx
movzbl 0x1e(%rsp), %eax
shll $0x8, %eax
xorl %eax, %ecx
movzbl 0x1f(%rsp), %eax
xorl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x60(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x60(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x551a
leaq 0x20(%rsp), %rdi
movl $0xff, %esi
movl $0x10, %edx
callq 0x2070
movq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x2200
addq $0x68, %rsp
retq
nopw (%rax,%rax)