// File: /workspace/github_cpp_makefile_star2_O1/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 0x2017(%rip), %xmm0     # 0x58f0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
leaq -0x1a8(%rbp), %rdi
movq %rbx, %rsi
callq 0x46bc
leaq -0x2f0(%rbp), %rdi
movq %rbx, %rsi
callq 0x46bc
leaq -0x1a8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x474a
leaq -0x2f0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x474a
leaq -0x188(%rbp), %rsi
leaq -0x178(%rbp), %rdx
leaq -0x40(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b78
movb $0x1, -0x87(%rbp)
leaq -0x2d0(%rbp), %rsi
leaq -0x2c0(%rbp), %rdx
leaq -0x50(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b78
movb $0x1, -0x1cf(%rbp)
leaq 0x20cb(%rip), %rsi      # 0x5a36
leaq -0x1a8(%rbp), %rdi
leaq -0x20(%rbp), %rcx
leaq -0x14(%rbp), %r8
movl $0x25, %edx
callq 0x4794
testb %al, %al
je 0x3aef
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x34d8
movq -0x20(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x2f0(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %r8
callq 0x484a
testb %al, %al
je 0x3b0e
movq -0x28(%rbp), %rbx
testq %rbx, %rbx
je 0x39e0
movq %rbx, %rdi
callq 0x1070
movq 0x4605(%rip), %rdi      # 0x7fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1130
jmp 0x39fe
movq 0x45f1(%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 0x45d3(%rip), %rdi      # 0x7fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x45b8(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10b0
leaq 0x1fff(%rip), %rsi      # 0x5a36
leaq -0x1a8(%rbp), %rdi
leaq -0x20(%rbp), %rcx
leaq -0x14(%rbp), %r8
movl $0x25, %edx
callq 0x4794
testb %al, %al
je 0x3b2d
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x34d8
movq -0x28(%rbp), %r14
testq %r14, %r14
je 0x3a89
movq %r14, %rdi
callq 0x1070
movq 0x455c(%rip), %rdi      # 0x7fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x1130
jmp 0x3aa0
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 0x451a(%rip), %rdi      # 0x7fd8
callq 0x1040
movq %rax, %rdi
callq 0x10b0
leaq -0x2f0(%rbp), %rdi
callq 0x494e
leaq -0x1a8(%rbp), %rdi
callq 0x494e
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x1f65(%rip), %rdi      # 0x5a5b
leaq 0x1e7d(%rip), %rsi      # 0x597a
leaq 0x1fa9(%rip), %rcx      # 0x5aad
movl $0x44, %edx
callq 0x1090
leaq 0x1fbd(%rip), %rdi      # 0x5ad2
leaq 0x1e5e(%rip), %rsi      # 0x597a
leaq 0x1f8a(%rip), %rcx      # 0x5aad
movl $0x49, %edx
callq 0x1090
leaq 0x1f27(%rip), %rdi      # 0x5a5b
leaq 0x1e3f(%rip), %rsi      # 0x597a
leaq 0x1f6b(%rip), %rcx      # 0x5aad
movl $0x4d, %edx
callq 0x1090
jmp 0x3b57
movq %rax, %rbx
jmp 0x3b66
jmp 0x3b57
jmp 0x3b57
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x494e
leaq -0x1a8(%rbp), %rdi
callq 0x494e
movq %rbx, %rdi
callq 0x11a0