// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aegis128/ref/encrypt.c
// Function: aegis128_initialization
void aegis128_initialization(const unsigned char *key, const unsigned char *iv, unsigned char *state)
{
        int i;
        unsigned char constant[32] = {0x0,0x1,0x01,0x02,0x03,0x05,0x08,0x0d,0x15,0x22,0x37,0x59,0x90,0xe9,0x79,0x62,0xdb,0x3d,0x18,0x55,0x6d,0xc2,0x2f,0xf1,0x20,0x11,0x31,0x42,0x73,0xb5,0x28,0xdd};

        unsigned char tmp[16];
        unsigned char keytmp[16];
        unsigned char ivtmp[16];

        memcpy(keytmp, key, 16);
        memcpy(ivtmp, iv, 16);

        memcpy(state, ivtmp, 16);
        memcpy(state+16, constant+16, 16);
        memcpy(state+32, constant+0,  16);

        XOR128(state+48, keytmp,  constant);
        XOR128(state+64, keytmp,  constant + 16);
        XOR128(state,    state,   keytmp);
        XOR128(keytmp,   keytmp,  ivtmp);

        for (i = 0; i < 10; i++)  {
             //state update function
             memcpy(tmp, state+64, 16);
             AESROUND(state+64, state+48, state+64);
             AESROUND(state+48, state+32, state+48);
             AESROUND(state+32, state+16, state+32);
             AESROUND(state+16, state+0,  state+16);
             AESROUND(state+0,  tmp,      state+0);

             //xor msg with state[0]
             XOR128(keytmp, keytmp, ivtmp);
             XOR128(state,  state,  keytmp);
        }
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq 0xc96(%rip), %rax       # 0x2000
movq %rax, 0x30(%rsp)
movq 0xc92(%rip), %rax       # 0x2008
movq %rax, 0x38(%rsp)
movq 0xc8e(%rip), %rax       # 0x2010
movq %rax, 0x40(%rsp)
movq 0xc8a(%rip), %rax       # 0x2018
movq %rax, 0x48(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, (%rax)
movq 0x8(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x60(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq 0x60(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x20(%rax)
movq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq 0x10(%rsp), %rcx
xorq 0x30(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x18(%rsp), %rcx
xorq 0x38(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x10(%rsp), %rcx
xorq 0x40(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x18(%rsp), %rcx
xorq 0x48(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x60(%rsp), %rax
movq (%rax), %rcx
xorq 0x10(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, (%rax)
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rcx
xorq 0x18(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
xorq (%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
xorq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x5c(%rsp)
cmpl $0xa, 0x5c(%rsp)
jge 0x15a9
movq 0x60(%rsp), %rax
movq 0x40(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x48(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x60(%rsp), %rdi
addq $0x40, %rdi
movq 0x60(%rsp), %rsi
addq $0x30, %rsi
movq 0x60(%rsp), %rdx
addq $0x40, %rdx
callq 0x1050
movq 0x60(%rsp), %rdi
addq $0x30, %rdi
movq 0x60(%rsp), %rsi
addq $0x20, %rsi
movq 0x60(%rsp), %rdx
addq $0x30, %rdx
callq 0x1050
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
movq 0x60(%rsp), %rsi
addq $0x10, %rsi
movq 0x60(%rsp), %rdx
addq $0x20, %rdx
callq 0x1050
movq 0x60(%rsp), %rdi
addq $0x10, %rdi
movq 0x60(%rsp), %rsi
movq 0x60(%rsp), %rdx
addq $0x10, %rdx
callq 0x1050
movq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x1050
movq 0x10(%rsp), %rax
xorq (%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
xorq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x60(%rsp), %rax
movq (%rax), %rcx
xorq 0x10(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, (%rax)
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rcx
xorq 0x18(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x8(%rax)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x149e
addq $0x78, %rsp
retq
nop