// File: /workspace/github_c_makefile_star2_O3/xiaowenhuyuehu[P]remote_access/src/utility/sha256/hmac-sha256.c
// Function: hmac_sha256
void
hmac_sha256 (uint8_t out[HMAC_SHA256_DIGEST_SIZE],
             const uint8_t *data, size_t data_len,
             const uint8_t *key, size_t key_len)
{
    api_check_return (out);
    api_check_return (data);
    api_check_return (key);
    api_check_return (key_len <= B);

    sha256_t ss;
#if defined(API_CHECK_DISABLE) && API_CHECK_DISABLE
    uint8_t kh[SHA256_DIGEST_SIZE];
    /*
     * If the key length is bigger than the buffer size B, apply the hash
     * function to it first and use the result instead.
     */
    if (key_len > B) {
        sha256_init (&ss);
        sha256_update (&ss, key, key_len);
        sha256_final (&ss, kh);
        key_len = SHA256_DIGEST_SIZE;
        key = kh;
    }
#endif
    /*
     * (1) append zeros to the end of K to create a B byte string
     *     (e.g., if K is of length 20 bytes and B=64, then K will be
     *     appended with 44 zero bytes 0x00)
     * (2) XOR (bitwise exclusive-OR) the B byte string computed in step
     *     (1) with ipad
     */
    uint8_t kx[B];
    size_t i = 0;
    for (i = 0; i < key_len; i++) kx[i] = I_PAD ^ key[i];
    for (i = key_len; i < B; i++) kx[i] = I_PAD ^ 0;

    /*
     * (3) append the stream of data 'text' to the B byte string resulting
     *     from step (2)
     * (4) apply H to the stream generated in step (3)
     */
    sha256_init (&ss);
    sha256_update (&ss, kx, B);
    sha256_update (&ss, data, data_len);
    sha256_final (&ss, out);

    /*
     * (5) XOR (bitwise exclusive-OR) the B byte string computed in
     *     step (1) with opad
     *
     * NOTE: The "kx" variable is reused.
     */
    for (i = 0; i < key_len; i++) kx[i] = O_PAD ^ key[i];
    for (i = key_len; i < B; i++) kx[i] = O_PAD ^ 0;

    /*
     * (6) append the H result from step (4) to the B byte string
     *     resulting from step (5)
     * (7) apply H to the stream generated in step (6) and output
     *     the result
     */
    sha256_init (&ss);
    sha256_update (&ss, kx, B);
    sha256_update (&ss, out, SHA256_DIGEST_SIZE);
    sha256_final (&ss, out);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
testq %rdi, %rdi
je 0x4627
movq %rsi, %r13
testq %rsi, %rsi
je 0x462e
movq %rcx, %r15
testq %rcx, %rcx
je 0x4635
movq %r8, %r14
cmpq $0x41, %r8
jae 0x463c
movq %rdi, %rbx
movq %rdx, 0x8(%rsp)
testq %r14, %r14
je 0x4536
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb $0x36, %cl
movb %cl, 0x10(%rsp,%rax)
incq %rax
cmpq %rax, %r14
jne 0x451a
movb $0x1, %r12b
cmpq $0x40, %r14
je 0x455f
leaq (%rsp,%r14), %rdi
addq $0x10, %rdi
xorl %r12d, %r12d
movl $0x3f, %eax
subq %r14, %rax
movl $0x0, %edx
cmovaeq %rax, %rdx
incq %rdx
movl $0x36, %esi
callq 0x2090
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
callq 0x4644
leaq 0x10(%rsp), %rsi
movl $0x40, %edx
movq %rbp, %rdi
callq 0x46a9
movq %rbp, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
callq 0x46a9
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x46fc
testq %r14, %r14
je 0x45b3
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb $0x5c, %cl
movb %cl, 0x10(%rsp,%rax)
incq %rax
cmpq %rax, %r14
jne 0x45a0
testb %r12b, %r12b
jne 0x45db
leaq (%rsp,%r14), %rdi
addq $0x10, %rdi
xorl %edx, %edx
movl $0x3f, %eax
subq %r14, %rax
cmovaeq %rax, %rdx
incq %rdx
movl $0x5c, %esi
callq 0x2090
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x4644
leaq 0x10(%rsp), %rsi
movl $0x40, %edx
movq %r14, %rdi
callq 0x46a9
movl $0x20, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x46a9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x46fc
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x26da
jmp 0x4615
callq 0x269c
jmp 0x4615
callq 0x265e
jmp 0x4615
callq 0x2620
jmp 0x4615
nop