// File: yangwanyuan[P]HLKVDS/src/KeyDigestHandle.cc
// Function: hlkvds::KeyDigestHandle::CalcDigest(hlkvds::Kvdb_Key const*, hlkvds::Kvdb_Digest&)
void KeyDigestHandle::CalcDigest(const Kvdb_Key *key, Kvdb_Digest &digest)
/*
 * returns RMD(message)
 * message should be a string terminated by '\0'
 */
{
    dword MDbuf[RMDsize / 32]; /* contains (A, B, C, D(, E))   */
    //static byte   hashcode[RMDsize/8]; /* for final hash-value         */
    byte hashcode[RMDsize / 8]; /* for final hash-value         */
    dword X[16]; /* current 16-word chunk        */
    unsigned int i; /* counter                      */
    dword length; /* length in bytes of message   */
    dword nbytes; /* # of bytes not yet processed */

    /* initialize */
    MDinit(MDbuf);

    length = key->GetLen();
    const char* value = key->GetValue();

    /* process message in 16-word chunks */
    for (nbytes = length; nbytes > 63; nbytes -= 64) {
        for (i = 0; i < 16; i++) {
            X[i] = BYTES_TO_DWORD(value);
            value += 4;
        }
        compress_(MDbuf, X);
    } /* length mod 64 bytes left */

    /* finish: */
    MDfinish(MDbuf, (byte *) value, length, 0);

    for (i = 0; i < RMDsize / 8; i += 4) {
        hashcode[i] = MDbuf[i >> 2]; /* implicit cast to byte  */
        hashcode[i + 1] = (MDbuf[i >> 2] >> 8); /*  extracts the 8 least  */
        hashcode[i + 2] = (MDbuf[i >> 2] >> 16); /*  significant bits.     */
        hashcode[i + 3] = (MDbuf[i >> 2] >> 24);
    }

    digest.SetDigest((unsigned char*) hashcode, RMDsize / 8);
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xcb60
movq 0xa0(%rsp), %rdi
callq 0x2a280
movl %eax, 0x18(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x2a290
movq %rax, 0x8(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x3f, 0x14(%rsp)
jbe 0x29f50
movl $0x0, 0x1c(%rsp)
cmpl $0x10, 0x1c(%rsp)
jae 0x29f2e
movq 0x8(%rsp), %rax
movsbl 0x3(%rax), %ecx
shll $0x18, %ecx
movq 0x8(%rsp), %rax
movsbl 0x2(%rax), %eax
shll $0x10, %eax
orl %eax, %ecx
movq 0x8(%rsp), %rax
movsbl 0x1(%rax), %eax
shll $0x8, %eax
orl %eax, %ecx
movq 0x8(%rsp), %rax
movsbl (%rax), %eax
orl %eax, %ecx
movl 0x1c(%rsp), %eax
movl %ecx, 0x20(%rsp,%rax,4)
movq 0x8(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x8(%rsp)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x29ed2
leaq 0x80(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xcbb0
movl 0x14(%rsp), %eax
subl $0x40, %eax
movl %eax, 0x14(%rsp)
jmp 0x29ebf
leaq 0x80(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x18(%rsp), %edx
xorl %ecx, %ecx
callq 0x10570
movl $0x0, 0x1c(%rsp)
cmpl $0x14, 0x1c(%rsp)
jae 0x2a00b
movl 0x1c(%rsp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl 0x80(%rsp,%rax,4), %eax
movb %al, %cl
movl 0x1c(%rsp), %eax
movb %cl, 0x60(%rsp,%rax)
movl 0x1c(%rsp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl 0x80(%rsp,%rax,4), %eax
shrl $0x8, %eax
movb %al, %cl
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movb %cl, 0x60(%rsp,%rax)
movl 0x1c(%rsp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl 0x80(%rsp,%rax,4), %eax
shrl $0x10, %eax
movb %al, %cl
movl 0x1c(%rsp), %eax
addl $0x2, %eax
movl %eax, %eax
movb %cl, 0x60(%rsp,%rax)
movl 0x1c(%rsp), %eax
shrl $0x2, %eax
movl %eax, %eax
movl 0x80(%rsp,%rax,4), %eax
shrl $0x18, %eax
movb %al, %cl
movl 0x1c(%rsp), %eax
addl $0x3, %eax
movl %eax, %eax
movb %cl, 0x60(%rsp,%rax)
movl 0x1c(%rsp), %eax
addl $0x4, %eax
movl %eax, 0x1c(%rsp)
jmp 0x29f70
movq 0x98(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x14, %edx
callq 0x29e10
addq $0xa8, %rsp
retq
nopw (%rax,%rax)