// File: /workspace/github_c_makefile_star2_O1/TimeToogo[P]ff-proxy/client/c/crypto.c
// Function: ff_client_encrypt_request
bool ff_client_encrypt_request(struct ff_request *request, struct ff_encryption_config *config)
{
    uint8_t encryption_mode = FF_CRYPTO_MODE_AES_256_GCM;
    uint8_t key_derive_mode = FF_KEY_DERIVE_MODE_PBKDF2;
    bool ret_val;
    uint8_t *iv = NULL;
    uint16_t iv_len = 0;
    uint8_t *tag = NULL;
    uint16_t tag_len = 0;
    uint8_t *salt = NULL;
    uint16_t salt_len = 16;

    if (config == NULL)
    {
        ff_log(FF_WARNING, "Encountered encrypted request and no pre-shared-key was set");
        goto error;
    }

    if (!ff_client_encrypt_request_aes_256_gcm_pbkdf2(request, config, &iv, &iv_len, &tag, &tag_len, &salt, &salt_len))
    {
        goto error;
    }

    request->options[request->options_length] = ff_request_option_node_alloc();
    request->options[request->options_length]->type = FF_REQUEST_OPTION_TYPE_ENCRYPTION_MODE;
    request->options[request->options_length]->length = 1;
    ff_request_option_load_buff(request->options[request->options_length], 1, &encryption_mode);
    request->options_length++;

    request->options[request->options_length] = ff_request_option_node_alloc();
    request->options[request->options_length]->type = FF_REQUEST_OPTION_TYPE_ENCRYPTION_IV;
    request->options[request->options_length]->length = iv_len;
    ff_request_option_load_buff(request->options[request->options_length], iv_len, iv);
    request->options_length++;

    request->options[request->options_length] = ff_request_option_node_alloc();
    request->options[request->options_length]->type = FF_REQUEST_OPTION_TYPE_ENCRYPTION_TAG;
    request->options[request->options_length]->length = tag_len;
    ff_request_option_load_buff(request->options[request->options_length], tag_len, tag);
    request->options_length++;

    request->options[request->options_length] = ff_request_option_node_alloc();
    request->options[request->options_length]->type = FF_REQUEST_OPTION_TYPE_KEY_DERIVE_MODE;
    request->options[request->options_length]->length = 1;
    ff_request_option_load_buff(request->options[request->options_length], 1, &key_derive_mode);
    request->options_length++;

    request->options[request->options_length] = ff_request_option_node_alloc();
    request->options[request->options_length]->type = FF_REQUEST_OPTION_TYPE_KEY_DERIVE_SALT;
    request->options[request->options_length]->length = salt_len;
    ff_request_option_load_buff(request->options[request->options_length], salt_len, salt);
    request->options_length++;

    goto done;

error:
    ret_val = false;
    goto cleanup;

done:
    ret_val = true;
    goto cleanup;

cleanup:
    if (iv != NULL)
    {
        FREE(iv);
    }

    if (tag != NULL)
    {
        FREE(tag);
    }

    if (salt != NULL)
    {
        FREE(salt);
    }

    return ret_val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movb $0x1, %al
movb %al, -0x12(%rbp)
movb %al, -0x11(%rbp)
xorl %eax, %eax
movq %rax, -0x30(%rbp)
movw %ax, -0x18(%rbp)
movq %rax, -0x28(%rbp)
movw %ax, -0x16(%rbp)
movq %rax, -0x20(%rbp)
movw $0x10, -0x14(%rbp)
testq %rsi, %rsi
je 0x336e
movq %rdi, %rbx
leaq -0x14(%rbp), %rax
leaq -0x20(%rbp), %r10
leaq -0x30(%rbp), %rdx
leaq -0x18(%rbp), %rcx
leaq -0x28(%rbp), %r8
leaq -0x16(%rbp), %r9
pushq %rax
pushq %r10
callq 0x33d4
addq $0x10, %rsp
testb %al, %al
je 0x3385
callq 0x3d84
movq 0x30(%rbx), %rcx
movzbl 0x28(%rbx), %edx
shll $0x3, %edx
movq %rax, (%rcx,%rdx)
movq 0x30(%rbx), %rax
movq (%rax,%rdx), %rdi
movl $0x1, (%rdi)
movw $0x1, %r14w
movw %r14w, 0x4(%rdi)
leaq -0x12(%rbp), %rdx
movl $0x1, %esi
callq 0x3da8
incb 0x28(%rbx)
callq 0x3d84
movq 0x30(%rbx), %rcx
movzbl 0x28(%rbx), %edx
shll $0x3, %edx
movq %rax, (%rcx,%rdx)
movq 0x30(%rbx), %rax
movq (%rax,%rdx), %rdi
movl $0x2, (%rdi)
movzwl -0x18(%rbp), %esi
movw %si, 0x4(%rdi)
movq -0x30(%rbp), %rdx
callq 0x3da8
incb 0x28(%rbx)
callq 0x3d84
movq 0x30(%rbx), %rcx
movzbl 0x28(%rbx), %edx
shll $0x3, %edx
movq %rax, (%rcx,%rdx)
movq 0x30(%rbx), %rax
movq (%rax,%rdx), %rdi
movl $0x3, (%rdi)
movzwl -0x16(%rbp), %esi
movw %si, 0x4(%rdi)
movq -0x28(%rbp), %rdx
callq 0x3da8
incb 0x28(%rbx)
callq 0x3d84
movq 0x30(%rbx), %rcx
movzbl 0x28(%rbx), %edx
shll $0x3, %edx
movq %rax, (%rcx,%rdx)
movq 0x30(%rbx), %rax
movq (%rax,%rdx), %rdi
movl $0x5, (%rdi)
movw %r14w, 0x4(%rdi)
leaq -0x11(%rbp), %rdx
movl $0x1, %esi
callq 0x3da8
incb 0x28(%rbx)
callq 0x3d84
movq 0x30(%rbx), %rcx
movzbl 0x28(%rbx), %edx
shll $0x3, %edx
movq %rax, (%rcx,%rdx)
movq 0x30(%rbx), %rax
movq (%rax,%rdx), %rdi
movl $0x6, (%rdi)
movzwl -0x14(%rbp), %esi
movw %si, 0x4(%rdi)
movq -0x20(%rbp), %rdx
callq 0x3da8
incb 0x28(%rbx)
movb $0x1, %bl
jmp 0x3387
leaq 0x211b(%rip), %rsi      # 0x5490
xorl %ebx, %ebx
movl $0x3, %edi
xorl %eax, %eax
callq 0x3c64
jmp 0x3387
xorl %ebx, %ebx
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x339d
callq 0x21d0
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rdi
testq %rdi, %rdi
je 0x33b3
callq 0x21d0
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rdi
testq %rdi, %rdi
je 0x33c9
callq 0x21d0
movq $0x0, -0x20(%rbp)
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq