// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
testq %rdi, %rdi
je 0x46b9
movq %rsi, %r13
testq %rsi, %rsi
je 0x46c0
movq %rcx, %r15
testq %rcx, %rcx
je 0x46c7
movq %r8, %r14
cmpq $0x41, %r8
jae 0x46ce
movq %rdx, %r12
movq %rdi, %rbx
testq %r14, %r14
je 0x45dc
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb $0x36, %cl
movb %cl, (%rsp,%rax)
incq %rax
cmpq %rax, %r14
jne 0x45c4
cmpq $0x40, %r14
je 0x45fb
leaq (%rsp,%r14), %rdi
xorl %edx, %edx
movl $0x3f, %eax
subq %r14, %rax
cmovaeq %rax, %rdx
incq %rdx
movl $0x36, %esi
callq 0x2090
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
callq 0x46d8
movq %rsp, %rsi
movl $0x40, %edx
movq %rbp, %rdi
callq 0x473d
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x473d
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4790
testq %r14, %r14
je 0x4650
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb $0x5c, %cl
movb %cl, (%rsp,%rax)
incq %rax
cmpq %rax, %r14
jne 0x4638
cmpq $0x40, %r14
je 0x466f
leaq (%rsp,%r14), %rdi
xorl %edx, %edx
movl $0x3f, %eax
subq %r14, %rax
cmovaeq %rax, %rdx
incq %rdx
movl $0x5c, %esi
callq 0x2090
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x46d8
movq %rsp, %rsi
movl $0x40, %edx
movq %r14, %rdi
callq 0x473d
movl $0x20, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x473d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4790
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x26ca
jmp 0x46a7
callq 0x268c
jmp 0x46a7
callq 0x264e
jmp 0x46a7
callq 0x2610
jmp 0x46a7
nopl (%rax)