// File: /workspace/github_cpp_makefile_star2_O1/DiplIngFrankGerlach[P]MST/UnitTest.cpp
// Function: duplicateObfuscationTest()
void duplicateObfuscationTest()
{
   uint8_t sharedKey[16] = {11,55,11,33,67,89,91,11,55,11,33,67,89,91,0,0};

   MST_Endpoint endpointA(sharedKey);
   MST_Endpoint endpointB(sharedKey);

   uint8_t mcA[16];
   endpointA.generateMaskCounterExchange(mcA);

   uint8_t mcB[16];
   endpointB.generateMaskCounterExchange(mcB);

   //exchange of masking counters
   endpointA.decryptMaskCounterExchange(mcB);
   endpointB.decryptMaskCounterExchange(mcA);
 
   
   //now we can securely encrypt with all assurances of the protocol
   const char* plaintext = "key up";
   uint8_t* secureMessage;
   uint32_t lengthSM;
   uint32_t lp = strlen(plaintext)+1;
   assert( endpointA.encryptToSecureMessage((uint8_t*)plaintext,lp,&secureMessage,&lengthSM) );

   uint32_t lengthSMSaved = lengthSM;
   uint8_t* secureMessageSaved = new uint8_t[lengthSM];
   memcpy(secureMessageSaved,secureMessage,lengthSM);
   
   assert( endpointA.encryptToSecureMessage((uint8_t*)plaintext,lp,&secureMessage,&lengthSM) );

   assert( (lengthSMSaved == lengthSM) && ( memcmp(secureMessageSaved,secureMessage,lengthSM) != 0 ) );

   cout << "the following two hex strings must look like uncorrelated noise strings:" << endl;
   Util::dumpHex(secureMessageSaved,lengthSM);
   Util::dumpHex(secureMessage,lengthSM);
   
   delete[] secureMessageSaved;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movaps 0x164c(%rip), %xmm0     # 0x58f0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
leaq -0x1a8(%rbp), %rdi
movq %rbx, %rsi
callq 0x46bc
leaq -0x2f0(%rbp), %rdi
movq %rbx, %rsi
callq 0x46bc
leaq -0x1a8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x474a
leaq -0x2f0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x474a
leaq -0x188(%rbp), %rsi
leaq -0x178(%rbp), %rdx
leaq -0x40(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b78
movb $0x1, -0x87(%rbp)
leaq -0x2d0(%rbp), %rsi
leaq -0x2c0(%rbp), %rdx
leaq -0x50(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b78
movb $0x1, -0x1cf(%rbp)
leaq 0x1b1a(%rip), %rsi      # 0x5e50
leaq -0x1a8(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x1c(%rbp), %r8
movl $0x7, %edx
callq 0x4794
testb %al, %al
je 0x4469
movl -0x1c(%rbp), %r14d
movq %r14, %rdi
callq 0x1030
movq %rax, %rbx
leaq -0x28(%rbp), %r15
movq (%r15), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x10e0
leaq 0x1ad1(%rip), %rsi      # 0x5e50
leaq -0x1a8(%rbp), %rdi
leaq -0x1c(%rbp), %r8
movl $0x7, %edx
movq %r15, %rcx
callq 0x4794
testb %al, %al
je 0x4488
movl -0x1c(%rbp), %edx
cmpl %edx, %r14d
jne 0x444a
movq -0x28(%rbp), %rsi
movq %rbx, %rdi
callq 0x1120
testl %eax, %eax
je 0x444a
movq 0x3c12(%rip), %r14      # 0x7fd8
leaq 0x1b04(%rip), %rsi      # 0x5ed1
movl $0x48, %edx
movq %r14, %rdi
callq 0x1130
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x3be0(%rip), %rdi      # 0x7fd8
callq 0x1040
movq %rax, %rdi
callq 0x10b0
movl -0x1c(%rbp), %esi
movq %rbx, %rdi
callq 0x34d8
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x34d8
movq %rbx, %rdi
callq 0x1150
leaq -0x2f0(%rbp), %rdi
callq 0x494e
leaq -0x1a8(%rbp), %rdi
callq 0x494e
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a26(%rip), %rdi      # 0x5e77
leaq 0x1522(%rip), %rsi      # 0x597a
leaq 0x19f8(%rip), %rcx      # 0x5e57
movl $0xfb, %edx
callq 0x1090
leaq 0x15eb(%rip), %rdi      # 0x5a5b
leaq 0x1503(%rip), %rsi      # 0x597a
leaq 0x19d9(%rip), %rcx      # 0x5e57
movl $0xf3, %edx
callq 0x1090
leaq 0x15cc(%rip), %rdi      # 0x5a5b
leaq 0x14e4(%rip), %rsi      # 0x597a
leaq 0x19ba(%rip), %rcx      # 0x5e57
movl $0xf9, %edx
callq 0x1090
jmp 0x44b2
jmp 0x44b2
movq %rax, %rbx
jmp 0x44c1
jmp 0x44b2
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x494e
leaq -0x1a8(%rbp), %rdi
callq 0x494e
movq %rbx, %rdi
callq 0x11a0