mfkey.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. } MFKeyError;
  29. typedef enum {
  30. Ready,
  31. Initializing,
  32. DictionaryAttack,
  33. MFKeyAttack,
  34. Complete,
  35. Error,
  36. Help,
  37. } MFKeyState;
  38. // TODO: Can we eliminate any of the members of this struct?
  39. typedef struct {
  40. FuriMutex* mutex;
  41. MFKeyError err;
  42. MFKeyState mfkey_state;
  43. int cracked;
  44. int unique_cracked;
  45. int num_completed;
  46. int total;
  47. int dict_count;
  48. int search;
  49. int eta_timestamp;
  50. int eta_total;
  51. int eta_round;
  52. bool mfkey32_present;
  53. bool nested_present;
  54. bool is_thread_running;
  55. bool close_thread_please;
  56. FuriThread* mfkeythread;
  57. } ProgramState;
  58. typedef enum { mfkey32, static_nested } AttackType;
  59. typedef struct {
  60. AttackType attack;
  61. MfClassicKey key; // key
  62. uint32_t uid; // serial number
  63. uint32_t nt0; // tag challenge first
  64. uint32_t nt1; // tag challenge second
  65. uint32_t uid_xor_nt0; // uid ^ nt0
  66. uint32_t uid_xor_nt1; // uid ^ nt1
  67. // Mfkey32
  68. uint32_t p64; // 64th successor of nt0
  69. uint32_t p64b; // 64th successor of nt1
  70. uint32_t nr0_enc; // first encrypted reader challenge
  71. uint32_t ar0_enc; // first encrypted reader response
  72. uint32_t nr1_enc; // second encrypted reader challenge
  73. uint32_t ar1_enc; // second encrypted reader response
  74. // Nested
  75. uint32_t ks1_1_enc; // first encrypted keystream
  76. uint32_t ks1_2_enc; // second encrypted keystream
  77. char par_1_str[5]; // first parity bits (string representation)
  78. char par_2_str[5]; // second parity bits (string representation)
  79. uint8_t par_1; // first parity bits
  80. uint8_t par_2; // second parity bits
  81. } MfClassicNonce;
  82. typedef struct {
  83. Stream* stream;
  84. uint32_t total_nonces;
  85. MfClassicNonce* remaining_nonce_array;
  86. size_t remaining_nonces;
  87. } MfClassicNonceArray;
  88. struct KeysDict {
  89. Stream* stream;
  90. size_t key_size;
  91. size_t key_size_symbols;
  92. size_t total_keys;
  93. };
  94. #endif // MFKEY_H