// File: /workspace/github_cpp_makefile_star2_O2/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 0x1c01(%rip), %xmm0     # 0x58f0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
leaq -0x2f0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4222
leaq -0x1a8(%rbp), %rdi
movq %rbx, %rsi
callq 0x4222
leaq -0x2f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4286
leaq -0x1a8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4286
leaq -0x2f0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x42d0
leaq -0x1a8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x42d0
leaq 0x204f(%rip), %rsi      # 0x5daa
leaq -0x2f0(%rbp), %rdi
pushq $0x32
popq %rdx
leaq -0x30(%rbp), %rcx
leaq -0x1c(%rbp), %r8
callq 0x4300
testb %al, %al
je 0x3e05
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 0x43b8
testb %al, %al
je 0x3e24
movl -0x1c(%rbp), %edx
leaq -0x1a8(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x20(%rbp), %r8
movq %rbx, %rsi
callq 0x43b8
testb %al, %al
jne 0x3e43
movq %rbx, %rdi
callq 0x1140
leaq -0x1a8(%rbp), %rdi
callq 0x44ae
leaq -0x2f0(%rbp), %rdi
callq 0x44ae
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c4f(%rip), %rdi      # 0x5a5b
leaq 0x1b67(%rip), %rsi      # 0x597a
leaq 0x1fc2(%rip), %rcx      # 0x5ddc
movl $0xcd, %edx
callq 0x10a0
leaq 0x1ca7(%rip), %rdi      # 0x5ad2
leaq 0x1b48(%rip), %rsi      # 0x597a
leaq 0x1fa3(%rip), %rcx      # 0x5ddc
movl $0xd4, %edx
callq 0x10a0
leaq 0x1fae(%rip), %rdi      # 0x5df8
leaq 0x1b29(%rip), %rsi      # 0x597a
leaq 0x1f84(%rip), %rcx      # 0x5ddc
movl $0xd7, %edx
callq 0x10a0
jmp 0x3e6f
jmp 0x3e6f
jmp 0x3e6f
movq %rax, %rbx
jmp 0x3e7e
jmp 0x3e6f
movq %rax, %rbx
leaq -0x1a8(%rbp), %rdi
callq 0x44ae
leaq -0x2f0(%rbp), %rdi
callq 0x44ae
movq %rbx, %rdi
callq 0x1180