mfkey.h 2.5 KB

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