mfkey.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef MFKEY_H
  2. #define MFKEY_H
  3. #include <furi_hal.h>
  4. #include <gui/gui.h>
  5. #include <gui/elements.h>
  6. #include <inttypes.h>
  7. #include <toolbox/keys_dict.h>
  8. #include <toolbox/stream/buffered_file_stream.h>
  9. #include <nfc/protocols/mf_classic/mf_classic.h>
  10. struct Crypto1State {
  11. uint32_t odd, even;
  12. };
  13. struct Msb {
  14. int tail;
  15. uint32_t states[768];
  16. };
  17. typedef enum {
  18. EventTypeTick,
  19. EventTypeKey,
  20. } EventType;
  21. typedef struct {
  22. EventType type;
  23. InputEvent input;
  24. } PluginEvent;
  25. typedef enum {
  26. MissingNonces,
  27. ZeroNonces,
  28. InsufficientRAM,
  29. } MFKeyError;
  30. typedef enum {
  31. Ready,
  32. Initializing,
  33. DictionaryAttack,
  34. MFKeyAttack,
  35. Complete,
  36. Error,
  37. Help,
  38. } MFKeyState;
  39. // TODO: Can we eliminate any of the members of this struct?
  40. typedef struct {
  41. FuriMutex* mutex;
  42. MFKeyError err;
  43. MFKeyState mfkey_state;
  44. int cracked;
  45. int unique_cracked;
  46. int num_completed;
  47. int total;
  48. int dict_count;
  49. int search;
  50. int eta_timestamp;
  51. int eta_total;
  52. int eta_round;
  53. bool mfkey32_present;
  54. bool nested_present;
  55. bool is_thread_running;
  56. bool close_thread_please;
  57. FuriThread* mfkeythread;
  58. } ProgramState;
  59. typedef enum { mfkey32, static_nested } AttackType;
  60. typedef struct {
  61. AttackType attack;
  62. MfClassicKey key; // key
  63. uint32_t uid; // serial number
  64. uint32_t nt0; // tag challenge first
  65. uint32_t nt1; // tag challenge second
  66. uint32_t uid_xor_nt0; // uid ^ nt0
  67. uint32_t uid_xor_nt1; // uid ^ nt1
  68. union {
  69. // Mfkey32
  70. struct {
  71. uint32_t p64; // 64th successor of nt0
  72. uint32_t p64b; // 64th successor of nt1
  73. uint32_t nr0_enc; // first encrypted reader challenge
  74. uint32_t ar0_enc; // first encrypted reader response
  75. uint32_t nr1_enc; // second encrypted reader challenge
  76. uint32_t ar1_enc; // second encrypted reader response
  77. };
  78. // Nested
  79. struct {
  80. uint32_t ks1_1_enc; // first encrypted keystream
  81. uint32_t ks1_2_enc; // second encrypted keystream
  82. char par_1_str[5]; // first parity bits (string representation)
  83. char par_2_str[5]; // second parity bits (string representation)
  84. uint8_t par_1; // first parity bits
  85. uint8_t par_2; // second parity bits
  86. };
  87. };
  88. } MfClassicNonce;
  89. typedef struct {
  90. Stream* stream;
  91. uint32_t total_nonces;
  92. MfClassicNonce* remaining_nonce_array;
  93. size_t remaining_nonces;
  94. } MfClassicNonceArray;
  95. struct KeysDict {
  96. Stream* stream;
  97. size_t key_size;
  98. size_t key_size_symbols;
  99. size_t total_keys;
  100. };
  101. #endif // MFKEY_H