// File: /workspace/github_cpp_makefile_star2_O3/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 0x16b4(%rip), %xmm0     # 0x58f0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
leaq -0x1a8(%rbp), %rdi
movq %rbx, %rsi
callq 0x4654
leaq -0x2f0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4654
leaq -0x1a8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x46e2
leaq -0x2f0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x46e2
leaq -0x188(%rbp), %rsi
leaq -0x178(%rbp), %rdx
leaq -0x40(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b25
movb $0x1, -0x87(%rbp)
leaq -0x2d0(%rbp), %rsi
leaq -0x2c0(%rbp), %rdx
leaq -0x50(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b25
movb $0x1, -0x1cf(%rbp)
leaq 0x1b82(%rip), %rsi      # 0x5e50
leaq -0x1a8(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x1c(%rbp), %r8
movl $0x7, %edx
callq 0x472c
testb %al, %al
je 0x4402
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 0x1b39(%rip), %rsi      # 0x5e50
leaq -0x1a8(%rbp), %rdi
leaq -0x1c(%rbp), %r8
movl $0x7, %edx
movq %r15, %rcx
callq 0x472c
testb %al, %al
je 0x4421
cmpl -0x1c(%rbp), %r14d
jne 0x43e3
movq -0x28(%rbp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1120
testl %eax, %eax
je 0x43e3
movq 0x3c79(%rip), %r14      # 0x7fd8
leaq 0x1b6b(%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 0x3c47(%rip), %rdi      # 0x7fd8
callq 0x1040
movq %rax, %rdi
callq 0x10b0
movl -0x1c(%rbp), %esi
movq %rbx, %rdi
callq 0x3470
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x3470
movq %rbx, %rdi
callq 0x1150
leaq -0x2f0(%rbp), %rdi
callq 0x48e6
leaq -0x1a8(%rbp), %rdi
callq 0x48e6
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a8d(%rip), %rdi      # 0x5e77
leaq 0x1589(%rip), %rsi      # 0x597a
leaq 0x1a5f(%rip), %rcx      # 0x5e57
movl $0xfb, %edx
callq 0x1090
leaq 0x1652(%rip), %rdi      # 0x5a5b
leaq 0x156a(%rip), %rsi      # 0x597a
leaq 0x1a40(%rip), %rcx      # 0x5e57
movl $0xf3, %edx
callq 0x1090
leaq 0x1633(%rip), %rdi      # 0x5a5b
leaq 0x154b(%rip), %rsi      # 0x597a
leaq 0x1a21(%rip), %rcx      # 0x5e57
movl $0xf9, %edx
callq 0x1090
jmp 0x444b
jmp 0x444b
movq %rax, %rbx
jmp 0x445a
jmp 0x444b
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x48e6
leaq -0x1a8(%rbp), %rdi
callq 0x48e6
movq %rbx, %rdi
callq 0x11a0