// File: /workspace/github_cpp_makefile_star2_O2/DiplIngFrankGerlach[P]MST/UnitTest.cpp
// Function: encryptedCommunicationExample()
void encryptedCommunicationExample()
{
   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 = "Schiller, Goethe, Von der Vogelweide";
   uint8_t* secureMessage;
   uint32_t lengthSM;
   uint32_t lp = strlen(plaintext)+1;
   assert( endpointA.encryptToSecureMessage((uint8_t*)plaintext,lp,&secureMessage,&lengthSM) );
   Util::dumpHex(secureMessage,lengthSM);

   uint8_t* plaintextDec;
   uint32_t lengthPT;
   assert( endpointB.decryptSecureMessage(secureMessage,lengthSM,&plaintextDec,&lengthPT) );

   cout << plaintextDec << endl;

   assert( endpointA.encryptToSecureMessage((uint8_t*)plaintext,lp,&secureMessage,&lengthSM) );
   Util::dumpHex(secureMessage,lengthSM);

   cout << plaintextDec << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x2e8, %rsp            # imm = 0x2E8
movaps 0x2249(%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 0x2323(%rip), %rsi      # 0x5a36
leaq -0x1a8(%rbp), %rdi
pushq $0x25
popq %rdx
leaq -0x18(%rbp), %rcx
leaq -0xc(%rbp), %r8
callq 0x4300
testb %al, %al
je 0x37e1
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x3312
movq -0x18(%rbp), %rsi
movl -0xc(%rbp), %edx
leaq -0x2f0(%rbp), %rdi
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
callq 0x43b8
testb %al, %al
je 0x37fa
movq -0x20(%rbp), %rsi
movq 0x486c(%rip), %rdi      # 0x7fd8
callq 0x1100
movq %rax, %rdi
callq 0x1080
leaq 0x22b6(%rip), %rsi      # 0x5a36
leaq -0x1a8(%rbp), %rdi
pushq $0x25
popq %rdx
leaq -0x18(%rbp), %rcx
leaq -0xc(%rbp), %r8
callq 0x4300
testb %al, %al
je 0x3813
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x3312
movq -0x20(%rbp), %rsi
movq 0x4826(%rip), %rdi      # 0x7fd8
callq 0x1100
movq %rax, %rdi
callq 0x1080
leaq -0x2f0(%rbp), %rdi
callq 0x44ae
leaq -0x1a8(%rbp), %rdi
callq 0x44ae
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %rbp
retq
leaq 0x2273(%rip), %rdi      # 0x5a5b
leaq 0x218b(%rip), %rsi      # 0x597a
leaq 0x22b7(%rip), %rcx      # 0x5aad
pushq $0x44
jmp 0x382a
leaq 0x22d1(%rip), %rdi      # 0x5ad2
leaq 0x2172(%rip), %rsi      # 0x597a
leaq 0x229e(%rip), %rcx      # 0x5aad
pushq $0x49
jmp 0x382a
leaq 0x2241(%rip), %rdi      # 0x5a5b
leaq 0x2159(%rip), %rsi      # 0x597a
leaq 0x2285(%rip), %rcx      # 0x5aad
pushq $0x4d
popq %rdx
callq 0x10a0
jmp 0x383b
movq %rax, %rbx
jmp 0x384a
jmp 0x383b
jmp 0x383b
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x44ae
leaq -0x1a8(%rbp), %rdi
callq 0x44ae
movq %rbx, %rdi
callq 0x1180