// File: 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
subq $0x330, %rsp            # imm = 0x330
movaps 0x222e(%rip), %xmm0     # 0x8f00
movaps %xmm0, -0x10(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x10(%rbp), %rsi
movq %rsi, -0x300(%rbp)
callq 0x7250
movq -0x300(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x7250
jmp 0x6d02
leaq -0x158(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x72f0
jmp 0x6d17
leaq -0x2a0(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x72f0
jmp 0x6d2c
leaq -0x158(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x7350
jmp 0x6d41
leaq -0x2a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x7350
jmp 0x6d56
leaq 0x2064(%rip), %rax      # 0x8dc1
movq %rax, -0x2d8(%rbp)
movq -0x2d8(%rbp), %rdi
callq 0x20a0
incl %eax
movl %eax, -0x2e8(%rbp)
movq -0x2d8(%rbp), %rsi
movl -0x2e8(%rbp), %edx
leaq -0x158(%rbp), %rdi
leaq -0x2e0(%rbp), %rcx
leaq -0x2e4(%rbp), %r8
callq 0x73a0
movb %al, -0x301(%rbp)
jmp 0x6da7
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x6db3
jmp 0x6db5
jmp 0x6e0e
leaq 0x1c10(%rip), %rdi      # 0x89cc
leaq 0x1b28(%rip), %rsi      # 0x88eb
movl $0xf3, %edx
leaq 0x1ff9(%rip), %rcx      # 0x8dc8
callq 0x20e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2a8(%rbp)
movl %eax, -0x2ac(%rbp)
jmp 0x6fb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2a8(%rbp)
movl %eax, -0x2ac(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x7610
jmp 0x6fb9
movl -0x2e4(%rbp), %eax
movl %eax, -0x2ec(%rbp)
movl -0x2e4(%rbp), %eax
movl %eax, %edi
callq 0x2030
movq %rax, -0x310(%rbp)
jmp 0x6e30
movq -0x310(%rbp), %rax
movq %rax, -0x2f8(%rbp)
movq -0x2f8(%rbp), %rdi
movq -0x2e0(%rbp), %rsi
movl -0x2e4(%rbp), %eax
movl %eax, %edx
callq 0x2130
movq -0x2d8(%rbp), %rsi
movl -0x2e8(%rbp), %edx
leaq -0x158(%rbp), %rdi
leaq -0x2e0(%rbp), %rcx
leaq -0x2e4(%rbp), %r8
callq 0x73a0
movb %al, -0x311(%rbp)
jmp 0x6e88
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0x6e94
jmp 0x6e96
jmp 0x6eb5
leaq 0x1b2f(%rip), %rdi      # 0x89cc
leaq 0x1a47(%rip), %rsi      # 0x88eb
movl $0xf9, %edx
leaq 0x1f18(%rip), %rcx      # 0x8dc8
callq 0x20e0
movl -0x2ec(%rbp), %ecx
xorl %eax, %eax
cmpl -0x2e4(%rbp), %ecx
movb %al, -0x312(%rbp)
jne 0x6ef2
movq -0x2f8(%rbp), %rdi
movq -0x2e0(%rbp), %rsi
movl -0x2e4(%rbp), %eax
movl %eax, %edx
callq 0x20b0
cmpl $0x0, %eax
setne %al
movb %al, -0x312(%rbp)
movb -0x312(%rbp), %al
testb $0x1, %al
jne 0x6efe
jmp 0x6f00
jmp 0x6f1f
leaq 0x1ee1(%rip), %rdi      # 0x8de8
leaq 0x19dd(%rip), %rsi      # 0x88eb
movl $0xfb, %edx
leaq 0x1eae(%rip), %rcx      # 0x8dc8
callq 0x20e0
movq 0x40b2(%rip), %rdi      # 0xafd8
leaq 0x1f15(%rip), %rsi      # 0x8e42
callq 0x2180
movq %rax, -0x320(%rbp)
jmp 0x6f3b
movq -0x320(%rbp), %rdi
movq 0x407f(%rip), %rsi      # 0xafc8
callq 0x21a0
jmp 0x6f50
movq -0x2f8(%rbp), %rdi
movl -0x2e4(%rbp), %esi
callq 0x5a10
jmp 0x6f64
movq -0x2e0(%rbp), %rdi
movl -0x2e4(%rbp), %esi
callq 0x5a10
jmp 0x6f78
movq -0x2f8(%rbp), %rax
movq %rax, -0x328(%rbp)
cmpq $0x0, %rax
je 0x6f98
movq -0x328(%rbp), %rdi
callq 0x2220
leaq -0x2a0(%rbp), %rdi
callq 0x7610
leaq -0x158(%rbp), %rdi
callq 0x7610
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
leaq -0x158(%rbp), %rdi
callq 0x7610
movq -0x2a8(%rbp), %rdi
callq 0x22a0
nopw %cs:(%rax,%rax)