title: Implementing OSDP encryption problems
body: <p>I'm having trouble implementing the encryption part of the OSDP protocol on an Arduino.
  <a href="http://www.siaonline.org/SiteAssets/SIAStore/Standards/OSDP_V2%201_5_2014.pdf" rel="nofollow">http://www.siaonline.org/SiteAssets/SIAStore/Standards/OSDP_V2%201_5_2014.pdf</a></p>
  
  <p>I've successfully done the negotiation part and have verified the RMAC-I response by decrypting the data and comparing with the plaintext. The part I'm stuck on is the encryption of the data packets. According to the spec, I use the RMAC-I response as my ICV for the aes128 CBC and I encrypt the packet using the S-MAC2 key.<br>
  My POLL packet (in hex) is as follows:<br>
  53 01 0e 00 0c 02 15 60<br>
  This gets padded<br>
  53 01 0e 00 0c 02 15 60 80 00 00 00 00 00 00 00<br>
  This gets xored with the ICV then encrypted with S-MAC2 as the key.<br>
  The first 4 bytes of the result is stored in the packet and sent<br>
  53 01 0e 00 0c 02 15 60 91 86 b9 3d 4a 29<br>
  Unfortunately the reader rejects the poll command with a NAK 06<br>
  I'm presuming my MAC values have not been computed correctly as I've compared my packet with the HID DTK tool (obviously the MAC and CRC values are the only difference). Can someone validate my process?</p>