This commit is contained in:
MX
2025-09-09 15:34:19 +03:00
parent ffb8eb7cff
commit 40c6c8b59c
3 changed files with 1269 additions and 1512 deletions

View File

@@ -9,115 +9,103 @@
#include <toolbox/stream/buffered_file_stream.h>
#include <nfc/protocols/mf_classic/mf_classic.h>
struct Crypto1State
{
uint32_t odd, even;
struct Crypto1State {
uint32_t odd, even;
};
struct Msb
{
int tail;
uint32_t states[768];
struct Msb {
int tail;
uint32_t states[768];
};
typedef enum
{
MissingNonces,
ZeroNonces,
InsufficientRAM,
typedef enum {
MissingNonces,
ZeroNonces,
InsufficientRAM,
} MFKeyError;
typedef enum
{
Ready,
Initializing,
DictionaryAttack,
MFKeyAttack,
Complete,
Error,
Help,
typedef enum {
Ready,
Initializing,
DictionaryAttack,
MFKeyAttack,
Complete,
Error,
Help,
} MFKeyState;
// TODO: Can we eliminate any of the members of this struct?
typedef struct
{
FuriMutex *mutex;
MFKeyError err;
MFKeyState mfkey_state;
int cracked;
int unique_cracked;
int num_completed;
int num_candidates;
int total;
int dict_count;
int search;
int eta_timestamp;
int eta_total;
int eta_round;
bool mfkey32_present;
bool nested_present;
bool close_thread_please;
FuriThread *mfkeythread;
KeysDict *cuid_dict;
MfClassicKey *key_buffer;
size_t key_buffer_size;
size_t key_buffer_count;
typedef struct {
FuriMutex* mutex;
MFKeyError err;
MFKeyState mfkey_state;
int cracked;
int unique_cracked;
int num_completed;
int num_candidates;
int total;
int dict_count;
int search;
int eta_timestamp;
int eta_total;
int eta_round;
bool mfkey32_present;
bool nested_present;
bool close_thread_please;
FuriThread* mfkeythread;
KeysDict* cuid_dict;
MfClassicKey* key_buffer;
size_t key_buffer_size;
size_t key_buffer_count;
} ProgramState;
typedef enum
{
mfkey32,
static_nested,
static_encrypted
typedef enum {
mfkey32,
static_nested,
static_encrypted
} AttackType;
typedef struct
{
AttackType attack;
MfClassicKey key; // key
uint32_t uid; // serial number
uint32_t nt0; // tag challenge first
uint32_t nt1; // tag challenge second
uint32_t uid_xor_nt0; // uid ^ nt0
uint32_t uid_xor_nt1; // uid ^ nt1
union
{
// Mfkey32
struct
{
uint32_t p64; // 64th successor of nt0
uint32_t p64b; // 64th successor of nt1
uint32_t nr0_enc; // first encrypted reader challenge
uint32_t ar0_enc; // first encrypted reader response
uint32_t nr1_enc; // second encrypted reader challenge
uint32_t ar1_enc; // second encrypted reader response
};
// Nested
struct
{
uint32_t ks1_1_enc; // first encrypted keystream
uint32_t ks1_2_enc; // second encrypted keystream
char par_1_str[5]; // first parity bits (string representation)
char par_2_str[5]; // second parity bits (string representation)
uint8_t par_1; // first parity bits
uint8_t par_2; // second parity bits
};
};
typedef struct {
AttackType attack;
MfClassicKey key; // key
uint32_t uid; // serial number
uint32_t nt0; // tag challenge first
uint32_t nt1; // tag challenge second
uint32_t uid_xor_nt0; // uid ^ nt0
uint32_t uid_xor_nt1; // uid ^ nt1
union {
// Mfkey32
struct {
uint32_t p64; // 64th successor of nt0
uint32_t p64b; // 64th successor of nt1
uint32_t nr0_enc; // first encrypted reader challenge
uint32_t ar0_enc; // first encrypted reader response
uint32_t nr1_enc; // second encrypted reader challenge
uint32_t ar1_enc; // second encrypted reader response
};
// Nested
struct {
uint32_t ks1_1_enc; // first encrypted keystream
uint32_t ks1_2_enc; // second encrypted keystream
char par_1_str[5]; // first parity bits (string representation)
char par_2_str[5]; // second parity bits (string representation)
uint8_t par_1; // first parity bits
uint8_t par_2; // second parity bits
};
};
} MfClassicNonce;
typedef struct
{
Stream *stream;
uint32_t total_nonces;
MfClassicNonce *remaining_nonce_array;
size_t remaining_nonces;
typedef struct {
Stream* stream;
uint32_t total_nonces;
MfClassicNonce* remaining_nonce_array;
size_t remaining_nonces;
} MfClassicNonceArray;
struct KeysDict
{
Stream *stream;
size_t key_size;
size_t key_size_symbols;
size_t total_keys;
struct KeysDict {
Stream* stream;
size_t key_size;
size_t key_size_symbols;
size_t total_keys;
};
#endif // MFKEY_H
#endif // MFKEY_H