// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x2e0, %rsp            # imm = 0x2E0
movaps 0x207f(%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 0x2133(%rip), %rsi      # 0x5a36
leaq -0x1a8(%rbp), %rdi
leaq -0x20(%rbp), %rcx
leaq -0x14(%rbp), %r8
movl $0x25, %edx
callq 0x472c
testb %al, %al
je 0x3a87
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x3470
movq -0x20(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x2f0(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %r8
callq 0x47e2
testb %al, %al
je 0x3aa6
movq -0x28(%rbp), %rbx
testq %rbx, %rbx
je 0x3978
movq %rbx, %rdi
callq 0x1070
movq 0x466d(%rip), %rdi      # 0x7fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1130
jmp 0x3996
movq 0x4659(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x1190
movq 0x463b(%rip), %rdi      # 0x7fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x4620(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10b0
leaq 0x2067(%rip), %rsi      # 0x5a36
leaq -0x1a8(%rbp), %rdi
leaq -0x20(%rbp), %rcx
leaq -0x14(%rbp), %r8
movl $0x25, %edx
callq 0x472c
testb %al, %al
je 0x3ac5
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x3470
movq -0x28(%rbp), %r14
testq %r14, %r14
je 0x3a21
movq %r14, %rdi
callq 0x1070
movq 0x45c4(%rip), %rdi      # 0x7fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x1130
jmp 0x3a38
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x1190
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x4582(%rip), %rdi      # 0x7fd8
callq 0x1040
movq %rax, %rdi
callq 0x10b0
leaq -0x2f0(%rbp), %rdi
callq 0x48e6
leaq -0x1a8(%rbp), %rdi
callq 0x48e6
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x1fcd(%rip), %rdi      # 0x5a5b
leaq 0x1ee5(%rip), %rsi      # 0x597a
leaq 0x2011(%rip), %rcx      # 0x5aad
movl $0x44, %edx
callq 0x1090
leaq 0x2025(%rip), %rdi      # 0x5ad2
leaq 0x1ec6(%rip), %rsi      # 0x597a
leaq 0x1ff2(%rip), %rcx      # 0x5aad
movl $0x49, %edx
callq 0x1090
leaq 0x1f8f(%rip), %rdi      # 0x5a5b
leaq 0x1ea7(%rip), %rsi      # 0x597a
leaq 0x1fd3(%rip), %rcx      # 0x5aad
movl $0x4d, %edx
callq 0x1090
jmp 0x3aef
movq %rax, %rbx
jmp 0x3afe
jmp 0x3aef
jmp 0x3aef
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x48e6
leaq -0x1a8(%rbp), %rdi
callq 0x48e6
movq %rbx, %rdi
callq 0x11a0