]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifareutil.c
Merge pull request #462 from pwpiwi/fix_hfmfsim
[proxmark3-svn] / armsrc / mifareutil.c
index 97f7b3d1afe0acd7c72e13d03b9f66ba34f97415..38ca934aa01687b542744965981e6eae886a6a1a 100644 (file)
@@ -9,13 +9,15 @@
 // 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
@@ -581,6 +587,19 @@ uint8_t FirstBlockOfSector(uint8_t sectorNo)
                \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
Impressum, Datenschutz