// File: /workspace/github_c_makefile_star2_O2/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 0x434b
movq %rsi, %r13
testq %rsi, %rsi
je 0x4375
movq %rcx, %r15
testq %rcx, %rcx
je 0x439f
movq %r8, %r14
cmpq $0x41, %r8
jae 0x43c9
movq %rdx, %r12
movq %rdi, %rbx
xorl %eax, %eax
cmpq %rax, %r14
je 0x429b
movb (%r15,%rax), %cl
xorb $0x36, %cl
movb %cl, (%rsp,%rax)
incq %rax
jmp 0x4287
movq %r14, %rax
cmpq $0x40, %rax
je 0x42ad
movb $0x36, (%rsp,%rax)
incq %rax
jmp 0x429e
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
callq 0x4418
movq %rsp, %rsi
pushq $0x40
popq %rdx
movq %rbp, %rdi
callq 0x4477
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4477
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x44c7
xorl %eax, %eax
cmpq %rax, %r14
je 0x42ff
movb (%r15,%rax), %cl
xorb $0x5c, %cl
movb %cl, (%rsp,%rax)
incq %rax
jmp 0x42e3
movb $0x5c, (%rsp,%r14)
incq %r14
cmpq $0x40, %r14
jne 0x42f7
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x4418
movq %rsp, %rsi
pushq $0x40
popq %rdx
movq %r14, %rdi
callq 0x4477
pushq $0x20
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4477
movq %r14, %rdi
movq %rbx, %rsi
callq 0x44c7
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7c96(%rip), %rax      # 0xbfe8
movq (%rax), %rbx
leaq 0x4115(%rip), %rsi      # 0x8471
leaq 0x4133(%rip), %rdx      # 0x8496
leaq 0x4130(%rip), %rcx      # 0x849a
leaq 0x4135(%rip), %r8       # 0x84a6
pushq $0x23
jmp 0x43f1
movq 0x7c6c(%rip), %rax      # 0xbfe8
movq (%rax), %rbx
leaq 0x40eb(%rip), %rsi      # 0x8471
leaq 0x413a(%rip), %rdx      # 0x84c7
leaq 0x4106(%rip), %rcx      # 0x849a
leaq 0x410b(%rip), %r8       # 0x84a6
pushq $0x24
jmp 0x43f1
movq 0x7c42(%rip), %rax      # 0xbfe8
movq (%rax), %rbx
leaq 0x40c1(%rip), %rsi      # 0x8471
leaq 0x4c49(%rip), %rdx      # 0x9000
leaq 0x40dc(%rip), %rcx      # 0x849a
leaq 0x40e1(%rip), %r8       # 0x84a6
pushq $0x25
jmp 0x43f1
movq 0x7c18(%rip), %rax      # 0xbfe8
movq (%rax), %rbx
leaq 0x4097(%rip), %rsi      # 0x8471
leaq 0x40eb(%rip), %rdx      # 0x84cc
leaq 0x40b2(%rip), %rcx      # 0x849a
leaq 0x40b7(%rip), %r8       # 0x84a6
pushq $0x26
popq %r9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2530
movq %rbx, %rdi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x25d0
nop