// File: /workspace/github_cpp_makefile_star2_O3/DiplIngFrankGerlach[P]MST/UnitTest.cpp
// Function: replayAttackFailTest()
void replayAttackFailTest()
{
   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 = "transfer $100 from Account No 19112119 to 1882122";
   uint8_t* secureMessage;
   uint32_t lengthSM;
   uint32_t lp = strlen(plaintext)+1;
   assert( endpointA.encryptToSecureMessage((uint8_t*)plaintext,lp,&secureMessage,&lengthSM) );

   uint8_t* replayMessage = new uint8_t[lengthSM];
   memcpy(replayMessage,secureMessage,lengthSM);
   
   uint8_t* plaintextDec;
   uint32_t lengthPT;
   assert( endpointB.decryptSecureMessage(secureMessage,lengthSM,&plaintextDec,&lengthPT));

   //now comes the replay attack
   assert( endpointB.decryptSecureMessage(replayMessage,lengthSM,&plaintextDec,&lengthPT) == false);

   delete[] replayMessage;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movaps 0x1896(%rip), %xmm0     # 0x58f0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
leaq -0x2f0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4654
leaq -0x1a8(%rbp), %rdi
movq %rbx, %rsi
callq 0x4654
leaq -0x2f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x46e2
leaq -0x1a8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x46e2
leaq -0x2d0(%rbp), %rsi
leaq -0x2c0(%rbp), %rdx
leaq -0x40(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b25
movb $0x1, -0x1cf(%rbp)
leaq -0x188(%rbp), %rsi
leaq -0x178(%rbp), %rdx
leaq -0x50(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b25
movb $0x1, -0x87(%rbp)
leaq 0x1cbe(%rip), %rsi      # 0x5daa
leaq -0x2f0(%rbp), %rdi
leaq -0x30(%rbp), %rcx
leaq -0x1c(%rbp), %r8
movl $0x32, %edx
callq 0x472c
testb %al, %al
je 0x4198
movl -0x1c(%rbp), %r14d
movq %r14, %rdi
callq 0x1030
movq %rax, %rbx
movq -0x30(%rbp), %r15
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x10e0
leaq -0x1a8(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x20(%rbp), %r8
movq %r15, %rsi
movl %r14d, %edx
callq 0x47e2
testb %al, %al
je 0x41b7
movl -0x1c(%rbp), %edx
leaq -0x1a8(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x20(%rbp), %r8
movq %rbx, %rsi
callq 0x47e2
testb %al, %al
jne 0x41d6
movq %rbx, %rdi
callq 0x1150
leaq -0x1a8(%rbp), %rdi
callq 0x48e6
leaq -0x2f0(%rbp), %rdi
callq 0x48e6
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18bc(%rip), %rdi      # 0x5a5b
leaq 0x17d4(%rip), %rsi      # 0x597a
leaq 0x1c2f(%rip), %rcx      # 0x5ddc
movl $0xcd, %edx
callq 0x1090
leaq 0x1914(%rip), %rdi      # 0x5ad2
leaq 0x17b5(%rip), %rsi      # 0x597a
leaq 0x1c10(%rip), %rcx      # 0x5ddc
movl $0xd4, %edx
callq 0x1090
leaq 0x1c1b(%rip), %rdi      # 0x5df8
leaq 0x1796(%rip), %rsi      # 0x597a
leaq 0x1bf1(%rip), %rcx      # 0x5ddc
movl $0xd7, %edx
callq 0x1090
jmp 0x4202
jmp 0x4202
jmp 0x4202
movq %rax, %rbx
jmp 0x4211
jmp 0x4202
movq %rax, %rbx
leaq -0x1a8(%rbp), %rdi
callq 0x48e6
leaq -0x2f0(%rbp), %rdi
callq 0x48e6
movq %rbx, %rdi
callq 0x11a0