// File: /workspace/github_cpp_makefile_star2_O1/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 0x182e(%rip), %xmm0     # 0x58f0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
leaq -0x2f0(%rbp), %rdi
movq %rbx, %rsi
callq 0x46bc
leaq -0x1a8(%rbp), %rdi
movq %rbx, %rsi
callq 0x46bc
leaq -0x2f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x474a
leaq -0x1a8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x474a
leaq -0x2d0(%rbp), %rsi
leaq -0x2c0(%rbp), %rdx
leaq -0x40(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b78
movb $0x1, -0x1cf(%rbp)
leaq -0x188(%rbp), %rsi
leaq -0x178(%rbp), %rdx
leaq -0x50(%rbp), %rdi
movl $0x80, %ecx
callq 0x1b78
movb $0x1, -0x87(%rbp)
leaq 0x1c56(%rip), %rsi      # 0x5daa
leaq -0x2f0(%rbp), %rdi
leaq -0x30(%rbp), %rcx
leaq -0x1c(%rbp), %r8
movl $0x32, %edx
callq 0x4794
testb %al, %al
je 0x4200
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 0x484a
testb %al, %al
je 0x421f
movl -0x1c(%rbp), %edx
leaq -0x1a8(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x20(%rbp), %r8
movq %rbx, %rsi
callq 0x484a
testb %al, %al
jne 0x423e
movq %rbx, %rdi
callq 0x1150
leaq -0x1a8(%rbp), %rdi
callq 0x494e
leaq -0x2f0(%rbp), %rdi
callq 0x494e
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1854(%rip), %rdi      # 0x5a5b
leaq 0x176c(%rip), %rsi      # 0x597a
leaq 0x1bc7(%rip), %rcx      # 0x5ddc
movl $0xcd, %edx
callq 0x1090
leaq 0x18ac(%rip), %rdi      # 0x5ad2
leaq 0x174d(%rip), %rsi      # 0x597a
leaq 0x1ba8(%rip), %rcx      # 0x5ddc
movl $0xd4, %edx
callq 0x1090
leaq 0x1bb3(%rip), %rdi      # 0x5df8
leaq 0x172e(%rip), %rsi      # 0x597a
leaq 0x1b89(%rip), %rcx      # 0x5ddc
movl $0xd7, %edx
callq 0x1090
jmp 0x426a
jmp 0x426a
jmp 0x426a
movq %rax, %rbx
jmp 0x4279
jmp 0x426a
movq %rax, %rbx
leaq -0x1a8(%rbp), %rdi
callq 0x494e
leaq -0x2f0(%rbp), %rdi
callq 0x494e
movq %rbx, %rdi
callq 0x11a0