// File: /workspace/github_c_makefile_star2_O0/zecoxao[P]ps3_decrypt_tools/lib/eid.c
// Function: eid3_decrypt_buffer
void eid3_decrypt_buffer(u8 *eid3) {
    u8 indiv[INDIV_SIZE];
    u8 key[0x10], iv[0x10];
    aes_context aes_ctxt;

    //Generate individuals.
    indiv_gen(eid3_indiv_seed, NULL, NULL, NULL, indiv);

    //Generate key.
    memset(iv, 0, 0x10);
    aes_setkey_enc(&aes_ctxt, indiv + 0x20, 0x100);
    aes_crypt_cbc(&aes_ctxt, AES_ENCRYPT, 0x10, iv, eid3_keyseed, key);

    //Calculate eid3 aes omac1.
    u8 digest[AES_OMAC1_DIGEST_SIZE];
    aes_omac1(digest, eid3, 0xF0, key, 0x80);



    if (memcmp(digest, eid3 + 0xF0, AES_OMAC1_DIGEST_SIZE) != 0)
        printf("warning: eid3 omac1 hash check failed!\n");

    //Decrypt eid3.
    aes_setkey_dec(&aes_ctxt, key, 0x80);
    memcpy(iv, eid3 + 0x10, 0x10);
    aes_crypt_cbc(&aes_ctxt, AES_DECRYPT, 0xD0, iv, eid3 + 0x20, eid3 + 0x20);

    //Decrypt second layer.
    memset(iv, 0, 0x10);
    aes_setkey_dec(&aes_ctxt, eid3_static_key, 0x80);
    aes_crypt_cbc(&aes_ctxt, AES_DECRYPT, 0xD0, iv, eid3 + 0x20, eid3 + 0x20);


    u8 sha1_digest[20];
    sha1(eid3 + 0x20, 0xB8, sha1_digest);



    if (memcmp(sha1_digest, eid3 + 0x20 + 0xB8, 20) != 0)
        printf("warning: eid3 sha1 hash check failed!\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x390, %rsp            # imm = 0x390
movq %rdi, -0x8(%rbp)
leaq -0x110(%rbp), %r8
leaq 0x9473(%rip), %rdi      # 0x14440
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x9a80
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1090
leaq -0x110(%rbp), %rsi
addq $0x20, %rsi
leaq -0x360(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x1250
leaq -0x130(%rbp), %rcx
leaq -0x120(%rbp), %r9
leaq -0x360(%rbp), %rdi
movl $0x1, %esi
movl $0x10, %edx
leaq 0x94cf(%rip), %r8       # 0x14500
callq 0x2eb0
leaq -0x370(%rbp), %rdi
movq -0x8(%rbp), %rsi
leaq -0x120(%rbp), %rcx
movl $0xf0, %edx
movl $0x80, %r8d
callq 0x9280
leaq -0x370(%rbp), %rax
movq -0x8(%rbp), %rcx
addq $0xf0, %rcx
movups (%rcx), %xmm1
movups (%rax), %xmm0
pcmpeqb %xmm1, %xmm0
pmovmskb %xmm0, %eax
subl $0xffff, %eax           # imm = 0xFFFF
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xb096
leaq 0x5d9c(%rip), %rdi      # 0x10e2b
movb $0x0, %al
callq 0x1080
leaq -0x120(%rbp), %rsi
leaq -0x360(%rbp), %rdi
movl $0x80, %edx
callq 0x1810
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x130(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x128(%rbp)
leaq -0x130(%rbp), %rcx
movq -0x8(%rbp), %r8
addq $0x20, %r8
movq -0x8(%rbp), %r9
addq $0x20, %r9
leaq -0x360(%rbp), %rdi
xorl %esi, %esi
movl $0xd0, %edx
callq 0x2eb0
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1090
leaq -0x360(%rbp), %rdi
leaq 0x93fd(%rip), %rsi      # 0x14510
movl $0x80, %edx
callq 0x1810
leaq -0x130(%rbp), %rcx
movq -0x8(%rbp), %r8
addq $0x20, %r8
movq -0x8(%rbp), %r9
addq $0x20, %r9
leaq -0x360(%rbp), %rdi
xorl %esi, %esi
movl $0xd0, %edx
callq 0x2eb0
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
leaq -0x390(%rbp), %rdx
movl $0xb8, %esi
callq 0x7280
leaq -0x390(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
addq $0xb8, %rsi
movl $0x14, %edx
callq 0x10a0
cmpl $0x0, %eax
je 0xb193
leaq 0x5cc7(%rip), %rdi      # 0x10e53
movb $0x0, %al
callq 0x1080
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
nopl (%rax)