textual
[RRG-proxmark3.git] / client / src / mifare / mifarehost.h
blob49adc8cbea5ac08a93987da107493030f08a0d31
1 // Merlok, 2011, 2019
2 // people from mifare@nethemba.com, 2010
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // High frequency ISO14443A commands
9 //-----------------------------------------------------------------------------
10 #ifndef __MIFARE_HOST_H
11 #define __MIFARE_HOST_H
13 #include "common.h"
15 #include "util.h" // FILE_PATH_SIZE
17 #define MIFARE_SECTOR_RETRY 10
19 // mifare tracer flags
20 #define TRACE_IDLE 0x00
21 #define TRACE_AUTH1 0x01
22 #define TRACE_AUTH2 0x02
23 #define TRACE_AUTH_OK 0x03
24 #define TRACE_READ_DATA 0x04
25 #define TRACE_WRITE_OK 0x05
26 #define TRACE_WRITE_DATA 0x06
27 #define TRACE_ERROR 0xFF
29 typedef struct {
30 union {
31 struct Crypto1State *slhead;
32 uint64_t *keyhead;
33 } head;
34 union {
35 struct Crypto1State *sltail;
36 uint64_t *keytail;
37 } tail;
38 uint32_t len;
39 uint32_t uid;
40 uint32_t blockNo;
41 uint32_t keyType;
42 uint32_t nt_enc;
43 uint32_t ks1;
44 } StateList_t;
46 typedef struct {
47 uint64_t Key[2];
48 uint8_t foundKey[2];
49 } sector_t;
51 typedef struct {
52 uint8_t keyA[6];
53 uint8_t keyB[6];
54 //uint8_t foundKey[2];
55 } icesector_t;
57 #define KEYS_IN_BLOCK ((PM3_CMD_DATA_SIZE - 5) / 6)
58 #define KEYBLOCK_SIZE (KEYS_IN_BLOCK * 6)
59 #define CANDIDATE_SIZE (0xFFFF * 6)
61 int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key);
62 int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *resultKey, bool calibrate);
63 int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *resultKey);
64 int mfCheckKeys(uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t *keyBlock, uint64_t *key);
65 int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk,
66 uint8_t strategy, uint32_t size, uint8_t *keyBlock, sector_t *e_sector, bool use_flashmemory);
68 int mfCheckKeys_file(uint8_t *destfn, uint64_t *key);
70 int mfKeyBrute(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint64_t *resultkey);
72 int mfReadSector(uint8_t sectorNo, uint8_t keyType, uint8_t *key, uint8_t *data);
73 int mfReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t *data);
75 int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);
76 int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);
77 int mfEmlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth);
79 int mfCSetUID(uint8_t *uid, uint8_t uidlen, uint8_t *atqa, uint8_t *sak, uint8_t *old_uid, uint8_t *verifed_uid, uint8_t wipecard);
80 int mfCWipe(uint8_t *uid, uint8_t *atqa, uint8_t *sak);
81 int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, uint8_t params);
82 int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);
84 int mfGen3UID(uint8_t *uid, uint8_t uidlen, uint8_t *oldUid);
85 int mfGen3Block(uint8_t *block, int blockLen, uint8_t *newBlock);
86 int mfGen3Freeze(void);
88 int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len);
90 int detect_classic_prng(void);
91 int detect_classic_nackbug(bool verbose);
92 int detect_mf_magic(bool is_mfc);
93 int detect_classic_static_nonce(void);
94 int detect_mfc_ev1_signature(uint8_t *signature);
96 void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool isEncrypted);
97 #endif