// Work with mifare cards.\r
//-----------------------------------------------------------------------------\r
\r
-#include <string.h>\r
#include "mifareutil.h"\r
+\r
+#include <string.h>\r
+#include <stdbool.h>\r
+\r
#include "proxmark3.h"\r
#include "apps.h"\r
#include "util.h"\r
#include "parity.h"\r
-\r
#include "iso14443crc.h"\r
#include "iso14443a.h"\r
#include "crapto1/crapto1.h"\r
int MF_DBGLEVEL = MF_DBG_ALL;\r
\r
// crypto1 helpers\r
-void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len){\r
+void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out){\r
uint8_t bt = 0;\r
int i;\r
\r
if (len != 1) {\r
for (i = 0; i < len; i++)\r
- data[i] = crypto1_byte(pcs, 0x00, 0) ^ data[i];\r
+ data_out[i] = crypto1_byte(pcs, 0x00, 0) ^ data_in[i];\r
} else {\r
bt = 0;\r
for (i = 0; i < 4; i++)\r
- bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data[0], i)) << i;\r
+ bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data_in[0], i)) << i;\r
\r
- data[0] = bt;\r
+ data_out[0] = bt;\r
}\r
return;\r
}\r
\r
+void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len){\r
+ mf_crypto1_decryptEx(pcs, data, len, data);\r
+}\r
+\r
void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par) {\r
uint8_t bt = 0;\r
int i;\r
\r
}\r
\r
+uint8_t SectorTrailer(uint8_t blockNo)\r
+{\r
+ if (blockNo < 32*4) {\r
+ return (blockNo | 0x03);\r
+ } else {\r
+ return (blockNo | 0x0f);\r
+ }\r
+}\r
+\r
+bool IsSectorTrailer(uint8_t blockNo)\r
+{\r
+ return (blockNo == SectorTrailer(blockNo));\r
+}\r
\r
// work with emulator memory\r
void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r