+int CalculateEncIVCommand(mf4Session *session, uint8_t *iv, bool verbose) {
+ memcpy(&iv[0], session->TI, 4);
+ memcpy(&iv[4], &session->R_Ctr, 2);
+ memcpy(&iv[6], &session->W_Ctr, 2);
+ memcpy(&iv[8], &session->R_Ctr, 2);
+ memcpy(&iv[10], &session->W_Ctr, 2);
+ memcpy(&iv[12], &session->R_Ctr, 2);
+ memcpy(&iv[14], &session->W_Ctr, 2);
+
+ return 0;
+}
+
+int CalculateEncIVResponse(mf4Session *session, uint8_t *iv, bool verbose) {
+ memcpy(&iv[0], &session->R_Ctr, 2);
+ memcpy(&iv[2], &session->W_Ctr, 2);
+ memcpy(&iv[4], &session->R_Ctr, 2);
+ memcpy(&iv[6], &session->W_Ctr, 2);
+ memcpy(&iv[8], &session->R_Ctr, 2);
+ memcpy(&iv[10], &session->W_Ctr, 2);
+ memcpy(&iv[12], session->TI, 4);
+
+ return 0;
+}
+
+
+int CalculateMAC(mf4Session *session, MACType_t mtype, uint8_t blockNum, uint8_t blockCount, uint8_t *data, int datalen, uint8_t *mac, bool verbose) {
+ if (!session || !session->Authenticated || !mac || !data || !datalen || datalen < 1)