4444#include "gen4.h"
4545#include "parity.h"
4646
47- int mfDarkside (uint8_t blockno , uint8_t key_type , uint64_t * key ) {
47+ int mf_dark_side (uint8_t blockno , uint8_t key_type , uint64_t * key ) {
4848 uint32_t uid = 0 ;
4949 uint32_t nt = 0 , nr = 0 , ar = 0 ;
5050 uint64_t par_list = 0 , ks_list = 0 ;
@@ -189,7 +189,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) {
189189 }
190190 }
191191
192- if (mfCheckKeys (blockno , key_type - 0x60 , false, size , keyBlock , key ) == PM3_SUCCESS ) {
192+ if (mf_check_keys (blockno , key_type - 0x60 , false, size , keyBlock , key ) == PM3_SUCCESS ) {
193193 break ;
194194 }
195195 }
@@ -208,7 +208,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) {
208208 return PM3_SUCCESS ;
209209}
210210
211- int mfCheckKeys (uint8_t blockNo , uint8_t keyType , bool clear_trace , uint8_t keycnt , uint8_t * keyBlock , uint64_t * key ) {
211+ int mf_check_keys (uint8_t blockNo , uint8_t keyType , bool clear_trace , uint8_t keycnt , uint8_t * keyBlock , uint64_t * key ) {
212212 if (key ) {
213213 * key = -1 ;
214214 }
@@ -249,7 +249,7 @@ int mfCheckKeys(uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keyc
249249// 0 == ok all keys found
250250// 1 ==
251251// 2 == Time-out, aborting
252- int mfCheckKeys_fast_ex (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
252+ int mf_check_keys_fast_ex (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
253253 uint32_t size , uint8_t * keyBlock , sector_t * e_sector , bool use_flashmemory ,
254254 bool verbose , bool quiet , uint16_t singleSectorParams ) {
255255
@@ -357,15 +357,15 @@ int mfCheckKeys_fast_ex(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChun
357357 return PM3_ESOFT ;
358358}
359359
360- int mfCheckKeys_fast (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
360+ int mf_check_keys_fast (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
361361 uint32_t size , uint8_t * keyBlock , sector_t * e_sector , bool use_flashmemory , bool verbose ) {
362- return mfCheckKeys_fast_ex (sectorsCnt , firstChunk , lastChunk , strategy , size , keyBlock , e_sector , use_flashmemory , verbose , false, 0 );
362+ return mf_check_keys_fast_ex (sectorsCnt , firstChunk , lastChunk , strategy , size , keyBlock , e_sector , use_flashmemory , verbose , false, 0 );
363363}
364364
365365// Trigger device to use a binary file on flash mem as keylist for mfCheckKeys.
366366// As of now, 255 keys possible in the file
367367// 6 * 255 = 1500 bytes
368- int mfCheckKeys_file (uint8_t * destfn , uint64_t * key ) {
368+ int mf_check_keys_file (uint8_t * destfn , uint64_t * key ) {
369369 * key = -1 ;
370370 clearCommandBuffer ();
371371
@@ -412,7 +412,7 @@ int mfCheckKeys_file(uint8_t *destfn, uint64_t *key) {
412412
413413// PM3 imp of J-Run mf_key_brute (part 2)
414414// ref: https://github.com/J-Run/mf_key_brute
415- int mfKeyBrute (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint64_t * resultkey ) {
415+ int mf_key_brute (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint64_t * resultkey ) {
416416
417417 uint64_t key64 ;
418418 uint8_t found = false;
@@ -441,7 +441,7 @@ int mfKeyBrute(uint8_t blockNo, uint8_t keyType, const uint8_t *key, uint64_t *r
441441 memcpy (keyBlock , candidates + i , KEYBLOCK_SIZE );
442442
443443 // check a block of generated key candidates.
444- if (mfCheckKeys (blockNo , keyType , true, KEYS_IN_BLOCK , keyBlock , & key64 ) == PM3_SUCCESS ) {
444+ if (mf_check_keys (blockNo , keyType , true, KEYS_IN_BLOCK , keyBlock , & key64 ) == PM3_SUCCESS ) {
445445 * resultkey = key64 ;
446446 found = true;
447447 break ;
@@ -483,7 +483,7 @@ __attribute__((force_align_arg_pointer))
483483 return statelist -> head .slhead ;
484484}
485485
486- int mfnested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey , bool calibrate ) {
486+ int mf_nested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey , bool calibrate ) {
487487
488488 uint32_t uid ;
489489 StateList_t statelists [2 ];
@@ -625,7 +625,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
625625 num_to_bytes (key64 , 6 , keyBlock + j * MIFARE_KEY_SIZE );
626626 }
627627
628- if (mfCheckKeys (statelists [0 ].blockNo , statelists [0 ].keyType , false, size , keyBlock , & key64 ) == PM3_SUCCESS ) {
628+ if (mf_check_keys (statelists [0 ].blockNo , statelists [0 ].keyType , false, size , keyBlock , & key64 ) == PM3_SUCCESS ) {
629629 free (statelists [0 ].head .slhead );
630630 free (statelists [1 ].head .slhead );
631631 num_to_bytes (key64 , 6 , resultKey );
@@ -669,7 +669,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
669669 return PM3_ESOFT ;
670670}
671671
672- int mfStaticNested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey ) {
672+ int mf_static_nested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey ) {
673673
674674 uint32_t uid ;
675675 StateList_t statelists [2 ];
@@ -902,9 +902,9 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBl
902902 free (mem );
903903 return res ;
904904 }
905- res = mfCheckKeys_file (fn , & key64 );
905+ res = mf_check_keys_file (fn , & key64 );
906906 } else {
907- res = mfCheckKeys (statelists [0 ].blockNo , statelists [0 ].keyType , true, chunk , mem , & key64 );
907+ res = mf_check_keys (statelists [0 ].blockNo , statelists [0 ].keyType , true, chunk , mem , & key64 );
908908 }
909909
910910 if (res == PM3_SUCCESS ) {
@@ -949,7 +949,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBl
949949}
950950
951951// MIFARE
952- int mfReadSector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
952+ int mf_read_sector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
953953
954954 clearCommandBuffer ();
955955 SendCommandMIX (CMD_HF_MIFARE_READSC , sectorNo , keyType , 0 , (uint8_t * )key , MIFARE_KEY_SIZE );
@@ -970,7 +970,7 @@ int mfReadSector(uint8_t sectorNo, uint8_t keyType, const uint8_t *key, uint8_t
970970 return PM3_SUCCESS ;
971971}
972972
973- int mfReadBlock (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
973+ int mf_read_block (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
974974 mf_readblock_t payload = {
975975 .blockno = blockNo ,
976976 .keytype = keyType
@@ -994,7 +994,7 @@ int mfReadBlock(uint8_t blockNo, uint8_t keyType, const uint8_t *key, uint8_t *d
994994 return PM3_SUCCESS ;
995995}
996996
997- int mfWriteBlock (uint8_t blockno , uint8_t keyType , const uint8_t * key , uint8_t * block ) {
997+ int mf_write_block (uint8_t blockno , uint8_t keyType , const uint8_t * key , uint8_t * block ) {
998998
999999 uint8_t data [26 ];
10001000 memcpy (data , key , MIFARE_KEY_SIZE );
@@ -1014,19 +1014,19 @@ int mfWriteBlock(uint8_t blockno, uint8_t keyType, const uint8_t *key, uint8_t *
10141014 return res ;
10151015}
10161016
1017- int mfWriteSector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * sector ){
1018-
1019- for (int i = 0 ; i < 4 ; i ++ ) {
1020- int res = mfWriteBlock ((sectorNo * 4 ) + i , keyType , key , sector + ( i * MFBLOCK_SIZE ));
1021- if (res != PM3_SUCCESS ) {
1022- return (i == 0 ) ? PM3_EFAILED : PM3_EPARTIAL ;
1017+ int mf_write_sector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * sector ){
1018+ int res ;
1019+ for (int i = 0 ; i < 4 ; i ++ ){
1020+ res = mf_write_block ((sectorNo * 4 ) + i , keyType , key , sector + ( i * MFBLOCK_SIZE ));
1021+ if (res != PM3_SUCCESS ){
1022+ return (i == 0 )? PM3_EFAILED : PM3_EPARTIAL ;
10231023 }
10241024 }
10251025 return PM3_SUCCESS ;
10261026}
10271027
10281028// EMULATOR
1029- int mfEmlGetMem (uint8_t * data , int blockNum , int blocksCount ) {
1029+ int mf_eml_get_mem (uint8_t * data , int blockNum , int blocksCount ) {
10301030
10311031 size_t size = blocksCount * MFBLOCK_SIZE ;
10321032 if (size > PM3_CMD_DATA_SIZE ) {
@@ -1056,11 +1056,11 @@ int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {
10561056 return resp .status ;
10571057}
10581058
1059- int mfEmlSetMem (uint8_t * data , int blockNum , int blocksCount ) {
1060- return mfEmlSetMem_xt (data , blockNum , blocksCount , MFBLOCK_SIZE );
1059+ int mf_elm_set_mem (uint8_t * data , int blockNum , int blocksCount ) {
1060+ return mf_eml_set_mem_xt (data , blockNum , blocksCount , MFBLOCK_SIZE );
10611061}
10621062
1063- int mfEmlSetMem_xt (uint8_t * data , int blockNum , int blocksCount , int blockBtWidth ) {
1063+ int mf_eml_set_mem_xt (uint8_t * data , int blockNum , int blocksCount , int blockBtWidth ) {
10641064
10651065 struct p {
10661066 uint8_t blockno ;
@@ -1089,13 +1089,13 @@ int mfEmlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidt
10891089}
10901090
10911091// "MAGIC" CARD
1092- int mfCSetUID (uint8_t * uid , uint8_t uidlen , const uint8_t * atqa , const uint8_t * sak , uint8_t * old_uid , uint8_t * verifed_uid , uint8_t wipecard , uint8_t gdm ) {
1092+ int mf_chinese_set_uid (uint8_t * uid , uint8_t uidlen , const uint8_t * atqa , const uint8_t * sak , uint8_t * old_uid , uint8_t * verifed_uid , uint8_t wipecard , uint8_t gdm ) {
10931093
10941094 uint8_t params = MAGIC_SINGLE | (gdm ? MAGIC_GDM_ALT_WUPC : MAGIC_WUPC );
10951095 uint8_t block0 [MFBLOCK_SIZE ];
10961096 memset (block0 , 0x00 , sizeof (block0 ));
10971097
1098- int res = mfCGetBlock (0 , block0 , params );
1098+ int res = mf_chinese_get_block (0 , block0 , params );
10991099 if (res == 0 ) {
11001100 PrintAndLogEx (SUCCESS , "old block 0... %s" , sprint_hex_inrow (block0 , sizeof (block0 )));
11011101 if (old_uid ) {
@@ -1140,11 +1140,11 @@ int mfCSetUID(uint8_t *uid, uint8_t uidlen, const uint8_t *atqa, const uint8_t *
11401140 params |= MAGIC_WIPE ;
11411141 }
11421142
1143- res = mfCSetBlock (0 , block0 , NULL , params );
1143+ res = mf_chinese_set_block (0 , block0 , NULL , params );
11441144 if (res == PM3_SUCCESS ) {
11451145 params = MAGIC_SINGLE | MAGIC_WUPC ;
11461146 memset (block0 , 0 , sizeof (block0 ));
1147- res = mfCGetBlock (0 , block0 , params );
1147+ res = mf_chinese_get_block (0 , block0 , params );
11481148 if (res == 0 ) {
11491149 if (verifed_uid ) {
11501150 memcpy (verifed_uid , block0 , uidlen );
@@ -1154,7 +1154,7 @@ int mfCSetUID(uint8_t *uid, uint8_t uidlen, const uint8_t *atqa, const uint8_t *
11541154 return res ;
11551155}
11561156
1157- int mfCWipe (uint8_t * uid , const uint8_t * atqa , const uint8_t * sak , uint8_t gdm ) {
1157+ int mf_chinese_wipe (uint8_t * uid , const uint8_t * atqa , const uint8_t * sak , uint8_t gdm ) {
11581158 uint8_t block0 [MFBLOCK_SIZE ] = {0x00 , 0x56 , 0x78 , 0xBB , 0x95 , 0x08 , 0x04 , 0x00 , 0x02 , 0xB2 , 0x1E , 0x24 , 0x23 , 0x27 , 0x1E , 0x1D };
11591159 // uint8_t block0[MFBLOCK_SIZE] = {0x04, 0x03, 0x02, 0x01, 0x04, 0x08, 0x04, 0x00, 0x64, 0xB9, 0x95, 0x11, 0x4D, 0x20, 0x42, 0x09};
11601160 uint8_t blockD [MFBLOCK_SIZE ] = {0x00 };
@@ -1180,12 +1180,12 @@ int mfCWipe(uint8_t *uid, const uint8_t *atqa, const uint8_t *sak, uint8_t gdm)
11801180 PrintAndLogEx (INPLACE , "wipe block %d" , blockNo );
11811181
11821182 if (blockNo == 0 ) {
1183- res = mfCSetBlock (blockNo , block0 , NULL , params );
1183+ res = mf_chinese_set_block (blockNo , block0 , NULL , params );
11841184 } else {
11851185 if (mfIsSectorTrailer (blockNo ))
1186- res = mfCSetBlock (blockNo , blockK , NULL , params );
1186+ res = mf_chinese_set_block (blockNo , blockK , NULL , params );
11871187 else
1188- res = mfCSetBlock (blockNo , blockD , NULL , params );
1188+ res = mf_chinese_set_block (blockNo , blockD , NULL , params );
11891189 }
11901190
11911191 if (res == PM3_SUCCESS )
@@ -1204,7 +1204,7 @@ int mfCWipe(uint8_t *uid, const uint8_t *atqa, const uint8_t *sak, uint8_t gdm)
12041204 return PM3_SUCCESS ;
12051205}
12061206
1207- int mfCSetBlock (uint8_t blockNo , uint8_t * data , uint8_t * uid , uint8_t params ) {
1207+ int mf_chinese_set_block (uint8_t blockNo , uint8_t * data , uint8_t * uid , uint8_t params ) {
12081208 clearCommandBuffer ();
12091209 SendCommandMIX (CMD_HF_MIFARE_CSETBL , params , blockNo , 0 , data , MFBLOCK_SIZE );
12101210 PacketResponseNG resp ;
@@ -1224,7 +1224,7 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, uint8_t params) {
12241224 return PM3_SUCCESS ;
12251225}
12261226
1227- int mfCGetBlock (uint8_t blockNo , uint8_t * data , uint8_t params ) {
1227+ int mf_chinese_get_block (uint8_t blockNo , uint8_t * data , uint8_t params ) {
12281228 clearCommandBuffer ();
12291229 SendCommandMIX (CMD_HF_MIFARE_CGETBL , params , blockNo , 0 , NULL , 0 );
12301230 PacketResponseNG resp ;
@@ -1241,7 +1241,7 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {
12411241 return PM3_SUCCESS ;
12421242}
12431243
1244- int mfGen3UID (uint8_t * uid , uint8_t uidlen , uint8_t * oldUid ) {
1244+ int mf_chinese_gen_3_uid (uint8_t * uid , uint8_t uidlen , uint8_t * oldUid ) {
12451245 clearCommandBuffer ();
12461246 SendCommandMIX (CMD_HF_MIFARE_GEN3UID , uidlen , 0 , 0 , uid , uidlen );
12471247 PacketResponseNG resp ;
@@ -1256,7 +1256,7 @@ int mfGen3UID(uint8_t *uid, uint8_t uidlen, uint8_t *oldUid) {
12561256 }
12571257}
12581258
1259- int mfGen3Block (uint8_t * block , int blockLen , uint8_t * newBlock ) {
1259+ int mf_chinese_gen_3_block (uint8_t * block , int blockLen , uint8_t * newBlock ) {
12601260 clearCommandBuffer ();
12611261 SendCommandMIX (CMD_HF_MIFARE_GEN3BLK , blockLen , 0 , 0 , block , MFBLOCK_SIZE );
12621262 PacketResponseNG resp ;
@@ -1271,7 +1271,7 @@ int mfGen3Block(uint8_t *block, int blockLen, uint8_t *newBlock) {
12711271 }
12721272}
12731273
1274- int mfGen3Freeze (void ) {
1274+ int mf_chinese_gen_3_freeze (void ) {
12751275 clearCommandBuffer ();
12761276 SendCommandNG (CMD_HF_MIFARE_GEN3FREEZ , NULL , 0 );
12771277 PacketResponseNG resp ;
@@ -1301,7 +1301,7 @@ void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool i
13011301 }
13021302}
13031303
1304- int tryDecryptWord (uint32_t nt , uint32_t ar_enc , uint32_t at_enc , uint8_t * data , int len ) {
1304+ int try_decrypt_word (uint32_t nt , uint32_t ar_enc , uint32_t at_enc , uint8_t * data , int len ) {
13051305
13061306 PrintAndLogEx (SUCCESS , "encrypted data... %s" , sprint_hex (data , len ));
13071307 uint32_t ks2 = ar_enc ^ prng_successor (nt , 64 );
@@ -1636,7 +1636,7 @@ uint16_t detect_mf_magic(bool is_mfc, uint8_t key_type, uint64_t key) {
16361636
16371637bool detect_mfc_ev1_signature (void ) {
16381638 uint64_t key = 0 ;
1639- int res = mfCheckKeys (69 , MF_KEY_B , false, 1 , (uint8_t * )g_mifare_signature_key_b , & key );
1639+ int res = mf_check_keys (69 , MF_KEY_B , false, 1 , (uint8_t * )g_mifare_signature_key_b , & key );
16401640 return (res == PM3_SUCCESS );
16411641}
16421642
@@ -1645,17 +1645,17 @@ int read_mfc_ev1_signature(uint8_t *signature) {
16451645 return PM3_EINVARG ;
16461646 }
16471647 uint8_t sign [32 ] = {0 };
1648- int res = mfReadBlock (69 , MF_KEY_B , g_mifare_signature_key_b , sign );
1648+ int res = mf_read_block (69 , MF_KEY_B , g_mifare_signature_key_b , sign );
16491649 if (res == PM3_SUCCESS ) {
1650- res = mfReadBlock (70 , MF_KEY_B , g_mifare_signature_key_b , sign + 16 );
1650+ res = mf_read_block (70 , MF_KEY_B , g_mifare_signature_key_b , sign + 16 );
16511651 if (res == PM3_SUCCESS ) {
16521652 memcpy (signature , sign , sizeof (sign ));
16531653 }
16541654 } else {
16551655 // try QL88
1656- res = mfReadBlock (69 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign );
1656+ res = mf_read_block (69 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign );
16571657 if (res == PM3_SUCCESS ) {
1658- res = mfReadBlock (70 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign + 16 );
1658+ res = mf_read_block (70 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign + 16 );
16591659 if (res == PM3_SUCCESS ) {
16601660 memcpy (signature , sign , sizeof (sign ));
16611661 }
0 commit comments