2012-12-05 07:43:19 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-07 08:58:03 +08:00
|
|
|
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
2012-12-05 07:43:19 +08:00
|
|
|
//
|
2022-01-07 08:58:03 +08:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// See LICENSE.txt for the text of the license.
|
2012-12-05 07:43:19 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// MIFARE type prototyping
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef _MIFARE_H_
|
|
|
|
#define _MIFARE_H_
|
|
|
|
|
2015-06-21 17:07:05 +08:00
|
|
|
#include "common.h"
|
2012-12-05 07:43:19 +08:00
|
|
|
|
2019-03-10 01:41:30 +08:00
|
|
|
#define MF_KEY_A 0
|
|
|
|
#define MF_KEY_B 1
|
2019-02-22 01:15:46 +08:00
|
|
|
|
2019-03-10 01:41:30 +08:00
|
|
|
#define MF_MAD1_SECTOR 0x00
|
|
|
|
#define MF_MAD2_SECTOR 0x10
|
2019-02-22 01:15:46 +08:00
|
|
|
|
2019-04-24 02:14:20 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Common types, used by client and ARM
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// New Ultralight/NTAG dump file format
|
|
|
|
// Length must be aligned to 4 bytes (UL/NTAG page)
|
|
|
|
#define MFU_DUMP_PREFIX_LENGTH 56
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t version[8];
|
|
|
|
uint8_t tbo[2];
|
|
|
|
uint8_t tbo1[1];
|
|
|
|
uint8_t pages; // max page number in dump
|
|
|
|
uint8_t signature[32];
|
|
|
|
uint8_t counter_tearing[3][4]; // 3 bytes counter, 1 byte tearing flag
|
|
|
|
uint8_t data[1024];
|
2019-10-18 04:32:09 +08:00
|
|
|
} PACKED mfu_dump_t;
|
2019-04-24 02:14:20 +08:00
|
|
|
|
2012-12-05 07:43:19 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// ISO 14443A
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
typedef struct {
|
2019-03-21 22:19:18 +08:00
|
|
|
uint8_t uid[10];
|
|
|
|
uint8_t uidlen;
|
|
|
|
uint8_t atqa[2];
|
|
|
|
uint8_t sak;
|
|
|
|
uint8_t ats_len;
|
|
|
|
uint8_t ats[256];
|
2019-07-16 19:50:38 +08:00
|
|
|
} PACKED iso14a_card_select_t;
|
2012-12-05 07:43:19 +08:00
|
|
|
|
2021-09-25 07:12:44 +08:00
|
|
|
typedef struct {
|
|
|
|
iso14a_card_select_t card_info;
|
|
|
|
uint8_t *dump;
|
|
|
|
uint16_t dumplen;
|
|
|
|
} iso14a_mf_extdump_t;
|
|
|
|
|
2012-12-05 07:43:19 +08:00
|
|
|
typedef enum ISO14A_COMMAND {
|
2019-03-10 07:00:59 +08:00
|
|
|
ISO14A_CONNECT = (1 << 0),
|
|
|
|
ISO14A_NO_DISCONNECT = (1 << 1),
|
|
|
|
ISO14A_APDU = (1 << 2),
|
|
|
|
ISO14A_RAW = (1 << 3),
|
2019-03-10 01:41:30 +08:00
|
|
|
ISO14A_REQUEST_TRIGGER = (1 << 4),
|
2019-03-10 07:00:59 +08:00
|
|
|
ISO14A_APPEND_CRC = (1 << 5),
|
|
|
|
ISO14A_SET_TIMEOUT = (1 << 6),
|
|
|
|
ISO14A_NO_SELECT = (1 << 7),
|
|
|
|
ISO14A_TOPAZMODE = (1 << 8),
|
|
|
|
ISO14A_NO_RATS = (1 << 9),
|
2021-10-17 17:38:37 +08:00
|
|
|
ISO14A_SEND_CHAINING = (1 << 10),
|
2021-10-24 00:54:44 +08:00
|
|
|
ISO14A_USE_ECP = (1 << 11),
|
|
|
|
ISO14A_USE_MAGSAFE = (1 << 12)
|
2012-12-05 07:43:19 +08:00
|
|
|
} iso14a_command_t;
|
|
|
|
|
2017-03-02 04:51:23 +08:00
|
|
|
typedef struct {
|
2019-03-10 07:00:59 +08:00
|
|
|
uint8_t *response;
|
|
|
|
uint8_t *modulation;
|
2019-03-16 04:04:25 +08:00
|
|
|
uint16_t response_n;
|
|
|
|
uint16_t modulation_n;
|
2019-03-10 01:41:30 +08:00
|
|
|
uint32_t ProxToAirDuration;
|
2019-03-16 04:04:25 +08:00
|
|
|
uint8_t par; // enough for precalculated parity of 8 Byte responses
|
2019-10-18 04:32:09 +08:00
|
|
|
} PACKED tag_response_info_t;
|
2020-03-17 18:37:38 +08:00
|
|
|
|
|
|
|
// DESFIRE_RAW flag enums
|
|
|
|
typedef enum DESFIRE_COMMAND {
|
|
|
|
NONE = 0x00,
|
|
|
|
INIT = 0x01,
|
|
|
|
DISCONNECT = 0x02,
|
|
|
|
CLEARTRACE = 0x04,
|
|
|
|
BAR = 0x10,
|
|
|
|
} desfire_command_t;
|
|
|
|
|
2020-04-11 17:32:31 +08:00
|
|
|
typedef enum {
|
|
|
|
MFDES_AUTH_DES = 1,
|
|
|
|
MFDES_AUTH_ISO = 2,
|
|
|
|
MFDES_AUTH_AES = 3,
|
|
|
|
MFDES_AUTH_PICC = 4
|
|
|
|
} mifare_des_authmode_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MFDES_ALGO_DES = 1,
|
|
|
|
MFDES_ALGO_3DES = 2,
|
2020-04-12 23:10:27 +08:00
|
|
|
MFDES_ALGO_3K3DES = 3,
|
|
|
|
MFDES_ALGO_AES = 4
|
2020-04-11 17:32:31 +08:00
|
|
|
} mifare_des_authalgo_t;
|
|
|
|
|
2020-10-31 15:54:28 +08:00
|
|
|
typedef enum {
|
|
|
|
MFDES_KDF_ALGO_NONE = 0,
|
|
|
|
MFDES_KDF_ALGO_AN10922 = 1,
|
Gallagher key checking is now supported on MIFARE Desfire
Both `hf mfdes auth` and `hf mfdes chk` now support Key Diversification for
AN10922 and as special treat, Gallagher issued cards.
For `hf mfdes auth`:
```
-d, --kdf <kdf> Key Derivation Function (KDF) (0=None, 1=AN10922, 2=Gallagher)
-i, --kdfi <kdfi> KDF input (HEX 1-31 bytes)
```
And for `hf mfdes chk`:
```
-f, --kdf <kdf> Key Derivation Function (KDF) (0=None, 1=AN10922, Gallagher)
-i, --kdfi <kdfi> KDF input (HEX 1-31 bytes)
```
Examples:
- `hf mfdes auth -a 2081f4 -m 3 -t 4 -d 2 -n 2 -k 00112233445566778899aabbccddeeff`
Will diversify the key for key `2` on AID `2081F4` for Gallagher issued cards
- `hf mfdes chk -f 1 -i 00112233 -d mfdes_default_keys`
Will read in all the default keys from the dictionary, and diversify them
using AN10922 with the input data `00112233`
- `hf mfdes chk -f 2 -d mfdes_default_keys`
Will read in all the default keys from the dictionary, and diversify them
using AN10922 but with input data generated from the card's UID, AID and
key number.
2020-11-01 20:22:19 +08:00
|
|
|
MFDES_KDF_ALGO_GALLAGHER = 2,
|
2020-10-31 15:54:28 +08:00
|
|
|
} mifare_des_kdf_algo_t;
|
|
|
|
|
2016-07-07 08:14:03 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2021-04-16 04:41:47 +08:00
|
|
|
// "hf 14a sim -x", "hf mf sim -x" attacks
|
2016-07-07 08:14:03 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
typedef struct {
|
2019-03-10 01:41:30 +08:00
|
|
|
uint32_t cuid;
|
|
|
|
uint32_t nonce;
|
|
|
|
uint32_t ar;
|
|
|
|
uint32_t nr;
|
|
|
|
uint32_t at;
|
|
|
|
uint32_t nonce2;
|
|
|
|
uint32_t ar2;
|
|
|
|
uint32_t nr2;
|
|
|
|
uint8_t sector;
|
|
|
|
uint8_t keytype;
|
|
|
|
enum {
|
|
|
|
EMPTY,
|
|
|
|
FIRST,
|
|
|
|
SECOND,
|
|
|
|
} state;
|
2019-10-18 04:32:09 +08:00
|
|
|
} PACKED nonces_t;
|
2016-03-21 02:33:07 +08:00
|
|
|
|
2018-01-29 20:48:18 +08:00
|
|
|
|
2012-12-05 07:43:19 +08:00
|
|
|
#endif // _MIFARE_H_
|