// File: 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
subq $0x320, %rsp            # imm = 0x320
movaps 0x2ede(%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 0x6052
leaq -0x158(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x72f0
jmp 0x6067
leaq -0x2a0(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x72f0
jmp 0x607c
leaq -0x158(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x7350
jmp 0x6091
leaq -0x2a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x7350
jmp 0x60a6
leaq 0x28fa(%rip), %rax      # 0x89a7
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 0x60f7
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x6103
jmp 0x6105
jmp 0x615e
leaq 0x28c0(%rip), %rdi      # 0x89cc
leaq 0x27d8(%rip), %rsi      # 0x88eb
movl $0x44, %edx
leaq 0x28ff(%rip), %rcx      # 0x8a1e
callq 0x20e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2a8(%rbp)
movl %eax, -0x2ac(%rbp)
jmp 0x62c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2a8(%rbp)
movl %eax, -0x2ac(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x7610
jmp 0x62c1
movq -0x2e0(%rbp), %rdi
movl -0x2e4(%rbp), %esi
callq 0x5a10
jmp 0x6172
movq -0x2e0(%rbp), %rsi
movl -0x2e4(%rbp), %edx
leaq -0x2a0(%rbp), %rdi
leaq -0x2f0(%rbp), %rcx
leaq -0x2f4(%rbp), %r8
callq 0x74c0
movb %al, -0x302(%rbp)
jmp 0x61a1
movb -0x302(%rbp), %al
testb $0x1, %al
jne 0x61ad
jmp 0x61af
jmp 0x61ce
leaq 0x288d(%rip), %rdi      # 0x8a43
leaq 0x272e(%rip), %rsi      # 0x88eb
movl $0x49, %edx
leaq 0x2855(%rip), %rcx      # 0x8a1e
callq 0x20e0
movq -0x2f0(%rbp), %rsi
movq 0x4dfc(%rip), %rdi      # 0xafd8
callq 0x2190
movq %rax, -0x310(%rbp)
jmp 0x61ea
movq -0x310(%rbp), %rdi
movq 0x4dd0(%rip), %rsi      # 0xafc8
callq 0x21a0
jmp 0x61ff
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 0x622e
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0x623a
jmp 0x623c
jmp 0x625b
leaq 0x2789(%rip), %rdi      # 0x89cc
leaq 0x26a1(%rip), %rsi      # 0x88eb
movl $0x4d, %edx
leaq 0x27c8(%rip), %rcx      # 0x8a1e
callq 0x20e0
movq -0x2e0(%rbp), %rdi
movl -0x2e4(%rbp), %esi
callq 0x5a10
jmp 0x626f
movq -0x2f0(%rbp), %rsi
movq 0x4d5b(%rip), %rdi      # 0xafd8
callq 0x2190
movq %rax, -0x320(%rbp)
jmp 0x628b
movq -0x320(%rbp), %rdi
movq 0x4d2f(%rip), %rsi      # 0xafc8
callq 0x21a0
jmp 0x62a0
leaq -0x2a0(%rbp), %rdi
callq 0x7610
leaq -0x158(%rbp), %rdi
callq 0x7610
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
leaq -0x158(%rbp), %rdi
callq 0x7610
movq -0x2a8(%rbp), %rdi
callq 0x22a0
nopl (%rax)