// File: /workspace/github_cpp_makefile_star2_O2/msotoodeh[P]asymmetric-passwords/demo/demo.cpp
// Function: SelfTest()
int SelfTest()
{
    int error_count = 0;
    // HMAC-SHA512 test vector from RFC4231 (test case 2)
    static const uint8_t hmac_sha512_tv1[64] =
    {
        0x16,0x4b,0x7a,0x7b,0xfc,0xf8,0x19,0xe2,0xe3,0x95,0xfb,0xe7,0x3b,0x56,0xe0,0xa3,
        0x87,0xbd,0x64,0x22,0x2e,0x83,0x1f,0xd6,0x10,0x27,0x0c,0xd7,0xea,0x25,0x05,0x54,
        0x97,0x58,0xbf,0x75,0xc0,0x5a,0x99,0x4a,0x6d,0x03,0x4f,0x65,0xf8,0xf0,0xe6,0xfd,
        0xca,0xea,0xb1,0xa3,0x4d,0x4a,0x6b,0x4b,0x63,0x6e,0x07,0x0a,0x38,0xbc,0xe7,0x37
    };

    // PBKDF2 test vectors from: https://github.com/Jither/PBKDF2/blob/master/Jither.PBKDF2.Test/PBKDF2DeriveBytesTest.cs
    static const uint8_t pbkdf2_key1[64] =
    {   // iterations = 1
        0x86,0x7f,0x70,0xcf,0x1a,0xde,0x02,0xcf,0xf3,0x75,0x25,0x99,0xa3,0xa5,0x3d,0xc4,
        0xaf,0x34,0xc7,0xa6,0x69,0x81,0x5a,0xe5,0xd5,0x13,0x55,0x4e,0x1c,0x8c,0xf2,0x52,
        0xc0,0x2d,0x47,0x0a,0x28,0x5a,0x05,0x01,0xba,0xd9,0x99,0xbf,0xe9,0x43,0xc0,0x8f,
        0x05,0x02,0x35,0xd7,0xd6,0x8b,0x1d,0xa5,0x5e,0x63,0xf7,0x3b,0x60,0xa5,0x7f,0xce
    };
    static const uint8_t pbkdf2_key2[64] =
    {   // iterations = 2
        0xe1,0xd9,0xc1,0x6a,0xa6,0x81,0x70,0x8a,0x45,0xf5,0xc7,0xc4,0xe2,0x15,0xce,0xb6,
        0x6e,0x01,0x1a,0x2e,0x9f,0x00,0x40,0x71,0x3f,0x18,0xae,0xfd,0xb8,0x66,0xd5,0x3c,
        0xf7,0x6c,0xab,0x28,0x68,0xa3,0x9b,0x9f,0x78,0x40,0xed,0xce,0x4f,0xef,0x5a,0x82,
        0xbe,0x67,0x33,0x5c,0x77,0xa6,0x06,0x8e,0x04,0x11,0x27,0x54,0xf2,0x7c,0xcf,0x4e
    };
    static const uint8_t pbkdf2_key4096[64] =
    {   // iterations = 4096
        0xd1,0x97,0xb1,0xb3,0x3d,0xb0,0x14,0x3e,0x01,0x8b,0x12,0xf3,0xd1,0xd1,0x47,0x9e,
        0x6c,0xde,0xbd,0xcc,0x97,0xc5,0xc0,0xf8,0x7f,0x69,0x02,0xe0,0x72,0xf4,0x57,0xb5,
        0x14,0x3f,0x30,0x60,0x26,0x41,0xb3,0xd5,0x5c,0xd3,0x35,0x98,0x8c,0xb3,0x6b,0x84,
        0x37,0x60,0x60,0xec,0xd5,0x32,0xe0,0x39,0xb7,0x42,0xa2,0x39,0x43,0x4a,0xf2,0xd5
    };

    uint8_t dk[64], mac[64];
    // HMAC-SHA512: rfc4321 test case 2
    if (APDigest::hmac((const uint8_t*)"Jefe", 4,
        (const uint8_t*)"what do ya want for nothing?", 28, mac, 64) != 64 ||
        memcmp(mac, hmac_sha512_tv1, 64) != 0)
    {
        error_count++;
        printf ("KAT error #%d: HMAC (1) failure.\n", error_count);
    }

    // PBKDF2-HMAC-SHA512
    APDigest::pbkdf2("password", 8, "salt", 4, 1, dk, sizeof(dk));
    if (memcmp(dk, pbkdf2_key1, sizeof(dk)) != 0)
    {
        error_count++;
        printf ("KAT error #%d: PBKDF2 (1) failure.\n", error_count);
    }
    APDigest::pbkdf2("password", 8, "salt", 4, 2, dk, sizeof(dk));
    if (memcmp(dk, pbkdf2_key2, sizeof(dk)) != 0)
    {
        error_count++;
        printf ("KAT error #%d: PBKDF2 (2) failure.\n", error_count);
    }
    APDigest::pbkdf2("password", 8, "salt", 4, 4096, dk, sizeof(dk));
    if (memcmp(dk, pbkdf2_key4096, sizeof(dk)) != 0)
    {
        error_count++;
        printf ("KAT error #%d: PBKDF2 (4096) failure.\n", error_count);
    }
    return error_count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
leaq 0x1745d8(%rip), %rdi    # 0x5792e8
leaq 0x1745d6(%rip), %rdx    # 0x5792ed
pushq $0x4
popq %rsi
pushq $0x1c
popq %rcx
leaq -0x90(%rbp), %r8
pushq $0x40
popq %r9
callq 0x40577a
cmpq $0x40, %rax
jne 0x404d51
leaq 0x1748c6(%rip), %rsi    # 0x579600
leaq -0x90(%rbp), %rdi
pushq $0x40
popq %rdx
callq 0x401098
testl %eax, %eax
je 0x404e68
leaq 0x1745b2(%rip), %rdi    # 0x57930a
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x4d0020
movq $0x40, (%rsp)
leaq 0x174659(%rip), %rdi    # 0x5793cc
leaq 0x1745b2(%rip), %rdx    # 0x57932c
pushq $0x8
popq %rsi
pushq $0x4
popq %rcx
pushq $0x1
popq %r8
leaq -0x50(%rbp), %r14
movq %r14, %r9
callq 0x405942
leaq 0x1748a9(%rip), %rsi    # 0x579640
pushq $0x40
popq %rdx
movq %r14, %rdi
callq 0x401098
testl %eax, %eax
je 0x404db8
incl %ebx
leaq 0x174582(%rip), %rdi    # 0x579331
movl %ebx, %esi
xorl %eax, %eax
callq 0x4d0020
movq $0x40, (%rsp)
leaq 0x174605(%rip), %rdi    # 0x5793cc
leaq 0x17455e(%rip), %rdx    # 0x57932c
pushq $0x8
popq %rsi
pushq $0x4
popq %rcx
pushq $0x2
popq %r8
movq %r14, %r9
callq 0x405942
leaq 0x174899(%rip), %rsi    # 0x579680
pushq $0x40
popq %rdx
movq %r14, %rdi
callq 0x401098
testl %eax, %eax
je 0x404e08
incl %ebx
leaq 0x174556(%rip), %rdi    # 0x579355
movl %ebx, %esi
xorl %eax, %eax
callq 0x4d0020
movq $0x40, (%rsp)
leaq 0x1745b5(%rip), %rdi    # 0x5793cc
leaq 0x17450e(%rip), %rdx    # 0x57932c
pushq $0x8
popq %rsi
pushq $0x4
popq %rcx
movl $0x1000, %r8d           # imm = 0x1000
movq %r14, %r9
callq 0x405942
leaq 0x174887(%rip), %rsi    # 0x5796c0
pushq $0x40
popq %rdx
movq %r14, %rdi
callq 0x401098
testl %eax, %eax
je 0x404e5a
incl %ebx
leaq 0x174528(%rip), %rdi    # 0x579379
movl %ebx, %esi
xorl %eax, %eax
callq 0x4d0020
movl %ebx, %eax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x404d64