// File: /workspace/github_cpp_makefile_star2_O2/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 0x1a47(%rip), %xmm0     # 0x58f0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
leaq -0x1a8(%rbp), %rdi
movq %rbx, %rsi
callq 0x4222
leaq -0x2f0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4222
leaq -0x1a8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4286
leaq -0x2f0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4286
leaq -0x1a8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x42d0
leaq -0x2f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x42d0
leaq 0x1f3b(%rip), %rsi      # 0x5e50
leaq -0x1a8(%rbp), %rdi
pushq $0x7
popq %rdx
leaq -0x28(%rbp), %rcx
leaq -0x1c(%rbp), %r8
callq 0x4300
testb %al, %al
je 0x4012
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 0x1ef4(%rip), %rsi      # 0x5e50
leaq -0x1a8(%rbp), %rdi
pushq $0x7
popq %rdx
leaq -0x1c(%rbp), %r8
movq %r15, %rcx
callq 0x4300
testb %al, %al
je 0x4031
cmpl -0x1c(%rbp), %r14d
jne 0x3ff3
movq -0x28(%rbp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1110
testl %eax, %eax
je 0x3ff3
movq 0x403e(%rip), %rdi      # 0x7fd8
leaq 0x1f30(%rip), %rsi      # 0x5ed1
callq 0x1100
movq %rax, %rdi
callq 0x1080
movl -0x1c(%rbp), %esi
movq %rbx, %rdi
callq 0x3312
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x3312
movq %rbx, %rdi
callq 0x1140
leaq -0x2f0(%rbp), %rdi
callq 0x44ae
leaq -0x1a8(%rbp), %rdi
callq 0x44ae
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e7d(%rip), %rdi      # 0x5e77
leaq 0x1979(%rip), %rsi      # 0x597a
leaq 0x1e4f(%rip), %rcx      # 0x5e57
movl $0xfb, %edx
callq 0x10a0
leaq 0x1a42(%rip), %rdi      # 0x5a5b
leaq 0x195a(%rip), %rsi      # 0x597a
leaq 0x1e30(%rip), %rcx      # 0x5e57
movl $0xf3, %edx
callq 0x10a0
leaq 0x1a23(%rip), %rdi      # 0x5a5b
leaq 0x193b(%rip), %rsi      # 0x597a
leaq 0x1e11(%rip), %rcx      # 0x5e57
movl $0xf9, %edx
callq 0x10a0
jmp 0x405b
jmp 0x405b
movq %rax, %rbx
jmp 0x406a
jmp 0x405b
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x44ae
leaq -0x1a8(%rbp), %rdi
callq 0x44ae
movq %rbx, %rdi
callq 0x1180