// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aegis128l/ref/ecrypt.c
// Function: aegis128L_initialization
void aegis128L_initialization(const unsigned char *key, const unsigned char *iv, unsigned char *state)
{
       int i;
       unsigned char tmp[16];
       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};

       XOR128(state,  key,  iv);
       memcpy(state+16, constant+16, 16);
       memcpy(state+32, constant,    16);
       memcpy(state+48, constant+16, 16);
       XOR128(state+64, key, iv);
       XOR128(state+80, key, constant);
       XOR128(state+96, key, constant+16);
       XOR128(state+112,key, constant);

       for (i = 0; i < 10; i++)  {
             //state update function;
             memcpy(tmp, state+112, 16);

             AESROUND(state+112,state+96, state+112);
             AESROUND(state+96, state+80, state+96);
             AESROUND(state+80, state+64, state+80);
             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);

             //message is used to update the state.
             XOR128(state, state, iv);
             XOR128(state+64, state+64, key);
       }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq (%rsi), %rax
xorq (%rdi), %rax
movq %rax, (%rdx)
movq 0x8(%rsi), %rax
xorq 0x8(%rdi), %rax
movq %rax, 0x8(%rdx)
leaq 0x10(%rdx), %rax
movq %rax, 0x28(%rsp)
vmovaps 0xd55(%rip), %ymm0      # 0x2000
leaq 0x20(%rdx), %rax
movq %rax, 0x20(%rsp)
vmovups %ymm0, 0x10(%rdx)
leaq 0x30(%rdx), %rax
movq %rax, 0x18(%rsp)
movabsq $-0xed03d92aae7c225, %rax # imm = 0xF12FC26D55183DDB
movq %rax, 0x30(%rdx)
movabsq $-0x22d74a8cbdceeee0, %rcx # imm = 0xDD28B57342311120
movq %rcx, 0x38(%rdx)
movq (%rsi), %rdx
xorq (%rdi), %rdx
leaq 0x40(%rbx), %r8
movq %r8, 0x10(%rsp)
movq %rdx, 0x40(%rbx)
movq %rsi, 0x38(%rsp)
movq 0x8(%rsi), %rdx
xorq 0x8(%rdi), %rdx
movq %rdx, 0x48(%rbx)
movabsq $0xd08050302010100, %rdx # imm = 0xD08050302010100
movq (%rdi), %rsi
xorq %rdx, %rsi
leaq 0x50(%rbx), %r8
movq %r8, 0x8(%rsp)
movq %rsi, 0x50(%rbx)
movabsq $0x6279e99059372215, %rsi # imm = 0x6279E99059372215
movq 0x8(%rdi), %r8
xorq %rsi, %r8
movq %r8, 0x58(%rbx)
xorq (%rdi), %rax
leaq 0x60(%rbx), %r12
movq %rax, 0x60(%rbx)
xorq 0x8(%rdi), %rcx
movq %rcx, 0x68(%rbx)
xorq (%rdi), %rdx
leaq 0x70(%rbx), %r13
movq %rdx, 0x70(%rbx)
movq %rdi, 0x30(%rsp)
xorq 0x8(%rdi), %rsi
movq %rsi, 0x78(%rbx)
pushq $0xa
popq %rbp
subl $0x1, %ebp
jb 0x1431
vmovups (%r13), %xmm0
vmovaps %xmm0, 0x40(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r13, %rdx
vzeroupper
callq 0x1050
movq %r12, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %r12, %rdx
callq 0x1050
movq %r14, %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x1050
movq %r15, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x1050
movq %r14, %rdi
movq 0x20(%rsp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x1050
movq %r15, %rdi
movq 0x28(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x1050
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1050
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
movq %rbx, %rdx
callq 0x1050
movq 0x38(%rsp), %rcx
movq (%rcx), %rax
xorq %rax, (%rbx)
movq 0x8(%rcx), %rax
xorq %rax, 0x8(%rbx)
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
xorq %rax, 0x40(%rbx)
movq 0x8(%rcx), %rax
xorq %rax, 0x48(%rbx)
jmp 0x1362
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq