+ opt_MAC(div_key_p,cc_nr, dest);
+ //The output MAC must also be reversed
+ opt_reverse_arraybytecpy(mac, dest,4);
+ return;
+}
+void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4])
+{
+ static uint8_t cc_nr[8+4+4];
+ opt_reverse_arraybytecpy(cc_nr, cc_p,12);
+ State _init = {
+ ((div_key_p[0] ^ 0x4c) + 0xEC) & 0xFF,// l
+ ((div_key_p[0] ^ 0x4c) + 0x21) & 0xFF,// r
+ 0x4c, // b
+ 0xE012 // t
+ };
+ opt_suc(div_key_p,&_init,cc_nr, 12,true);
+ uint8_t dest []= {0,0,0,0};
+ opt_output(div_key_p,&_init, dest);
+ //The output MAC must also be reversed
+ opt_reverse_arraybytecpy(mac, dest,4);
+ return;
+
+}
+/**
+ * The tag MAC can be divided (both can, but no point in dividing the reader mac) into
+ * two functions, since the first 8 bytes are known, we can pre-calculate the state
+ * reached after feeding CC to the cipher.
+ * @param cc_p
+ * @param div_key_p
+ * @return the cipher state
+ */
+State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p)
+{
+ static uint8_t cc_nr[8];
+ opt_reverse_arraybytecpy(cc_nr, cc_p,8);
+ State _init = {
+ ((div_key_p[0] ^ 0x4c) + 0xEC) & 0xFF,// l
+ ((div_key_p[0] ^ 0x4c) + 0x21) & 0xFF,// r
+ 0x4c, // b
+ 0xE012 // t
+ };
+ opt_suc(div_key_p,&_init,cc_nr, 8,false);
+ return _init;
+}
+/**
+ * The second part of the tag MAC calculation, since the CC is already calculated into the state,
+ * this function is fed only the NR, and internally feeds the remaining 32 0-bits to generate the tag
+ * MAC response.
+ * @param _init - precalculated cipher state
+ * @param nr - the reader challenge
+ * @param mac - where to store the MAC
+ * @param div_key_p - the key to use
+ */
+void opt_doTagMAC_2(State _init, uint8_t* nr, uint8_t mac[4], const uint8_t* div_key_p)
+{
+ static uint8_t _nr [4];
+ opt_reverse_arraybytecpy(_nr, nr, 4);
+ opt_suc(div_key_p,&_init,_nr, 4, true);
+ //opt_suc(div_key_p,&_init,nr, 4, false);
+ uint8_t dest []= {0,0,0,0};
+ opt_output(div_key_p,&_init, dest);